Skip to content

CJK punctuation compression overlaps glyphs in proportional Japanese fonts (e.g. BIZ UDPGothic) #9104

Open

Description

@gotahu

Description

With a proportional Japanese font such as BIZ UDPGothic (free, Google Fonts), adjacent CJK punctuation overlaps. Typst applies its CJK punctuation compression as if every glyph were full-width (1em), but in this font the punctuation is already half-width.

#set text(lang: "ja", size: 14pt)
#let s = [出典:『辞典』第6版「place」「shoe」の項、『PEU』]

#text(font: "BIZ UDPGothic", s)  // overlaps
#text(font: "BIZ UDGothic", s)   // fine (same family, full-width punctuation)

With BIZ UDPGothic:

  • :『: the colon is squeezed under the opening bracket and is almost invisible.
  • 」「, 』第, 、『: the brackets touch or overlap the neighbouring glyph.

BIZ UDGothic, Hiragino Sans and Ryumin (all full-width punctuation) render the same line correctly. The overlap also happens with lang: "en", and region: "tw" does not avoid it.

Cause (as far as I can tell). The punctuation in BIZ UDPGothic has these advances in hmtx (unitsPerEm 2048):

glyph BIZ UDGothic BIZ UDPGothic
: 『 』 「 」 ( ) 2048 1024
、 。 2048 1229

In crates/typst-layout/src/inline/shaping.rs, is_cjk_left_aligned_punctuation and is_cjk_right_aligned_punctuation classify :, 『, 」 and similar characters by code point alone. Only ”’“‘ are checked against x_advance + stretchability == Em::one(). base_adjustability then allows shrinking by width / 2, and calculate_adjustability removes width / 2 between consecutive punctuation. For a glyph that is already 0.5em wide, this removes half of the remaining advance, which eats into the ink.

Expected. Punctuation whose advance is already narrower than 1em (proportional fonts, or fonts shaped with palt/halt) should not be compressed again. One option would be to apply the same full-width check used for the curly quotes to all CJK punctuation.

Workaround. Use a full-width face for the Japanese text and the proportional face only for Latin letters and digits:

#set text(font: ((name: "BIZ UDPGothic", covers: regex("[A-Za-z0-9]")), "BIZ UDGothic"))

Related but different: #7643 (option to turn compression off), #8390 (centered punctuation).

Operating system

macOS

Typst version

  • I am using the latest version of Typst (0.15.1)

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions