wapFontFaceCss function
CSS @font-face rule embedding fontAsset, cached per asset.
Implementation
Future<String> wapFontFaceCss(String fontAsset) async {
final cached = _fontFaceCssCache[fontAsset];
if (cached != null) return cached;
try {
final bytes = await rootBundle.load(fontAsset);
final b64 = base64Encode(bytes.buffer.asUint8List());
final css = '''
@font-face {
font-family: "WapReportFont";
src: url(data:font/ttf;base64,$b64) format("truetype");
}
* { font-family: "WapReportFont", "Microsoft JhengHei", "Noto Sans TC", sans-serif !important; }
''';
_fontFaceCssCache[fontAsset] = css;
return css;
} catch (e) {
debugPrint(
'[wapform_report] Font embedding failed, falling back to the system default font: $e');
return '';
}
}