using FluentAssertions; using Oms.Application.Labeling.Hiprint; namespace Oms.Tests; public class LabelPdfFontTests { [Fact] public void EnsureRegistered_ShouldLoadEmbeddedCjkFont() { var family = LabelPdfFontRegistrar.EnsureRegistered(); family.Should().Be(LabelPdfFontRegistrar.FamilyName); LabelPdfFontRegistrar.RegisteredSource.Should().NotBeNullOrWhiteSpace(); LabelPdfFontRegistrar.RegisteredSource.Should().StartWith("embedded:"); } [Fact] public async Task Render_ShouldEmbedChineseWithoutThrowing() { LabelPdfFontRegistrar.EnsureRegistered().Should().NotBeNull(); const string templateJson = """ { "panels": [{ "width": 100, "height": 50, "printElements": [{ "options": { "left": 2, "top": 2, "width": 90, "height": 20, "title": "红米手机 摘要×25", "fontSize": 12 }, "printElementType": { "type": "text" } }] }] } """; var renderer = new QuestPdfLabelRenderer(new HiprintTemplateParser()); var pdf = await renderer.RenderAsync( templateJson, new Dictionary { ["skuSummary"] = "红米手机 512g×25" }); pdf.Should().NotBeNull(); pdf.Length.Should().BeGreaterThan(500); // RegisterFontWithCustomName 后 PDF 仍写入真实 PostScript 名(如 SimHei) var ascii = System.Text.Encoding.ASCII.GetString(pdf); ascii.Should().Match(s => s.Contains("SimHei", StringComparison.OrdinalIgnoreCase) || s.Contains("OmsLabelSans", StringComparison.OrdinalIgnoreCase) || s.Contains("Noto", StringComparison.OrdinalIgnoreCase)); } }