c24e7f40b4
Add font… picks one or more files, checks them with a bounded sfnt reader (name table family, OS/2 weight), registers them with FontLoader before storing, and chooses the new family. Added fonts list below the bundled ones with Rename and Remove; removing the chosen one falls back to System default. Bytes live in the app support directory natively and in IndexedDB on the web (localStorage is too small); a shared_preferences index names them. Limits: 10 MB per file, 40 MB total. The capture kit gains a files= step.
91 lines
2.5 KiB
Dart
91 lines
2.5 KiB
Dart
import 'font_choice.dart';
|
|
|
|
/// The bundled interface typefaces a device can choose. [AppFont.system] keeps the
|
|
/// platform's own typography (Roboto on Android and the web, SF on iOS); every
|
|
/// other option is an open-licence (SIL OFL 1.1) family bundled under
|
|
/// `fonts/<directory>/` as plain assets, not under pubspec `fonts:`, so a web
|
|
/// page downloads only the family it actually shows.
|
|
enum AppFont implements FontChoice {
|
|
system('system', 'System default', null, null, <String>[]),
|
|
inter('inter', 'Inter', 'Inter', 'inter', <String>[
|
|
'Inter-Regular.ttf',
|
|
'Inter-Medium.ttf',
|
|
'Inter-SemiBold.ttf',
|
|
'Inter-Bold.ttf',
|
|
]),
|
|
ibmPlexSans(
|
|
'ibm-plex-sans',
|
|
'IBM Plex Sans',
|
|
'IBM Plex Sans',
|
|
'ibm-plex-sans',
|
|
<String>[
|
|
'IBMPlexSans-Regular.ttf',
|
|
'IBMPlexSans-Medium.ttf',
|
|
'IBMPlexSans-SemiBold.ttf',
|
|
'IBMPlexSans-Bold.ttf',
|
|
],
|
|
),
|
|
sourceSans3(
|
|
'source-sans-3',
|
|
'Source Sans 3',
|
|
'Source Sans 3',
|
|
'source-sans-3',
|
|
<String>[
|
|
'SourceSans3-Regular.ttf',
|
|
'SourceSans3-Medium.ttf',
|
|
'SourceSans3-Semibold.ttf',
|
|
'SourceSans3-Bold.ttf',
|
|
],
|
|
),
|
|
atkinsonHyperlegible(
|
|
'atkinson-hyperlegible-next',
|
|
'Atkinson Hyperlegible Next',
|
|
'Atkinson Hyperlegible Next',
|
|
'atkinson-hyperlegible-next',
|
|
<String>[
|
|
'AtkinsonHyperlegibleNext-Regular.ttf',
|
|
'AtkinsonHyperlegibleNext-Medium.ttf',
|
|
'AtkinsonHyperlegibleNext-SemiBold.ttf',
|
|
'AtkinsonHyperlegibleNext-Bold.ttf',
|
|
],
|
|
);
|
|
|
|
const AppFont(this.id, this.label, this.family, this._directory, this._files);
|
|
|
|
@override
|
|
final String id;
|
|
|
|
@override
|
|
final String label;
|
|
|
|
@override
|
|
final String? family;
|
|
|
|
final String? _directory;
|
|
final List<String> _files;
|
|
|
|
/// Every weight's asset (400, 500, 600 and 700, in that order).
|
|
List<String> get assets => <String>[
|
|
for (final file in _files) 'fonts/$_directory/$file',
|
|
];
|
|
|
|
/// The regular weight alone: enough to preview the option's name.
|
|
String? get previewAsset => _files.isEmpty ? null : assets.first;
|
|
|
|
@override
|
|
List<String> get sources => assets;
|
|
|
|
@override
|
|
String? get previewSource => previewAsset;
|
|
|
|
/// The licence shipped beside the files.
|
|
String? get licenseAsset =>
|
|
_directory == null ? null : 'fonts/$_directory/OFL.txt';
|
|
|
|
/// The option a stored id names; an unknown or missing id is the default.
|
|
static AppFont fromId(String? id) => AppFont.values.firstWhere(
|
|
(font) => font.id == id,
|
|
orElse: () => AppFont.system,
|
|
);
|
|
}
|