我需要解析一个 TrueType 字体文件来提取某些信息,而且一切顺利,我能够解析很多文件的许多表格类型,只是它在处理一个特定文件的字形数据表(“glyf”)时遇到了麻烦。
我正在解析 indexToLoc 表,因此我知道字形在表中的位置,当我查看该特定字形的数据时,我看到了这个(带有我的注释的十六进制值):
00 02 numContours
FF D1 Xmin=-47
00 00 YMin=0
04 5D XMax=1117
05 87 YMax=1415
00 08 endPoint=8 so the first contour has 9 points [0, 8]
00 16 endPoint=0x16 so the second contour has 14 points [9, 22]
00 2F instructionLength=47
instructions:
40 2C 04 01 00 04 01 4A 05 01 00 00 02 01 00 02
61 00 04 04 63 4B 03 01 01 01 64 01 4C 00 00 16
15 14 12 0F 0E 0A 09 00 08 00 08 06 0A 14 2B
Reading flags for first contour (has 9 points)
01 Flag[0] = OnCurve
03 Flag[1] = OnCurve, XShort
2E Flag[2] = XShort, YShort, Repeat, YSameOrPositive
01 Repeat count = 1 so Flag[3]=XShort, YShort, (Repeat), YSameOrPositive
27 Flag[4] = OnCurve, XShort, YShort, YSameOrPositive
0E Flag[5] = XShort, YShort, Repeat
01 Repeat count = 1 so Flag[6] = XShort, YShort, (Repeat)
07 Flag[7] = OnCurve, XShort, YShort
09 Flag[8] = OnCurve, Repeat
01 Repeat count = 1 so Flag[9] = OnCurve, (Repeat)
23 22 26 27 03 21 03 0E 01 2B 01 01 33 03 78 AF 04 08 04 0A 13 08 FE A0 03 29 4D 0E 10 03 65 FD 86 CB 05 16 0D 4C 02 C2 63 02 01 02 D0 12 2B 19 19 2B 13 FD 31 FD FF 0F 0B 01 9E FE 62 0B 0F 05 87 00 00
如您所见,第一个轮廓有 9 个点,因此我预计有 9 个标志值,但第 9 个标志设置了“重复”标志,因此我最终得到 10 个标志值。
当“重复”标志位于最后一个标志上时,我是否应该忽略它?还是我在解析这些字节时做了其他错误的事情?