load static method

Future<PrintFonts> load()

Implementation

static Future<PrintFonts> load() async {
  final cached = _cached;
  if (cached != null) return cached;
  // Inside an app the fonts are package assets; when the library runs on
  // its own (the demo) they are plain assets.
  Future<pw.Font> font(String file) async {
    try {
      return pw.Font.ttf(
        await rootBundle.load('packages/report_flutter/assets/fonts/$file'),
      );
    } catch (_) {
      return pw.Font.ttf(await rootBundle.load('assets/fonts/$file'));
    }
  }

  final loaded = PrintFonts(
    sans: await font('NotoSans-Regular.ttf'),
    sansBold: await font('NotoSans-Bold.ttf'),
    serif: await font('NotoSerif-Regular.ttf'),
    serifBold: await font('NotoSerif-Bold.ttf'),
  );
  _cached = loaded;
  return loaded;
}