Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/google_fonts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.0.1

- Fixes WOFF2/WOFF font selection when loading fonts bundled with the app to prefer compressed formats regardless of asset manifest order.

## 8.0.0

- Added fonts:
Expand Down
19 changes: 11 additions & 8 deletions packages/google_fonts/lib/src/google_fonts_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,17 @@ String? findFamilyWithVariantAssetPath(
? ['.woff2', '.woff', '.ttf', '.otf']
: ['.ttf', '.otf'];

for (final String asset in manifestValues) {
for (final String matchingSuffix in fileTypes.where(asset.endsWith)) {
final String assetWithoutExtension = asset.substring(
0,
asset.length - matchingSuffix.length,
);
if (assetWithoutExtension.endsWith(apiFilenamePrefix)) {
return asset;
// Iterate by file type priority, ensuring preferred formats are selected.
for (final fileType in fileTypes) {
for (final String asset in manifestValues) {
if (asset.endsWith(fileType)) {
final String assetWithoutExtension = asset.substring(
0,
asset.length - fileType.length,
);
if (assetWithoutExtension.endsWith(apiFilenamePrefix)) {
return asset;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/google_fonts/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_fonts
description: A Flutter package to use fonts from fonts.google.com. Supports HTTP fetching, caching, and asset bundling.
repository: https://github.com/flutter/packages/tree/main/packages/google_fonts
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_fonts%22
version: 8.0.0
version: 8.0.1

environment:
sdk: ^3.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ void main() {
expect(result, equals('google_fonts/Roboto-Regular.otf'));
});

test('returns first matching asset in manifest order', () {
// Returns the first asset that matches, regardless of file type
test('prefers woff2 over other formats regardless of manifest order', () {
// Returns the highest priority file type regardless of the order in
// which assets appear in the manifest.
final String? result =
findFamilyWithVariantAssetPath(familyWithVariant, <String>[
'google_fonts/Roboto-Regular.ttf',
'google_fonts/Roboto-Regular.woff2',
'google_fonts/Roboto-Regular.woff',
], isWeb: true);
expect(result, equals('google_fonts/Roboto-Regular.ttf'));
expect(result, equals('google_fonts/Roboto-Regular.woff2'));
});

test('ignores unsupported file extensions', () {
Expand Down