7d2c3412a1
Adds the Paper design and generalises design tokens (transcript, composer, selected-row styles, reading type, panel fill, chat colour saturation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.5 KiB
Dart
45 lines
1.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
/// Paper's reading serif (fonts/README.md): Source Serif 4.
|
|
const String paperSerifFamily = 'Source Serif 4';
|
|
|
|
const String _directory = 'fonts/source-serif-4';
|
|
|
|
/// The licence shipped beside the files, registered with the app's other
|
|
/// font licences.
|
|
const String paperSerifLicenseAsset = '$_directory/OFL.txt';
|
|
|
|
/// Every face of [paperSerifFamily]: regular, italic, semibold and semibold
|
|
/// italic. The loader reads each file's own weight and style.
|
|
const List<String> paperSerifAssets = <String>[
|
|
'$_directory/SourceSerif4-Regular.ttf',
|
|
'$_directory/SourceSerif4-It.ttf',
|
|
'$_directory/SourceSerif4-Semibold.ttf',
|
|
'$_directory/SourceSerif4-SemiboldIt.ttf',
|
|
];
|
|
|
|
Future<void>? _loading;
|
|
|
|
/// Registers [paperSerifFamily] the first time Paper's theme is built. The
|
|
/// files are plain assets, not a `fonts:` family, so the web build fetches
|
|
/// them only for a device that chooses Paper. Once registered the engine
|
|
/// reports a font change and text lays out again in the serif; until then
|
|
/// it reads in the interface face (the reading style's fallback). A failed
|
|
/// load is logged and the interface face stays.
|
|
Future<void> ensurePaperFonts() => _loading ??= _load();
|
|
|
|
Future<void> _load() async {
|
|
try {
|
|
final loader = FontLoader(paperSerifFamily);
|
|
for (final asset in paperSerifAssets) {
|
|
loader.addFont(rootBundle.load(asset));
|
|
}
|
|
await loader.load();
|
|
} catch (error) {
|
|
debugPrint('Paper serif font did not load: $error');
|
|
}
|
|
}
|