-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[google_fonts] Add WOFF and WOFF2 font format support for web #10703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,7 @@ | ||||||||||||||||||||||||||||||||||
| ## 6.4.0 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - Adds support for WOFF2 and WOFF font formats on web platforms for improved performance and smaller bundle sizes. | ||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please clarify that this only concerns loading fonts locally during development, or bundled with the app (or in this case hosted in the site's assets). When relevant files aren't found in the asset manifest, the package fetches font files from the Google Fonts API, and I'm not sure what the current behavior is (does it detect web requests and return woff2?). In any case, please also create an issue to associate with this PR and any future work regarding HTTP fetching of woff2 files.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Done in 1bac768.
I've tested this and it downloads a ttf, not a woff2. When checking the source I learned that it's hard-coded to ttf: packages/packages/google_fonts/lib/src/google_fonts_descriptor.dart Lines 36 to 51 in 2e46240
I'll do that and add a link to this PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Done: flutter/flutter#180998. |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ## 6.3.3 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - Replaces use of the deprecated `FontWeight.index`. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:google_fonts/src/google_fonts_base.dart'; | ||
| import 'package:google_fonts/src/google_fonts_family_with_variant.dart'; | ||
| import 'package:google_fonts/src/google_fonts_variant.dart'; | ||
|
|
||
| void main() { | ||
| group('findFamilyWithVariantAssetPath', () { | ||
| const familyWithVariant = GoogleFontsFamilyWithVariant( | ||
| family: 'Roboto', | ||
| googleFontsVariant: GoogleFontsVariant( | ||
| fontWeight: FontWeight.w400, | ||
| fontStyle: FontStyle.normal, | ||
| ), | ||
| ); | ||
|
|
||
| group('common behavior', () { | ||
| for (final isWeb in [true, false]) { | ||
| test('returns null when manifestValues is null (web: $isWeb)', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| null, | ||
| isWeb: isWeb, | ||
| ); | ||
| expect(result, isNull); | ||
| }); | ||
|
|
||
| test('returns null when manifestValues is empty (web: $isWeb)', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>[], | ||
| isWeb: isWeb, | ||
| ); | ||
| expect(result, isNull); | ||
| }); | ||
|
|
||
| test('returns null when font family does not match (web: $isWeb)', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>[ | ||
| 'google_fonts/Lato-Regular.ttf', | ||
| 'google_fonts/OpenSans-Regular.ttf', | ||
| ], | ||
| isWeb: isWeb, | ||
| ); | ||
| expect(result, isNull); | ||
| }); | ||
|
|
||
| test('returns null when variant does not match (web: $isWeb)', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>[ | ||
| 'google_fonts/Roboto-Bold.ttf', | ||
| 'google_fonts/Roboto-Italic.ttf', | ||
| ], | ||
| isWeb: isWeb, | ||
| ); | ||
| expect(result, isNull); | ||
| }); | ||
|
|
||
| test('matches correct variant with multiple fonts (web: $isWeb)', () { | ||
| const boldItalicVariant = GoogleFontsFamilyWithVariant( | ||
| family: 'Roboto', | ||
| googleFontsVariant: GoogleFontsVariant( | ||
| fontWeight: FontWeight.w700, | ||
| fontStyle: FontStyle.italic, | ||
| ), | ||
| ); | ||
| final String? result = | ||
| findFamilyWithVariantAssetPath(boldItalicVariant, <String>[ | ||
| 'google_fonts/Roboto-Regular.ttf', | ||
| 'google_fonts/Roboto-Bold.ttf', | ||
| 'google_fonts/Roboto-BoldItalic.ttf', | ||
| 'google_fonts/Roboto-Italic.ttf', | ||
| ], isWeb: isWeb); | ||
| expect(result, equals('google_fonts/Roboto-BoldItalic.ttf')); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| group('on web', () { | ||
| test('supports woff2 format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>['google_fonts/Roboto-Regular.woff2'], | ||
| isWeb: true, | ||
| ); | ||
| expect(result, equals('google_fonts/Roboto-Regular.woff2')); | ||
| }); | ||
|
|
||
| test('supports woff format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>['google_fonts/Roboto-Regular.woff'], | ||
| isWeb: true, | ||
| ); | ||
| expect(result, equals('google_fonts/Roboto-Regular.woff')); | ||
| }); | ||
|
|
||
| test('supports ttf format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>['google_fonts/Roboto-Regular.ttf'], | ||
| isWeb: true, | ||
| ); | ||
| expect(result, equals('google_fonts/Roboto-Regular.ttf')); | ||
| }); | ||
|
|
||
| test('supports otf format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>['google_fonts/Roboto-Regular.otf'], | ||
| isWeb: true, | ||
| ); | ||
| 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 | ||
| 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')); | ||
| }); | ||
|
|
||
| test('ignores unsupported file extensions', () { | ||
| final String? result = | ||
| findFamilyWithVariantAssetPath(familyWithVariant, <String>[ | ||
| 'google_fonts/Roboto-Regular.eot', | ||
| 'google_fonts/Roboto-Regular.svg', | ||
| 'google_fonts/Roboto-Regular.woff2', | ||
| ], isWeb: true); | ||
| expect(result, equals('google_fonts/Roboto-Regular.woff2')); | ||
| }); | ||
| }); | ||
|
|
||
| group('on non-web', () { | ||
| test('supports ttf format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>['google_fonts/Roboto-Regular.ttf'], | ||
| isWeb: false, | ||
| ); | ||
| expect(result, equals('google_fonts/Roboto-Regular.ttf')); | ||
| }); | ||
|
|
||
| test('supports otf format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>['google_fonts/Roboto-Regular.otf'], | ||
| isWeb: false, | ||
| ); | ||
| expect(result, equals('google_fonts/Roboto-Regular.otf')); | ||
| }); | ||
|
|
||
| test('does not select woff2 format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>[ | ||
| 'google_fonts/Roboto-Regular.woff2', | ||
| 'google_fonts/Roboto-Regular.ttf', | ||
| ], | ||
| isWeb: false, | ||
| ); | ||
| expect(result, equals('google_fonts/Roboto-Regular.ttf')); | ||
| }); | ||
|
|
||
| test('does not select woff format', () { | ||
| final String? result = findFamilyWithVariantAssetPath( | ||
| familyWithVariant, | ||
| <String>[ | ||
| 'google_fonts/Roboto-Regular.woff', | ||
| 'google_fonts/Roboto-Regular.otf', | ||
| ], | ||
| isWeb: false, | ||
| ); | ||
| expect(result, equals('google_fonts/Roboto-Regular.otf')); | ||
| }); | ||
| }); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please pull updates and correct version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1bac768.