-
Notifications
You must be signed in to change notification settings - Fork 158
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
Allow obtaining the font files #102
Comments
++1 |
That would be awesome!!! |
Any progress on this? would be great to have this feature. |
Much Needed Feature! |
bump |
Absolutely Required |
I will love it |
This is a much required feature please |
any new news !! |
anu update ? |
I am also using Google Fonts, I first download it and using like this
|
@GuvanchBayryyyev can you please elaborate? |
This is proving more complex than initially thought and requires a thorough refactor, along with tackling #129. |
It seems that this could be done somewhat reasonably by allowing users to construct a class _Config {
// .. snip ..
/// If provided, this function will be invoked to construct a font loader
/// instance for loading the given family name. If left null, a font loader
/// instance will be constructed automatically.
FontLoader Function(String familyName)? fontLoaderBuilder;
} Then in Future<void> loadFontByteData(
String familyWithVariantString,
Future<ByteData?>? byteData,
) async {
if (byteData == null) return;
final fontData = await byteData;
if (fontData == null) return;
final FontLoader fontLoader =
GoogleFonts.config.fontLoaderBuilder?.call(familyWithVariantString) ??
FontLoader(familyWithVariantString);
fontLoader.addFont(Future.value(fontData));
await fontLoader.load();
} Users could then implement a FontLoader subclass like so: class MyFontLoader extends FontLoader {
MyFontLoader(super.family);
@override
void addFont(Future<ByteData> bytes) {
super.addFont(bytes.then((bytes) {
log('Loaded font $family, size ${bytes.lengthInBytes}');
return bytes;
}));
}
} and register it like this:
@guidezpl If this seems appropriate I am happy to open a PR with this change. |
This adds a new public API, `GoogleFontsLoader`, and a corresponding new instance field `fontLoader` in the global `GoogleFonts.config` class. The new API allows users to hook the loading of fonts into the Flutter engine, which is useful in scenarios where the actual font data is needed for other purposes. The newly added default font loader simply uses Flutter's `FontLoader` as before. Fixes material-foundation#102.
NB most of the Google-served fonts are packaged in WOFF2 format, which is not directly supported by Flutter. In that sense this API addition is somewhat questionable, though it could be considered future-facing for a later Flutter that does support WOFF2. |
Request
I'm the developer of the library pdf. This library renders PDF files from dart code. It can load TTF fonts to draw text in the document.
As far as I can see, this google-fonts library does not expose the font files, URL, or bytes in any way.
I would need something to get the Uint8List font data for any available fonts without duplicating this library.
Usage
Platforms:
The text was updated successfully, but these errors were encountered: