-
Notifications
You must be signed in to change notification settings - Fork 8
/
ttfdump.c
1324 lines (1096 loc) · 27 KB
/
ttfdump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Truetype font parser.
* 2004-2009 (C) Tor Andersson.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nil ((void*)0)
#define byte unsigned char
#define ushort unsigned short
#define ulong unsigned long
static int g_nglyphs;
static int g_locafmt;
void panic(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
putc('\n', stderr);
va_end(ap);
exit(1);
}
#define TAG(a,b,c,d) ((ulong) (a<<24) | (b<<16) | (c<<8) | (d) )
static inline short readshort(FILE *f)
{
byte a = getc(f);
byte b = getc(f);
return (a << 8) | b;
}
static inline ushort readushort(FILE *f)
{
byte a = getc(f);
byte b = getc(f);
return (a << 8) | b;
}
static inline long readlong(FILE *f)
{
byte a = getc(f);
byte b = getc(f);
byte c = getc(f);
byte d = getc(f);
return (a << 24) | (b << 16) | (c << 8) | d;
}
static inline ulong readulong(FILE *f)
{
byte a = getc(f);
byte b = getc(f);
byte c = getc(f);
byte d = getc(f);
return (a << 24) | (b << 16) | (c << 8) | d;
}
/*
* OpenType tables
*/
void readlangtable(FILE *f, ulong langofs)
{
fseek(f, langofs, 0);
(void) readushort(f); /* lookup order. reserved. */
ushort reqfeatidx = readushort(f);
ushort featurecount = readushort(f);
if (reqfeatidx != 0xFFFF)
printf("req %u ", reqfeatidx);
int i;
for (i = 0; i < featurecount; i++)
{
ushort featidx = readushort(f);
printf("%u ", featidx);
}
}
void readscriptlist(FILE *f, ulong scriptlistofs)
{
ushort scriptcount;
int i, k;
fseek(f, scriptlistofs, 0);
scriptcount = readushort(f);
byte scripttag[scriptcount][4];
ushort scriptofs[scriptcount];
for (i = 0; i < scriptcount; i++)
{
fread(scripttag[i], 1, 4, f);
scriptofs[i] = readushort(f);
}
for (i = 0; i < scriptcount; i++)
{
printf(" script %4.4s\n {\n", scripttag[i]);
fseek(f, scriptlistofs + scriptofs[i], 0);
ushort defofs = readushort(f);
ushort langcount = readushort(f);
byte langtag[langcount][4];
ushort langofs[langcount];
for (k = 0; k < langcount; k++) {
fread(langtag[k], 1, 4, f);
langofs[k] = readushort(f);
}
if (defofs) {
printf("\tlang default [ ");
readlangtable(f, scriptlistofs + scriptofs[i] + defofs);
printf("]\n");
}
for (k = 0; k < langcount; k++) {
printf("\tlang %4.4s [ ", langtag[k]);
readlangtable(f, scriptlistofs + scriptofs[i] + langofs[k]);
printf("]\n");
}
printf(" }\n");
}
}
void readfeature(FILE *f, ulong ofs)
{
fseek(f, ofs, 0);
(void) readushort(f); /* feature params. reserved. */
ushort count = readushort(f);
int i;
for (i = 0; i < count; i++)
{
ushort lookup = readushort(f);
printf("%u ", lookup);
}
}
void readfeaturelist(FILE *f, ulong featlistofs)
{
ushort featcount;
int i;
fseek(f, featlistofs, 0);
featcount = readushort(f);
for (i = 0; i < featcount; i++)
{
byte tag[4];
fread(tag, 1, 4, f);
ulong featofs = readushort(f);
ulong tmpofs = ftell(f);
printf(" feat %4.4s [ ", tag);
readfeature(f, featlistofs + featofs);
printf("] %% %d\n", i);
fseek(f, tmpofs, 0);
}
}
enum { GPOS, GSUB };
void readlookup(FILE *f, ulong lookupofs, int what)
{
fseek(f, lookupofs, 0);
ushort type = readushort(f);
printf("\ttype = ");
if (what == GPOS)
{
switch (type)
{
case 1: puts("Single adjustment"); break;
case 2: puts("Pair adjustment"); break;
case 3: puts("Cursive attachment"); break;
case 4: puts("MarkToBase attachment"); break;
case 5: puts("MarkToLigature attachment"); break;
case 6: puts("MarkToMark attachment"); break;
case 7: puts("Context positioning"); break;
case 8: puts("Chained Context positioning"); break;
case 9: puts("Extension positioning"); break;
default: puts("<unknown>"); break;
}
}
else if (what == GSUB)
{
switch (type)
{
case 1: puts("Single"); break;
case 2: puts("Multiple"); break;
case 3: puts("Alternate"); break;
case 4: puts("Ligature"); break;
case 5: puts("Context"); break;
case 6: puts("Chaining Context"); break;
case 7: puts("Extension Substitution"); break;
case 8: puts("Reverse chaining context single"); break;
default: puts("<unknown>"); break;
}
}
else printf("%u\n", type);
ushort flag = readushort(f);
printf("\tflag = [ ");
if (flag & 0x0001) printf("RTL ");
if (flag & 0x0002) printf("IgnBase ");
if (flag & 0x0004) printf("IgnLiga ");
if (flag & 0x0008) printf("IgnMark ");
if (flag & 0xFF00) printf("MarkAttType ");
printf("]\n");
ushort subcount = readushort(f);
printf("\tsubtables (%d)\n", subcount);
}
void readlookuplist(FILE *f, ulong lookuplistofs, int what)
{
int i;
fseek(f, lookuplistofs, 0);
ushort count = readushort(f);
ushort lookup[count];
for (i = 0; i < count; i++)
lookup[i] = readushort(f);
for (i = 0; i < count; i++)
{
printf(" look %d\n {\n", i);
readlookup(f, lookuplistofs + lookup[i], what);
printf(" }\n\n");
}
}
void readGSUB(FILE *f, ulong ofs)
{
fseek(f, ofs, 0);
(void) readulong(f); /* version */
ushort scriptlist = readushort(f);
ushort featurelist = readushort(f);
ushort lookuplist = readushort(f);
printf("GSUB\n{\n");
readscriptlist(f, ofs + scriptlist);
printf("\n");
readfeaturelist(f, ofs + featurelist);
printf("\n");
readlookuplist(f, ofs + lookuplist, GSUB);
printf("}\n\n");
}
void readGPOS(FILE *f, ulong ofs)
{
fseek(f, ofs, 0);
(void) readulong(f); /* version */
ushort scriptlist = readushort(f);
ushort featurelist = readushort(f);
ushort lookuplist = readushort(f);
printf("GPOS\n{\n");
readscriptlist(f, ofs + scriptlist);
printf("\n");
readfeaturelist(f, ofs + featurelist);
printf("\n");
readlookuplist(f, ofs + lookuplist, GPOS);
printf("}\n\n");
}
/*
* CMAP encoding tables
*/
void readcmap0(FILE *f)
{
int i;
ushort length;
ushort language;
length = readushort(f);
language = readushort(f);
printf("\tformat = 0\n");
printf("\tlanguage = %u\n", language);
printf("\tgids = [\n");
for (i = 0; i < 256; i++)
{
byte gid = getc(f);
if (i % 16 == 0) printf("\t ");
printf("%02x", gid);
putchar(i % 16 == 15 ? '\n' : ' ');
}
printf("\t]\n");
}
void readcmap2(FILE *f)
{
int nsubheaders;
int ngids;
int i;
ushort length;
ushort language;
ushort subheadkeys[256];
length = readushort(f);
language = readushort(f);
printf("\tformat = 2\n");
printf("\tlanguage = %u\n", language);
printf("\tsubheadkeys = [\n");
nsubheaders = 0;
for (i = 0; i < 256; i++) {
ushort key = readushort(f) / 8;
subheadkeys[i] = key;
if (nsubheaders < key)
nsubheaders = key;
if (i % 16 == 0) printf("\t ");
printf("%u", key);
putchar(i % 16 == 15 ? '\n' : ' ');
}
printf("\t]\n");
ngids = (length / 2) - ((256 + 3) + nsubheaders * 4);
printf("\tsubhead = [\n");
for (i = 0; i < nsubheaders; i++)
{
ushort first = readushort(f);
ushort count = readushort(f);
short delta = readshort(f);
ushort rangeofs = readushort(f) - (nsubheaders - i) * 8 - 2;
printf("\t <%04x> %5u %6d %5u\n",
first, count, delta, rangeofs);
}
printf("\t]\n");
if (ngids)
{
printf("\tgids = [\n");
for (i = 0; i < ngids; i++)
{
ushort gid = readushort(f);
if (i % 12 == 0) printf("\t ");
printf("%04x", gid);
putchar(i % 12 == 11 ? '\n' : ' ');
}
if (i % 12 != 0) putchar('\n');
printf("\t]\n");
}
}
void readcmap4(FILE *f)
{
int segcount;
int i;
ushort length;
ushort language;
ushort segcountx2;
length = readushort(f);
language = readushort(f);
segcountx2 = readushort(f);
(void) readushort(f); /* searchRange */
(void) readushort(f); /* entrySelector */
(void) readushort(f); /* rangeShift */
segcount = segcountx2 / 2;
printf("\tformat = 4\n");
printf("\tlanguage = %u\n", language);
ushort endcode[segcount];
ushort startcode[segcount];
short iddelta[segcount];
ushort idrangeofs[segcount];
for (i = 0; i < segcount; i++)
endcode[i] = readushort(f);
(void) readushort(f); /* reservedPad */
for (i = 0; i < segcount; i++)
startcode[i] = readushort(f);
for (i = 0; i < segcount; i++)
iddelta[i] = readshort(f);
for (i = 0; i < segcount; i++)
idrangeofs[i] = readushort(f);
printf("\tranges = [\n");
for (i = 0; i < segcount; i++) {
printf("\t <%04x> <%04x> %6d %5u\n",
startcode[i], endcode[i], iddelta[i], idrangeofs[i]);
}
printf("\t]\n");
ushort gidlen = length - (4 * segcount * 2 + 16);
if (gidlen)
{
printf("\tgids = [\n");
for (i = 0; i < gidlen; i++)
{
ushort gid = readushort(f);
if (i % 12 == 0) printf("\t ");
printf("%04x", gid);
putchar(i % 12 == 11 ? '\n' : ' ');
}
if (i % 12 != 0) putchar('\n');
printf("\t]\n");
}
}
void readcmap6(FILE *f)
{
int i;
ushort length;
ushort language;
ushort first;
ushort count;
length = readushort(f);
language = readushort(f);
printf("\tformat = 6\n");
printf("\tlanguage = %u\n", language);
first = readushort(f);
count = readushort(f);
printf("\tfirst = <%04x>\n", first);
printf("\tgids = [\n");
for (i = 0; i < count; i++)
{
printf("\tgids = [\n");
for (i = 0; i < count; i++)
{
ushort gid = readushort(f);
if (i % 12 == 0) printf("\t ");
printf("%04x", gid);
putchar(i % 12 == 11 ? '\n' : ' ');
}
if (i % 12 != 0) putchar('\n');
printf("\t]\n");
}
}
void readcmap8(FILE *f)
{
int i;
ulong length;
ulong language;
byte is32[65536 / 8];
ulong ngroups;
ulong startchar;
ulong endchar;
ulong startglyph;
length = readulong(f);
language = readulong(f);
fread(is32, 1, 65536 / 8, f);
ngroups = readulong(f);
printf("\tformat = 8\n");
printf("\tlanguage = %lu\n", language);
printf("\tngroups %lu\n", ngroups);
for (i = 0; i < ngroups; i++)
{
startchar = readulong(f);
endchar = readulong(f);
startglyph = readulong(f);
}
}
void readcmap10(FILE *f)
{
int i;
ulong length;
ulong language;
ulong startchar;
ulong count;
length = readulong(f);
language = readulong(f);
startchar = readulong(f);
count = readulong(f);
printf("\tformat = 10\n");
printf("\tlanguage = %lu\n", language);
for (i = 0; i < count; i++)
{
(void) readushort(f);
}
}
void readcmap12(FILE *f)
{
int i;
ulong length;
ulong language;
ulong ngroups;
ulong startchar;
ulong endchar;
ulong startglyph;
length = readulong(f);
language = readulong(f);
ngroups = readulong(f);
printf("\tformat = 12\n");
printf("\tlanguage = %lu\n", language);
printf("\tngroups %lu\n", ngroups);
for (i = 0; i < ngroups; i++)
{
startchar = readulong(f);
endchar = readulong(f);
startglyph = readulong(f);
printf("\t\t<%lx> <%lx> %lu\n", startchar, endchar, startglyph);
}
}
void readcmap(FILE *f, ulong cmapofs)
{
int i;
ushort version;
ushort nsubtables;
ushort format;
ushort subformat;
fseek(f, cmapofs, 0);
version = readushort(f);
printf("cmap\n{\n");
nsubtables = readushort(f);
ulong offsets[nsubtables];
ushort pids[nsubtables];
ushort eids[nsubtables];
for (i = 0; i < nsubtables; i++)
{
pids[i] = readushort(f);
eids[i] = readushort(f);
offsets[i] = readulong(f);
}
for (i = 0; i < nsubtables; i++)
{
printf(" platform %u encoding %u\n", pids[i], eids[i]);
printf(" {\n");
fseek(f, cmapofs + offsets[i], 0);
format = readushort(f);
if (format > 6)
subformat = readushort(f);
else
subformat = 0;
switch (format)
{
case 0: readcmap0(f); break;
case 2: readcmap2(f); break;
case 4: readcmap4(f); break;
case 6: readcmap6(f); break;
case 8: readcmap8(f); break;
case 10: readcmap10(f); break;
case 12: readcmap12(f); break;
default: panic("unknown cmap format: %u\n", format);
}
printf(" }\n\n");
}
printf("}\n\n");
}
/*
* Misc TrueType headers and metrics and icky bits.
*/
void readhead(FILE *f, ulong headofs)
{
fseek(f, headofs, 0);
ulong tableversion = readulong(f);
ulong fontrevision = readulong(f);
//ulong checksumadj = readulong(f);
(void) readulong(f);
ulong magicnumber = readulong(f);
ushort flags = readushort(f);
ushort unitsperem = readushort(f);
//struct datetime created = readdatetime(f);
(void) readulong(f);
(void) readulong(f);
//struct datetime modified = readdatetime(f);
(void) readulong(f);
(void) readulong(f);
//short xmin = readshort(f);
//short ymin = readshort(f);
//short xmax = readshort(f);
//short ymax = readshort(f);
(void) readshort(f);
(void) readshort(f);
(void) readshort(f);
(void) readshort(f);
ushort macstyle = readushort(f);
//ushort lowestrecppem = readushort(f);
(void) readushort(f);
short fontdirhint = readshort(f);
short indextolocfmt = readshort(f);
//short glyphdatafmt = readshort(f);
(void) readshort(f);
if (tableversion != 0x00010000)
panic("unknown version of head table: 0x%08x\n", tableversion);
if (magicnumber != 0x5F0F3CF5)
panic("bad voodoo: 0x%08x\n", magicnumber);
printf("head\n{\n");
printf(" font-revision = 0x%08lx\n", fontrevision);
printf(" units-per-em = %u\n", unitsperem);
printf(" bidi = ");
if (fontdirhint == 0) puts("fully-mixed-directional-glyphs");
else if (fontdirhint == 1) puts("strongly-ltr");
else if (fontdirhint == 2) puts("ltr-with-neutrals");
else if (fontdirhint == -1) puts("strongly-rtl");
else if (fontdirhint == -2) puts("rtl-with-neutrals");
else puts("unknown");
printf(" style = [ ");
if (macstyle & 0x0001) printf("bold ");
if (macstyle & 0x0002) printf("italic ");
if (macstyle & 0x0004) printf("underline ");
if (macstyle & 0x0008) printf("outline ");
if (macstyle & 0x0010) printf("shadow ");
if (macstyle & 0x0020) printf("condensed ");
if (macstyle & 0x0040) printf("extended ");
printf("]\n");
printf(" flags = [\n");
if (flags & 0x0001) puts("\tbaseline at y=0");
if (flags & 0x0002) puts("\txmin is lsb");
if (flags & 0x0004) puts("\tinstructions may depend on point size");
if (flags & 0x0008) puts("\tuse integer scaling instead of fractional");
if (flags & 0x0010) puts("\tinstructions may alter advance width");
/* apple flags */
if (flags & 0x0020) puts("\tapple: vertical baseline x=0");
if (flags & 0x0080) puts("\tapple: requires layout");
if (flags & 0x0100) puts("\tapple: has gx morph effects by default");
if (flags & 0x0200) puts("\tapple: has strong rtl glyphs");
if (flags & 0x0400) puts("\tapple: has indic rearrangement");
/* adobe flags */
if (flags & 0x0800) puts("\tadobe: lossless fontdata");
if (flags & 0x1000) puts("\tadobe: converted font");
if (flags & 0x2000) puts("\tadobe: optimised for cleartype");
printf(" ]\n");
printf(" locaformat = %s\n", indextolocfmt == 0 ? "short" : "long");
printf("}\n\n");
g_locafmt = indextolocfmt;
}
void readmaxp(FILE *f, ulong maxpofs)
{
ulong version;
ushort nglyphs;
ushort maxpoints;
ushort maxcontours;
ushort maxcpoints;
ushort maxccontours;
/* ... */
fseek(f, maxpofs, 0);
printf("maxp\n{\n");
version = readulong(f);
if (version == 0x00005000) {
nglyphs = readushort(f);
printf(" numglyphs = %u\n", nglyphs);
}
else if (version == 0x00010000) {
nglyphs = readushort(f);
maxpoints = readushort(f);
maxcontours = readushort(f);
maxcpoints = readushort(f);
maxccontours = readushort(f);
printf(" numglyphs = %u\n", nglyphs);
printf(" maxpoints = %u\n", maxpoints);
printf(" maxcontours = %u\n", maxcontours);
printf(" maxcompositepoints = %u\n", maxcpoints);
printf(" maxcompositecontours = %u\n", maxccontours);
}
else {
panic("unknown maxp version: 0x%08x\n", version);
nglyphs = 0;
}
printf("}\n\n");
g_nglyphs = nglyphs;
}
void readname(FILE *f, ulong nameofs)
{
int i, k;
ushort format;
ushort count;
ushort strofs;
ushort pid;
ushort eid;
ushort langid;
ushort nameid;
ushort length;
ushort offset;
fseek(f, nameofs, 0);
format = readushort(f);
count = readushort(f);
strofs = readushort(f);
printf("name\n{\n");
for (i = 0; i < count; i++)
{
pid = readushort(f);
eid = readushort(f);
langid = readushort(f);
nameid = readushort(f);
length = readushort(f);
offset = readushort(f);
if ((pid == 1 && eid == 0 && langid == 0) ||
(pid == 3 && eid == 1 && langid == 0x0409))
{
char s[256];
switch (nameid)
{
case 0: sprintf(s, "copyright"); break;
case 1: sprintf(s, "family"); break;
case 2: sprintf(s, "subfamily"); break;
case 3: sprintf(s, "fontid"); break;
case 4: sprintf(s, "fullname"); break;
case 5: sprintf(s, "version"); break;
case 6: sprintf(s, "psname"); break;
case 7: sprintf(s, "trademark"); break;
case 8: sprintf(s, "manufacturer"); break;
case 9: sprintf(s, "designer"); break;
case 10: sprintf(s, "description"); break;
case 11: sprintf(s, "vendor-url"); break;
case 12: sprintf(s, "designer-url"); break;
case 13: sprintf(s, "license"); break;
case 14: sprintf(s, "license-url"); break;
case 15: sprintf(s, "<reserved>"); break;
case 16: sprintf(s, "preferred-family"); break;
case 17: sprintf(s, "preferred-subfamily"); break;
case 18: sprintf(s, "compatible-full-name"); break;
case 19: sprintf(s, "sampletext"); break;
case 20: sprintf(s, "cid-findfont-name"); break;
default: sprintf(s, "<unknown-%d>", nameid); break;
}
byte string[length];
ulong oldofs = ftell(f);
fseek(f, nameofs + strofs + offset, 0);
fread(string, 1, length, f);
printf(" %-12s = \"", s);
if (pid == 3)
for (k = 1; k < length; k += 2)
putchar(string[k]);
else
fwrite(string, 1, length, stdout);
printf("\"\n");
fseek(f, oldofs, 0);
}
}
printf("}\n\n");
}
void readhheahmtx(FILE *f, ulong hheaofs, ulong hmtxofs, char hv)
{
int i;
fseek(f, hheaofs, 0);
ulong version = readulong(f);
short ascender = readshort(f);
short descender = readshort(f);
short linegap = readshort(f);
ushort maxadvw; maxadvw = readushort(f);
short minlsb; minlsb = readshort(f);
short minrsb; minrsb = readshort(f);
short xmaxext; xmaxext = readshort(f);
short caretrise = readshort(f);
short caretrun = readshort(f);
short caretoffset = readshort(f);
(void) readshort(f);
(void) readshort(f);
(void) readshort(f);
(void) readshort(f);
short metricfmt; metricfmt = readshort(f);
ushort nmetrics = readushort(f);
printf("%chea\n{\n", hv);
printf(" ascender = %d\n", ascender);
printf(" descender = %d\n", descender);
printf(" linegap = %d\n", linegap);
printf(" caret = %d / %d + %d\n", caretrise, caretrun, caretoffset);
printf("}\n\n");
fseek(f, hmtxofs, 0);
printf("%cmtx\n{\n", hv);
for (i = 0; i < nmetrics; i++)
{
ushort advw = readushort(f);
short lsb = readshort(f);
printf(" %5u %6d\n", advw, lsb);
}
for ( ; i < g_nglyphs; i++)
{
short lsb = readshort(f);
printf(" %6d\n", lsb);
}
printf("}\n\n");
}
void readpost(FILE *f, ulong postofs)
{
int i;
fseek(f, postofs, 0);
long format = readlong(f); // Fixed
long italicangle = readlong(f); // Fixed
short underlineposition = readshort(f); // FWord
short underlinethickness = readshort(f); // FWord
ulong isfixedpitch = readulong(f);
readulong(f); // minMemType42
readulong(f); // maxMemType42
readulong(f); // minMemType1
readulong(f); // maxMemType1
printf("post\n{\n");
printf(" italic angle = %g\n", italicangle / 65536.0);
printf(" underline position = %d\n", underlineposition);
printf(" underline thickness = %d\n", underlinethickness);
printf(" fixed pitch = %d\n", isfixedpitch);
switch (format)
{
case 1 << 16:
printf(" format 1 (standard macintosh ordering)\n");
break;
case 2 << 16:
printf(" format 2\n");
printf(" {\n");
ushort numberofglyphs = readushort(f);
int numberofnewglyphs = 0;
printf(" number of glyphs = %d\n", numberofglyphs);
for (i = 0; i < numberofglyphs; i++)
{
int nameidx = readushort(f);
printf(" glyph %d = name %d\n", i, nameidx);
if (nameidx > 258)
{
nameidx -= 258;
if (nameidx > numberofnewglyphs)
numberofnewglyphs = nameidx;
}
}
for (i = 0; i < numberofnewglyphs; i++)
{
int n = getc(f);
printf(" name %d = (", i + 258);
while (n--)
putchar(getc(f));
printf(")\n");
}
printf(" }\n");
break;
default:
printf(" format %g\n", format / 65536.0);
}
printf("}\n\n");
}
/*
* Outlines
*/
ulong readglyfofs(FILE *f, ulong locaofs, int gid)
{
if (g_locafmt == 0) {
fseek(f, locaofs + gid * 2, 0);
return readushort(f) * 2;
}
else {
fseek(f, locaofs + gid * 4, 0);
return readulong(f);
}
}
ulong readglyflen(FILE *f, ulong locaofs, int gid)
{
ulong a, b;
if (g_locafmt == 0) {
fseek(f, locaofs + gid * 2, 0);
a = readushort(f) * 2;
b = readushort(f) * 2;
}
else {
fseek(f, locaofs + gid * 4, 0);
a = readulong(f);
b = readulong(f);
}
return b - a;
}
void readoneglyf(FILE *f, ulong ofs, ulong len)
{
short ncont;
short xmin, ymin, xmax, ymax;
int i;
fseek(f, ofs, 0);
ncont = readshort(f);
xmin = readshort(f);
ymin = readshort(f);
xmax = readshort(f);
ymax = readshort(f);
/* simple glyph */
if (ncont > 0)
{
ushort endpts[ncont];
for (i = 0; i < ncont; i++)
endpts[i] = readushort(f);
ushort instlen = readushort(f);