Skip to content

The inferred writing script is not passed to HarfBuzz, making locl ineffective #7396

Open

Description

@YDX-2147483647

Description

The inferred writing script (e.g., latn/hani) is not passed to rustybuzz::UnicodeBuffer, making the OpenType locl (Localized forms) feature ineffective.

Outcome of this issue

When using certain fonts and languages, the position of period marks (U+3002 。 ideographic full stop) between generated texts are not stable.

In the example below, the first period is placed at the center of the square space, but the second period is placed at the lower left corner.

#set text(lang: "zh", region: "TW", font: "Noto Serif CJK SC")
#set heading(numbering: "1")
= Heading <a>

句號。@a。@a 何故?
Image

The problem happens if the glyph for 。 should be a non-default localized form provided by the locl feature.

Background and explanation

Typographical rules may have regional differences. For example, when writing Chinese horizontally, the period mark is placed at the lower left corner in the square space in Chinese Mainland, but placed at the center in Taiwan and Hong Kong.

Some fonts handle these differences with the locl feature. For instance, Noto Sans/Serif CJK, the language-specific version (also the version shipped on typst.app), contains all variants of the period mark, and the layout engine can select the needed glyph for each language from the font.

Note that locl requires the text to be properly tagged with both the language system and the script. If not, the default glyph will be used.

In the GSUB table of Noto CJK:

  1. There are a default script (DFLT) and 6 non-default scripts (cyrl, grek, hang, hani, kana, latn).
  2. The DFLT script contains only the default language system, and the non-default scripts also contain 5 non-default language systems (JAN, KOR, ZHH, ZHS, ZHT).
  3. The locl feature is only available for non-default scripts and language systems.

In Typst:

  • The locl feature is somewhat supported and enabled by default.

  • The language system can be tagged by applying set text(lang: "ja", region: "JP") (JAN), ko-KR (KOR), zh-HK (ZHH), zh-CN (ZHS), or zh-TW (ZHT).

  • The script can be manually tagged by applying set text(script: "hani") etc.

    However, ideally, the default set text(script: auto) should just work and Typst should infer the script from the used characters.

Typst has problems on inferring the script from characters. Specifically, the Unicode script property of 。 is Common, which means it may be used with multiple scripts.

  • When 。 is shaped in 句號。, HarfBuzz can infer from the context that the script is hani, so locl is applicable and the correct localized glyph will be used.
  • But if 。 is shaped alone, as the 。 in @a。@a, then HarfBuzz cannot determine the script and will use the DFLT script, so locl is not available and the default glyph will be used.

In the latter case, Typst is responsible for telling HarfBuzz that it is hani. However, Typst v0.14.0 only does so if the end author set text(script: "hani") manually. This should be improved.

if let Some(script) = ctx.styles.get(TextElem::script).custom().and_then(|script| {
rustybuzz::Script::from_iso15924_tag(Tag::from_bytes(script.as_bytes()))
}) {
buffer.set_script(script)
}

Further examples

Period marks between strong, emph, highlight, ref, or colored texts are all affected, as shown below.

#set text(lang: "zh", region: "CN", font: "Noto Serif CJK TC")
桑之未落,其叶沃若。于嗟鸠兮,无食桑葚!\
桑之未落,#text(red)[其叶沃若]。#text(blue)[于嗟鸠兮],无食桑葚!\
桑之未落,#highlight[其叶沃若]。#highlight[于嗟鸠兮],无食桑葚!\
#show ref: _ => [于嗟鸠兮]
桑之未落,*其叶沃若*。@key,无食桑葚!
Image

Characters that are not specific to a single script are affected, including 、,。.?!:;≤≥≮≯.

Workaround

Use other versions of Noto CJK that set your desired glyphs as the defaults, or tag the script manually:

#show "。": set text(script: "hani")

Notes

This issue was originally reported on 2025-08-14. Nothing was actionable until we tested the behavior of HarfBuzz (with the hb-view CLI), Firefox, and XeLaTeX / LuaLaTeX, and contacted an expert on typography by email.

Previous discussions was recorded in typst-doc-cn/clreq#41, in Chinese, but with many screenshots.

Previous attempts

#7415 fixed this issue, but it was rejected because the implementation was too ad-hoc.

Script segmentation should be done to full paragraph text at once, just like bidi. So inline markup should not interrupt it.

the proper way forward is to implement proper full-paragraph script detection akin to BiDi detection

People also listed reference implementations under that PR, namely, ICU4C, Pango, Skia, ICU4J, and Raqm.


Relates to #5474.

Reproduction URL

No response

Operating system

Web app, Windows, Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Nov 17, 2025
  2. YDX-2147483647 commented on Nov 17, 2025

    @YDX-2147483647
    ContributorAuthor

    Noto CJK fonts in https://github.com/typst/typst-dev-assets/ are v1.001. They does not support locl. Could they be updated to v2.x?

    Details

    Versions of Noto fonts

    ~/.../typst-dev-assets-2d6086a955e2074c/fddbf8b/files/fonts (main) $ otfinfo -i Noto* | grep Version:
    NotoColorEmoji-Regular-COLR.subset.ttf:Version:             Version 2.042;GOOG;noto-emoji:20231129:7f49a00d523ae5f94e52fd9f9a39bac9cf65f958
    NotoSansArabic-Regular.ttf:Version:             Version 2.000;GOOG;noto-source:20170915:90ef993387c0
    NotoSansSymbols2-Regular.ttf:Version:             Version 2.008; ttfautohint (v1.8.4.7-5d5b)
    NotoSansThai-Regular.ttf:Version:             Version 2.001; ttfautohint (v1.8.4.7-5d5b)
    NotoSerifCJKjp-Regular.otf:Version:             Version 1.001;PS 1.001;hotconv 16.6.54;makeotf.lib2.5.65590
    NotoSerifCJKkr-Regular.otf:Version:             Version 1.001;PS 1.001;hotconv 16.6.54;makeotf.lib2.5.65590
    NotoSerifCJKsc-Bold.otf:Version:             Version 1.001;PS 1.001;hotconv 16.6.54;makeotf.lib2.5.65590
    NotoSerifCJKsc-Regular.otf:Version:             Version 1.001;PS 1.001;hotconv 16.6.54;makeotf.lib2.5.65590
    NotoSerifCJKtc-Bold.otf:Version:             Version 1.001;PS 1.001;hotconv 16.6.54;makeotf.lib2.5.65590
    NotoSerifCJKtc-Regular.otf:Version:             Version 1.001;PS 1.001;hotconv 16.6.54;makeotf.lib2.5.65590
    NotoSerifHebrew-Bold.ttf:Version:             Version 2.000;GOOG;noto-source:20170915:90ef993387c0
    NotoSerifHebrew-Regular.ttf:Version:             Version 2.000;GOOG;noto-source:20170915:90ef993387c0

    List of supported features

    No locl.

    ~/.cargo/git/checkouts/typst-dev-assets-2d6086a955e2074c/0b12d75/files/fonts $ otfinfo --features * | sd '.+:' '' | sort | uniq --count
         14 aalt    Access All Alternates
          1 abvm    Above-base Mark Positioning
          1 abvs    Above-base Substitutions
          1 akhn    Akhand
          1 blwf    Below-base Forms
          1 blwm    Below-base Mark Positioning
          1 blws    Below-base Substitutions
          1 c2sc    Small Capitals From Capitals
          1 calt    Contextual Alternates
          7 case    Case-Sensitive Forms
         13 ccmp    Glyph Composition/Decomposition
          1 cjct    Conjunct Forms
          2 cpsp    Capital Spacing
          2 cv01    Character Variants 1
          1 cv02    Character Variants 2
          1 cv03    Character Variants 3
          1 cv04    Character Variants 4
          4 dlig    Discretionary Ligatures
         14 dnom    Denominators
          1 dtls    Dotless Forms
          2 fina    Terminal Forms
         16 frac    Fractions
          1 half    Half Forms
          1 hist    Historical Forms
          2 init    Initial Forms
         20 kern    Kerning
         17 liga    Standard Ligatures
          5 lnum    Lining Figures
         15 mark    Mark Positioning
          2 medi    Medial Forms
          8 mkmk    Mark to Mark Positioning
          1 nukt    Nukta Forms
         14 numr    Numerators
          5 onum    Oldstyle Figures
         15 ordn    Ordinals
          7 pnum    Proportional Figures
          1 pres    Pre-base Substitutions
          1 psts    Post-base Substitutions
          1 rclt    Required Contextual Alternates
          1 rkrf    Rakar Forms
          2 rlig    Required Ligatures
          1 rphf    Reph Forms
          2 rtlm    Right-to-left Mirrored Forms
          9 salt    Stylistic Alternates
         13 sinf    Scientific Inferiors
          1 smcp    Small Capitals
         17 ss01    Stylistic Set 1
         17 ss02    Stylistic Set 2
         11 ss03    Stylistic Set 3
         10 ss04    Stylistic Set 4
         10 ss05    Stylistic Set 5
          3 ss06    Stylistic Set 6
          3 ss07    Stylistic Set 7
          2 ss08    Stylistic Set 8
          2 ss09    Stylistic Set 9
          2 ss10    Stylistic Set 10
          1 ss11    Stylistic Set 11
          1 ss12    Stylistic Set 12
          1 ss13    Stylistic Set 13
          1 ss14    Stylistic Set 14
          1 ss15    Stylistic Set 15
          1 ss16    Stylistic Set 16
          1 ss19    Stylistic Set 19
          2 ss20    Stylistic Set 20
          1 ssty    Math Script Style Alternates
         11 subs    Subscript
         14 sups    Superscript
          6 tnum    Tabular Figures
          1 unic    Unicase
          8 zero    Slashed Zero

    Update on 2026-09-11:
    Discussions about the font version are moved to typst/typst-dev-assets#18.

  3. added
    text
    on Nov 17, 2025
  4. added 2 commits that reference this issue on Nov 19, 2025
    ac766e0
    4bbf7cc
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

    bugtext

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions