Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Fonts for every language in HWPX → PDF, version 1.10.3

KnifeLemondd8e7f476a16
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5fffc224..5b166faa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,24 @@ version it publishes under "What's Changed" in the GitHub release notes, above t
Add a `## <version>` section before tagging a release. Write what someone using Filee notices: what's new, where to
find it, what it does and doesn't do.
+## 1.10.3
+
+### New
+
+- **LibreOffice for Word and Excel → PDF** (issue #66). Settings → Engines → "When LibreOffice is installed" has two
+ new switches, off by default: "Word documents → PDF" (DOCX, DOC, ODT, RTF, laid out as in Word, with Chinese and
+ Japanese punctuation rules) and "Spreadsheets → PDF" (XLSX, XLS, ODS, CSV, with the workbook's print area and page
+ setup).
+
+### Fixed
+
+- **Excel page breaks** (issue #67). XLSX → PDF starts a new page where a page break was set in Excel (Page Layout →
+ Breaks), with frozen header rows repeated at the top. This works without LibreOffice.
+- **Fonts for every language in PDFs** (issue #64). Markdown, text, HTML and other documents Filee turns into PDF used
+ Korean fonts, so Chinese text mixed two fonts character by character. Chinese (Simplified or Traditional) and
+ Japanese text now gets a Chinese or Japanese font already on the computer (e.g. Microsoft YaHei), and text in other
+ scripts (Russian, Greek, Thai, Arabic, …) a font that has all its characters. Filee does not download or ship fonts.
+
## 1.10.2
### Fixed
diff --git a/Directory.Build.props b/Directory.Build.props
index 000a85a6..3cfabe1c 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -14,7 +14,7 @@
parameters of a member is fine (CS1573). -->
<NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
- <Version>1.10.2</Version>
+ <Version>1.10.3</Version>
<Product>Filee</Product>
<Authors>Filee contributors</Authors>
<Copyright>Copyright (c) Filee contributors</Copyright>
diff --git a/src/Filee.Engines/Hwp/RhwpFonts.cs b/src/Filee.Engines/Hwp/RhwpFonts.cs
index 15a73b85..fbcd76ee 100644
--- a/src/Filee.Engines/Hwp/RhwpFonts.cs
+++ b/src/Filee.Engines/Hwp/RhwpFonts.cs
@@ -1,15 +1,28 @@
-// Fonts rhwp cannot put into a PDF. rhwp uses the fonts installed on the computer; a variable font with CFF2 outlines
-// (Source Han Serif VF, "思源宋体 VF" in Chinese Word documents) fails its font subsetter, and the page came out blank
-// (issue #61). Such a font is swapped for an installed font of the same script and style before rhwp runs. Nothing is
-// downloaded or shipped: the replacement is always a font the computer already has.
+// Fonts for rhwp, chosen from the fonts installed on the computer. Nothing is downloaded or shipped.
+//
+// - Language: documents Filee writes (Markdown, text, HTML → HWPX) name Korean fonts in every slot. In a Chinese or
+// Japanese document those drew Korean-style Hanja and, for characters they lack, a different fallback font per
+// character (issue #64). Without Hangul in the text, Korean fonts are swapped for an installed Chinese (Simplified
+// or Traditional) or Japanese font of the same style.
+// - Coverage: rhwp draws a character with the font of its slot when that font has it, else with a fallback of its own
+// (Arabic came out in a calligraphic font). In text without Hangul, Han or kana, a slot's font is swapped for an
+// installed one of the same style that has every character of the text the old one had, and more of the rest:
+// Russian, Greek, Thai or Arabic text gets one consistent font.
+// - CFF2: variable fonts with CFF2 outlines (Source Han Serif VF, "思源宋体 VF") fail rhwp's font subsetter and the
+// page came out blank (issue #61); they are always swapped.
using System.Collections.Concurrent;
+using System.Globalization;
+using System.Text;
using System.IO.Compression;
using System.Xml.Linq;
using SkiaSharp;
namespace Filee.Engines.Hwp;
+/// <summary>An installed font: whether rhwp can embed it and which characters it has.</summary>
+internal sealed record InstalledFont(bool Usable, Func<int, bool> Has);
+
internal static class RhwpFonts
{
private static readonly string[] Styles =
@@ -26,56 +39,59 @@ internal static class RhwpFonts
["Yu Gothic", "Meiryo", "MS Gothic", "Noto Sans JP", "Hiragino Sans", "Noto Sans CJK JP"]),
["ko"] = (["Batang", "HCR Batang", "Noto Serif KR", "AppleMyungjo", "Noto Serif CJK KR"],
["Malgun Gothic", "Noto Sans KR", "Apple SD Gothic Neo", "NanumGothic", "Noto Sans CJK KR"]),
- [""] = (["Times New Roman", "Georgia", "Noto Serif", "DejaVu Serif", "Liberation Serif"],
- ["Arial", "Segoe UI", "Noto Sans", "Helvetica", "DejaVu Sans", "Liberation Sans"]),
+ // Wide coverage first (Tahoma and Times New Roman also have Greek, Cyrillic, Arabic, Hebrew; Tahoma Thai).
+ [""] = (["Times New Roman", "Noto Serif", "DejaVu Serif", "Georgia", "Liberation Serif"],
+ ["Segoe UI", "Tahoma", "Arial", "Noto Sans", "DejaVu Sans", "Helvetica", "Liberation Sans"]),
};
- private static readonly ConcurrentDictionary<string, bool?> Usable = new(StringComparer.OrdinalIgnoreCase);
+ /// <summary>Scripts whose fonts rhwp falls back to on its own and the computer may have better ones for.</summary>
+ private static readonly string[] WideFonts = ["Leelawadee UI", "Nirmala UI", "Microsoft Sans Serif", "Arial Unicode MS"];
/// <summary>
- /// For each face that is installed but unusable, an installed replacement. Faces that are fine, or not installed
- /// (rhwp falls back on its own), are left out.
+ /// Simplified and Traditional forms of common characters: which form a Chinese text uses. Forms Japanese writes
+ /// the same way (国, 学, 会, 点, …) are left out.
/// </summary>
- /// <param name="usable">True when rhwp can use the font, false when it can't, null when it is not installed.</param>
- public static Dictionary<string, string> Substitutions(IEnumerable<string> faces, Func<string, bool?>? usable = null)
- {
- usable ??= IsUsable;
- var result = new Dictionary<string, string>(StringComparer.Ordinal);
- foreach (var face in faces.Distinct(StringComparer.Ordinal))
- {
- if (face.Length == 0 || usable(face) != false)
- continue;
- var (serif, sans) = Candidates[Script(face)];
- var order = IsSerif(face) ? serif.Concat(sans) : sans.Concat(serif);
- if (order.FirstOrDefault(c => usable(c) == true) is { } replacement)
- result[face] = replacement;
- }
- return result;
- }
+ private const string SimplifiedOnly = "这们说为时个对发经过还进动东车长门间问见现实从开关书无让应该话样";
+ private const string TraditionalOnly = "這們說為時個對發經過還進動東車長門間問見現實從開關書無讓應該話樣";
+
+ private static readonly ConcurrentDictionary<string, InstalledFont?> Fonts = new(StringComparer.OrdinalIgnoreCase);
/// <summary>
- /// A copy of the HWPX in <paramref name="workDirectory"/> with unusable fonts replaced, or null when every font is
- /// fine (or the file is not an HWPX package).
+ /// A copy of the HWPX in <paramref name="workDirectory"/> naming better fonts, or null when every font is fine (or
+ /// the file is not an HWPX package).
/// </summary>
- public static string? Prepare(string hwpx, string workDirectory, Func<string, bool?>? usable = null)
+ /// <param name="lookup">The installed font with a name, or null (tests pass a fake computer).</param>
+ public static string? Prepare(string hwpx, string workDirectory, Func<string, InstalledFont?>? lookup = null)
{
try
{
XDocument header;
+ var text = new StringBuilder();
using (var zip = ZipFile.OpenRead(hwpx))
{
if (zip.GetEntry("Contents/header.xml") is not { } entry)
return null;
- using var stream = entry.Open();
- header = XDocument.Load(stream);
+ using (var stream = entry.Open())
+ header = XDocument.Load(stream);
+ foreach (var section in zip.Entries.Where(e => e.FullName.StartsWith("Contents/section", StringComparison.Ordinal)))
+ {
+ using var stream = section.Open();
+ foreach (var t in XDocument.Load(stream).Descendants().Where(e => e.Name.LocalName == "t"))
+ if (text.Length < 200_000)
+ text.Append(t.Value);
+ }
}
- var fonts = header.Descendants().Where(e => e.Name.LocalName == "font" && e.Attribute("face") is not null).ToList();
- var substitutions = Substitutions(fonts.Select(f => (string)f.Attribute("face")!), usable);
- if (substitutions.Count == 0)
+
+ var fonts = header.Descendants()
+ .Where(e => e.Name.LocalName == "font" && e.Attribute("face") is not null && e.Parent?.Name.LocalName == "fontface")
+ .Select(e => (Element: e, Slot: (string?)e.Parent!.Attribute("lang") ?? "", Face: (string)e.Attribute("face")!))
+ .ToList();
+ var plan = Plan(fonts.Select(f => (f.Slot, f.Face)).ToList(), text.ToString(), lookup ?? Find);
+ if (plan.Count == 0)
return null;
foreach (var font in fonts)
- if (substitutions.TryGetValue((string)font.Attribute("face")!, out var replacement))
- font.SetAttributeValue("face", replacement);
+ if (plan.TryGetValue((font.Slot, font.Face), out var replacement))
+ font.Element.SetAttributeValue("face", replacement);
var copy = Path.Combine(workDirectory, $"rhwp-fonts-{Guid.NewGuid():N}.hwpx");
File.Copy(hwpx, copy);
@@ -93,19 +109,146 @@ internal static class RhwpFonts
}
}
+ /// <summary>Replacements by (slot, face): the language, coverage and CFF2 rules above.</summary>
+ internal static Dictionary<(string Slot, string Face), string> Plan(
+ IReadOnlyList<(string Slot, string Face)> slots, string text, Func<string, InstalledFont?> lookup)
+ {
+ var characters = Characters(text);
+ var language = Language(text);
+ var result = new Dictionary<(string, string), string>();
+ foreach (var (slot, face) in slots.Distinct())
+ {
+ if (face.Length == 0)
+ continue;
+ var serif = IsSerif(face);
+ var chosen = face;
+ var current = lookup(face);
+
+ // Korean fonts in a Chinese or Japanese text; a font rhwp cannot embed.
+ if (language is not ("ko" or "") && Script(face) == "ko" || current is { Usable: false })
+ {
+ var script = current is { Usable: false } && Script(face) is { Length: > 0 } own ? own : language;
+ if (Preferred(script, serif).FirstOrDefault(name => lookup(name) is { Usable: true }) is { } replacement)
+ chosen = replacement;
+ }
+
+ // Text without Hangul, Han or kana (Russian, Greek, Thai, Arabic, …): a font of the same style with every
+ // character the chosen one has, and more of the others. In Korean, Chinese and Japanese text the language
+ // font stays, and rhwp's own fallback draws the odd foreign word as before.
+ var mine = language != "" || slot is "HANJA" or "JAPANESE"
+ ? []
+ : characters.Where(c => !IsHan(c) && !IsKana(c) && (slot == "HANGUL" || !IsHangul(c))).ToList();
+ if (mine.Count > 0 && lookup(chosen) is { Usable: true } font)
+ {
+ var covered = mine.Where(c => font.Has(c)).ToList();
+ if (covered.Count < mine.Count)
+ {
+ var best = chosen;
+ var bestCount = covered.Count;
+ var sameStyle = (serif ? Styled(language).Serif.Concat(Styled("").Serif) : Styled(language).Sans.Concat(Styled("").Sans).Concat(WideFonts))
+ .Distinct(StringComparer.OrdinalIgnoreCase);
+ foreach (var name in sameStyle)
+ {
+ if (lookup(name) is not { Usable: true } other || !covered.All(other.Has))
+ continue;
+ var count = mine.Count(other.Has);
+ if (count == mine.Count)
+ {
+ (best, bestCount) = (name, count); // the first one in order that has everything
+ break;
+ }
+ if (count > bestCount)
+ (best, bestCount) = (name, count);
+ }
+ chosen = best;
+ }
+ }
+
+ if (!string.Equals(chosen, face, StringComparison.Ordinal))
+ result[(slot, face)] = chosen;
+ }
+ return result;
+ }
+
+ private static IEnumerable<string> Preferred(string script, bool serif)
+ {
+ var (serifs, sans) = Styled(script);
+ return serif ? serifs.Concat(sans) : sans.Concat(serifs);
+ }
+
+ private static (string[] Serif, string[] Sans) Styled(string script) =>
+ Candidates.TryGetValue(script, out var c) ? c : Candidates[""];
+
+ private static bool IsHangul(int c) => c is >= 0xAC00 and <= 0xD7A3 or >= 0x1100 and <= 0x11FF or >= 0x3130 and <= 0x318F;
+
+ private static bool IsKana(int c) => c is >= 0x3040 and <= 0x30FF;
+
+ private static bool IsHan(int c) => c is >= 0x4E00 and <= 0x9FFF or >= 0x3400 and <= 0x4DBF or >= 0x20000 and <= 0x2FFFF;
+
+ /// <summary>
+ /// The language the Han characters of a text are in: Korean with Hangul, Japanese with kana, else Simplified or
+ /// Traditional Chinese by common characters; "" without Han characters.
+ /// </summary>
+ internal static string Language(string text)
+ {
+ int hangul = 0, kana = 0, han = 0, simplified = 0, traditional = 0;
+ foreach (var c in text)
+ {
+ if (c is >= '가' and <= '힣' or >= 'ᄀ' and <= 'ᇿ' or >= '㄰' and <= '㆏')
+ hangul++;
+ else if (c is >= '぀' and <= 'ヿ')
+ kana++;
+ else if (c is >= '一' and <= '鿿' or >= '㐀' and <= '䶿')
+ {
+ han++;
+ if (SimplifiedOnly.Contains(c))
+ simplified++;
+ else if (TraditionalOnly.Contains(c))
+ traditional++;
+ }
+ }
+ if (hangul > 0)
+ return "ko";
+ // Japanese prose is mostly kana; a Chinese text quoting a Japanese title is not.
+ if (kana > 0 && (simplified + traditional == 0 || kana * 3 >= han))
+ return "ja";
+ if (han > 0)
+ return traditional > simplified ? "zh-Hant" : "zh-Hans";
+ return "";
+ }
+
+ /// <summary>Distinct characters of the text that need a glyph (no spaces or controls), at most 4000.</summary>
+ private static List<int> Characters(string text)
+ {
+ var set = new HashSet<int>();
+ foreach (var rune in text.EnumerateRunes())
+ {
+ if (set.Count >= 4000)
+ break;
+ if (Rune.GetUnicodeCategory(rune) is not (UnicodeCategory.SpaceSeparator or UnicodeCategory.Control
+ or UnicodeCategory.Format or UnicodeCategory.LineSeparator or UnicodeCategory.ParagraphSeparator
+ or UnicodeCategory.NonSpacingMark or UnicodeCategory.PrivateUse or UnicodeCategory.OtherNotAssigned))
+ set.Add(rune.Value);
+ }
+ return set.ToList();
+ }
+
/// <summary>
- /// Whether an installed font can be embedded by rhwp: false for variable fonts with CFF2 outlines, null when no
- /// installed font has that name. "思源宋体 VF Medium" names a style of "思源宋体 VF", so trailing style words are tried off too.
+ /// An installed font by name, or null. "思源宋体 VF Medium" names a style of "思源宋体 VF", so trailing style words
+ /// are tried off too.
/// </summary>
- internal static bool? IsUsable(string face) => Usable.GetOrAdd(face, static name =>
+ internal static InstalledFont? Find(string face) => Fonts.GetOrAdd(face, static name =>
{
foreach (var candidate in Names(name))
{
- using var typeface = SKFontManager.Default.MatchFamily(candidate);
+ var typeface = SKFontManager.Default.MatchFamily(candidate);
// Windows matches localized names ("思源宋体 VF") and returns nothing for unknown ones; fontconfig always
// returns some font, so elsewhere only a font with the requested name counts.
- if (typeface is not null && (OperatingSystem.IsWindows() || string.Equals(typeface.FamilyName, candidate, StringComparison.OrdinalIgnoreCase)))
- return IsUsable(typeface);
+ if (typeface is null)
+ continue;
+ if (OperatingSystem.IsWindows() || string.Equals(typeface.FamilyName, candidate, StringComparison.OrdinalIgnoreCase))
+ return new InstalledFont(IsUsable(typeface), codePoint => typeface.GetGlyph(codePoint) != 0);
+ typeface.Dispose();
}
return null;
});
@@ -135,7 +278,8 @@ internal static class RhwpFonts
return "zh-Hant";
if (Word("JP", "J") || Has("明朝", "ゴシック", "游"))
return "ja";
- if (Word("KR", "K") || face.Any(c => c is >= '가' and <= '힣'))
+ if (Word("KR", "K") || face.Any(c => c is >= '가' and <= '힣')
+ || Candidates["ko"].Serif.Concat(Candidates["ko"].Sans).Contains(face, StringComparer.OrdinalIgnoreCase))
return "ko";
if (face.Any(c => c is >= '一' and <= '鿿'))
return "zh-Hans";
diff --git a/tests/Filee.Engines.Tests/RhwpFontsTests.cs b/tests/Filee.Engines.Tests/RhwpFontsTests.cs
index 8fd0af90..1fd2b98e 100644
--- a/tests/Filee.Engines.Tests/RhwpFontsTests.cs
+++ b/tests/Filee.Engines.Tests/RhwpFontsTests.cs
@@ -1,4 +1,4 @@
-// Fonts rhwp cannot embed (variable fonts with CFF2 outlines) are swapped for installed ones before HWPX → PDF.
+// Fonts for rhwp from the fonts on the computer: language (#64), coverage, and CFF2 variable fonts (#61).
using System.IO.Compression;
using System.Xml.Linq;
@@ -8,30 +8,81 @@ namespace Filee.Engines.Tests;
public class RhwpFontsTests(EngineFixture fx) : IClassFixture<EngineFixture>
{
- // What the fake computer has: true = usable, false = installed but a CFF2 variable font, missing = not installed.
- private static readonly Dictionary<string, bool> Installed = new()
+ private const string Latin = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,";
+ private const string Cyrillic = "АБВГДЕЖЗИКЛМНОПРСТУФХЦЧШЩЭЮЯабвгдежзиклмнопрстуфхцчшщэюя";
+ private const string Hangul = "한글문서대한민국섞인장입니다";
+ private const string Han = "改造我们的学习这是一个测试文档说话国家和会时间漢字";
+
+ /// <summary>A fake computer: font name → (embeddable, characters it has).</summary>
+ private static readonly Dictionary<string, (bool Usable, string Chars)> Computer = new()
{
- ["思源宋体 VF Medium"] = false,
- ["Source Han Sans SC VF"] = false,
- ["Some VF"] = false,
- ["SimSun"] = true,
- ["Microsoft YaHei"] = true,
- ["Malgun Gothic"] = true,
- ["Arial"] = true,
+ ["맑은 고딕"] = (true, Latin + Hangul + "漢字國"),
+ ["함초롬바탕"] = (true, Latin + Hangul + "漢字國"),
+ ["Microsoft YaHei"] = (true, Latin + Cyrillic + Han),
+ ["SimSun"] = (true, Latin + Han),
+ ["Yu Gothic"] = (true, Latin + Han + "日本語のテキスト"),
+ ["Segoe UI"] = (true, Latin + Cyrillic),
+ ["Times New Roman"] = (true, Latin + Cyrillic),
+ ["思源宋体 VF Medium"] = (false, Latin + Han),
};
- private static bool? Usable(string face) => Installed.TryGetValue(face, out var usable) ? usable : null;
+ private static InstalledFont? Lookup(string name) =>
+ Computer.TryGetValue(name, out var font) ? new InstalledFont(font.Usable, c => font.Chars.Contains((char)c)) : null;
+
+ private static Dictionary<(string Slot, string Face), string> Plan(string text, params (string Slot, string Face)[] slots) =>
+ RhwpFonts.Plan(slots, text, Lookup);
+
+ [Fact]
+ public void Chinese_text_gets_a_chinese_font_instead_of_the_korean_defaults()
+ {
+ // Issue #64: Markdown → PDF in Chinese mixed Malgun Gothic and a fallback font character by character.
+ var plan = Plan("改造我们的学习 这是一个测试文档。", ("HANJA", "맑은 고딕"), ("LATIN", "맑은 고딕"), ("HANJA", "함초롬바탕"));
+
+ Assert.Equal("Microsoft YaHei", plan[("HANJA", "맑은 고딕")]); // sans for 고딕
+ Assert.Equal("Microsoft YaHei", plan[("LATIN", "맑은 고딕")]);
+ Assert.Equal("SimSun", plan[("HANJA", "함초롬바탕")]); // serif for 바탕
+ }
+
+ [Fact]
+ public void Korean_text_keeps_its_fonts()
+ {
+ Assert.Empty(Plan("대한민국 漢字 섞인 문장입니다. English 123.", ("HANGUL", "맑은 고딕"), ("HANJA", "맑은 고딕"), ("LATIN", "맑은 고딕")));
+ }
[Fact]
- public void Unusable_fonts_get_an_installed_font_of_the_same_script_and_style()
+ public void A_font_without_the_text_s_characters_gets_one_that_has_them_all()
{
- // Issue #61: a Chinese Word document in 思源宋体 VF (Source Han Serif) came out as blank pages.
- var map = RhwpFonts.Substitutions(["思源宋体 VF Medium", "Source Han Sans SC VF", "Some VF", "SimSun", "Not Installed"], Usable);
+ // Russian in a document Filee wrote: Malgun Gothic has no Cyrillic, Segoe UI has it and all the Latin.
+ var plan = Plan("Привет мир. Hello.", ("HANGUL", "맑은 고딕"), ("LATIN", "맑은 고딕"));
- Assert.Equal("SimSun", map["思源宋体 VF Medium"]); // Simplified Chinese serif
- Assert.Equal("Microsoft YaHei", map["Source Han Sans SC VF"]); // Simplified Chinese sans
- Assert.Equal("Arial", map["Some VF"]); // no script in the name: Latin sans
- Assert.Equal(3, map.Count); // usable and missing fonts stay (rhwp falls back itself)
+ Assert.Equal("Segoe UI", plan[("HANGUL", "맑은 고딕")]);
+ // With Hangul in the text no font without Hangul replaces it, whatever else it has.
+ Assert.Empty(Plan("한글 Привет", ("HANGUL", "맑은 고딕")));
+ }
+
+ [Fact]
+ public void A_cff2_variable_font_is_always_replaced()
+ {
+ // Issue #61: 思源宋体 VF left the pages blank.
+ Assert.Equal("SimSun", Plan("这是一个测试文档", ("HANJA", "思源宋体 VF Medium"))[("HANJA", "思源宋体 VF Medium")]);
+ }
+
+ [Fact]
+ public void Fonts_that_are_not_installed_are_left_to_rhwp()
+ {
+ Assert.Empty(Plan("这是一个测试文档", ("HANJA", "Not Installed")));
+ }
+
+ [Theory]
+ [InlineData("这是我们的国家", "zh-Hans")]
+ [InlineData("這是我們的國家", "zh-Hant")]
+ [InlineData("日本語のテキスト", "ja")]
+ [InlineData("这是一个测试文档,我们说的话和时间。书名:日本語のテキスト", "zh-Hans")] // a Japanese title in Chinese text
+ [InlineData("한국어 漢字", "ko")]
+ [InlineData("Привет", "")]
+ public void The_language_of_han_characters_comes_from_the_text(string text, string language)
+ {
+ Assert.Equal(language, RhwpFonts.Language(text));
}
[Theory]
@@ -40,6 +91,7 @@ public class RhwpFontsTests(EngineFixture fx) : IClassFixture<EngineFixture>
[InlineData("Noto Serif TC", "zh-Hant", true)]
[InlineData("Source Han Serif K VF", "ko", true)]
[InlineData("함초롬돋움", "ko", false)]
+ [InlineData("Malgun Gothic", "ko", false)]
[InlineData("Source Han Sans JP", "ja", false)]
[InlineData("Inter", "", false)]
public void Script_and_style_come_from_the_font_name(string face, string script, bool serif)
@@ -52,11 +104,13 @@ public class RhwpFontsTests(EngineFixture fx) : IClassFixture<EngineFixture>
public async Task A_copy_of_the_hwpx_names_the_replacement_and_still_converts()
{
var dir = fx.NewFolder();
- var hwpx = await fx.MakeHwpxAsync(dir);
+ var hwpx = await fx.MakeHwpxAsync(dir); // Korean text with a few Han characters, Filee's default fonts
var faces = Faces(hwpx);
var broken = faces.First();
- var copy = RhwpFonts.Prepare(hwpx, dir, face => face == broken ? false : face == "Malgun Gothic" ? true : null);
+ var copy = RhwpFonts.Prepare(hwpx, dir, face => face == broken
+ ? new InstalledFont(false, _ => true)
+ : face == "Malgun Gothic" ? new InstalledFont(true, _ => true) : null);
Assert.NotNull(copy);
Assert.DoesNotContain(broken, Faces(copy));
@@ -64,7 +118,7 @@ public class RhwpFontsTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal(faces, Faces(hwpx)); // the original is untouched
using (var zip = ZipFile.OpenRead(copy))
Assert.Equal("mimetype", zip.Entries[0].FullName); // still a valid HWPX package
- Assert.Null(RhwpFonts.Prepare(hwpx, dir, _ => true)); // nothing to replace: no copy
+ Assert.Null(RhwpFonts.Prepare(hwpx, dir, _ => new InstalledFont(true, _ => true))); // nothing to replace: no copy
}
private static List<string> Faces(string hwpx)