Repository navigation
Make test cases independent to font fallbacks - #8991
Open
YDX-2147483647 wants to merge 11 commits into
Open
YDX-2147483647 wants to merge 11 commits into
YDX-2147483647 wants to merge 11 commits into
Conversation
YDX-2147483647
marked this pull request as draft
October 22, 2026 14:42
YDX-2147483647
force-pushed
the
test-font-fallback
branch
from
October 22, 2026 14:48
d74c058 to
531d0e5
Compare
…dded This test case predates the _unknown font family_ warning (typst#3854). I guess the original author wanted to test IBM Plex Mono, but did not realize that the font falls back to Libertinus Serif.
…anged due to the metadata of language, and other hashes unchanged
…ashes changed due to font names, while png outputs unchanged
… pdf outputs changed
…es changed due to font names, while png outputs unchanged
YDX-2147483647
force-pushed
the
test-font-fallback
branch
from
October 22, 2026 14:49
531d0e5 to
a90bbb5
Compare
YDX-2147483647
marked this pull request as ready for review
October 22, 2026 14:49
1 task done
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.
At present, many test cases rely on the specific font fallback rule of Typst, especially those using Arabic, Han/CJK, Hebrew, Thai, and other non-Latin characters.
This PR makes them independent to font fallbacks by explicitly adding either
set text(font: …)orset text(fallback: true).Disadvantages of having test cases dependent on font fallbacks:
Adding a new font to typst-dev-assets can change the output of these test cases. For some test cases, even renaming an existing font can change the output.
This prevents us from updating the Noto CJK / Source Han fonts. (Update Noto CJK or add Source Han typst-dev-assets#18)
As a concrete example, Add
FontFlagsexceptions for Libertinus fonts #9048 added an exception for Libertinus Serif, and it caused U+3002。IDEOGRAPHIC FULL STOP in two test cases changed from Garamond-Math to Noto Serif CJK JP.Sometimes the resulting fallback font is confusing or even wrong. It is unsuitable to use them as the reference outputs.
Here are some examples of font fallback quirks:
Code
Also note that a font may affect the output even if it is not embedded in the resulting PDF: it can change the width of space characters.
Typst can hardly improve the font fallback mechanism (see the discussions in Writing non-Latin (e.g. Chinese) text without a configured font leads to unpredictable font fallback #5040, Chinese rendering error #5900, etc.), so it's better not to depend on it.
(Update on 2026-11-26: The example of
。was somehow changed in AddFontFlagsexceptions for Libertinus fonts #9048.)Previous discussions on Discord 2026-10-21:
Besides, #2648 (comment) once discussed about the font fallbacks in
text-lang-unknown-regionand related test cases.Technical details
This PR makes sure that all test cases produce the identical output when they are prepended with the following prelude:
(At first I also added Twitter Color Emoji to test cases, but later I found that there are too many test cases containing emojis, and emojis won't be affected when we update CJK fonts in the future.)
I recommend to review this PR commit by commits. I organized the changes as the following steps. You can run
cargo testiton any intermediate commit and observe that it passes.Lock font settings without changing hashes.
There are many test cases that rely on font fallbacks. I categorized them into three types:
intended use cases:
text.lang.For intended use cases, locking font settings is the only change needed.
half intended use cases:
text.langhas to be changed.For half intended use cases, I added
NOTE(font): …comments during this step. I'll improve them in step 4.unintended use cases:
For unintended use cases, I added
TODO(font): …comments during this step. I'll fix them later.Improve a specific test case.
The test case named text-edge uses IBM Plex Mono, but this font does not exist in typst-dev-assets.
This test case predates the unknown font family warning (Warn about unknown font families during parsing #3854). I guess the original author wanted to test IBM Plex Mono, but did not realize that it actually falls back to Libertinus Serif.
Therefore, I split it into two tests: one testing text edges, and the other testing the font warning.
Edit
TestWorldand disable font fallback.Fix font settings. This step changes the hashes.
For half-intended use cases, I replaced the
NOTE(font): …comments with the actual fix.For unintended use cases, if the problem could be fixed without updating typst-dev-assets, I replaced the
TODO(font): …comment with the actual fix; otherwise, I left the comment as is (I plan to fix them when Source Han Sans is added to typst-dev-assets).Revert the edit to
TestWorld.Please be aware that the above steps can only prove that I didn't miss anything, but it cannot rule out the possibility of having redundant changes. Specifically, if I added
set text(font: (A, B, C)), it's possible thatset text(font: (A, B))is sufficient.However, since I edited the files incrementally, it should be unlikely to have redundant changes. With that said, I did come across a redundant change where A,B,C are Noto Serif CJK variants (which has now been fixed)…