问题
How to check if a unicode character is full width?
I use Win32 / MFC
For example, 中
is full width, A
is not full width, F
is full width, F
is not full width.
回答1:
What you need is to retrieve the East Asian Width of the character. You can do it by parsing the EastAsianWidth.txt file from the Unicode Character Database. I could not find a Win32 API that returns this info, but in Python, for example, you can use unicodedata.east_asian_width(unichr).
See the Annex #11 for the background of the problem and more information.
回答2:
What do you mean by "full width"? The width of a character depends on the font it is being displayed in.
If you mean whether it is a single byte character or not, it's still not clear. A single byte character in what encoding? In UTF-8, it will be a single byte character if (and only if) the code point is less than 128; if you're using UTF-16 (probable, since you're under Windows), just compare the character with 128. A single byte encoding in ISO 8859-1 (another wide spread encoding): compare with 256. For anything less than 256, the UTF-16 unit will be numerically identical to the code point in ISO 8859-1 (sometimes known as Latin-1). For the single byte encoding ASCII (almost never used today, but most of the common encodings are identical with it for the first 128 code points), anything less that 128 is good.
来源:https://stackoverflow.com/questions/20661434/c-check-if-unicode-character-is-full-width