import 'package:flutter/services.dart' show rootBundle; import 'package:pdf/widgets.dart' as pw; /// Fonts and theme shared by every generated PDF (labels, catalog, recovery /// sheet). [theme] is the document-wide default; [bold] is exposed for the few /// places that set a heading weight explicitly — merging against [theme] keeps /// its script fallbacks, so bold Arabic/CJK still renders. typedef PdfFonts = ({pw.ThemeData theme, pw.Font bold}); /// Loads the PDF fonts. /// /// The base face is DejaVu (Latin extended, Cyrillic, Greek) with Noto Arabic /// and Noto CJK registered as per-glyph fallbacks, so vernacular species names, /// user notes, and localized labels in Arabic (RTL) or CJK render instead of /// showing tofu boxes. The `pdf` package subsets fonts to the glyphs actually /// used, so bundling the full Noto faces does not bloat the output file. /// /// Fonts are a per-locale resource, extensible to any script — widen the /// fallback list as more scripts land. Future loadPdfFonts() async { final base = pw.Font.ttf( await rootBundle.load('assets/fonts/DejaVuSans.ttf'), ); final bold = pw.Font.ttf( await rootBundle.load('assets/fonts/DejaVuSans-Bold.ttf'), ); final arabic = pw.Font.ttf( await rootBundle.load('assets/fonts/NotoSansArabic.ttf'), ); final cjk = pw.Font.ttf(await rootBundle.load('assets/fonts/NotoSansJP.ttf')); final theme = pw.ThemeData.withFont( base: base, bold: bold, italic: base, fontFallback: [arabic, cjk], ); return (theme: theme, bold: bold); }