2005年12月15日

消えたukaiの謎

ttf-arphic-ukaiのukai.ttf、ttf-arphic-umingのuming.ttfに対してfontforgeでフォント切り出しをしたときに、ポイント番号21033の「利」が常に空になってしまう(これだけでなく、ほかにもいくつか同様のものがある)。このせいでsazanamiが使われて中国語ユーザーには嬉しくないことになってしまうわけか。

原因がよくわからなくて困り中。元のフォントには正しく「利」と出ているし、sazanamiでやってみるとちゃんと入る。

stripttfスクリプト。これに「./stripttf /usr/share/fonts/truetype/arphic/uming.ttf test.ttf 21033」とやってみると、「Warning: Glyph 1 is named .null which should mean it is mapped to Unicode U+0000, but Glyph 3 already has that encoding. 警告: フォント内にグリフがありません」になっちゃうなぁ。

#! /usr/bin/fontforge 
#
# stripttf - Strip TrueType font of unused characters
#
# Copyright (c) 2005 Hidetaka Iwai  
#  

if ($argc < 4)
   Print( "Usage: stripttf in out used_codepoint..." )
   Quit()
endif

Open($1); shift
Reencode("unicode")
out = $1; shift

# Get the size of array from the last argument 
# (to do this, the given list must be sorted)
num = Strtol($argv[$argc - 1]) + 1

# Create an array to select used characters.
used = Array(num)

# Select used characters according to the given list
i = 0
while (i < num && $argc > 1)
  if (i == Strtol($1))
    used[i] = 1; shift
  else
    used[i] = 0
  endif
  ++i
endloop

# Remove unused characters.
Select(used); SelectInvert(); Clear()

# Output the result
Generate(out, "")
Quit()