1 /*******************************************************************
5 * TrueType Open GPOS table support
7 * Copyright 1996-1999 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
10 * This file is part of the FreeType project, and may only be used
11 * modified and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
16 ******************************************************************/
19 #error "Don't include this file! Use ftxopen.h instead."
29 #define TTO_Err_Invalid_GPOS_SubTable_Format 0x1020
30 #define TTO_Err_Invalid_GPOS_SubTable 0x1021
33 /* Lookup types for glyph positioning */
35 #define GPOS_LOOKUP_SINGLE 1
36 #define GPOS_LOOKUP_PAIR 2
37 #define GPOS_LOOKUP_CURSIVE 3
38 #define GPOS_LOOKUP_MARKBASE 4
39 #define GPOS_LOOKUP_MARKLIG 5
40 #define GPOS_LOOKUP_MARKMARK 6
41 #define GPOS_LOOKUP_CONTEXT 7
42 #define GPOS_LOOKUP_CHAIN 8
45 struct TTO_GPOSHeader_
52 TTO_ScriptList ScriptList
;
53 TTO_FeatureList FeatureList
;
54 TTO_LookupList LookupList
;
59 typedef struct TTO_GPOSHeader_ TTO_GPOSHeader
;
64 struct TTO_ValueRecord_
66 TT_Short XPlacement
; /* horizontal adjustment for
68 TT_Short YPlacement
; /* vertical adjustment for
70 TT_Short XAdvance
; /* horizontal adjustment for
72 TT_Short YAdvance
; /* vertical adjustment for
74 TTO_Device XPlacementDevice
; /* device table for horizontal
76 TTO_Device YPlacementDevice
; /* device table for vertical
78 TTO_Device XAdvanceDevice
; /* device table for horizontal
80 TTO_Device YAdvanceDevice
; /* device table for vertical
82 TT_UShort XIdPlacement
; /* horizontal placement metric ID */
83 TT_UShort YIdPlacement
; /* vertical placement metric ID */
84 TT_UShort XIdAdvance
; /* horizontal advance metric ID */
85 TT_UShort YIdAdvance
; /* vertical advance metric ID */
88 typedef struct TTO_ValueRecord_ TTO_ValueRecord
;
91 /* Mask values to scan the value format of the ValueRecord structure.
92 We always expand compressed ValueRecords of the font. */
94 #define HAVE_X_PLACEMENT 0x0001
95 #define HAVE_Y_PLACEMENT 0x0002
96 #define HAVE_X_ADVANCE 0x0004
97 #define HAVE_Y_ADVANCE 0x0008
98 #define HAVE_X_PLACEMENT_DEVICE 0x0010
99 #define HAVE_Y_PLACEMENT_DEVICE 0x0020
100 #define HAVE_X_ADVANCE_DEVICE 0x0040
101 #define HAVE_Y_ADVANCE_DEVICE 0x0080
102 #define HAVE_X_ID_PLACEMENT 0x0100
103 #define HAVE_Y_ID_PLACEMENT 0x0200
104 #define HAVE_X_ID_ADVANCE 0x0400
105 #define HAVE_Y_ID_ADVANCE 0x0800
108 struct TTO_AnchorFormat1_
110 TT_Short XCoordinate
; /* horizontal value */
111 TT_Short YCoordinate
; /* vertical value */
114 typedef struct TTO_AnchorFormat1_ TTO_AnchorFormat1
;
117 struct TTO_AnchorFormat2_
119 TT_Short XCoordinate
; /* horizontal value */
120 TT_Short YCoordinate
; /* vertical value */
121 TT_UShort AnchorPoint
; /* index to glyph contour point */
124 typedef struct TTO_AnchorFormat2_ TTO_AnchorFormat2
;
127 struct TTO_AnchorFormat3_
129 TT_Short XCoordinate
; /* horizontal value */
130 TT_Short YCoordinate
; /* vertical value */
131 TTO_Device XDeviceTable
; /* device table for X coordinate */
132 TTO_Device YDeviceTable
; /* device table for Y coordinate */
135 typedef struct TTO_AnchorFormat3_ TTO_AnchorFormat3
;
138 struct TTO_AnchorFormat4_
140 TT_UShort XIdAnchor
; /* horizontal metric ID */
141 TT_UShort YIdAnchor
; /* vertical metric ID */
144 typedef struct TTO_AnchorFormat4_ TTO_AnchorFormat4
;
149 TT_UShort PosFormat
; /* 1, 2, 3, or 4 -- 0 indicates
150 that there is no Anchor table */
154 TTO_AnchorFormat1 af1
;
155 TTO_AnchorFormat2 af2
;
156 TTO_AnchorFormat3 af3
;
157 TTO_AnchorFormat4 af4
;
161 typedef struct TTO_Anchor_ TTO_Anchor
;
164 struct TTO_MarkRecord_
166 TT_UShort Class
; /* mark class */
167 TTO_Anchor MarkAnchor
; /* anchor table */
170 typedef struct TTO_MarkRecord_ TTO_MarkRecord
;
173 struct TTO_MarkArray_
175 TT_UShort MarkCount
; /* number of MarkRecord tables */
176 TTO_MarkRecord
* MarkRecord
; /* array of MarkRecord tables */
179 typedef struct TTO_MarkArray_ TTO_MarkArray
;
184 struct TTO_SinglePosFormat1_
186 TTO_ValueRecord Value
; /* ValueRecord for all covered
190 typedef struct TTO_SinglePosFormat1_ TTO_SinglePosFormat1
;
193 struct TTO_SinglePosFormat2_
195 TT_UShort ValueCount
; /* number of ValueRecord tables */
196 TTO_ValueRecord
* Value
; /* array of ValueRecord tables */
199 typedef struct TTO_SinglePosFormat2_ TTO_SinglePosFormat2
;
202 struct TTO_SinglePos_
204 TT_UShort PosFormat
; /* 1 or 2 */
205 TTO_Coverage Coverage
; /* Coverage table */
207 TT_UShort ValueFormat
; /* format of ValueRecord table */
211 TTO_SinglePosFormat1 spf1
;
212 TTO_SinglePosFormat2 spf2
;
216 typedef struct TTO_SinglePos_ TTO_SinglePos
;
221 struct TTO_PairValueRecord_
223 TT_UShort SecondGlyph
; /* glyph ID for second glyph */
224 TTO_ValueRecord Value1
; /* pos. data for first glyph */
225 TTO_ValueRecord Value2
; /* pos. data for second glyph */
228 typedef struct TTO_PairValueRecord_ TTO_PairValueRecord
;
233 TT_UShort PairValueCount
;
234 /* number of PairValueRecord tables */
235 TTO_PairValueRecord
* PairValueRecord
;
236 /* array of PairValueRecord tables */
239 typedef struct TTO_PairSet_ TTO_PairSet
;
242 struct TTO_PairPosFormat1_
244 TT_UShort PairSetCount
; /* number of PairSet tables */
245 TTO_PairSet
* PairSet
; /* array of PairSet tables */
248 typedef struct TTO_PairPosFormat1_ TTO_PairPosFormat1
;
251 struct TTO_Class2Record_
253 TTO_ValueRecord Value1
; /* pos. data for first glyph */
254 TTO_ValueRecord Value2
; /* pos. data for second glyph */
257 typedef struct TTO_Class2Record_ TTO_Class2Record
;
260 struct TTO_Class1Record_
262 TTO_Class2Record
* Class2Record
; /* array of Class2Record tables */
265 typedef struct TTO_Class1Record_ TTO_Class1Record
;
268 struct TTO_PairPosFormat2_
270 TTO_ClassDefinition ClassDef1
; /* class def. for first glyph */
271 TTO_ClassDefinition ClassDef2
; /* class def. for second glyph */
272 TT_UShort Class1Count
; /* number of classes in ClassDef1
274 TT_UShort Class2Count
; /* number of classes in ClassDef2
276 TTO_Class1Record
* Class1Record
; /* array of Class1Record tables */
279 typedef struct TTO_PairPosFormat2_ TTO_PairPosFormat2
;
284 TT_UShort PosFormat
; /* 1 or 2 */
285 TTO_Coverage Coverage
; /* Coverage table */
286 TT_UShort ValueFormat1
; /* format of ValueRecord table
288 TT_UShort ValueFormat2
; /* format of ValueRecord table
293 TTO_PairPosFormat1 ppf1
;
294 TTO_PairPosFormat2 ppf2
;
298 typedef struct TTO_PairPos_ TTO_PairPos
;
303 struct TTO_EntryExitRecord_
305 TTO_Anchor EntryAnchor
; /* entry Anchor table */
306 TTO_Anchor ExitAnchor
; /* exit Anchor table */
310 typedef struct TTO_EntryExitRecord_ TTO_EntryExitRecord
;
312 struct TTO_CursivePos_
314 TT_UShort PosFormat
; /* always 1 */
315 TTO_Coverage Coverage
; /* Coverage table */
316 TT_UShort EntryExitCount
;
317 /* number of EntryExitRecord tables */
318 TTO_EntryExitRecord
* EntryExitRecord
;
319 /* array of EntryExitRecord tables */
322 typedef struct TTO_CursivePos_ TTO_CursivePos
;
327 struct TTO_BaseRecord_
329 TTO_Anchor
* BaseAnchor
; /* array of base glyph anchor
333 typedef struct TTO_BaseRecord_ TTO_BaseRecord
;
336 struct TTO_BaseArray_
338 TT_UShort BaseCount
; /* number of BaseRecord tables */
339 TTO_BaseRecord
* BaseRecord
; /* array of BaseRecord tables */
342 typedef struct TTO_BaseArray_ TTO_BaseArray
;
345 struct TTO_MarkBasePos_
347 TT_UShort PosFormat
; /* always 1 */
348 TTO_Coverage MarkCoverage
; /* mark glyph coverage table */
349 TTO_Coverage BaseCoverage
; /* base glyph coverage table */
350 TT_UShort ClassCount
; /* number of mark classes */
351 TTO_MarkArray MarkArray
; /* mark array table */
352 TTO_BaseArray BaseArray
; /* base array table */
355 typedef struct TTO_MarkBasePos_ TTO_MarkBasePos
;
360 struct TTO_ComponentRecord_
362 TTO_Anchor
* LigatureAnchor
; /* array of ligature glyph anchor
366 typedef struct TTO_ComponentRecord_ TTO_ComponentRecord
;
369 struct TTO_LigatureAttach_
371 TT_UShort ComponentCount
;
372 /* number of ComponentRecord tables */
373 TTO_ComponentRecord
* ComponentRecord
;
374 /* array of ComponentRecord tables */
377 typedef struct TTO_LigatureAttach_ TTO_LigatureAttach
;
380 struct TTO_LigatureArray_
382 TT_UShort LigatureCount
; /* number of LigatureAttach tables */
383 TTO_LigatureAttach
* LigatureAttach
;
384 /* array of LigatureAttach tables */
387 typedef struct TTO_LigatureArray_ TTO_LigatureArray
;
390 struct TTO_MarkLigPos_
392 TT_UShort PosFormat
; /* always 1 */
393 TTO_Coverage MarkCoverage
; /* mark glyph coverage table */
394 TTO_Coverage LigatureCoverage
;
395 /* ligature glyph coverage table */
396 TT_UShort ClassCount
; /* number of mark classes */
397 TTO_MarkArray MarkArray
; /* mark array table */
398 TTO_LigatureArray LigatureArray
; /* ligature array table */
401 typedef struct TTO_MarkLigPos_ TTO_MarkLigPos
;
406 struct TTO_Mark2Record_
408 TTO_Anchor
* Mark2Anchor
; /* array of mark glyph anchor
412 typedef struct TTO_Mark2Record_ TTO_Mark2Record
;
415 struct TTO_Mark2Array_
417 TT_UShort Mark2Count
; /* number of Mark2Record tables */
418 TTO_Mark2Record
* Mark2Record
; /* array of Mark2Record tables */
421 typedef struct TTO_Mark2Array_ TTO_Mark2Array
;
424 struct TTO_MarkMarkPos_
426 TT_UShort PosFormat
; /* always 1 */
427 TTO_Coverage Mark1Coverage
; /* first mark glyph coverage table */
428 TTO_Coverage Mark2Coverage
; /* second mark glyph coverave table */
429 TT_UShort ClassCount
; /* number of combining mark classes */
430 TTO_MarkArray Mark1Array
; /* MarkArray table for first mark */
431 TTO_Mark2Array Mark2Array
; /* MarkArray table for second mark */
434 typedef struct TTO_MarkMarkPos_ TTO_MarkMarkPos
;
437 /* needed by both lookup type 7 and 8 */
439 struct TTO_PosLookupRecord_
441 TT_UShort SequenceIndex
; /* index into current
443 TT_UShort LookupListIndex
; /* Lookup to apply to that pos. */
446 typedef struct TTO_PosLookupRecord_ TTO_PosLookupRecord
;
453 TT_UShort GlyphCount
; /* total number of input glyphs */
454 TT_UShort PosCount
; /* number of PosLookupRecord tables */
455 TT_UShort
* Input
; /* array of input glyph IDs */
456 TTO_PosLookupRecord
* PosLookupRecord
;
457 /* array of PosLookupRecord tables */
460 typedef struct TTO_PosRule_ TTO_PosRule
;
463 struct TTO_PosRuleSet_
465 TT_UShort PosRuleCount
; /* number of PosRule tables */
466 TTO_PosRule
* PosRule
; /* array of PosRule tables */
469 typedef struct TTO_PosRuleSet_ TTO_PosRuleSet
;
472 struct TTO_ContextPosFormat1_
474 TTO_Coverage Coverage
; /* Coverage table */
475 TT_UShort PosRuleSetCount
; /* number of PosRuleSet tables */
476 TTO_PosRuleSet
* PosRuleSet
; /* array of PosRuleSet tables */
479 typedef struct TTO_ContextPosFormat1_ TTO_ContextPosFormat1
;
482 struct TTO_PosClassRule_
484 TT_UShort GlyphCount
; /* total number of context classes */
485 TT_UShort PosCount
; /* number of PosLookupRecord tables */
486 TT_UShort
* Class
; /* array of classes */
487 TTO_PosLookupRecord
* PosLookupRecord
;
488 /* array of PosLookupRecord tables */
491 typedef struct TTO_PosClassRule_ TTO_PosClassRule
;
494 struct TTO_PosClassSet_
496 TT_UShort PosClassRuleCount
;
497 /* number of PosClassRule tables */
498 TTO_PosClassRule
* PosClassRule
; /* array of PosClassRule tables */
501 typedef struct TTO_PosClassSet_ TTO_PosClassSet
;
504 /* The `MaxContextLength' field is not defined in the TTO specification
505 but simplifies the implementation of this format. It holds the
506 maximal context length used in the context rules. */
508 struct TTO_ContextPosFormat2_
510 TT_UShort MaxContextLength
;
511 /* maximal context length */
512 TTO_Coverage Coverage
; /* Coverage table */
513 TTO_ClassDefinition ClassDef
; /* ClassDef table */
514 TT_UShort PosClassSetCount
;
515 /* number of PosClassSet tables */
516 TTO_PosClassSet
* PosClassSet
; /* array of PosClassSet tables */
519 typedef struct TTO_ContextPosFormat2_ TTO_ContextPosFormat2
;
522 struct TTO_ContextPosFormat3_
524 TT_UShort GlyphCount
; /* number of input glyphs */
525 TT_UShort PosCount
; /* number of PosLookupRecord tables */
526 TTO_Coverage
* Coverage
; /* array of Coverage tables */
527 TTO_PosLookupRecord
* PosLookupRecord
;
528 /* array of PosLookupRecord tables */
531 typedef struct TTO_ContextPosFormat3_ TTO_ContextPosFormat3
;
534 struct TTO_ContextPos_
536 TT_UShort PosFormat
; /* 1, 2, or 3 */
540 TTO_ContextPosFormat1 cpf1
;
541 TTO_ContextPosFormat2 cpf2
;
542 TTO_ContextPosFormat3 cpf3
;
546 typedef struct TTO_ContextPos_ TTO_ContextPos
;
551 struct TTO_ChainPosRule_
553 TT_UShort BacktrackGlyphCount
;
554 /* total number of backtrack glyphs */
555 TT_UShort
* Backtrack
; /* array of backtrack glyph IDs */
556 TT_UShort InputGlyphCount
;
557 /* total number of input glyphs */
558 TT_UShort
* Input
; /* array of input glyph IDs */
559 TT_UShort LookaheadGlyphCount
;
560 /* total number of lookahead glyphs */
561 TT_UShort
* Lookahead
; /* array of lookahead glyph IDs */
562 TT_UShort PosCount
; /* number of PosLookupRecords */
563 TTO_PosLookupRecord
* PosLookupRecord
;
564 /* array of PosLookupRecords */
567 typedef struct TTO_ChainPosRule_ TTO_ChainPosRule
;
570 struct TTO_ChainPosRuleSet_
572 TT_UShort ChainPosRuleCount
;
573 /* number of ChainPosRule tables */
574 TTO_ChainPosRule
* ChainPosRule
; /* array of ChainPosRule tables */
577 typedef struct TTO_ChainPosRuleSet_ TTO_ChainPosRuleSet
;
580 struct TTO_ChainContextPosFormat1_
582 TTO_Coverage Coverage
; /* Coverage table */
583 TT_UShort ChainPosRuleSetCount
;
584 /* number of ChainPosRuleSet tables */
585 TTO_ChainPosRuleSet
* ChainPosRuleSet
;
586 /* array of ChainPosRuleSet tables */
589 typedef struct TTO_ChainContextPosFormat1_ TTO_ChainContextPosFormat1
;
592 struct TTO_ChainPosClassRule_
594 TT_UShort BacktrackGlyphCount
;
595 /* total number of backtrack
597 TT_UShort
* Backtrack
; /* array of backtrack classes */
598 TT_UShort InputGlyphCount
;
599 /* total number of context classes */
600 TT_UShort
* Input
; /* array of context classes */
601 TT_UShort LookaheadGlyphCount
;
602 /* total number of lookahead
604 TT_UShort
* Lookahead
; /* array of lookahead classes */
605 TT_UShort PosCount
; /* number of PosLookupRecords */
606 TTO_PosLookupRecord
* PosLookupRecord
;
607 /* array of substitution lookups */
610 typedef struct TTO_ChainPosClassRule_ TTO_ChainPosClassRule
;
613 struct TTO_ChainPosClassSet_
615 TT_UShort ChainPosClassRuleCount
;
616 /* number of ChainPosClassRule
618 TTO_ChainPosClassRule
* ChainPosClassRule
;
619 /* array of ChainPosClassRule
623 typedef struct TTO_ChainPosClassSet_ TTO_ChainPosClassSet
;
626 /* The `MaxXXXLength' fields are not defined in the TTO specification
627 but simplifies the implementation of this format. It holds the
628 maximal context length used in the specific context rules. */
630 struct TTO_ChainContextPosFormat2_
632 TTO_Coverage Coverage
; /* Coverage table */
634 TT_UShort MaxBacktrackLength
;
635 /* maximal backtrack length */
636 TTO_ClassDefinition BacktrackClassDef
;
637 /* BacktrackClassDef table */
638 TT_UShort MaxInputLength
;
639 /* maximal input length */
640 TTO_ClassDefinition InputClassDef
;
641 /* InputClassDef table */
642 TT_UShort MaxLookaheadLength
;
643 /* maximal lookahead length */
644 TTO_ClassDefinition LookaheadClassDef
;
645 /* LookaheadClassDef table */
647 TT_UShort ChainPosClassSetCount
;
648 /* number of ChainPosClassSet
650 TTO_ChainPosClassSet
* ChainPosClassSet
;
651 /* array of ChainPosClassSet
655 typedef struct TTO_ChainContextPosFormat2_ TTO_ChainContextPosFormat2
;
658 struct TTO_ChainContextPosFormat3_
660 TT_UShort BacktrackGlyphCount
;
661 /* number of backtrack glyphs */
662 TTO_Coverage
* BacktrackCoverage
;
663 /* array of backtrack Coverage
665 TT_UShort InputGlyphCount
;
666 /* number of input glyphs */
667 TTO_Coverage
* InputCoverage
;
668 /* array of input coverage
670 TT_UShort LookaheadGlyphCount
;
671 /* number of lookahead glyphs */
672 TTO_Coverage
* LookaheadCoverage
;
673 /* array of lookahead coverage
675 TT_UShort PosCount
; /* number of PosLookupRecords */
676 TTO_PosLookupRecord
* PosLookupRecord
;
677 /* array of substitution lookups */
680 typedef struct TTO_ChainContextPosFormat3_ TTO_ChainContextPosFormat3
;
683 struct TTO_ChainContextPos_
685 TT_UShort PosFormat
; /* 1, 2, or 3 */
689 TTO_ChainContextPosFormat1 ccpf1
;
690 TTO_ChainContextPosFormat2 ccpf2
;
691 TTO_ChainContextPosFormat3 ccpf3
;
695 typedef struct TTO_ChainContextPos_ TTO_ChainContextPos
;
698 union TTO_GPOS_SubTable_
700 TTO_SinglePos single
;
702 TTO_CursivePos cursive
;
703 TTO_MarkBasePos markbase
;
704 TTO_MarkLigPos marklig
;
705 TTO_MarkMarkPos markmark
;
706 TTO_ContextPos context
;
707 TTO_ChainContextPos chain
;
710 typedef union TTO_GPOS_SubTable_ TTO_GPOS_SubTable
;
713 /* finally, the GPOS API */
716 TT_Error
TT_Init_GPOS_Extension( TT_Engine engine
);
719 TT_Error
TT_Load_GPOS_Table( TT_Face face
,
720 TTO_GPOSHeader
* gpos
,
721 TTO_GDEFHeader
* gdef
);
724 TT_Error
TT_GPOS_Select_Script( TTO_GPOSHeader
* gpos
,
726 TT_UShort
* script_index
);
728 TT_Error
TT_GPOS_Select_Language( TTO_GPOSHeader
* gpos
,
729 TT_ULong language_tag
,
730 TT_UShort script_index
,
731 TT_UShort
* language_index
,
732 TT_UShort
* req_feature_index
);
734 TT_Error
TT_GPOS_Select_Feature( TTO_GPOSHeader
* gpos
,
735 TT_ULong feature_tag
,
736 TT_UShort script_index
,
737 TT_UShort language_index
,
738 TT_UShort
* feature_index
);
741 TT_Error
TT_GPOS_Query_Scripts( TTO_GPOSHeader
* gpos
,
742 TT_ULong
** script_tag_list
);
744 TT_Error
TT_GPOS_Query_Languages( TTO_GPOSHeader
* gpos
,
745 TT_UShort script_index
,
746 TT_ULong
** language_tag_list
);
748 TT_Error
TT_GPOS_Query_Features( TTO_GPOSHeader
* gpos
,
749 TT_UShort script_index
,
750 TT_UShort language_index
,
751 TT_ULong
** feature_tag_list
);
754 TT_Error
TT_GPOS_Add_Feature( TTO_GPOSHeader
* gpos
,
755 TT_UShort feature_index
,
756 TT_UShort property
);
758 TT_Error
TT_GPOS_Clear_Features( TTO_GPOSHeader
* gpos
);
764 #endif /* FTXGPOS_H */