2538Real displayed width of a character
- Oct 24, 2008Hi all,
I have a question about "displayed width" (and not encoding length!) of a character. How does vim "decide" the width of a character, in term of number of columns? Does it use some function like "wcwidth" (POSIX function)? Some home-made similar function?
The reason I ask this is that some characters sometimes would be single or double column depending on the used font. Moreover Unicode, as far as I could read, does not explicitely give a prefered size for characters, in the exception of some characters (mostly East-Asian), which are in dedicated Unicode planes (full-width and half-width characters). This is explained in this Technical Report for instance (the only paper from the Unicode Consortium I found which was dealing about character width as the main topic,elsewhere I could only find allusions, or small notes, as though it was implicit)
An extract from this:
Except for a few characters, which are explicitly called out as fullwidth or halfwidth in the Unicode Standard, characters are not duplicated based on distinction in width. Some characters, such as the ideographs, are always wide; others are always narrow; and some can be narrow or wide, depending on the context. The Unicode character property East_Asian_Width provides a default classification of characters, which an implementation can use to decide at runtime whether to treat a character as narrow or wide.
Even though it is focused on East-Asian characters, I could find some other characters which have very different sizes in different fonts. For instance I found a few fonts with '@' being double size compared to "typical" western characters (A-Z 0-9, etc.). Also this true for the European money character (euro: €), or even the Latin characters œ or æ (used in French among other places). I would even say that this seems logical as these characters are formed by including 2 characters in each other... So being double size seems normal to me, isn't it?
Unfortunately a function like wcwidth considers it must be "one column wide", and apparently the function used by vim too (being the same or another). Then I must find a font which has these characters but the same width than the rest (so mono or close). If I don't, the characters are "cut" by vim.
Would you have an idea about this? Couldn't vim be improved in such a way it would consider the font really used? This seems complicated as the font is defined in the Terminal Emulator, not in vim itself. And I could not find yet if there is some possible to advertise the used font in any terminal protocol (VT100 or else). But then what if there was an option in vim where the user could explicitely tell "I am using this font". So that when vim displays characters and then ask the terminal to "jump" to this or that column, it can calculate the right place to go, without cutting text?
You received this message from the "vim_multibyte" maillist.
For more information, visit http://www.vim.org/maillist.php
- Next post in topic >>