Open DavBfr opened 4 years ago
++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
theme: pw.ThemeData.withFont(
base:
Font.ttf(await rootBundle.load("assets/fonts/Sarabun-Regular.ttf")),
bold: Font.ttf(await rootBundle.load("assets/fonts/Sarabun-Bold.ttf")),
),
@GuvanchBayryyyev can you please elaborate?
This is proving more complex than initially thought and requires a thorough refactor, along with tackling https://github.com/material-foundation/flutter-packages/issues/129.
It seems that this could be done somewhat reasonably by allowing users to construct a FontLoader
instance instead of always constructing one in loadFontByteData
. Something like this, in google_fonts.dart
:
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 google_fonts_base.dart
:
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:
GoogleFonts.config.fontLoaderBuilder = (n) => MyFontLoader(n);
@guidezpl If this seems appropriate I am happy to open a PR with this change.
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: