Skip to content

iPhone terminal: Hangul, kana and Han glyphs leave a gap in their two-cell slot, so Korean looks broken apart #268

Closed

Description

@devswha

What happened

On an iPhone, the terminal view draws every Hangul syllable with a visible gap after it, so Korean
text looks spread out and broken into pieces ("자모가 떨어져 보임"). Japanese and Chinese have
the same problem. English is fine. Desktop Chrome on Linux shows the same pane correctly.

The text itself is intact and the grid holds: every | in the test pattern below lines up, and
NFD (decomposed) Hangul and NFD dakuten compose into whole syllables. What's wrong is where each
wide glyph sits in its two-cell slot.

Results per script (iOS 27 simulator, Safari tab, 13px terminal font, pane=w1:p1 on an
isolated herdr session):

Script Sample iOS Safari Desktop Chrome (Linux)
English The quick brown fox… OK OK
Korean, NFC 다람쥐 헌 쳇바퀴에…, 값읽궯뷁쀍뚫똠 gap after every syllable (28% of the slot) OK (about 1px)
Korean, NFD (U+1100 jamo) 한글 자모 테스트 composes into syllables, same gaps as NFC OK
Korean compatibility jamo ㄱㄴㄷㅏㅑ same gaps OK
Japanese kana and kanji ひらがなカタカナ漢字日本語です same gaps, and drawn in the Korean font (see below) OK
Japanese halfwidth kana ハンカクカタカナ small gap (1.3px) OK
Japanese, NFD dakuten がぎぐ パピプ composes, same gaps OK
Chinese, simplified and traditional 简体中文测试…, 繁體中文測試… gaps (17% of the slot) OK
Mixed AB가나CDあいEF中文GH a wide glyph touches the Latin letter before it and leaves a gap after it OK
Box drawing ┌──┐│ ━┃╋ lines broken, heavy ━┃╋ drawn like -|+ also broken, so not iOS-specific and out of scope here

Why

The terminal uses xterm's DOM renderer. For each cell it sets
letter-spacing = width × cellWidth − measuredGlyphWidth
(DomRendererRowFactory.ts, spacing = width * cellWidth - widthCache.get(chars, …)). The glyph
starts at the left edge of its slot and the spacing all lands after it.

On iOS the cell comes from Menlo (0.602em, 7.83px at 13px), so a wide slot is 1.204em (15.67px).
No font on iOS draws Hangul that wide. Measured in iOS Safari with a canvas at 100px:

Font 한 あ 漢 简 W
app stack (FONT_STACK) 0.87 0.87 0.87 1.00 0.60
Apple SD Gothic Neo 0.87 0.87 0.87 1.00 0.85
Hiragino Sans 0.87 1.00 1.00 1.00 1.02
PingFang SC 0.87 0.87 1.00 1.00 0.93
  • Hangul: every iOS font draws it at 0.87em, so each syllable gets 0.335em (4.4px at 13px)
    of empty space after it. That gap is what reads as text falling apart.
  • Japanese: nothing in FONT_STACK names a Japanese font, so on this Korean-locale simulator
    WebKit falls back to Apple SD Gothic Neo for kana and kanji. They get the same 0.87em width and
    Korean glyph shapes. Hiragino Sans would draw them at 1em.
  • Chinese: PingFang is 1em, so the gap is smaller (2.7px) but still visible.
  • Desktop Chrome on Linux: Noto Sans CJK is 1em against a slightly narrower cell, so the gap
    is about 1px and nobody sees it.

document.fonts.check() answers true for every family on iOS Safari, including fonts that aren't
installed, so it can't be used to detect which font won.

Possible fixes (not yet evaluated)

  1. Center wide glyphs in their slot instead of left-aligning them. The DOM renderer has no
    option for this. Check whether @xterm/addon-webgl or the canvas renderer centers wide glyphs,
    or whether a renderer change is needed.
  2. Name per-script fallbacks in FONT_STACK after the Latin monospace fonts, for example
    "Hiragino Sans" for Japanese and "PingFang SC" for Chinese. That gets kana and kanji to 1em
    and the right glyph shapes on Apple devices. It doesn't help Hangul, which stays at 0.87em.
  3. Widen the Hangul glyphs. An @font-face with src: local("Apple SD Gothic Neo"),
    size-adjust and a Hangul unicode-range would make them wider, but also taller, so check it
    against the line height.
  4. Serve a monospace CJK font that is exactly two cells wide (Custom terminal/chat font, and app-served fonts for phones #204, part 2).

Steps to reproduce

  1. Run this in a pane:

    test pattern
    printf '\033]0;cjk test\007'; clear; cat <<'EOF'
        |012345678901234567890123456789|
    EN  |The quick brown fox jumps over|
    KO  |한글한글한글한글한글한글한글한| NFC
    KO  |다람쥐 헌 쳇바퀴에 타고파 띄어| NFC
    KO  |값읽궯뷁쀍뚫똠방각하ㄱㄴㄷㅏㅑ| NFC+compat jamo
    KOd |한글 자모 테스트              | NFD conjoining jamo
    JA  |ひらがなカタカナ漢字日本語です|
    JA  |いろはにほへとちりぬるをわかよ|
    JAh |ハンカクカタカナ アイウエオ halfwidth      | halfwidth kana
    JAd |がぎぐ パピプ                 | NFD dakuten
    ZHs |简体中文测试汉字显示正常吗你好|
    ZHt |繁體中文測試漢字顯示正常嗎妳好|
    MIX |AB가나CDあいEF中文GH한ア字IJKL|
    BOX |┌──┐│한│ア│中│└──┘ ━┃╋        |
    EOF

    The KOd and JAd rows must be NFD. Generate them with
    python3 -c 'import unicodedata;print(unicodedata.normalize("NFD","한글 자모 테스트"))',
    because pasting usually turns them back into NFC.

  2. Open the pane on an iPhone (or the iOS Simulator), Terminal lens.

  3. Compare with desktop Chrome.

How often

Every time.

herdr web ui version

0.3.39 (87ba715, main)

How it runs

bun run server (source checkout, isolated test session)

Server PC

Linux x64, herdr 0.9.0

Device and browser

iOS Simulator: iPhone 17 Pro, iOS 27.0 runtime, Safari tab, Korean locale. Not yet checked on a
real iPhone or in the installed app. The fonts are the system ones, so the result should be the
same there.

How the device reaches the server

SSH tunnel

Agent and PC

No agent: a plain shell printing the pattern above, local PC.

Related: #204 (terminal font choice and fonts served by the app; it reports the same narrow-Hangul
gaps on Android).

Activity

  1. added
    bug
    on Oct 1, 2026
  2. devswha commented on Oct 1, 2026

    @devswha
    OwnerAuthor

    I tested more scripts with the same setup (iOS 27 simulator Safari against desktop Chrome on Linux, 13px).

    Script iOS Safari Desktop Chrome
    French, German, Russian, Greek, precomposed Vietnamese OK OK, except Greek, which loses its accents (a Linux font problem; iOS is fine)
    Vietnamese, NFD (e + U+0302 + U+0301) Only the first mark is drawn. Tiếng shows as Tiêng, and ắ ằ ẳ all show as ă. The cell text holds every mark (checked in the DOM), so this is a rendering problem. OK
    Thai น้ำ U+0E33 SARA AM gets its own cell and is drawn with a dotted circle (◌ำ). Everything else on the row is fine. OK
    Emoji Glyphs are wider than their two-cell slot. xterm gives them negative letter-spacing (−9.2px), and they overlap their neighbours. slight overlap
    Emoji ZWJ and flag sequences 🇰🇷👨‍👩‍👧 One cell holds 1f1f0 1f1f7 1f468 200d 1f469 200d, and 👧 (U+1F467) is missing Same: 👧 is missing, so this is not iOS-specific. Cause not yet traced (herdr's attach output or xterm).
    Arabic, Hebrew, Devanagari No bidi or complex shaping: Arabic letters are spaced apart, and Devanagari conjuncts and vowel signs break apart with dotted circles. Also broken, and worse in one way: Chrome reorders the Arabic run right to left, which pushes the row's closing `

    The new iOS-specific items are NFD Vietnamese, Thai SARA AM and emoji overflow. The lost emoji
    character happens on every platform and probably needs its own issue once the cause is known.

  3. devswha commented on Oct 1, 2026

    @devswha
    OwnerAuthor

    PRs for the parts that can be fixed now:

    Not covered by these PRs:

    Item Why not here
    Thai น้ำ dotted circle on iPhone herdr puts SARA AM in a cell of its own, and #273 keeps that so the grid matches. Drawing it joined would mean drawing across cells.
    Arabic, Hebrew, Devanagari shaping and direction The cell grid has no bidi or complex shaping; native terminals mostly lack them too.
    Box drawing ┌─┐ ━┃╋ (desktop and iPhone) Lines are drawn from font glyphs. Pixel-exact lines need xterm's custom glyphs, which only the WebGL or canvas renderer has. Switching renderers is a separate, larger change.
    a + U+FE0F and a lone combining mark at column 0 The 2 samples out of 62 where #273 still disagrees with herdr. Both are rare, and Unicode 6 gets them wrong today too.
  4. devswha commented on Oct 1, 2026

    @devswha
    OwnerAuthor

    #272 and #273 are merged into main and will ship in the next release. I checked them on the iOS 27 simulator, which uses the same WebKit engine and system fonts as a real iPhone, but not on a real iPhone yet. If you have one, a quick look at a Korean, Japanese or emoji line in the terminal after the release would help. This issue stays open for the items not fixed yet: the Thai SARA AM dotted circle, box-drawing lines, and right-to-left and Indic shaping.

  5. devswha commented on Oct 1, 2026

    @devswha
    OwnerAuthor

    Checked again on the released build, v0.3.41, against the build before the fix (0.3.39), with the test pattern from this issue: iOS 27 simulator (iPhone 17 Pro, Safari tab, Korean locale), a pane in an isolated herdr session.

    Row 0.3.39 v0.3.41
    Korean (NFC, NFD, compatibility jamo) a gap after every syllable syllables evenly spaced, almost touching
    Japanese, Chinese same gaps fill their cells
    Mixed AB가나CDあいEF中文GH wide glyphs touch the letter before, gap after centered
    Decomposed Vietnamese drawn drawn, every mark
    ⏺ a blue emoji over the next character a text circle in its own cell
    👨‍👩‍👧 🇰🇷 ok the family emoji and the flag overlap ok, 👧 missing each in its two cells, ok clear of them

    Every row's closing | lines up in both builds.

    This was the simulator, which runs the same WebKit and system fonts as an iPhone, not a real phone. If Korean still looks spread apart on a real iPhone running v0.3.40 or later, please reopen with a screenshot.

    The items this issue listed as not covered (box-drawing lines, Thai SARA AM, right-to-left and Indic shaping) are now in #289.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions