|
| 1 | +--- |
| 2 | +name: puzzmo-fonts |
| 3 | +description: Set up Puzzmo platform fonts in a game using the SDK font utilities |
| 4 | +--- |
| 5 | + |
| 6 | +# Use Puzzmo Fonts |
| 7 | + |
| 8 | +Configure the game to use Puzzmo's font stack. These are ASCII-subset fonts optimized for small payloads -- they may not contain all characters, so always provide fallbacks. |
| 9 | + |
| 10 | +## Available Font Families |
| 11 | + |
| 12 | +| Family | Weights | Use Case | |
| 13 | +| ------------------ | -------------------------------------------------------------- | -------------------------------------------------------- | |
| 14 | +| **Poppins** | ExtraLight, Light, Regular, Medium, SemiBold, Bold, BoldItalic | Primary UI text -- labels, buttons, modals, tile letters | |
| 15 | +| **Red Hat Mono** | Regular, Bold | Monospace -- timers, scores, coordinate labels | |
| 16 | +| **Zodiak** | Light, Regular, Bold, Extrabold, Black (+ italics) | Display/heading text -- titles, large decorative type | |
| 17 | +| **Dongle** | Light, Regular, Bold | Playful/casual display text | |
| 18 | +| **Rubik** | Light, Regular | Geometric sans-serif alternative | |
| 19 | +| **League Spartan** | Variable (200-800), Bold | Compact headings and UI labels | |
| 20 | +| **Cody Star** | Regular | Decorative/star-outline display | |
| 21 | + |
| 22 | +## Steps |
| 23 | + |
| 24 | +1. **Choose fonts for the game.** Most games use Poppins as the base and pick one or two others for variety. Common combos: |
| 25 | + - Word/tile games: `Poppins-SemiBold` for tiles, `RedHatMono-Bold` for scores |
| 26 | + - Display-heavy games: `Zodiak-Bold` for headings, `Poppins-Regular` for body |
| 27 | + |
| 28 | +2. **Load fonts via CSS.** Create or update a fonts stylesheet that declares `@font-face` rules pointing at the Puzzmo CDN subset URLs: |
| 29 | + |
| 30 | + ```css |
| 31 | + @font-face { |
| 32 | + font-family: "Poppins-SemiBold"; |
| 33 | + src: url("https://www.puzzmo.com/assets/fonts-subset/Poppins-SemiBold-subset.ttf"); |
| 34 | + font-display: swap; |
| 35 | + } |
| 36 | + |
| 37 | + @font-face { |
| 38 | + font-family: "RedHatMono-Bold"; |
| 39 | + src: url("https://www.puzzmo.com/assets/fonts-subset/RedHatMono-Bold-subset.ttf"); |
| 40 | + font-display: swap; |
| 41 | + } |
| 42 | + ``` |
| 43 | + |
| 44 | + Include this stylesheet in your `index.html` or import it from your entry point. |
| 45 | + |
| 46 | +3. **Apply fonts in game styles.** Always include system fallbacks since the subset fonts only cover ASCII: |
| 47 | + |
| 48 | + ```css |
| 49 | + .game-root { |
| 50 | + font-family: "Poppins-SemiBold", system-ui, sans-serif; |
| 51 | + } |
| 52 | + |
| 53 | + .score { |
| 54 | + font-family: "RedHatMono-Bold", ui-monospace, monospace; |
| 55 | + } |
| 56 | + ``` |
| 57 | + |
| 58 | +4. **For SVG thumbnails**, use the SDK's font utilities in your `appBundle.ts` to embed fonts directly in the SVG: |
| 59 | + |
| 60 | + ```ts |
| 61 | + import { svgFontFaceCSSRaw } from "@puzzmo/sdk/fonts" |
| 62 | + |
| 63 | + export function renderThumbnail(puzzle: string): string { |
| 64 | + return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"> |
| 65 | + <style>${svgFontFaceCSSRaw(["Poppins-SemiBold", "RedHatMono-Bold"])}</style> |
| 66 | + <!-- thumbnail content --> |
| 67 | + </svg>` |
| 68 | + } |
| 69 | + ``` |
| 70 | + |
| 71 | + Available font names for `svgFontFaceCSSRaw`: `Poppins-Regular`, `Poppins-Bold`, `Poppins-BoldItalic`, `Poppins-Medium`, `Poppins-SemiBold`, `Poppins-ExtraLight`, `Poppins-Light`, `RedHatMono-Bold`, `RedHatMono-Regular`, `Dongle-Regular`, `Rubik-Light`, `Rubik-Regular`, `NotoSansSymbols2-Regular`. |
| 72 | + |
| 73 | +## Important Notes |
| 74 | + |
| 75 | +- These are **ASCII subset** fonts. Characters outside the basic Latin range will fall through to the fallback font. Do not rely on them for extended Unicode, accented characters, or symbols. |
| 76 | +- `NotoSansSymbols2-Regular` is the only full (non-subset) font -- use it when you need symbol glyphs. |
| 77 | +- Use `font-display: swap` so the game remains interactive while fonts load. |
| 78 | +- Per-game font choice is a style decision. Pick fonts that match the game's personality and keep the set small for fast loading. |
| 79 | + |
| 80 | +## Success Criteria |
| 81 | + |
| 82 | +- Font `@font-face` declarations load without network errors |
| 83 | +- Game text renders with the chosen Puzzmo fonts |
| 84 | +- SVG thumbnails embed fonts correctly via `svgFontFaceCSSRaw` |
| 85 | +- System fallbacks are specified for all `font-family` declarations |
0 commit comments