|
| 1 | +// ==== FONT STACKER ==== // |
| 2 | + |
| 3 | +// Read more about this Sass micro-library: https://github.com/synapticism/sass-font-stacker |
| 4 | + |
| 5 | +// Set a default font stack; if you see monospaced type something probably went wrong ;) |
| 6 | +$k-font-stack-default: courier; |
| 7 | + |
| 8 | +// Font stack definitions |
| 9 | +$k-font-stacks: ( |
| 10 | + |
| 11 | + // Serif stacks |
| 12 | + cambria: (Cambria, Constantia, "URW Palladio L", "Palatino Linotype", Palatino, Georgia, "Book Antiqua", "Times New Roman", serif), |
| 13 | + georgia: (Georgia, "Palatino Linotype", Palatino, "URW Palladio L", "Book Antiqua", "Times New Roman", serif), |
| 14 | + times: ("Times New Roman", Times, Georgia, "DejaVu Serif", serif), |
| 15 | + |
| 16 | + // Sans-serif stacks |
| 17 | + arial: (Arial, Helvetica, "Nimbus Sans L", sans-serif), |
| 18 | + calibri: (Calibri, "DejaVu Sans Condensed", Tahoma, "Lucida Sans", "Lucida Grande", "Bitstream Vera Sans", "Liberation Sans", Verdana, sans-serif), |
| 19 | + corbel: (Corbel, "Helvetica Neue", Helvetica, Arial, "Nimbus Sans L", "Liberation Sans", sans-serif), |
| 20 | + helvetica: (Helvetica, Arial, "Nimbus Sans L", sans-serif), |
| 21 | + helvetica-n: ("Helvetica Neue", Helvetica, Arial, "Nimbus Sans L", "Liberation Sans", Corbel, sans-serif), // Targets OS X |
| 22 | + helvetica-nl: ("HelveticaNeue-Light", "Helvetica-Neue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Nimbus Sans L", "Liberation Sans", Corbel, sans-serif), // Targets OS X |
| 23 | + tahoma: (Tahoma, "DejaVu Sans", "Lucida Sans", "Lucida Grande", "Bitstream Vera Sans", "Liberation Sans", Verdana, sans-serif), |
| 24 | + verdana: (Verdana, Tahoma, "DejaVu Sans", sans-serif), |
| 25 | + |
| 26 | + // Monospace stacks |
| 27 | + andale: ("Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace), |
| 28 | + consolas: (Consolas, "Bitstream Vera Sans Mono", "Andale Mono", Monaco, "DejaVu Sans Mono", "Lucida Console", monospace), |
| 29 | + courier: ("Courier 10 Pitch", "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace), |
| 30 | + |
| 31 | + // Chinese stacks (experimental) |
| 32 | + zh-sans: ("Heiti TC", "Heiti SC", "微軟正黑體", "Microsoft JhengHei", "Microsoft YaHei New", "Microsoft Yahei", "微软雅黑", "宋体", SimSun, STXihei, "华文细黑"), |
| 33 | + zh-serif: ("LiSong Pro", "新細明體", PMingLiU, STSong, STKaiti), |
| 34 | + |
| 35 | + // Fundamentals |
| 36 | + monospace: (monospace), |
| 37 | + sans-serif: (sans-serif), |
| 38 | + serif: (serif) |
| 39 | +); |
| 40 | + |
| 41 | +// Font stacker function; accepts an arbitrary list font names (including none at all) ending in the name of a valid font stack from the list above |
| 42 | +@function k-font-stack($fonts...) { |
| 43 | + |
| 44 | + // Assume the target stack is the last value in the arglist; break it off into a string |
| 45 | + $stack: nth($fonts, -1); |
| 46 | + |
| 47 | + // Remove the last value from the arglist to avoid duplication or create an empty list as needed |
| 48 | + @if length($fonts) > 1 { |
| 49 | + $fonts: set-nth($fonts, -1, null); |
| 50 | + } @else { |
| 51 | + $fonts: (); |
| 52 | + } |
| 53 | + |
| 54 | + // Check to see if the stack exists and return the combined list; fallback to the default if nothing else |
| 55 | + @if map-has-key($k-font-stacks, $stack) { |
| 56 | + @return join($fonts, map-get($k-font-stacks, $stack)); |
| 57 | + } @else { |
| 58 | + @warn "Font stack not found: '#{$stack}'."; |
| 59 | + @if map-has-key($k-font-stacks, $k-font-stack-default) { |
| 60 | + @return join($fonts, map-get($k-font-stacks, $stack)); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + // Font stack could not be found and default could not be loaded (since we're still here); issue another warning |
| 65 | + @warn "Font stacks could not be loaded."; |
| 66 | + |
| 67 | + // Don't just sit there, do something! |
| 68 | + @return monospace; |
| 69 | +} |
| 70 | + |
| 71 | +// A simple wrapper to output the complete font family declaration |
| 72 | +@mixin k-font-family($fonts...) { |
| 73 | + font-family: font-stack($fonts...); |
| 74 | +} |
0 commit comments