All checks were successful
Build and Deploy / deploy (push) Successful in 1m10s
将黑体随程序嵌入 QuestPDF;页级默认中文字体,禁止对单 Regular 调 Bold。 Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
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<string, object?> { ["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));
|
||
}
|
||
}
|