Recursive AI

Check Unicode East Asian Width in C#

onefont is a free, open-source font and text-shaping library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

IsEastAsianWide checks a Unicode code point’s East Asian Width.

It returns true for Wide, Fullwidth, or Halfwidth and false otherwise. It doesn’t return the six-way category.

Terminal
dotnet add package RecursiveAI.OneFont

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using System.Text;
using OneFont;
foreach (var rune in "AA漢カ".EnumerateRunes())
{
    bool match = TextSegmentation
        .IsEastAsianWide(rune.Value);
    Console.WriteLine($"{rune}: {match}");
}

Unzip the example, then dotnet run.

Prints whether each code point in AA漢カ is Wide, Fullwidth, or Halfwidth.

Text
A: False
A: True
漢: True
カ: True

The full program

C#
using System;
using System.Text;
using OneFont;
 
foreach (Rune rune in "AA漢カ".EnumerateRunes())
{
    bool match = TextSegmentation
        .IsEastAsianWide(rune.Value);
    Console.WriteLine($"{rune}: {match}");
}
Text
A: False
A: True
漢: True
カ: True

The method returns false for values outside the Unicode code point range; that result isn’t a validity check. Use Rune when the input is a Unicode scalar value.

Variations

Check a supplementary code point

Append this to check U+20000, a Han ideograph that takes two UTF-16 code units but only one Rune.

C#
var ideograph = new Rune(0x20000);
bool isWide = TextSegmentation
    .IsEastAsianWide(ideograph.Value);
Console.WriteLine($"U+{ideograph.Value:X}: {isWide}");
Text
U+20000: True

Find Unicode grapheme boundaries

Measure text width


The short answer

Call TextSegmentation.IsEastAsianWide(codePoint) for a Boolean check. Despite the name, true means Wide, Fullwidth, or Halfwidth; it doesn’t mean strictly Wide. Use EnumerateRunes() for a string so you pass each Unicode scalar value once, rather than passing each UTF-16 char.

What are the Unicode East Asian Width categories?

Unicode Standard Annex #11 defines six default categories: Wide (W), Fullwidth (F), Halfwidth (H), Narrow (Na), Neutral (N), and Ambiguous (A). In the snippet, 漢 is Wide, A is Fullwidth, and カ is Halfwidth. They all return true. ASCII A is Narrow and returns false. The Boolean doesn’t tell you which of the three matching categories you found or distinguish among the other three. If you need the six labels, look up the individual values in Unicode’s EastAsianWidth.txt for the Unicode version you support.

This grouping is documented in OneFont’s shaping and segmentation guide: “IsEastAsianWide(codePoint) is the East_Asian_Width Fullwidth, Wide or Halfwidth test.” It’s independent of which font you have installed and doesn’t tell you whether a specific font has a glyph for a character.

Can you use East Asian Width to measure terminal columns?

Not with this check. Counting every true result as two columns treats halfwidth カ the same as fullwidth A. Counting every false as one column also ignores how the terminal handles ambiguous-width characters and characters that combine. Unicode’s scope note says the property isn’t an off-the-shelf solution for modern terminals. Use a width policy that matches your terminal for a character sequence, or use shaped advances when you need the width of text in a particular font rather than a column count.

All onefont recipes