Skip to content

Also select font via localized family name #7468

Open

Description

@YDX-2147483647

Description

Some fonts provide their names in multiple languages.
For example, each Source Han Sans/Serif font has both an English name and a localized name, as shown in following table extracted from Adobe's font readme.

It would be good if typst supports selecting font via any name.
Relates-to: #2098

Image

Note

It has to be Source Han Sans/Serif released by Adobe, not Noto Sans/Serif CJK released by Google.
Google also releases fonts with localized name table strings, but the actual strings are identical to the English-language ones.

Use Case

At present, typst supports selecting font via only a single name. Sometimes it's the English name, and sometimes it's the localized name. It is difficult to predict which one it is.

As an example of this chaos:

  • Source Han Sans SC (思源黑体) can only be selected by "Source Han Sans SC".
  • Source Han Sans TC (思源黑體) can only be selected by "思源黑體". If you specify "Source Han Sans TC", you'll get a font-not-found warning.

The following is a screenshot of typst fonts shared by Runge on 2025-11-14. You can see that TC is somewhat unique. All fonts use English names, except TC.

Image

2026-04-14 update:
A (A is a username) complaints that he/she installed a font whose name in Windows Font settings is in Simplified Chinese.
However, its name in Typst is in Traditional Chinese, and the font won't appear in the completion menu unless the Traditional Chinese charater is typed explicitly.
As a result, it's really hard for A to select that font, because A doesn't use Traditional Chinese and hence can't type that character.

Cause of the inconsistency

The original Chinese version 中文原版

Adobe 发布的思源黑体 Source Han Sans 提供了简体中文 SC、繁体中文 TC 等版本。在 Typst 中使用时,前者要写“Source Han Sans SC”,后者却要写“思源黑體”而非“Source Han Sans TC”。
这是因为 Adobe 在字体中提供了英文、中文(繁简之一)两版字体名,Typst 会选择靠前的名字。那么为什么 SC 版英文名靠前,而 TC 版中文名靠前呢?
根据 OpenType 规范,名字要按照语言 ID 排序。对于包括思源在内的很多字体来说,这个语言 ID 是微软的 Windows Language Code Identifier (LCID)。
LCID 用数字代码表示语言,大致低位对应语言,高位对应地区。于是 zh-TW = 0x0404, en-US = 0x0409, zh-CN = 0x0804。可排序还是从高到低排呀,于是繁体中文在英文前面,英文在简体中文前面……

Adobe provides both English and Chinese (either traditional or simplified) names in the font, and Typst will choose the earliest name with find_map.

/// Try to find and decode the name with the given id.
pub(super) fn find_name(ttf: &ttf_parser::Face, name_id: u16) -> Option<String> {
ttf.names().into_iter().find_map(|entry| {
if entry.name_id == name_id {
if let Some(string) = entry.to_string() {
return Some(string);
}
if entry.platform_id == PlatformId::Macintosh && entry.encoding_id == 0 {
return Some(decode_mac_roman(entry.name));
}
}
None
})
}

So why does the English name come first in SC, but the Chinese name come first in TC?

According to the OpenType specification, names should be sorted by language ID. For many fonts, including Source Han Sans, this Language ID is Microsoft's Windows Language Code Identifier (LCID).

LCID represents a language with a numeric code, with the lower bits roughly corresponding to the language and the higher bits to the region. So zh-TW = 0x0404, en-US = 0x0409, zh-CN = 0x0804.

Image

However, the IDs are sorted as numbers, and highers bits matter more. So Traditional Chinese (TC, zh-TW) comes before English (en-US), and English comes before Simplified Chinese (SC, zh-CN)...

Why this is discovered so late

Most people only use one version of Source Han, so won't encounter such inconsistency.

I noticed it while I was debugging #7396. I shared it in the Chinese QQ chat group and everyone was surprised. But after testing, we found that the behavior is reproducible.

Reference implementations

MS Paint, Word, etc. only show localized names.

Image

Activity

  1. RungeCC commented on Nov 25, 2025

    @RungeCC
    Contributor
    1. This only viable iff a name string is encoding in some certain platform + encoding (the meaning of encoding_id depends on platform_id), so it maybe weird if a certain font contains some localzied name encoded in, e.g., Macintosh_Korean (I think there's no way Typst could support all this legacy encodings...), user can see it with system font manager (or, with MS Word? not, sure(, but can not actually use this name as font name in Typst. This shouldn't be a major issue for common scenarios—for example, every localized name in the Source Han fonts is still encoded within the Unicode BMP—though it might cause some inconsistencies in edge cases.
    2. Currently Typst typographic_family is designed to work with English language, so if using localized name it may break -- although it is already riddled with problems as it is. Since Typst relies the result of it to distinguish fonts (as key of FontBook), so I wander that if allow multi-language family name may cause more ambiguity.

    Possible solutions:

    1. Let font_name return a single string in English (United State) if possible (otherwise localized string). After that, family name given by Typst will be more consistent, else part of font.rs could remain unchange. However, after so Typst can no longer find "思源黑體" but only "Source Han Sans TC", cuasing compatiblity issue.
    2. Let font_name return a list containing all strings matching name_id, where the first one should be in English (United States) if possible. Use English (United States) name as FontBook key (after typographic_family stuff) if possible, and also store each localized (decodeable) string, then it's possible to find font through localized name, but may cause some inconsistency between user provided family name and Typst used name (can be introspected with #context text.font).

    I think Option 2 is more feasible (although the changes to book.rs are larger), or should we wait for the font object design? CC: @laurmaedje.

    Appendix: name mapping of Source Han Sans.ttc:

    Image
  2. added
    text
    cjk
    on Nov 26, 2025
  3. added a commit that references this issue on Dec 13, 2025
  4. sungodmoth commented on Feb 22, 2026

    @sungodmoth

    For what I'm pretty sure is the same reason, Noto Sans Egyptian Hieroglyphs is accessible only as "Noto Sans EgyptHiero" (although it provides both this and "Noto Sans Egyptian Hieroglyphs" as family names). This issue is thus not exclusive to fonts with names in multiple languages.

  5. YDX-2147483647 commented on Feb 22, 2026

    @YDX-2147483647
    ContributorAuthor

    The story of Noto Sans Egyptian Hieroglyphs is a bit different.
    It relates to different name IDs, rather than different language IDs.

    Name ID and its meaning defined in the spec Language ID and its meanding Value
    1 Font Family name 0x409 en-US Noto Sans EgyptHiero
    4 Full font name that reflects all family and relevant subfamily descriptors 0x409 en-US Noto Sans Egyptian Hieroglyphs Regular
    16 Typographic Family name 0x409 en-US Noto Sans Egyptian Hieroglyphs
    Raw data

    Version: https://github.com/notofonts/egyptian-hieroglyphs/releases/tag/NotoSansEgyptianHieroglyphs-v2.002

    $ ttx -t name -o - full/otf/NotoSansEgyptianHieroglyphs-Regular.otf | rg 'Noto Sans' --context 1
    Dumping "full/otf/NotoSansEgyptianHieroglyphs-Regular.otf" to "<stdout>"...
    Dumping 'name' table...
        <namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
          Noto Sans EgyptHiero
        </namerecord>
    --
        <namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
          Noto Sans Egyptian Hieroglyphs Regular
        </namerecord>
    --
        <namerecord nameID="16" platformID="3" platEncID="1" langID="0x409">
          Noto Sans Egyptian Hieroglyphs
        </namerecord>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cjkfeature requesttext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions