vanilla_respondage/files/fonts/README.md

107 lines
5.5 KiB
Markdown
Raw Normal View History

# Fonts bundled with this theme
This theme ships four open source fonts so users can see that self-hosted
(custom) fonts work just as well as the browser/system fonts (row 228 set):
| Font | Style | File(s) | License | Role |
|---|---|---|---|---|
| Atkinson Hyperlegible | sans-serif | `atkinson-hyperlegible-400.woff2`, `atkinson-hyperlegible-700.woff2` | OFL 1.1 (`OFL-atkinson-hyperlegible.txt`) | accessibility variant (reading impairments) |
| Inter | sans-serif | `inter-var.woff2` | OFL 1.1 (`OFL-inter.txt`) | **default font** — best screen readability of the set |
| Noto Sans | sans-serif | `noto-sans-var.woff2` | OFL 1.1 (`OFL-noto-sans.txt`) | multilingual fallback, stacked behind Inter in `css/fonts.css` |
| Noto Serif | serif | `noto-serif-var.woff2` | OFL 1.1 (`OFL-noto-serif.txt`) | the one bundled serif (covers non-Latin scripts) |
Inter, Noto Sans and Noto Serif are variable fonts (weight axis declared in
the `@font-face` rule in `css/fonts.css`; Noto Sans/Serif also carry a width
axis, left at its default); Atkinson Hyperlegible is static, so its 400 and
700 weights are shipped as separate files (like Liberation Sans was). All are
served locally by the theme — no external requests.
Purged in row 228 (kept out of the bundle on purpose): EB Garamond (print-first
hairlines degrade at 16px on low-quality screens), Liberation Sans 400/700
(redundant next to Inter/Noto Sans; the browser's own Arial is the Arial
fallback), Open Sans (duplicated Inter's role), Source Serif 4 (superfluous
next to Noto Serif). See the theme README.md "Default font" for the rationale.
# How to add your own font (walkthrough)
LimeSurvey only knows its **core font packages** (`application/config/fonts.php`),
so a theme cannot register a `font-*` package itself. Instead, the theme ships
the font file plus a small css file. The font chosen in the theme options is
applied as the class `font-<value>` on `<body>` (see `views/layout_survey_list.twig`).
1. **License** — only use fonts with a free/open license (SIL OFL 1.1,
Apache-2.0, MIT, …). Put a copy of the license text in this folder,
e.g. `OFL-myfont.txt`, and keep the font's copyright notice.
2. **Font file** — drop the font file in this folder. Prefer `.woff2`
(small, supported everywhere). A `.ttf`/`.otf` also works — use
`format('truetype')` / `format('opentype')` in the `src` then.
Variable fonts are fine: declare their weight range, e.g.
`font-weight: 100 900;`.
3. **CSS** — add an `@font-face` rule and a GENERIC class rule (`.font-<value>`,
not `body.font-<value>`!) to `css/fonts.css`:
```css
@font-face {
font-family: 'My Font';
src: url('../files/fonts/my-font.woff2') format('woff2');
font-weight: 100 900; /* the weight range your (variable) font supports */
font-style: normal;
font-display: swap;
}
.font-my_font {
font-family: 'My Font', Arial, Helvetica, sans-serif; /* keep fallbacks */
}
```
The rule must be generic because the class is applied in two ways: on `<body>`
for the base font, and on individual elements (header, progress bar, question
titles, answers, group titles/descriptions, buttons) for the per-element font
overrides (the `fontselect` options).
`../files/fonts/...` works because the asset manager copies the whole theme
directory to the assets folder. Rather not touch the shared `fonts.css`?
Create your own file (e.g. `css/myfonts.css`) and register it in
`config.xml` under `<files><css><add>css/myfonts.css</add>…`.
4. **Dropdown entry** — add the font to the font dropdown in `config.xml`,
inside the optgroup `"Bundled open source fonts"` (keep options ordered
alphabetically):
```xml
<option class="font-my_font" value="my_font" data-font-package="websafe">My Font</option>
```
- `value` becomes the class `font-<value>`: use only `[a-z0-9_]`.
- Keep `data-font-package="websafe"`: LimeSurvey only knows its core
packages and `websafe` is the neutral one, so no missing package is
requested. The real font is loaded by your css, not by a package.
- To make your font the default for new installs, set the default value of
the `font` option: `<font …>my_font</font>`.
5. **Activate** — copy/upload the theme into
`upload/themes/survey/vanilla_respondage/` and **reset the theme** in
LimeSurvey (Survey settings → Theme options → Reset) so `config.xml` is
re-imported into the DB. While developing you can force the XML instead:
in `upload/config.php` add `'force_xmlsettings_for_survey_rendering' => true`.
6. **Verify** — open a survey, select your font in the theme options, then in
the browser devtools check Network (the `.woff2` loads, HTTP 200) and
Elements → Computed → `font-family` on `<body>`.
## Keeping font files small
Subset the font to the languages you actually need and compress to woff2,
e.g. with `pyftsubset` (fonttools):
```bash
pyftsubset MyFont.ttf --flavor=woff2 \
--unicodes="U+0000-00FF,U+0100-024F,U+2000-206F" \
--name-IDs='*' --name-languages='*' --layout-features='*' \
--output-file=my-font.woff2
```
## Client-specific fonts (variants)
Do **not** add client house-style fonts here. Per-client fonts are built per
variant from the private variants repo: font files in the variant's
`files/fonts/`, the `@font-face` in the variant's own css (e.g.
`css/variant.css`), declared via `fontOptions` + `files_add` in
`variants/<client>.json` and processed by `variants/build.php`
(see the theme `README.md`, "Custom fonts per variant").