You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should Combining characters of Category 'Mc' be width 1? #155
I'm certain I've researched this several times before, and our current measurement of 'Mc' category codes as 0 width is the result of coordination of at least 3 of the issues listed above.
Probably the largest obstacle has been finding 1 or 2 Terminal emulators that correctly display languages that include Mc characters.
UAX #44: Mc (Spacing_Mark): "a spacing combining mark (positive advance width)"
Our history,
2015: Improve handling of combining characters #1172ef7fe@philipc: Fixed bug where Mc was treated as zero-width, On problem: "it classified spacing marks (category Mc) as zero width [...] Characters with a general category of Mc are not included [in zero-width table], and so use the default width of 1."
Unicode Specification (theoretical): Mc = "positive advance width" -- should be width 1
Terminal Reality (practical): - Indic scripts like Devanagari, Tamil, Kannada render Mc characters as combining marks with zero terminal cells - Issue #47 documented: text alignment broke when Mc was width 1
Our interpretation is INCORRECT per Unicode specs, but CORRECT for matching actual terminal behavior. This library aims to be a general purpose measuring library that (independently) best reflects how most terminals supporting unicode measure width.
I recall on this issue in particular, even if "correctly measured", they may not be legible in most (any?) terminals.
The kinds of languages with issues like this are probably best served with variable-sized fonts and be free from constraints of monospacing.
I've been investigating this within Ghostty as part of this PR to use my uucode library grapheme break implementation, which actually caused the ucs-detect score for Ghostty to go down.
To research this, I have a branch that measures the visual width of a glyph (the position.x + glyph.size.width), and compares that to the uucode-determined width and logs any mismatches. A mismatch is defined with a tolerance of X pixels, treating the actual width as either including the next cell or not if it spills up to X pixels into it (e.g. a tolerance of 3 px for a 17px-wide cell grid allows a glyph that has a visual width of 20 px to be counted as either one or two cells, but a glyph with visual width 16.999px is treated as one cell).
I tried running ucs-detect but the logs were more stable when I looped over the UDHR files several lines at a time with sleeps in between (see ttylang). I repeated this process both with Mc and Cf as zero width and with no special treatment (East Asian Width with exceptions).
Results
Taking the logs and doing a sort -u on the graphemes results in the following table (the cell grid being 17px wide, so 8.5px being half):
Tolerance
Zero
Spacing
Error Reduction
2.5px
5701
4643
19%
4px
5602
4522
19%
8.5px
5534
4384
21%
(Note: I tried getting the total number of graphemes and got 9659 by logging on every glyph instead of mismatches, though I'm not sure how much I trust that number because there was a lot of log pressure and rendering didn't look as smooth.)
And now a series of screenshots, comparing the spacing variant first, and the zero variant second. This first prints the grapheme followed by a full block, then the grapheme printed twice on the next line:
spacing:
zero:
spacing:
zero:
spacing:
zero:
A case where spacing is wrong while zero is right:
spacing (note that Ghostty caps the width to 2, so to simulate the uucode width of 3 I add a space):
zero:
spacing:
zero:
Notes
This is with Coretext (Ghostty's default on Mac), though I'd like to try Harfbuzz at some point too.
My font is the Ghostty default "JetBrains Mono", but logging the fallback fonts gives me this (showing the first code point where a fallback font is used):
found codepoint 0x4E16 in fallback face=PingFang SC Regular
found codepoint 0xC138 in fallback face=Arial Unicode MS
found codepoint 0xA78C in fallback face=Menlo Regular
found codepoint 0x712 in fallback face=Noto Sans Syriac Regular Regular
found codepoint 0x1235 in fallback face=Kefa III Regular Regular
found codepoint 0xAA81 in fallback face=Noto Sans Tai Viet Regular
found codepoint 0x1111F in fallback face=Noto Sans Chakma Regular
found codepoint 0x13C2 in fallback face=Geneva
found codepoint 0x1401 in fallback face=Euphemia UCAS
found codepoint 0x791 in fallback face=Noto Sans Thaana Regular
found codepoint 0x1E907 in fallback face=Noto Sans Adlam Regular
found codepoint 0xA2E7 in fallback face=Songti SC Regular
found codepoint 0xA9A5 in fallback face=Noto Sans Javanese Regular
found codepoint 0x92 in fallback face=Songti SC Black
found codepoint 0x179F in fallback face=Khmer MN
found codepoint 0x1A20 in fallback face=Noto Sans Tai Tham
found codepoint 0xD7B in fallback face=Malayalam MN
found codepoint 0x6CF in fallback face=Courier New
found codepoint 0x101C in fallback face=Noto Serif Myanmar Regular
found codepoint 0x529 in fallback face=DIN Condensed Bold
found codepoint 0x1132E in fallback face=Grantha Sangam MN Regular
found codepoint 0xDB8 in fallback face=Sinhala Sangam MN
found codepoint 0x1700 in fallback face=Noto Sans Tagalog Regular
found codepoint 0x2D49 in fallback face=Noto Sans Tifinagh Regular
found codepoint 0xA57A in fallback face=Noto Sans Vai Regular
Finally, you may notice in the gist above that some graphemes log with 0 visual width or multiple times with different visual widths. I'm not too familiar with font shaping, so I'm not positive what's happening there (though my investigation did catch a bug in Ghostty that I'll be PR'ing soon). There are interesting things I caught it doing, like rendering some Tai Tham vowels before the consonants that they follow.
Summary
Handling the many scripts that don't have monospaced fonts in a terminal context is a tricky endeavor. With spacing marks, it's not correct to simply "add one to the width for every spacing mark", but the above shows treating them all as zero width isn't good either. (Note, I even tried "add 0.5 to the width, and take the ceil", but that did worse than the spacing variant above that mostly adds 1.)
So, what then should be done? We could investigate better algorithms that match closer to the existing fonts in these languages. Until then, I think it's better to treat spacing marks according to East Asian Width (usually width 1), and limit the number of overlapping glyphs, like the ones seen above.
Thanks for all of this. It sounds like you suggest that a width of 1 is better "default" for category Mc, even though it is in error for some, the total number of errors are fewer than when it is defined as a width of 0.
With spacing marks, it's not correct to simply "add one to the width for every spacing mark", but the above shows treating them all as zero width isn't good either.
I think i see two classes of issues?
complex combining rules, "when codepoint is following any of codepoints, width of X, otherwise width of Y". This is common for some kinds of characters, they can be displayed individually, but may sometimes modify the previous, depending on what was displayed previously, one example test case on "combining of HANGUL CHOSEONG and JUNGSEONG"
also to note, this library has a "combining browser" but it is made pretty useless because of this rule, it does not know what it should be combined with and combines everything with the letter o. Execute bin/wcwidth-browser.py with argument --combining --wide=1 and --wide=2
the combined width of complex scripts may be measured as partial cells (pixels) and not discrete cells (0, 1 or 2) as measured in this library.
That has always been my finding, and a difficulty with this specific POSIX-compatible library interface, that it is mainly deciding whether it advances 0, 1, or 2 cells as each next character is processed. There is no allowance for pixels or half-cell calculations by the current API.
But I'm very open to ideas. Do you think it is possible to involve a font engine in our code generation step to create tables to help decide whether a Mc category text is "usually" a width of 0 or 1 when used in its usual way? Or even, to build complex tables, eg. "when codepoint is following any of codepoints, width of X, otherwise width of Y",
If there is anything I can do in ucs-detect to more correctly measure the results I'm happy to help or merge. I could add a --line-sleep-delay, or, maybe I can improve ucs-detect accuracy by mixing in yaml declarations, "expect this result from this series of codepoints", generated by help of a font engine, bypassing wcwidth's naive calculations.
Hey @jquast, yeah, my research pointed to a width of 1 being a better default than 0, despite it being wrong in many cases. I went with just calling these width 1 in uucode, here until some better standard comes along.
I did solve the "default" problem, but I think I am close to solving the "Virama Conjunct Formation" problem, I think this is all that remains to solve for and its becoming more clear as I work on it
Activity
jquast commentedon Nov 16, 2025
UAX #44: Mc (Spacing_Mark): "a spacing combining mark (positive advance width)"
Our history,
Unicode Specification (theoretical): Mc = "positive advance width" -- should be width 1
Terminal Reality (practical): - Indic scripts like Devanagari, Tamil, Kannada render Mc characters as combining marks with zero terminal cells - Issue #47 documented: text alignment broke when Mc was width 1
Our interpretation is INCORRECT per Unicode specs, but CORRECT for matching actual terminal behavior. This library aims to be a general purpose measuring library that (independently) best reflects how most terminals supporting unicode measure width.
I recall on this issue in particular, even if "correctly measured", they may not be legible in most (any?) terminals.
The kinds of languages with issues like this are probably best served with variable-sized fonts and be free from constraints of monospacing.
jacobsandlund commentedon Dec 9, 2025
I've been investigating this within Ghostty as part of this PR to use my uucode library grapheme break implementation, which actually caused the
ucs-detectscore for Ghostty to go down.To research this, I have a branch that measures the visual width of a glyph (the
position.x + glyph.size.width), and compares that to theuucode-determined width and logs any mismatches. A mismatch is defined with a tolerance of X pixels, treating the actual width as either including the next cell or not if it spills up to X pixels into it (e.g. a tolerance of 3 px for a 17px-wide cell grid allows a glyph that has a visual width of 20 px to be counted as either one or two cells, but a glyph with visual width 16.999px is treated as one cell).I tried running
ucs-detectbut the logs were more stable when I looped over the UDHR files several lines at a time with sleeps in between (see ttylang). I repeated this process both withMcandCfas zero width and with no special treatment (East Asian Width with exceptions).Results
Taking the logs and doing a
sort -uon the graphemes results in the following table (the cell grid being 17px wide, so 8.5px being half):(Note: I tried getting the total number of graphemes and got 9659 by logging on every glyph instead of mismatches, though I'm not sure how much I trust that number because there was a lot of log pressure and rendering didn't look as smooth.)
Diff
Taking the
git diff --no-indexbetween the zero-width and spacing variants, also includingxas visual width (not included in thesort -ucounts above), gives the results in this gist: https://gist.github.com/jacobsandlund/3cef918093a7b328d645924f438d4891For example, here's a dense section (red are errors only present in the
zerovariant, and green are errors only present in thespacingvariant):Screenshots
And now a series of screenshots, comparing the
spacingvariant first, and thezerovariant second. This first prints the grapheme followed by a full block, then the grapheme printed twice on the next line:spacing:

zero:

spacing:
zero:
spacing:
zero:
A case where
spacingis wrong whilezerois right:spacing (note that Ghostty caps the width to 2, so to simulate the
uucodewidth of 3 I add a space):zero:
spacing:
zero:
Notes
This is with Coretext (Ghostty's default on Mac), though I'd like to try Harfbuzz at some point too.
My font is the Ghostty default "JetBrains Mono", but logging the fallback fonts gives me this (showing the first code point where a fallback font is used):
Finally, you may notice in the gist above that some graphemes log with 0 visual width or multiple times with different visual widths. I'm not too familiar with font shaping, so I'm not positive what's happening there (though my investigation did catch a bug in Ghostty that I'll be PR'ing soon). There are interesting things I caught it doing, like rendering some Tai Tham vowels before the consonants that they follow.
Summary
Handling the many scripts that don't have monospaced fonts in a terminal context is a tricky endeavor. With spacing marks, it's not correct to simply "add one to the width for every spacing mark", but the above shows treating them all as zero width isn't good either. (Note, I even tried "add 0.5 to the width, and take the ceil", but that did worse than the
spacingvariant above that mostly adds 1.)So, what then should be done? We could investigate better algorithms that match closer to the existing fonts in these languages. Until then, I think it's better to treat spacing marks according to East Asian Width (usually width 1), and limit the number of overlapping glyphs, like the ones seen above.
font/coretext: Use positions to correct glyph placement (#9883)
jquast commentedon Jan 11, 2026
Thanks for all of this. It sounds like you suggest that a width of 1 is better "default" for category Mc, even though it is in error for some, the total number of errors are fewer than when it is defined as a width of 0.
I think i see two classes of issues?
codepointis following any ofcodepoints, width of X, otherwise width of Y". This is common for some kinds of characters, they can be displayed individually, but may sometimes modify the previous, depending on what was displayed previously, one example test case on "combining of HANGUL CHOSEONG and JUNGSEONG"o. Execute bin/wcwidth-browser.py with argument--combining --wide=1and--wide=2That has always been my finding, and a difficulty with this specific POSIX-compatible library interface, that it is mainly deciding whether it advances 0, 1, or 2 cells as each next character is processed. There is no allowance for pixels or half-cell calculations by the current API.
But I'm very open to ideas. Do you think it is possible to involve a font engine in our code generation step to create tables to help decide whether a Mc category text is "usually" a width of 0 or 1 when used in its usual way? Or even, to build complex tables, eg. "when
codepointis following any ofcodepoints, width of X, otherwise width of Y",If there is anything I can do in ucs-detect to more correctly measure the results I'm happy to help or merge. I could add a --line-sleep-delay, or, maybe I can improve ucs-detect accuracy by mixing in yaml declarations, "expect this result from this series of codepoints", generated by help of a font engine, bypassing wcwidth's naive calculations.
font/coretext: Use positions to correct glyph placement (#9883)
jacobsandlund commentedon Jan 27, 2026
Hey @jquast, yeah, my research pointed to a width of 1 being a better default than 0, despite it being wrong in many cases. I went with just calling these width 1 in uucode, here until some better standard comes along.
Have you seen the Proper Complex Script Support
in Text Terminals paper? I was in a group that discussed this. If you're interested in chatting more about this, drop in to the Ghostty discord and ping me (@jacobsandlund)
jquast commentedon Jan 28, 2026
Yes I have read that paper, I used it as a basis of several core unicode tests,
references from test_core.py
wcwidth/tests/test_core.py
Line 294 in 17b0bad
wcwidth/tests/test_core.py
Line 303 in 17b0bad
wcwidth/tests/test_core.py
Line 318 in 17b0bad
wcwidth/tests/test_core.py
Line 323 in 17b0bad
wcwidth/tests/test_core.py
Line 339 in 17b0bad
wcwidth/tests/test_core.py
Line 346 in 17b0bad
wcwidth/tests/test_core.py
Line 361 in 17b0bad
wcwidth/tests/test_core.py
Line 368 in 17b0bad
jquast commentedon Jan 29, 2026
I did solve the "default" problem, but I think I am close to solving the "Virama Conjunct Formation" problem, I think this is all that remains to solve for and its becoming more clear as I work on it
Update Category "Mc" code, specs, tests (jquast#200)
Add Virama conjunct for the Brahmic scripts (jquast#204)