Repository navigation
Conversation
Use char.IsWhiteSpace instead of a hardcoded list of whitespace characters in HasUsableGlyph to prevent unnecessary font fallback for characters without visible outlines, such as U+3000.
henry3260
reviewed
Nov 26, 2026
| private static bool HasUsableGlyph(byte[] ttf, int codePoint, ushort gid) | ||
| { | ||
| if (codePoint is ' ' or 0x00A0 or 0x2009) return true; | ||
| if (codePoint <= char.MaxValue && char.IsWhiteSpace((char)codePoint)) return true; |
Member
There was a problem hiding this comment.
Could we add a regression test for this? For example, a text block with U+3000 and a preferred font whose U+3000 glyph has no outline, asserting that only the preferred font is embedded. If there is no suitable font available in CI, a before/after file size in the PR description is fine too.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
HasUsableGlyphrecognizes only three whitespace characters as valid glyphs without outlines. As a result, an ideographic space (U+3000) can trigger unnecessary font fallback even when the preferred TrueType font supports it.In my case, converting a six-page Japanese Excel report to PDF produced a 14 MB file because MiniPdf embedded the entire Noto Sans CJK JP font alongside IPAexGothic and IPAexMincho.
Inspecting the embedded font's ToUnicode CMap confirmed that U+3000 was the only character assigned to Noto Sans CJK JP.
Solution
Replace the hardcoded whitespace check with
char.IsWhiteSpace, allowing Unicode whitespace characters to use their existing glyphs without requiring visible outlines.This preserves the intended font selection and avoids unnecessary font embedding.
Summary by CodeRabbit