104 lines
5.1 KiB
Markdown
104 lines
5.1 KiB
Markdown
|
|
# Fonts bundled with this theme
|
||
|
|
|
||
|
|
This theme ships seven open source fonts so users can see that self-hosted
|
||
|
|
(custom) fonts work just as well as the browser/system fonts:
|
||
|
|
|
||
|
|
| Font | Style | File(s) | License |
|
||
|
|
|---|---|---|---|
|
||
|
|
| EB Garamond | serif | `eb-garamond-var.woff2` | OFL 1.1 (`OFL-eb-garamond.txt`) |
|
||
|
|
| Inter | sans-serif | `inter-var.woff2` | OFL 1.1 (`OFL-inter.txt`) |
|
||
|
|
| Liberation Sans | sans-serif | `liberation-sans-400.woff2`, `liberation-sans-700.woff2` | OFL 1.1 (`OFL-liberation-sans.txt`) |
|
||
|
|
| Noto Sans | sans-serif | `noto-sans-var.woff2` | OFL 1.1 (`OFL-noto-sans.txt`) |
|
||
|
|
| Noto Serif | serif | `noto-serif-var.woff2` | OFL 1.1 (`OFL-noto-serif.txt`) |
|
||
|
|
| Open Sans | sans-serif | `open-sans-var.woff2` | OFL 1.1 (`OFL-open-sans.txt`) |
|
||
|
|
| Source Serif 4 | serif | `source-serif-4-var.woff2` | OFL 1.1 (`OFL-source-serif-4.txt`) |
|
||
|
|
|
||
|
|
All except Liberation Sans are variable fonts (weight axis declared in the
|
||
|
|
`@font-face` rule in `css/fonts.css`; Noto Sans/Serif and Open Sans also carry
|
||
|
|
a width axis, left at its default); Liberation Sans is static, so its 400 and
|
||
|
|
700 weights are shipped as separate files. All are subsetted to latin +
|
||
|
|
latin-ext and served locally by the theme — no external requests.
|
||
|
|
|
||
|
|
# 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").
|