East Asian Widthと矩形編集
EclipseにはICU4Jがプラグインとして組み込まれているようなので、矩形編集のカラム計算にEast Asian Widthを使うようにしてみました。個々の文字幅の計算は、以下のようにしています。
public final class CharacterUtils { private CharacterUtils() {} private static List<String> EAST_ASIAN_LANGS = Arrays.asList("ja", "vi", "kr", "zh"); public static int getWidth(int codePoint) { return getWidth(codePoint, Locale.getDefault()); } public static int getWidth(int codePoint, Locale locale) { if(locale == null) { throw new NullPointerException("locale is null"); } int value = UCharacter.getIntPropertyValue(codePoint, UProperty.EAST_ASIAN_WIDTH); switch(value) { case UCharacter.EastAsianWidth.NARROW: case UCharacter.EastAsianWidth.NEUTRAL: case UCharacter.EastAsianWidth.HALFWIDTH: return 1; case UCharacter.EastAsianWidth.FULLWIDTH: case UCharacter.EastAsianWidth.WIDE: return 2; case UCharacter.EastAsianWidth.AMBIGUOUS: if(EAST_ASIAN_LANGS.contains(locale.getLanguage())) { return 2; } else { return 1; } default: return 1; } } }