Skip to content

Commit

Permalink
Refactor font manifest loading
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Nov 20, 2024
1 parent 4aa1c72 commit 6090718
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions lib/src/screenshot/load_fonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,21 @@ Future<void> _loadFontsFromFontManifest() async {
final fontManifest = _FontManifest.fromJson(json);

for (final item in fontManifest.fontFamilies) {
final String fontFamilyName;
final asset =
item.assets.firstOrNullWhere((it) => it.startsWith('packages'));
final packageName = asset?.split('/')[1];

final rawFamily = item.family;
if (rawFamily.startsWith('packages/')) {
fontFamilyName = rawFamily.split('/').last;
final bool isFontFromPackage = item.family.startsWith('packages/');
if (!isFontFromPackage) {
await loadFont(item.family, item.assets);
} else {
fontFamilyName = rawFamily;
}
final fontFamilyName = item.family.split('/').last;
await loadFont(fontFamilyName, item.assets);

// Apps directly use the fontFamily name
await loadFont(fontFamilyName, item.assets);
if (packageName != null) {
// packages use the full path
await loadFont('packages/$packageName/$fontFamilyName', item.assets);
final packageAsset =
item.assets.firstOrNullWhere((it) => it.startsWith('packages'));
final packageName = packageAsset?.split('/')[1];
if (packageName != null) {
await loadFont('packages/$packageName/$fontFamilyName', item.assets);
} else {
// could not extract the package name, that should be impossible
}
}
}
}
Expand Down

0 comments on commit 6090718

Please sign in to comment.