Skip to content

Add FontFlags exceptions for Libertinus fonts - #9048

Merged
laurmaedje merged 1 commit into
typst:mainfrom
diogotcorreia:font-serif-from-name
Nov 24, 2026
Merged

laurmaedje merged 1 commit into
typst:mainfrom
diogotcorreia:font-serif-from-name

Conversation

@diogotcorreia

@diogotcorreia diogotcorreia commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Some tests changed because a different fallback font is now selected.
Sadly, some fonts like Libertinus Math are still not detected as serif. For instance, in test issue-2214-baseline-math, one of the "W" characters changed from Libertinus Math to IBM Plex Math, which is not ideal, but I don't see a good way around this.

@laurmaedje

Copy link
Copy Markdown
Member

I'm not a huge fan of adding more hacks like this to the detection. I wanted to try to move into the opposite direction down the road.

How about we extend the font exception mechanism (crates/typst-library/src/text/font/exceptions.rs) instead and add an exception for Libertinus?

@laurmaedje laurmaedje added the waiting-on-author Pull request waits on author label Nov 19, 2026
@diogotcorreia

Copy link
Copy Markdown
Collaborator Author

I didn't know exceptions existed, I agree that is much much better, thanks!
As a bonus, the issue-2214-baseline-math test is now unchanged since Libertinus Math also gets the SERIF flag.

@diogotcorreia diogotcorreia changed the title Infer whether font is serif from family name in addition to PANOSE Add FontFlags exception for Libertinus fonts Nov 22, 2026
@laurmaedje laurmaedje changed the title Add FontFlags exception for Libertinus fonts Add FontFlags exceptions for Libertinus fonts Nov 24, 2026
@laurmaedje laurmaedje removed the waiting-on-author Pull request waits on author label Nov 24, 2026
@laurmaedje
laurmaedje added this pull request to the merge queue Nov 24, 2026
@laurmaedje

Copy link
Copy Markdown
Member

Nice :)

Merged via the queue into typst:main with commit eb6ca39 Nov 24, 2026
9 checks passed
@diogotcorreia
diogotcorreia deleted the font-serif-from-name branch November 24, 2026 12:12
@YDX-2147483647

YDX-2147483647 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Hi! By flipping a font flag of the default font, this PR also changes how Typst selects fallback fonts.

Previously, fonts without FontFlags::SERIF took precedence; while after this PR, fonts with FontFlags::SERIF take precedence.
This seems like a good change. However, note that when font fallback is needed, the concept of sans-serif and serif could be less applicable than the Latin case. Therefore, the change may surprise end authors.

For example, on my machine, the CJK/Han fallback font changes from KaiTi to LXGW WenKai GB.
In CJK context, there are four types of fonts: 宋体 (≈ serif), 黑体 (≈ sans), 楷体, 仿宋.1
Both KaiTi and LXGW WenKai GB belong to 楷体, but in their OS/2 panose data, KaiTi declares 1 (which becomes FontFlags::empty()), and LXGW WenKai GB declares 2 (which becomes FontFlags::SERIF)…

(I don't know how significant the impact is, so I'm just putting a small warning here for now.)

Footnotes

  1. The names are different among C, J, and K. The names here are Chinese. Refer to Type classification in CJK: Chinese – Fonts Knowledge - Google Fonts for the details. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants