summaryrefslogtreecommitdiff
path: root/Build/source/texk/ttfdump/include/tables.h
blob: cef49726cb948c1c7a449ab0ebe150a55c4764d4 (plain)
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
/* table.h -- define data structures for various ttf file internal tables 
 * See Also: True Type Font Specification
 */

#ifndef __TTF_TABLE_H
#define __TTF_TABLE_H

/* $Id: tables.h,v 1.2 1998/07/06 06:07:01 werner Exp $ */

/* Offset Table:
 * Into the beginning of a True Type font file
 */
typedef struct _OffsetTable
{
  Fixed version;
  USHORT numTables;
  USHORT searchRange;
  USHORT entrySelector;
  USHORT rangeShift;
}
OffsetTable, *OffsetTablePtr;

/* Table Directory:
 * The directory to find each table in a True Type font file
 */
typedef struct _TableDir
{
  ULONG tag;
  ULONG checksum;
  ULONG offset;
  ULONG length;
}
TableDir, *TableDirPtr;


/* cmap: Character to Glyph Index Mapping Table
 * There are four kinds of cmap, format 0, 2, 4, and 6.  They are defined
 * as follows
 */
typedef struct
{
  BYTE glyphIndexArray[256];
}
CMAP0;

typedef struct _subHeaders
{
  USHORT firstCode;
  USHORT entryCount;
  SHORT idDelta;
  USHORT idRangeOffset;
}
SubHeader, *SubHeaderPtr;

typedef struct
{
  USHORT subHeaderKeys[256];
  SubHeaderPtr subHeaders;
  USHORT *glyphIndexArray;
}
CMAP2;

typedef struct
{
  USHORT segCountX2;
  USHORT searchRange;
  USHORT entrySelector;
  USHORT rangeShift;
  USHORT *endCount;
  USHORT reservedPad;
  USHORT *startCount;
  USHORT *idDelta;
  USHORT *idRangeOffset;
  USHORT *glyphIndexArray;
}

CMAP4;
typedef struct
{
  USHORT firstCode;
  USHORT entryCount;
  USHORT *glyphIndexArray;
}
CMAP6;

/* SubTable: one for each encoding scheme */
typedef struct
{
  /* encoding table */
  USHORT PlatformID;
  USHORT EncodingID;
  ULONG offset;

  USHORT format;
  USHORT length;
  USHORT version;
  union
  {
    CMAP0 *cmap0;
    CMAP2 *cmap2;
    CMAP4 *cmap4;
    CMAP6 *cmap6;
  }
  map;
}
SubTable, *SubTablePtr;

typedef struct _cmap
{
  USHORT version;
  USHORT numberOfEncodings;
  SubTablePtr subTables;        /* size = numberOfEncodings */
}
CMAP, *CMAPPtr;

/* glyf: Glyph Data table 
 * It is necessary to load "loca" table first to know where to load a specific
 * glyph; the "loca" table itself depends on "head" and "maxp" tables
 */
typedef F2Dot14 SCALE;

typedef struct
{
  F2Dot14 xscale;
  F2Dot14 yscale;
}
VECTOR;

typedef struct
{
  F2Dot14 xscale;
  F2Dot14 scale01;
  F2Dot14 scale10;
  F2Dot14 yscale;
}
TENSOR;

typedef struct
{
  SHORT args[2];                /* need reconsideration */
  union
  {
    SCALE scale;
    VECTOR vector;
    TENSOR tensor;
  }
  transform;
}
CompositeData;

typedef struct _component
{
  USHORT flags;
  USHORT glyphIndex;
  CompositeData data;
  struct _component *next, *previous;   /* linked list used, no way to know 
                                         * how many components in advance */
}
Component;

typedef struct
{
  SHORT numberOfContours;
  FWord xMin;
  FWord yMin;
  FWord xMax;
  FWord yMax;
  /* simple glyph data */
  USHORT *endPtsOfContours;     /* size = numberOfContours */
  USHORT instructionLength;
  BYTE *instructions;           /* size = instructionLength */
  BYTE *flags;                  /* size = the total # of x,y 
                                 * coordinates, i.e. last number
                                 * of endPtsOfContour */
  SHORT *xCoordinates;
  SHORT *yCoordinates;
  Component *comp;              /* a pointer to a linked list of 
                                 * composite components */
}
GLYF, *GLYFPtr;

/* Flags for Coordinates */
#define FLAGS_ON_CURVE       1
#define FLAGS_X_SHORT_VECTOR 2
#define FLAGS_Y_SHORT_VECTOR 4
#define FLAGS_REPEAT         8
#define FLAGS_X_SAME      0x10
#define FLAGS_Y_SAME      0x20

/* Flags for Composite Glyph */
#define ARG_1_AND_2_ARE_WORDS    0x001
#define ARGS_ARE_XY_VALUES       0x002
#define ROUND_XY_TO_GRID         0x004
#define WE_HAVE_A_SCALE          0x008
#define RESERVE                  0x010
#define NO_OVERLAP               0x010
#define MORE_COMPONENT           0x020
#define WE_HAVE_AN_X_AND_Y_SCALE 0x040
#define WE_HAVE_A_TWO_BY_TWO     0x080
#define WE_HAVE_INSTRUCTIONS     0x100
#define USE_MY_METRICS           0x200
#define OVERLAP_COMPOUND         0x400  /* from Apple's TTF specs */

typedef struct
{
  Fixed version;
  Fixed fontRevision;
  ULONG checkSumAdj;
  ULONG magicNumber;
  USHORT flags;
  USHORT unitsPerEm;
  BYTE created[8];
  BYTE modified[8];
  FWord xMin;
  FWord yMin;
  FWord xMax;
  FWord yMax;
  USHORT macStyle;
  USHORT lowestRecPPEM;
  SHORT fontDirectionHint;
  SHORT indexToLocFormat;       /* 0 => ushort, 1 => ulong */
  SHORT glyphDataFormat;
}
HEAD, *HEADPtr;

#define FLAGS_Y_0 1
#define FLAGS_X_0 2
#define FLAGS_SIZE_DEP 4
#define FLAGS_INT_PPEM 8
#define FLAGS_ALT_WIDTH 0x10
#define MAC_STYLE_BOLD 1
#define MAC_STYLE_ITALIC 2
#define FONT_DIR_MIX 0
#define FONT_DIR_L2R 1
#define FONT_DIR_L2R_NEUTRALS 2
#define FONT_DIR_R2L -1
#define FONT_DIR_R2L_NEUTRALS -2
#define LOCA_OFFSET_SHORT 0
#define LOCA_OFFSET_LONG 1

typedef struct
{
  Fixed version;
  FWord Ascender;
  FWord Descender;
  FWord LineGap;
  uFWord advanceWidthMax;
  FWord minLeftSideBearing;
  FWord minRightSideBearing;
  FWord xMaxExtent;
  SHORT caretSlopeRise;
  SHORT caretSlopeRun;
  SHORT reserved[5];
  SHORT metricDataFormat;
  USHORT numberOfHMetrics;
}
HHEA, *HHEAPtr;

/* for a new created HMTX, one have to fill numberofHMetrics manually for
 * hhea */
typedef struct _longHorMetric
{
  uFWord advanceWidth;
  FWord lsb;
}
longHorMetric;

typedef struct
{                               /* depends on hhea */
  USHORT numberOfHMetrics;      /* defined in hhea */
  USHORT numberOfLSB;           /* numGlyph - numberOfHMetrics */
  longHorMetric *hMetrics;
  FWord *leftSideBearing;
}
HMTX, *HMTXPtr;

/* for a newly created LOCA, one have to fill indexToLocFormat from head and
 * numGlyphs from maxp manually */
typedef struct
{                               /* depends on head and maxp */
  SHORT indexToLocFormat;       /* defined in head */
  USHORT numGlyphs;             /* defined in maxp */
  ULONG *offset;
}
LOCA, *LOCAPtr;

typedef struct
{
  Fixed version;
  USHORT numGlyphs;
  USHORT maxPoints;
  USHORT maxContours;
  USHORT maxCompositePoints;
  USHORT maxCompositeContours;
  USHORT maxZones;
  USHORT maxTwilightPoints;
  USHORT maxStorage;
  USHORT maxFunctionDefs;
  USHORT maxInstructionDefs;
  USHORT maxStackElements;
  USHORT maxSizeOfInstructions;
  USHORT maxComponentElements;
  USHORT maxComponentDepth;
}
MAXP, *MAXPPtr;

typedef struct
{
  USHORT PlatformID;
  USHORT EncodingID;
  USHORT LanguageID;
  USHORT NameID;
  USHORT length;
  USHORT offset;
  char *data;
}
NameRecord, *NameRecordPtr;

typedef struct
{
  USHORT format;
  USHORT numberOfRecords;
  USHORT offset;
  NameRecordPtr NameRecords;
}
NAME, *NAMEPtr;

typedef struct
{
  USHORT numGlyphs;     /* Should be the same as numGlyphs defined in maxp */
  USHORT *glyphNameIndex;
  CHAR **GlyphName;
}
Format20;

typedef struct
{
  char *offset;
}
Format25;

typedef struct
{
  Fixed format;
  Fixed italicAngle;
  FWord underlinePosition;
  FWord underlineThickness;
  ULONG isFixedPitch;
  ULONG minMemType42;
  ULONG maxMemType42;
  ULONG minMemType1;
  ULONG maxMemType1;
  /* the elements below exist only for 2.0 and 2.5 format */
  union
  {
    Format20 *format20;
    Format25 *format25;
  }
  name;
}
POST, *POSTPtr;

typedef struct
{
  USHORT version;
  SHORT xAvgCharWidth;
  USHORT usWeightClass;
  USHORT usWidthClass;
  USHORT fsType;
  SHORT ySubscriptXSize;
  SHORT ySubscriptYSize;
  SHORT ySubscriptXOffset;
  SHORT ySubscriptYOffset;
  SHORT ySuperscriptXSize;
  SHORT ySuperscriptYSize;
  SHORT ySuperscriptXOffset;
  SHORT ySuperscriptYOffset;
  SHORT yStrikeoutSize;
  SHORT yStrikeoutPosition;
  SHORT sFamilyClass;
  CHAR panose[10];
  ULONG ulUnicodeRange1;
  ULONG ulUnicodeRange2;
  ULONG ulUnicodeRange3;
  ULONG ulUnicodeRange4;
  CHAR achVendID[5];
  USHORT fsSelection;
  USHORT usFirstCharIndex;
  USHORT usLastCharIndex;
  SHORT sTypoAscender;
  SHORT sTypoDescender;
  SHORT sTypoLineGap;
  USHORT usWinAscent;
  USHORT usWinDescent;
  ULONG ulCodePageRange1;
  ULONG ulCodePageRange2;
}
OS_2, *OS_2Ptr;

typedef struct
{
  USHORT rangeMaxPPEM;
  USHORT rangeGaspBehavior;
}
GASPRANGE;

typedef struct
{
  USHORT version;
  USHORT numRanges;
  GASPRANGE *gaspRange;         /* length = numRanges */
}
GASP, *GASPPtr;

/* flags for gasp */
#define GASP_GRIDFIT 0x0001
#define GASP_DOGRAY  0x0002

typedef struct
{
  BYTE PixelSize;
  BYTE MaxWidth;
  BYTE *Width;                  /* length = numGlyphs */
}
DeviceRecord;

typedef struct
{
  USHORT numGlyphs;             /* defined in maxp, artifitial */
  USHORT version;
  SHORT numDevices;
  LONG size;
  DeviceRecord *Records;
}
HDMX, *HDMXPtr;

typedef struct
{
  USHORT version;
  USHORT length;
  USHORT coverage;
  union
  {
    struct
    {
      USHORT nPairs;
      USHORT searchRange;
      USHORT entrySelector;
      USHORT rangeShift;
      struct kernpair
      {
        USHORT left;
        USHORT right;
        FWord value;
      }
      *pairs;
    }
    kern0;

    struct
    {
      USHORT rowWidth;
      USHORT leftClassTable;
      USHORT rightClassTable;
      USHORT array;
    }
    kern2;
  }
  kern;
}
KernSubtable;

typedef struct
{
  USHORT version;
  USHORT nTables;
  KernSubtable *subtable;
}
KERN, *KERNPtr;

typedef struct
{
  USHORT version;
  USHORT numGlyphs;
  BYTE *yPels;                  /* length = numGlyphs */
}
LTSH, *LTSHPtr;

typedef struct
{
  Fixed version;
  ULONG FontNumber;
  USHORT Pitch;
  USHORT xHeight;
  USHORT Style;
  USHORT TypeFamily;
  USHORT CapHeight;
  USHORT SymbolSet;
  CHAR Typeface[16];
  CHAR CharacterComplement[8];
  CHAR FileName[6];
  CHAR StrokeWeight;
  CHAR WidthType;
  BYTE SerifStyle;
  BYTE reserved;
}
PCLT, *PCLTPtr;

typedef struct
{
  BYTE CharSet;
  BYTE xRatio;
  BYTE yStartRatio;
  BYTE yEndRatio;
}
Ratios;

typedef struct
{
  USHORT yPelHeight;
  SHORT yMax;
  SHORT yMin;
}
vTable;

typedef struct
{
  USHORT recs;
  BYTE startsz;
  BYTE endsz;
  vTable *entry;
}
Vdmx;

typedef struct
{
  USHORT version;
  USHORT numRecs;
  USHORT numRatios;
  Ratios *ratRange;             /* length = numRatios */
  USHORT *offset;               /* length = numRatios */
  Vdmx *groups;
}
VDMX, *VDMXPtr;

typedef struct
{
  Fixed version;
  SHORT ascent;
  SHORT descent;
  SHORT lineGap;
  SHORT advanceHeightMax;
  SHORT minTopSideBearing;
  SHORT minBottomSideBearing;
  SHORT yMaxExtent;
  SHORT caretSlopeRise;
  SHORT caretSlopeRun;
  SHORT caretOffset;
  SHORT reserved[4];
  SHORT metricDataFormat;
  USHORT numOfLongVerMetrics;
}
VHEA, *VHEAPtr;

typedef struct
{
  uFWord advanceHeight;
  FWord topSideBearing;
}
longVerMetric;

typedef struct
{
  /* depends on vhea */
  USHORT numOfLongVerMetrics;   /* defined in vhea */
  USHORT numOfTSB;              /* numGlyph - numberOfHMetrics */
  longVerMetric *vMetrics;
  FWord *topSideBearing;
}
VMTX, *VMTXPtr;

#endif /* __TTF_TABLE_H */


/* end of tables.h */