using System.Reflection; using PdfSharpCore.Fonts; namespace GB5Shared.Export.NativePdf { /// /// PdfSharpCore's XGraphics needs an explicit on platforms /// without Windows GDI font enumeration (confirmed: no such implementation existed anywhere in this /// repo before this). Every requested font family is routed to Lato — SIL Open Font License 1.1 /// (see Fonts/Lato-OFL-LICENSE.txt), embedded directly as resources in this project rather /// than referenced from the QuestPDF package that incidentally also ships it, so this resolver keeps /// working even if QuestPDF is later removed for its own, unrelated commercial-licensing reasons. /// Only Regular/Bold/Italic are embedded (no BoldItalic) — bold+italic requests fall back to Bold. /// public sealed class LatoFontResolver : IFontResolver { public string DefaultFontName => "Lato"; public byte[] GetFont(string faceName) { var resourceName = faceName switch { "Lato#Bold" => "GB5Shared.Export.NativePdf.Fonts.Lato-Bold.ttf", "Lato#Italic" => "GB5Shared.Export.NativePdf.Fonts.Lato-Italic.ttf", _ => "GB5Shared.Export.NativePdf.Fonts.Lato-Regular.ttf", }; using var stream = typeof(LatoFontResolver).Assembly.GetManifestResourceStream(resourceName) ?? throw new InvalidOperationException($"Embedded font resource '{resourceName}' not found."); using var ms = new MemoryStream(); stream.CopyTo(ms); return ms.ToArray(); } public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic) { if (isBold) return new FontResolverInfo("Lato#Bold"); if (isItalic) return new FontResolverInfo("Lato#Italic"); return new FontResolverInfo("Lato#Regular"); } } }