Skip to content

Force-override/ignore underline metrics for MOESongUN #7449

@YDX-2147483647

Description

@YDX-2147483647

Original title: underline + MOESongUN generates scary black rectangles

Description

As shown below, using underline for texts in MOESongUN generates scary black rectangles.

This font is also known as edusong, and is shipped on typst.app after typst/webapp-issues#380 (2024-06).

#set text(font: "MOESongUN", lang: "zh", region: "TW", fallback: false)
#underline[某君昆仲。今隐其名,皆余昔日在中学校时良友;分隔多年,消息渐阙。日前偶闻其一大病;适归故乡,迂道往访,则仅晤一人,言病者其弟也。劳君远道来视,然已早愈,赴某地候补矣。因大笑,出示日记二册,谓可见当日病状,不妨献诸旧友。持归阅一过,知所患盖『迫害狂』之类。语颇错杂无伦次,又多荒唐之言;亦不著月日,惟墨色字体不一,知非一时所书。间亦有略具联络者,今撮录一篇,以供医家研究,记中语误,一字不易;惟人名虽皆村人,不为世间所知,无关大体,亦悉易去。至于书名,则本人愈后所题,不复改也。七年四月二日识。]
Image

For comparison, the following is the result without underline.

Image

Cause

MOESongUN provides wrong underline_metrics.

$ ttx -t head -t post 'eduSong_Unicode(2024年12月).ttf' -o -
Dumping 'head' table...
    <unitsPerEm value="2048"/>
    …
Dumping 'post' table...
    <underlinePosition value="614"/>
    <underlineThickness value="1872"/>
    …
Version of the tested font

https://github.com/typst-doc-cn/moe-tw-fonts/blob/main/fonts/eduSong_Unicode-v4.2-2024-12.ttf

  • Versions in the name table are inconsistent: platformID="3" says Version 4.2, December, 2024, while platformID="1" says Version 4.1, July, 2024.
  • SHA256 of the ttf file: 7af7ebab00ef2518314f9ae22971d5e68a8e7666ec18ddabd784e9e4e6f83399

Edit on 2026-01-21: v4.4 2025-12, the new version, does not change the metrics.

The above is equivalent to the following typst code.

#let unit = 1em / 2048
#set underline(
  offset: -614 * unit,
  stroke: 1872 * unit,
)

As a result, underlines becomes thick rectanangles, and they're discontinuous due to underline.evade.

Image
Typst code
#set page(height: auto, width: auto, margin: 15pt)

#set underline(background: true, stroke: orange)
#show underline: set text(
  font: "MOESongUN",
  lang: "zh",
  region: "TW",
  fallback: false,
)


#let unit = 1em / 2048
// The line below copies metrics from the font, so uncommenting it should have no effect visually.
// #set underline(stroke: 1872 * unit, offset: -614 * unit)

#table(
  columns: 3,
  stroke: none,

  [], [*Font stroke*], [*Corrected stroke*],
  table.hline(),
  table.vline(x: 1),

  [*Font offset*],
  underline[某君昆仲。],
  underline(stroke: 0.06em)[某君昆仲。],

  [*Corrected offset*],
  underline(offset: 0.25em)[某君昆仲。],
  underline(offset: 0.25em, stroke: 0.06em)[某君昆仲。],
)

Links

Relates to #7664, which is a similar issue for a well-known font caused incorrect font metrics.

(You may argue that notorious is a better word for MOESongUN than well-known.)

Importance

MOESongUN is a font for Traditional Chinese.

At present, it is the font with the shortest name that covers Han characters. Therefore, it becomes the default fallback font on typst.app for Chinese. (Or more precisely, it's the default fallback font for Traditional Chinese characters and characters with the same form in both Traditional and Simplified Chinese.) See #5040 for a screenshot.

In spite of it, all Chinese users are affected. Today in the Chinese QQ chat group, a new user using Simplified Chinese encountered this issue, and quickly concluded that typst does not support Chinese.

Image

Reproduction URL

No response

Operating system

Web app

Typst version

  • I am using the latest version of Typst

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcjkChinese, Japanese, Korean typography.textRelated to the text category, which is all about text handling, shaping, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions