自定义 OpenType / TrueType 字体不起作用且难以调试
Posted
技术标签:
【中文标题】自定义 OpenType / TrueType 字体不起作用且难以调试【英文标题】:Custom OpenType / TrueType font not working and difficult to debug 【发布时间】:2019-06-08 03:56:45 【问题描述】:我只是用opentype.js 随意编译了一个字体文件。这是我的最终文件的样子:
hexdump -C font.ttf
00000000 4f 54 54 4f 00 07 00 40 00 02 00 30 68 6d 74 78 |OTTO...@...0hmtx|
00000010 15 c3 8c 00 00 00 00 08 c3 b0 00 00 00 c3 b8 63 |...............c|
00000020 66 66 20 36 07 08 63 00 00 02 c2 a4 00 00 06 4a |ff 6..c........J|
00000030 70 6f 73 74 00 03 00 00 00 00 02 c2 84 00 00 00 |post............|
00000040 20 63 6d 61 70 0e c3 b8 0e c2 a7 00 00 00 70 00 | cmap.........p.|
00000050 00 02 14 6d 61 78 70 00 3e 50 00 00 00 00 68 00 |...maxp.>P....h.|
00000060 00 00 06 68 68 65 61 00 01 00 01 00 00 00 44 00 |...hhea.......D.|
00000070 00 00 24 68 65 61 64 0f c3 96 c3 be c3 bf 00 00 |..$head.........|
00000080 00 0c 00 00 00 36 00 01 00 00 00 01 00 00 00 00 |.....6..........|
00000090 00 00 5f 0f 3c c3 b5 00 00 03 c3 a8 00 00 00 00 |.._.<...........|
000000a0 c3 98 61 c3 9f 11 00 00 00 00 c3 98 61 c3 9f 11 |..a.........a...|
000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 |................|
000000c0 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 |................|
000000d0 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 |................|
000000e0 00 00 00 00 00 00 00 00 00 00 50 00 00 3e 00 00 |..........P..>..|
000000f0 00 00 00 01 00 03 00 01 00 00 00 0c 00 04 00 00 |................|
00000100 00 00 00 7e 00 40 00 05 00 3e 00 30 00 31 00 32 |...~.@...>.0.1.2|
00000110 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 41 |.3.4.5.6.7.8.9.A|
00000120 00 42 00 43 00 44 00 45 00 46 00 47 00 48 00 49 |.B.C.D.E.F.G.H.I|
00000130 00 4a 00 4b 00 4c 00 4d 00 4e 00 4f 00 50 00 51 |.J.K.L.M.N.O.P.Q|
00000140 00 52 00 53 00 54 00 55 00 56 00 57 00 58 00 59 |.R.S.T.U.V.W.X.Y|
00000150 00 5a 00 61 00 62 00 63 00 64 00 65 00 66 00 67 |.Z.a.b.c.d.e.f.g|
00000160 00 68 00 69 00 6a 00 6b 00 6c 00 6d 00 6e 00 6f |.h.i.j.k.l.m.n.o|
00000170 00 70 00 71 00 72 00 73 00 74 00 75 00 76 00 77 |.p.q.r.s.t.u.v.w|
00000180 00 78 00 79 00 7a c3 bf c3 bf 00 00 00 30 00 31 |.x.y.z.......0.1|
00000190 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 |.2.3.4.5.6.7.8.9|
000001a0 00 41 00 42 00 43 00 44 00 45 00 46 00 47 00 48 |.A.B.C.D.E.F.G.H|
000001b0 00 49 00 4a 00 4b 00 4c 00 4d 00 4e 00 4f 00 50 |.I.J.K.L.M.N.O.P|
000001c0 00 51 00 52 00 53 00 54 00 55 00 56 00 57 00 58 |.Q.R.S.T.U.V.W.X|
000001d0 00 59 00 5a 00 61 00 62 00 63 00 64 00 65 00 66 |.Y.Z.a.b.c.d.e.f|
000001e0 00 67 00 68 00 69 00 6a 00 6b 00 6c 00 6d 00 6e |.g.h.i.j.k.l.m.n|
000001f0 00 6f 00 70 00 71 00 72 00 73 00 74 00 75 00 76 |.o.p.q.r.s.t.u.v|
00000200 00 77 00 78 00 79 00 7a c3 bf c3 bf 00 04 00 04 |.w.x.y.z........|
00000210 00 04 00 04 00 04 00 04 00 04 00 04 00 04 00 04 |................|
00000220 c3 bf c3 99 c3 bf c3 99 c3 bf c3 99 c3 bf c3 99 |................|
*
00000280 c3 bf c3 99 c3 bf c3 99 c3 bf c2 9f c3 bf c2 9f |................|
00000290 c3 bf c2 9f c3 bf c2 9f c3 bf c2 9f c3 bf c2 9f |................|
*
000002f0 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000370 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000380 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000390 01 00 04 01 00 01 01 01 04 66 6f 6f 00 01 01 01 |.........foo....|
000003a0 26 c3 b8 1b 00 c3 b8 1c 02 c3 b8 1d 03 c3 b8 1e |&...............|
000003b0 04 c2 8b c2 8b c3 b7 5c c3 a5 05 1d 00 00 00 c3 |.......\........|
000003c0 88 0f 1d 00 00 01 43 11 c2 8b 1d 00 00 06 4a 12 |......C.......J.|
000003d0 00 41 01 01 06 0b 0e 0f 10 11 12 13 14 15 16 17 |.A..............|
000003e0 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 |........ !"#$%&'|
000003f0 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 |()*+,-./01234567|
00000400 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 |89:;<=>?@ABCDEFG|
00000410 48 49 4a 4b 4c 30 2e 30 2e 30 66 6f 6f 20 20 66 |HIJKL0.0.0foo f|
00000420 6f 6f 20 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e |oo bcdefghijklmn|
00000430 6f 70 71 72 73 74 75 76 77 78 79 7a 41 42 43 44 |opqrstuvwxyzABCD|
00000440 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 |EFGHIJKLMNOPQRST|
00000450 55 56 57 58 59 5a 30 31 32 33 34 35 36 37 38 39 |UVWXYZ0123456789|
00000460 00 00 00 01 c2 8b 01 c2 8c 01 c2 8d 01 c2 8e 01 |................|
00000470 c2 8f 01 c2 90 01 c2 91 01 c2 92 01 c2 93 01 c2 |................|
00000480 94 01 c2 95 01 c2 96 01 c2 97 01 c2 98 01 c2 99 |................|
00000490 01 c2 9a 01 c2 9b 01 c2 9c 01 c2 9d 01 c2 9e 01 |................|
000004a0 c2 9f 01 c2 a0 01 c2 a1 01 c2 a2 01 c2 a3 01 c2 |................|
000004b0 a4 01 c2 a5 01 c2 a6 01 c2 a7 01 c2 a8 01 c2 a9 |................|
000004c0 01 c2 aa 01 c2 ab 01 c2 ac 01 c2 ad 01 c2 ae 01 |................|
000004d0 c2 af 01 c2 b0 01 c2 b1 01 c2 b2 01 c2 b3 01 c2 |................|
000004e0 b4 01 c2 b5 01 c2 b6 01 c2 b7 01 c2 b8 01 c2 b9 |................|
000004f0 01 c2 ba 01 c2 bb 01 c2 bc 01 c2 bd 01 c2 be 01 |................|
00000500 c2 bf 01 c3 80 01 c3 81 01 c3 82 01 c3 83 01 c3 |................|
00000510 84 01 c3 85 01 c3 86 01 c3 87 00 3e 02 00 01 00 |...........>....|
00000520 1f 00 31 00 33 00 45 00 56 00 67 00 7f 00 c2 94 |..1.3.E.V.g.....|
00000530 00 c2 a8 00 c2 b9 00 c3 91 00 c3 9c 00 c3 b5 01 |................|
00000540 0d 01 19 01 2c 01 3f 01 56 01 64 01 72 01 7d 01 |....,.?.V.d.r..|
00000550 c2 88 01 c2 a2 01 c2 b0 01 c3 81 01 c3 95 01 c3 |................|
00000560 a9 02 02 02 11 02 2f 02 46 02 5a 02 75 02 c2 8c |....../.F.Z.u...|
00000570 02 c2 a3 02 c2 b6 02 c3 8f 02 c3 9b 02 c3 af 03 |................|
00000580 01 03 0c 03 1f 03 31 03 4a 03 56 03 65 03 72 03 |......1.J.V.e.r.|
00000590 7f 03 c2 92 03 c2 a3 03 c2 b4 03 c3 89 03 c3 9a |................|
000005a0 03 c3 b1 04 08 04 19 04 2e 04 3c 04 50 04 5f 04 |..........<.P._.|
000005b0 74 04 c2 87 c3 a5 c2 95 c3 b7 34 05 c2 8b 77 15 |t.........4...w.|
000005c0 c3 9b c2 9f 05 3b c2 8b 05 c3 9b c2 8b 15 3b 77 |.....;........;w|
000005d0 05 c2 8b c3 87 15 c3 9b 4f 05 c2 8b c3 87 15 0e |........O.......|
000005e0 c3 a5 c2 95 c2 9f 05 c2 8b c3 b7 48 15 c2 8b 27 |...........H...'|
000005f0 05 c2 a9 c2 8b 15 6d c3 af 15 0e c3 a5 0e c3 a5 |......m.........|
00000600 c3 a5 c2 9f 05 c2 8b c3 b7 48 15 c2 8b 27 05 6d |.........H...'.m|
00000610 c2 8b 15 c2 a9 c3 af 15 0e c3 a5 c3 a5 c3 af 05 |................|
00000620 6d c2 8b 15 c2 a9 c3 af 15 3b 59 05 c3 91 c2 8b |m........;Y.....|
00000630 15 0e c3 a5 c3 a5 c3 af 05 6d c2 8b 15 59 c3 af |.........m...Y..|
00000640 15 c2 8b 59 05 c3 91 c2 8b 15 0e c3 a5 c3 a5 c3 |...Y............|
00000650 af 05 6d c2 8b 15 c2 a9 c3 af 15 c2 8b 59 05 63 |..m..........Y.c|
00000660 c2 8b 15 c2 b3 c2 8b 05 c2 8b c3 b7 16 15 0e c3 |................|
00000670 a5 c2 95 c2 9f 05 c2 8b c3 b7 48 15 c2 8b 59 05 |..........H...Y.|
00000680 c3 9b c2 8b 15 c2 8b 59 05 c2 8b c3 af 15 0e c3 |.......Y........|
00000690 a5 c2 95 c3 af 05 c3 9b c2 8b 15 63 c2 8b 05 c2 |...........c....|
000006a0 8b c3 af 15 63 c2 8b 05 c3 9b c2 8b 15 0e c3 a5 |....c...........|
000006b0 c2 95 c3 af 05 c3 9b c2 8b 15 3b c3 af 05 c2 a9 |..........;.....|
000006c0 c2 8b 15 c2 a9 27 15 0e c3 a5 c2 95 c2 9f 05 c2 |.....'..........|
000006d0 8b c3 b7 48 15 c2 8b 59 05 c2 b3 c2 8b 15 c2 a9 |...H...Y........|
000006e0 59 15 c2 95 c3 af 05 3b 59 15 0e c3 a5 c2 95 c3 |Y......;Y.......|
000006f0 af 05 c2 8b c3 91 15 c3 9b c2 a9 15 0e c3 a5 c2 |................|
00000700 95 c3 b7 0c 05 c2 8b c2 8b 05 c2 8b c3 9b 15 c2 |................|
00000710 b3 3b 05 c2 8b c3 9b 15 c2 b3 3b 05 c2 8b c3 b7 |.;........;.....|
00000720 34 15 0e c3 a5 c2 95 c3 b7 02 05 c2 8b c2 8b 05 |4...............|
00000730 c2 8b c3 a5 15 c2 95 27 05 c3 87 c3 af 15 c2 8b |.......'........|
00000740 c2 8b 05 c2 95 27 15 0e c3 a5 c2 95 c3 b7 20 05 |.....'........ .|
00000750 c3 9b c2 9f 15 3b 77 15 0e c3 a5 c2 95 c3 af 05 |.....;w.........|
00000760 c2 8b c3 b7 48 15 c2 8b c3 bb 48 05 c2 a9 c2 8b |....H.....H.....|
00000770 15 6d c3 af 15 0e c3 a5 c3 a5 c3 af 05 c2 8b c3 |.m..............|
00000780 b7 48 15 c2 8b c3 bb 48 05 6d c2 8b 15 c2 a9 c3 |.H.....H.m......|
00000790 af 15 0e c3 a5 c2 95 c3 af 05 c2 8b c3 af 15 c2 |................|
000007a0 8b 59 05 c2 b3 c2 8b 15 63 59 15 c3 9b c3 af 05 |.Y......cY......|
000007b0 3b 59 15 0e c3 a5 c3 a5 c3 af 05 54 c2 8b 15 c2 |;Y.........T....|
000007c0 a9 c2 bd 15 54 c2 bd 15 0e c3 a5 c2 95 c3 af 05 |....T...........|
000007d0 c3 9b c2 8b 15 63 c2 8b 05 c2 8b c3 af 15 0e c3 |.....c..........|
000007e0 a5 c2 95 c3 af 05 c2 8b c3 87 15 c3 9b 4f 15 0e |.............O..|
000007f0 c3 a5 c2 95 c3 af 05 c2 b3 c3 af 15 c2 b3 27 15 |..............'.|
00000800 0e c3 a5 c2 95 c3 af 05 c2 8b c3 9b 15 c2 8b c2 |................|
00000810 8b 05 c2 8b 3b 15 c2 b3 c3 9b 05 c2 8b 3b 15 c2 |....;........;..|
00000820 b3 c3 9b 05 c2 8b 3b 15 0e c3 a5 c2 95 c3 af 05 |......;.........|
00000830 c3 9b c3 af 15 c2 8b 27 05 3b c3 af 15 0e c3 a5 |.......'.;......|
00000840 c2 95 c3 af 05 c2 8b c3 87 15 c3 9b 4f 15 63 c3 |............O.c.|
00000850 af 05 c2 8b c3 9b 15 0e c3 a5 c2 95 c3 af 05 c3 |................|
00000860 9b c2 8b 15 c2 8b c2 8b 05 3b c3 af 15 c2 8b c2 |.........;......|
00000870 8b 05 c3 9b c2 8b 15 0e c3 a5 c2 95 c3 b7 5c 05 |..............\.|
00000880 c2 b3 c3 bb 48 15 c2 b3 c3 b7 48 15 4b 3b 05 c2 |....H.....H.K;..|
00000890 bd c2 8b 15 0e c3 a5 c2 95 c2 9f 05 c2 8b c3 b7 |................|
000008a0 48 15 c2 8b c3 bb 48 05 c2 a9 c2 8b 15 6d c3 9b |H.....H......m..|
000008b0 15 c2 a9 c2 8b 05 6d c3 af 15 0e c3 a5 c3 a5 c2 |......m.........|
000008c0 9f 05 6d c2 8b 15 59 c3 b7 16 15 c3 9b c2 bd 15 |..m...Y.........|
000008d0 0e c3 a5 c2 95 c2 9f 05 c2 a9 c2 8b 15 c2 bd c2 |................|
000008e0 bd 05 59 c3 b7 16 05 c2 bd c3 bb 16 15 59 c3 b7 |..Y..........Y..|
000008f0 16 05 6d c2 8b 15 c2 8b c3 bb 48 15 0e c3 a5 c3 |..m.......H.....|
00000900 a5 c2 9f 05 3b c2 8b 15 c2 8b c3 9b 15 c3 91 c2 |....;...........|
00000910 8b 15 45 c2 8b 05 c2 8b c3 af 15 c3 9b c2 8b 15 |..E.............|
00000920 0e c3 a5 c3 a5 c2 9f 05 3b c2 8b 15 c2 8b c3 9b |........;.......|
00000930 15 c3 91 c2 8b 15 45 c2 8b 05 c2 8b c3 af 15 0e |......E.........|
00000940 c3 a5 c3 a5 c2 9f 05 6d c2 8b 15 59 c3 b7 16 15 |.......m...Y....|
00000950 c3 9b c2 bd 15 c2 8b 3b 05 c2 8b c3 9b 15 c2 8b |.......;........|
00000960 3b 05 63 c2 8b 15 0e c3 a5 c2 95 c2 9f 05 c2 8b |;.c.............|
00000970 c3 b7 48 15 c3 9b c3 bb 48 05 c2 8b c3 b7 48 15 |..H.....H.....H.|
00000980 3b 27 05 c3 9b c2 8b 15 0e c3 a5 c2 bd c2 9f 05 |;'..............|
00000990 c2 8b c3 b7 48 15 63 c3 bb 48 05 c3 9b c2 8b 15 |....H.c..H......|
000009a0 3b c3 b7 48 05 c3 9b c2 8b 15 0e c3 a5 c2 95 c2 |;..H............|
000009b0 9f 05 c3 9b c2 8b 15 3b c3 b7 48 05 c2 a9 c2 8b |.......;..H.....|
000009c0 15 c2 a9 c3 bb 48 15 0e c3 a5 c2 95 c2 9f 05 c2 |.....H..........|
000009d0 8b c3 b7 48 15 c2 8b 27 05 c2 a9 c2 8b 15 c2 b3 |...H...'........|
000009e0 3b 15 c2 95 c3 b7 48 05 c2 8b 59 15 0e c3 a5 c2 |;.....H...Y.....|
000009f0 95 c2 9f 05 c2 8b c3 b7 2a 15 c3 9b c2 a9 15 0e |........*.......|
00000a00 c3 a5 c2 95 c3 b7 5c 05 c2 8b c3 bb 48 15 c2 b3 |......\.....H...|
00000a10 c3 9b 15 c2 b3 3b 15 c2 8b c3 b7 48 15 0e c3 a5 |.....;.....H....|
00000a20 c2 95 c3 b7 5c 05 c2 8b c3 bb 48 15 c3 9b c3 b7 |....\.....H.....|
00000a30 48 15 c2 8b c3 bb 48 15 0e c3 a5 c2 95 c3 87 05 |H.....H.........|
00000a40 c3 9b c3 af 15 3b 27 15 0e c3 a5 c2 95 c2 9f 05 |.....;'.........|
00000a50 c2 8b c3 b7 48 15 c2 8b c3 bb 48 05 c2 a9 c2 8b |....H.....H.....|
00000a60 15 6d c3 af 15 0e c3 a5 c2 95 c3 87 05 c3 9b c3 |.m..............|
00000a70 af 15 3b 27 15 c2 bd c3 b7 02 05 c2 a9 c2 a9 15 |..;'............|
00000a80 0e c3 a5 c2 95 c2 9f 05 c2 8b c3 b7 48 15 c2 8b |............H...|
00000a90 c3 bb 48 05 c2 a9 c2 8b 15 6d c3 9b 15 c3 9b c3 |..H......m......|
00000aa0 af 05 c2 8b 59 15 0e c3 a5 c3 a5 c2 9f 05 63 c2 |....Y.........c.|
00000ab0 8b 15 63 c3 b7 48 15 0e c3 a5 c2 95 c2 9f 05 c3 |..c..H..........|
00000ac0 9b c2 8b 15 63 c2 8b 05 c2 8b c3 b7 48 15 0e c3 |....c.......H...|
00000ad0 a5 c2 95 c2 9f 05 c2 8b c3 b7 20 15 c3 9b c3 bb |.......... .....|
00000ae0 20 15 0e c3 a5 c2 95 c2 9f 05 c2 b3 c3 b7 48 15 | .............H.|
00000af0 c2 b3 c3 bb 48 15 0e c3 a5 c2 95 c2 9f 05 c2 8b |....H...........|
00000b00 c3 b7 48 15 c2 b3 3b 15 c2 b3 c3 9b 15 c2 8b c3 |..H...;.........|
00000b10 bb 48 15 0e c3 a5 c2 95 c2 9f 05 c3 9b c3 b7 48 |.H.............H|
00000b20 15 c2 8b c3 bb 48 05 3b c3 b7 48 15 0e c3 a5 c2 |.....H.;..H.....|
00000b30 95 c2 9f 05 c2 b3 c3 9b 15 c2 b3 3b 15 63 c3 9b |...........;.c..|
00000b40 05 c2 8b c3 af 15 0e c3 a5 c2 95 c2 9f 05 c3 9b |................|
00000b50 c2 8b 15 c2 8b c2 8b 05 3b c3 b7 48 15 c2 8b c2 |........;..H....|
00000b60 8b 05 c3 9b c2 8b 15 0e c3 a5 c2 95 c3 87 05 c3 |................|
00000b70 9b c3 af 15 3b 27 15 c2 b3 c2 b3 05 c2 8b c2 9f |....;'..........|
00000b80 15 0e c3 a5 c2 bd c2 9f 05 c2 8b c3 b7 48 15 77 |.............H.w|
00000b90 c3 bb 34 05 c2 9f 77 15 63 c3 b7 48 05 c3 9b c2 |..4...w.c..H....|
00000ba0 8b 15 0e c3 a5 c2 95 c3 87 05 c3 9b c2 9f 15 3b |...............;|
00000bb0 c3 b7 0c 05 c3 9b c3 bb 0c 15 3b c3 b7 0c 05 c3 |..........;.....|
00000bc0 9b c2 8b 15 0e c3 a5 c2 95 c2 9f 05 c2 a9 c2 8b |................|
00000bd0 15 c2 86 c3 9b 15 c2 90 c2 8b 05 6d c3 af 15 0e |...........m....|
00000be0 c3 a5 c2 95 c2 9f 05 c3 9b c2 8b 15 c2 8b c2 8b |................|
00000bf0 05 3b c3 b7 48 15 c2 8b c2 8b 05 c3 9b c2 8b 15 |.;..H...........|
00000c00 0e c3 a5 c3 a5 c2 9f 05 3b c2 8b 15 c2 8b c3 9b |........;.......|
00000c10 15 c2 8b c3 af 15 0e c3 a5 c2 95 c3 b7 20 05 c3 |............. ..|
00000c20 9b c2 9f 15 3b 77 15 c2 b3 c3 bb 0c 05 63 c3 b7 |....;w.......c..|
00000c30 02 15 0e c3 a5 c2 95 c2 9f 05 c3 9b c2 8b 15 c2 |................|
00000c40 8b c2 8b 05 54 c3 b7 48 15 0e c3 a5 c2 95 c3 b7 |....T..H........|
00000c50 20 05 c3 9b c2 9f 15 3b 77 15 c2 95 31 05 c3 87 | ......;w...1...|
00000c60 c2 9f 15 4f 77 15 0e c3 a5 c2 95 c3 87 05 c3 9b |...Ow...........|
00000c70 c2 9f 15 3b 77 15 c2 b3 c3 b7 20 05 c2 b3 c3 bb |...;w..... .....|
00000c80 02 15 0e 00 00 00 5a 00 00 00 5a 00 00 00 5a 00 |......Z...Z...Z.|
00000c90 00 00 5a 00 00 00 5a 00 00 00 5a 00 00 00 5a 00 |..Z...Z...Z...Z.|
*
00000d70 00 00 5a 00 00 00 5a 00 00 00 5a 00 00 |..Z...Z...Z..|
00000d7d
这是我的font.html
文件用来测试它的样子:
<style>
@font-face
font-family: 'FooLatin';
src: url('font.ttf') format('truetype');
body
font-family: 'FooLatin';
</style>
<body>
Hello World
</body>
我不确定我使用的是 truetype 还是 opentype。但是使用此配置,我在浏览器中收到此错误:
font.html:1 Failed to decode downloaded font: file:~/tests/font.ttf
font.html:1 OTS parsing error: hmtx: invalid table offset
如果我将@font-face
定义更改为使用format('embedded-opentype')
:
<style>
@font-face
font-family: 'FooLatin';
src: url('font.ttf') format('embedded-opentype');
body
font-family: 'FooLatin';
</style>
<body>
Hello World
</body>
..错误消失了,但什么也没发生,它仍然不起作用。
我刚刚注意到这实际上是一个半有用的错误:
hmtx: invalid table offset
我会对此进行更多研究。但我还想问在这种情况下是否有任何技术可以调试字体。上面贴了程序的hexdump,但是不知道要找什么。
【问题讨论】:
头部的 OTTO 表示字体是 OpenType,如果有帮助的话 【参考方案1】:十六进制转储显示了许多严重的问题:
表目录条目未正确对齐。每个 tag/checkSum/offset/length 条目应占用 16 个字节。从转储中,您的条目似乎有一些额外的字节
表目录条目未按标签升序排序
表目录中的偏移量可疑(hmtx
的偏移量为 8,在表目录本身之前)。表目录中的偏移量是绝对的(从字体的字节 0 开始),而不是相对的(尽管在这种情况下,即使是 8 的相对偏移量也是错误的)。
CFF 表的正确标记是'CFF
'(即'C'、'F'、'F'、'',并且应该是大写,而不是小写)。
表目录似乎没有name
或OS/2
表。这些都是必需的表(请参阅OpenType specification)。虽然在某些平台上您可能无需使用 OS/2
表,但对于最小的有效字体确实需要 name
表。
这实际上是次要的,但基于 CFF 的字体应该使用扩展名 .otf
,而不是 .ttf
。但是你真的应该首先解决我上面提到的问题,并确保表目录偏移和长度条目正确指向文件其余部分中的正确数据。
一般来说,我建议花一些时间,也许是大量的时间来研究 OpenType 规范。
【讨论】:
如果你能描述一下你是如何通过查看十六进制转储来解决这个问题的,那将会有所帮助。我希望我能做到。 如果您查看 OpenType 规范,特别是“OpenType 字体文件”部分,这相当容易。该规范详细介绍了文件的内容。以上是关于自定义 OpenType / TrueType 字体不起作用且难以调试的主要内容,如果未能解决你的问题,请参考以下文章
OpenType 字体和 TrueType 字体。有啥不同?
PHP:读取字体文件的 TrueType/OpenType 元数据