Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

FontForgeスクリプトでフォントに含まれるすべてのグリフの情報を取得する

Noto Sans CJKフォントを開いたFontForgeののウィンドウの一番下を見てみると、ウィンドウ左上のIDが「66183」など65535を超える数値担っていることがわかる*1。一方で、グリフの名前は"Identity.65530"など最大65535個を表す数値のように見える。

そこで、FontForgeスクリプトを使って、フォントファイルに含まれるグリフの情報を洗いざらい出力してみることにした*2。使用したスクリプトは以下。

Open($1)
Reencode("unicode")

maxp = 66163
i = 0

while (i<maxp)
  Select(i)
  name = GlyphInfo("Name")
  unicode = GlyphInfo("Unicode")
  encoding = GlyphInfo("Encoding")
  comment = GlyphInfo("Comment")
  Print(name, " / ", unicode, " / ", encoding, " / ", comment)
  i = i+1
endloop

これを以下のように実行した。実際にフォントファイルに65535個以上のグリフが含まれているならそれだけの情報が出力されるだろうと考えたためである。 実際の実行結果配下。

$ fontforge -script get_cid_list.pe /mnt/c/tmp/NotoSansCJK-Medium001.ttf > out.txt
Copyright (c) 2000-2020. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20190801
 Based on sources from 03:10 UTC  6-Mar-2020-ML-D-GDK3.
The following table(s) in the font have been ignored by FontForge
  Ignoring 'VORG' vertical origin table
No glyph with unicode U+04e0d in font
No glyph with unicode U+04e32 in font
No glyph with unicode U+04e39 in font
No glyph with unicode U+04e82 in font
No glyph with unicode U+04e86 in font
No glyph with unicode U+04eae in font
No glyph with unicode U+04ec0 in font
No glyph with unicode U+04ee4 in font
No glyph with unicode U+04f86 in font
No glyph with unicode U+04f8b in font
No glyph with unicode U+04fbf in font
No glyph with unicode U+0502b in font
No glyph with unicode U+050da in font
No glyph with unicode U+05169 in font
No glyph with unicode U+0516d in font
No glyph with unicode U+051b7 in font
No glyph with unicode U+051c9 in font
No glyph with unicode U+051cc in font
No glyph with unicode U+051dc in font
No glyph with unicode U+05207 in font
No glyph with unicode U+05217 in font
No glyph with unicode U+05229 in font
No glyph with unicode U+0523a in font
No glyph with unicode U+05289 in font
No glyph with unicode U+0529b in font
No glyph with unicode U+052a3 in font
No glyph with unicode U+052d2 in font
No glyph with unicode U+052de in font
No glyph with unicode U+052f5 in font
No glyph with unicode U+05317 in font
No glyph with unicode U+0533f in font
No glyph with unicode U+05375 in font
No glyph with unicode U+053c3 in font
No glyph with unicode U+053e5 in font
No glyph with unicode U+0540f in font
No glyph with unicode U+0541d in font
No glyph with unicode U+05442 in font
No glyph with unicode U+054bd in font
No glyph with unicode U+05587 in font
No glyph with unicode U+056f9 in font
No glyph with unicode U+0585e in font
No glyph with unicode U+058d8 in font
No glyph with unicode U+058df in font
No glyph with unicode U+05948 in font
No glyph with unicode U+05973 in font
No glyph with unicode U+05b85 in font
No glyph with unicode U+05bee in font
No glyph with unicode U+05c3f in font
No glyph with unicode U+05c62 in font
No glyph with unicode U+05c65 in font
No glyph with unicode U+05d19 in font
No glyph with unicode U+05d50 in font
No glyph with unicode U+05dba in font
No glyph with unicode U+05e74 in font
No glyph with unicode U+05ea6 in font
No glyph with unicode U+05ed3 in font
No glyph with unicode U+05eec in font
No glyph with unicode U+05f04 in font
No glyph with unicode U+05f8b in font
No glyph with unicode U+05fa9 in font
No glyph with unicode U+05ff5 in font
No glyph with unicode U+06012 in font
No glyph with unicode U+0601c in font
No glyph with unicode U+060e1 in font
No glyph with unicode U+06144 in font
No glyph with unicode U+06190 in font
No glyph with unicode U+061f6 in font
No glyph with unicode U+06200 in font
No glyph with unicode U+0622e in font
No glyph with unicode U+062c9 in font
No glyph with unicode U+062cf in font
No glyph with unicode U+062d3 in font
No glyph with unicode U+062fe in font
No glyph with unicode U+0637b in font
No glyph with unicode U+063a0 in font
No glyph with unicode U+0649a in font
No glyph with unicode U+064c4 in font
No glyph with unicode U+06578 in font
No glyph with unicode U+06599 in font
No glyph with unicode U+06613 in font
No glyph with unicode U+06688 in font
No glyph with unicode U+066b4 in font
No glyph with unicode U+066c6 in font
No glyph with unicode U+066f4 in font
No glyph with unicode U+06713 in font
No glyph with unicode U+0674e in font
No glyph with unicode U+0677b in font
No glyph with unicode U+06797 in font
No glyph with unicode U+067f3 in font
No glyph with unicode U+06817 in font
No glyph with unicode U+06881 in font
No glyph with unicode U+068a8 in font
No glyph with unicode U+06a02 in font
No glyph with unicode U+06a13 in font
No glyph with unicode U+06ad3 in font
No glyph with unicode U+06adb in font
No glyph with unicode U+06af8 in font
No glyph with unicode U+06b77 in font
No glyph with unicode U+06bae in font
No glyph with unicode U+06c88 in font
No glyph with unicode U+06ccc in font
No glyph with unicode U+06ce5 in font
No glyph with unicode U+06d1b in font
No glyph with unicode U+06d1e in font
No glyph with unicode U+06d41 in font
No glyph with unicode U+06d6a in font
No glyph with unicode U+06dcb in font
No glyph with unicode U+06dda in font
No glyph with unicode U+06dea in font
No glyph with unicode U+06e9c in font
No glyph with unicode U+06ed1 in font
No glyph with unicode U+06f0f in font
No glyph with unicode U+06f23 in font
No glyph with unicode U+06feb in font
No glyph with unicode U+06ffe in font
No glyph with unicode U+07099 in font
No glyph with unicode U+070c8 in font
No glyph with unicode U+070d9 in font
No glyph with unicode U+07149 in font
No glyph with unicode U+071ce in font
No glyph with unicode U+071d0 in font
No glyph with unicode U+07210 in font
No glyph with unicode U+0721b in font
No glyph with unicode U+07262 in font
No glyph with unicode U+072c0 in font
No glyph with unicode U+072fc in font
No glyph with unicode U+07375 in font
No glyph with unicode U+07387 in font
No glyph with unicode U+073b2 in font
No glyph with unicode U+073de in font
No glyph with unicode U+07406 in font
No glyph with unicode U+07409 in font
No glyph with unicode U+07469 in font
No glyph with unicode U+07489 in font
No glyph with unicode U+07498 in font
No glyph with unicode U+07559 in font
No glyph with unicode U+07565 in font
No glyph with unicode U+07570 in font
No glyph with unicode U+075e2 in font
No glyph with unicode U+07642 in font
No glyph with unicode U+07669 in font
No glyph with unicode U+076e7 in font
No glyph with unicode U+07701 in font
No glyph with unicode U+0786b in font
No glyph with unicode U+0788c in font
No glyph with unicode U+078ca in font
No glyph with unicode U+078fb in font
No glyph with unicode U+0792a in font
No glyph with unicode U+0797f in font
No glyph with unicode U+079ae in font
No glyph with unicode U+079ca in font
No glyph with unicode U+07a1c in font
No glyph with unicode U+07acb in font
No glyph with unicode U+07b20 in font
No glyph with unicode U+07c60 in font
No glyph with unicode U+07c92 in font
No glyph with unicode U+07ce7 in font
No glyph with unicode U+07d10 in font
No glyph with unicode U+07d22 in font
No glyph with unicode U+07d2f in font
No glyph with unicode U+07da0 in font
No glyph with unicode U+07dbe in font
No glyph with unicode U+07e37 in font
No glyph with unicode U+07f79 in font
No glyph with unicode U+07f85 in font
No glyph with unicode U+07f9a in font
No glyph with unicode U+08001 in font
No glyph with unicode U+08046 in font
No glyph with unicode U+0806f in font
No glyph with unicode U+0807e in font
No glyph with unicode U+0808b in font
No glyph with unicode U+081d8 in font
No glyph with unicode U+081e8 in font
No glyph with unicode U+0826f in font
No glyph with unicode U+082e5 in font
No glyph with unicode U+08336 in font
No glyph with unicode U+083c9 in font
No glyph with unicode U+083f1 in font
No glyph with unicode U+0843d in font
No glyph with unicode U+08449 in font
No glyph with unicode U+084fc in font
No glyph with unicode U+085cd in font
No glyph with unicode U+085fa in font
No glyph with unicode U+08606 in font
No glyph with unicode U+0863f in font
No glyph with unicode U+087ba in font
No glyph with unicode U+0881f in font
No glyph with unicode U+0884c in font
No glyph with unicode U+088c2 in font
No glyph with unicode U+088cf in font
No glyph with unicode U+088e1 in font
No glyph with unicode U+088f8 in font
No glyph with unicode U+08964 in font
No glyph with unicode U+0898b in font
No glyph with unicode U+08aaa in font
No glyph with unicode U+08ad2 in font
No glyph with unicode U+08ad6 in font
No glyph with unicode U+08afe in font
No glyph with unicode U+08b58 in font
No glyph with unicode U+08c48 in font
No glyph with unicode U+08cc2 in font
No glyph with unicode U+08cc8 in font
No glyph with unicode U+08def in font
No glyph with unicode U+08eca in font
No glyph with unicode U+08f26 in font
No glyph with unicode U+08f2a in font
No glyph with unicode U+08f3b in font
No glyph with unicode U+08f62 in font
No glyph with unicode U+08fb0 in font
No glyph with unicode U+09038 in font
No glyph with unicode U+0908f in font
No glyph with unicode U+090ce in font
No glyph with unicode U+090de in font
No glyph with unicode U+0916a in font
No glyph with unicode U+091b4 in font
No glyph with unicode U+091cc in font
No glyph with unicode U+091cf in font
No glyph with unicode U+091d1 in font
No glyph with unicode U+09234 in font
No glyph with unicode U+09304 in font
No glyph with unicode U+0934a in font
No glyph with unicode U+095ad in font
No glyph with unicode U+0962e in font
No glyph with unicode U+0964b in font
No glyph with unicode U+09675 in font
No glyph with unicode U+09678 in font
No glyph with unicode U+096b7 in font
No glyph with unicode U+096b8 in font
No glyph with unicode U+096e2 in font
No glyph with unicode U+096f6 in font
No glyph with unicode U+096f7 in font
No glyph with unicode U+09732 in font
No glyph with unicode U+09748 in font
No glyph with unicode U+09818 in font
No glyph with unicode U+099f1 in font
No glyph with unicode U+09a6a in font
No glyph with unicode U+09b6f in font
No glyph with unicode U+09c57 in font
No glyph with unicode U+09dfa in font
No glyph with unicode U+09e1e in font
No glyph with unicode U+09e7f in font
No glyph with unicode U+09ece in font
No glyph with unicode U+09f8d in font
No glyph with unicode U+0fa23 in font
No glyph with unicode U+20984 in font
No glyph with unicode U+233cc in font
No glyph with unicode U+29fce in font
No glyph with unicode U+051a4 in font
No glyph with unicode U+05be7 in font
No glyph with unicode U+05c60 in font
No glyph with unicode U+06753 in font
No glyph with unicode U+06eba in font
No glyph with unicode U+07c3e in font
Select: Character is not in font: 65536
Called from...
 get_cid_list.pe: line 9

出力結果の中身は以下のようになっており、たしかにグリフは65535個で打ち止めになっていることが確認できた*3

$ wc -l out.txt
65536 out.txt
$ tail -5 out.txt
Identity.65531 / -1 / 1761331619 /
Identity.65532 / -1 / 1761331619 /
Identity.65533 / -1 / 1761331619 /
Identity.65534 / -1 / 1761331619 /
Identity.65535 / -1 / 1761331619 /

*1:これが何をあらわす数値なのか、マニュアルからは読み取れなかった。CID?

*2:参考:スクリプトのヘルプは日本語版マニュアルのほうが使いやすい。 https://fontforge.org/docs/old/ja/scripting.html

*3:それにしてもすべてのグリフのUnicodeの値が-1になっているのはどうしてなんだろう。あと、FontForgeGUIでグリフの名前の後に表示されている文字列を取る方法がわからない……