David PHAM-VAN

Add Google Fonts fallback to Helvetica

... ... @@ -70,7 +70,7 @@ abstract class PdfBaseCache {
final bytes = await _download(uri, headers: headers);
if (bytes == null) {
throw FlutterError('Unable to find the asset $name');
throw FlutterError('Unable to download $uri');
}
if (cache) {
... ...
... ... @@ -19,7 +19,7 @@ class DownloadbleFont {
static var cache = PdfBaseCache.defaultCache;
/// Get the font to use in a Pdf document
Future<TtfFont> getFont({
Future<Font> getFont({
PdfBaseCache? pdfCache,
bool protect = false,
Map<String, String>? headers,
... ... @@ -38,16 +38,22 @@ class DownloadbleFont {
}
pdfCache ??= PdfBaseCache.defaultCache;
final bytes = await pdfCache.resolve(
name: name,
uri: Uri.parse(url),
headers: headers,
cache: cache,
);
return TtfFont(
bytes.buffer.asByteData(bytes.offsetInBytes, bytes.lengthInBytes),
protect: protect,
);
try {
final bytes = await pdfCache.resolve(
name: name,
uri: Uri.parse(url),
headers: headers,
cache: cache,
);
return TtfFont(
bytes.buffer.asByteData(bytes.offsetInBytes, bytes.lengthInBytes),
protect: protect,
);
} catch (e) {
print('$e\nError loading $name, fallback to Helvetica.');
return Font.helvetica();
}
}
}
... ...