60 lines
2.2 KiB
Dart
60 lines
2.2 KiB
Dart
/// The typefaces bundled with the client (spec 8.2: the reader chooses).
|
|
/// Pure data, shared by the settings page that offers them and the renderer
|
|
/// that applies them.
|
|
library;
|
|
|
|
/// One bundled family: the name used in pubspec.yaml and stored in settings,
|
|
/// the id of its display name in the locale file, and where to look when it
|
|
/// has no glyph for a character.
|
|
typedef ReaderFont = ({String family, String labelId, List<String> fallback});
|
|
|
|
/// Offered in this order: the two sans faces first, then the two serifs.
|
|
/// Adding a font is four files in assets/fonts, one `fonts` entry in
|
|
/// pubspec.yaml, one entry here, one label in the locale file, and its licence
|
|
/// beside the files.
|
|
///
|
|
/// Each face names where to look for a character it has no glyph for. Hebrew
|
|
/// comes from a bundled Hebrew face, matched to the shape of the chosen one,
|
|
/// so it never depends on what the device happens to have installed. The
|
|
/// serifs also cover Greek, Cyrillic and a wide Latin range, so each falls
|
|
/// back to the other; the sans faces are narrow and have no bundled sans to
|
|
/// turn to, so for those the platform answers, and it answers a sans with a
|
|
/// sans. Scripts nothing here covers, such as Arabic and the CJK languages,
|
|
/// always come from the platform.
|
|
const readerFonts = <ReaderFont>[
|
|
(
|
|
family: 'Atkinson Hyperlegible',
|
|
labelId: 'settings-font-atkinson',
|
|
fallback: [hebrewSans],
|
|
),
|
|
(
|
|
family: 'Luciole',
|
|
labelId: 'settings-font-luciole',
|
|
fallback: [hebrewSans],
|
|
),
|
|
(
|
|
family: 'Literata',
|
|
labelId: 'settings-font-literata',
|
|
fallback: ['Charis SIL', hebrewSerif],
|
|
),
|
|
(
|
|
family: 'Charis SIL',
|
|
labelId: 'settings-font-charis',
|
|
fallback: ['Literata', hebrewSerif],
|
|
),
|
|
];
|
|
|
|
/// Bundled to be fallen back on, never offered: the reader picks a face for
|
|
/// the Latin text they are reading, and Hebrew follows its shape.
|
|
const hebrewSans = 'Noto Sans Hebrew';
|
|
const hebrewSerif = 'Noto Serif Hebrew';
|
|
|
|
const defaultFontFamily = 'Atkinson Hyperlegible';
|
|
|
|
/// Where to look after [family], or nothing when it is not one of ours.
|
|
List<String> fallbackFor(String family) {
|
|
for (final font in readerFonts) {
|
|
if (font.family == family) return font.fallback;
|
|
}
|
|
return const [];
|
|
}
|