1/*
2 * Copyright (C) 1998-2004  David Turner and Werner Lemberg
3 * Copyright (C) 2006  Behdad Esfahbod
4 *
5 * This is part of HarfBuzz, an OpenType Layout engine library.
6 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 */
25
26#ifndef HARFBUZZ_GSUB_PRIVATE_H
27#define HARFBUZZ_GSUB_PRIVATE_H
28
29#include "harfbuzz-impl.h"
30#include "harfbuzz-stream-private.h"
31#include "harfbuzz-gsub.h"
32
33HB_BEGIN_HEADER
34
35#ifdef HB_USE_PACKED_STRUCTS
36#pragma pack(push, 1)
37#endif
38
39typedef union HB_GSUB_SubTable_  HB_GSUB_SubTable;
40
41/* LookupType 1 */
42
43struct  HB_SingleSubstFormat1_
44{
45  HB_Short  DeltaGlyphID;             /* constant added to get
46					 substitution glyph index */
47};
48
49typedef struct HB_SingleSubstFormat1_  HB_SingleSubstFormat1;
50
51
52struct  HB_SingleSubstFormat2_
53{
54  HB_UShort*  Substitute;             /* array of substitute glyph IDs */
55  HB_UShort   GlyphCount;             /* number of glyph IDs in
56					 Substitute array              */
57};
58
59typedef struct HB_SingleSubstFormat2_  HB_SingleSubstFormat2;
60
61
62struct  HB_SingleSubst_
63{
64  union
65  {
66    HB_SingleSubstFormat1  ssf1;
67    HB_SingleSubstFormat2  ssf2;
68  } ssf;
69
70  HB_Coverage  Coverage;             /* Coverage table */
71  HB_Byte     SubstFormat;            /* 1 or 2         */
72};
73
74typedef struct HB_SingleSubst_  HB_SingleSubst;
75
76
77/* LookupType 2 */
78
79struct  HB_Sequence_
80{
81  HB_UShort*  Substitute;             /* string of glyph IDs to
82					 substitute                 */
83  HB_UShort   GlyphCount;             /* number of glyph IDs in the
84					 Substitute array           */
85};
86
87typedef struct HB_Sequence_  HB_Sequence;
88
89
90struct  HB_MultipleSubst_
91{
92  HB_Sequence*  Sequence;            /* array of Sequence tables  */
93  HB_Coverage   Coverage;            /* Coverage table            */
94  HB_UShort      SubstFormat;         /* always 1                  */
95  HB_UShort      SequenceCount;       /* number of Sequence tables */
96};
97
98typedef struct HB_MultipleSubst_  HB_MultipleSubst;
99
100
101/* LookupType 3 */
102
103struct  HB_AlternateSet_
104{
105  HB_UShort*  Alternate;              /* array of alternate glyph IDs */
106  HB_UShort   GlyphCount;             /* number of glyph IDs in the
107					 Alternate array              */
108};
109
110typedef struct HB_AlternateSet_  HB_AlternateSet;
111
112
113struct  HB_AlternateSubst_
114{
115  HB_AlternateSet*  AlternateSet;    /* array of AlternateSet tables  */
116  HB_Coverage       Coverage;        /* Coverage table                */
117  HB_UShort          SubstFormat;     /* always 1                      */
118  HB_UShort          AlternateSetCount;
119				      /* number of AlternateSet tables */
120};
121
122typedef struct HB_AlternateSubst_  HB_AlternateSubst;
123
124
125/* LookupType 4 */
126
127struct  HB_Ligature_
128{
129  HB_UShort*  Component;              /* array of component glyph IDs     */
130  HB_UShort   LigGlyph;               /* glyphID of ligature
131					 to substitute                    */
132  HB_UShort   ComponentCount;         /* number of components in ligature */
133};
134
135typedef struct HB_Ligature_  HB_Ligature;
136
137
138struct  HB_LigatureSet_
139{
140  HB_Ligature*  Ligature;            /* array of Ligature tables  */
141  HB_UShort      LigatureCount;       /* number of Ligature tables */
142};
143
144typedef struct HB_LigatureSet_  HB_LigatureSet;
145
146
147struct  HB_LigatureSubst_
148{
149  HB_LigatureSet*  LigatureSet;      /* array of LigatureSet tables  */
150  HB_Coverage      Coverage;         /* Coverage table               */
151  HB_UShort         SubstFormat;      /* always 1                     */
152  HB_UShort         LigatureSetCount; /* number of LigatureSet tables */
153};
154
155typedef struct HB_LigatureSubst_  HB_LigatureSubst;
156
157
158/* needed by both lookup type 5 and 6 */
159
160struct  HB_SubstLookupRecord_
161{
162  HB_UShort  SequenceIndex;           /* index into current
163					 glyph sequence               */
164  HB_UShort  LookupListIndex;         /* Lookup to apply to that pos. */
165};
166
167typedef struct HB_SubstLookupRecord_  HB_SubstLookupRecord;
168
169
170/* LookupType 5 */
171
172struct  HB_SubRule_
173{
174  HB_UShort*              Input;      /* array of input glyph IDs     */
175  HB_SubstLookupRecord*  SubstLookupRecord;
176				      /* array of SubstLookupRecord
177					 tables                       */
178  HB_UShort               GlyphCount; /* total number of input glyphs */
179  HB_UShort               SubstCount; /* number of SubstLookupRecord
180					 tables                       */
181};
182
183typedef struct HB_SubRule_  HB_SubRule;
184
185
186struct  HB_SubRuleSet_
187{
188  HB_SubRule*  SubRule;              /* array of SubRule tables  */
189  HB_UShort     SubRuleCount;         /* number of SubRule tables */
190};
191
192typedef struct HB_SubRuleSet_  HB_SubRuleSet;
193
194
195struct  HB_ContextSubstFormat1_
196{
197  HB_SubRuleSet*  SubRuleSet;        /* array of SubRuleSet tables  */
198  HB_Coverage     Coverage;          /* Coverage table              */
199  HB_UShort        SubRuleSetCount;   /* number of SubRuleSet tables */
200};
201
202typedef struct HB_ContextSubstFormat1_  HB_ContextSubstFormat1;
203
204
205struct  HB_SubClassRule_
206{
207  HB_UShort*              Class;      /* array of classes                */
208  HB_SubstLookupRecord*  SubstLookupRecord;
209				      /* array of SubstLookupRecord
210					 tables                          */
211  HB_UShort               GlyphCount; /* total number of context classes */
212  HB_UShort               SubstCount; /* number of SubstLookupRecord
213					 tables                          */
214};
215
216typedef struct HB_SubClassRule_  HB_SubClassRule;
217
218
219struct  HB_SubClassSet_
220{
221  HB_SubClassRule*  SubClassRule;    /* array of SubClassRule tables  */
222  HB_UShort          SubClassRuleCount;
223				      /* number of SubClassRule tables */
224};
225
226typedef struct HB_SubClassSet_  HB_SubClassSet;
227
228
229/* The `MaxContextLength' field is not defined in the TTO specification
230   but simplifies the implementation of this format.  It holds the
231   maximal context length used in the context rules.                    */
232
233struct  HB_ContextSubstFormat2_
234{
235  HB_SubClassSet*     SubClassSet;   /* array of SubClassSet tables  */
236  HB_Coverage         Coverage;      /* Coverage table               */
237  HB_ClassDefinition  ClassDef;      /* ClassDef table               */
238  HB_UShort            SubClassSetCount;
239				      /* number of SubClassSet tables */
240  HB_UShort            MaxContextLength;
241				      /* maximal context length       */
242};
243
244typedef struct HB_ContextSubstFormat2_  HB_ContextSubstFormat2;
245
246
247struct  HB_ContextSubstFormat3_
248{
249  HB_Coverage*           Coverage;   /* array of Coverage tables      */
250  HB_SubstLookupRecord*  SubstLookupRecord;
251				      /* array of substitution lookups */
252  HB_UShort               GlyphCount; /* number of input glyphs        */
253  HB_UShort               SubstCount; /* number of SubstLookupRecords  */
254};
255
256typedef struct HB_ContextSubstFormat3_  HB_ContextSubstFormat3;
257
258
259struct  HB_ContextSubst_
260{
261  union
262  {
263    HB_ContextSubstFormat1  csf1;
264    HB_ContextSubstFormat2  csf2;
265    HB_ContextSubstFormat3  csf3;
266  } csf;
267
268  HB_Byte  SubstFormat;               /* 1, 2, or 3 */
269};
270
271typedef struct HB_ContextSubst_  HB_ContextSubst;
272
273
274/* LookupType 6 */
275
276struct  HB_ChainSubRule_
277{
278  HB_UShort*              Backtrack;  /* array of backtrack glyph IDs     */
279  HB_UShort*              Input;      /* array of input glyph IDs         */
280  HB_UShort*              Lookahead;  /* array of lookahead glyph IDs     */
281  HB_SubstLookupRecord*  SubstLookupRecord;
282				      /* array of SubstLookupRecords      */
283  HB_UShort               BacktrackGlyphCount;
284				      /* total number of backtrack glyphs */
285  HB_UShort               InputGlyphCount;
286				      /* total number of input glyphs     */
287  HB_UShort               LookaheadGlyphCount;
288				      /* total number of lookahead glyphs */
289  HB_UShort               SubstCount; /* number of SubstLookupRecords     */
290};
291
292typedef struct HB_ChainSubRule_  HB_ChainSubRule;
293
294
295struct  HB_ChainSubRuleSet_
296{
297  HB_ChainSubRule*  ChainSubRule;    /* array of ChainSubRule tables  */
298  HB_UShort          ChainSubRuleCount;
299				      /* number of ChainSubRule tables */
300};
301
302typedef struct HB_ChainSubRuleSet_  HB_ChainSubRuleSet;
303
304
305struct  HB_ChainContextSubstFormat1_
306{
307  HB_ChainSubRuleSet*  ChainSubRuleSet;
308				      /* array of ChainSubRuleSet tables  */
309  HB_Coverage          Coverage;     /* Coverage table                   */
310  HB_UShort             ChainSubRuleSetCount;
311				      /* number of ChainSubRuleSet tables */
312};
313
314typedef struct HB_ChainContextSubstFormat1_  HB_ChainContextSubstFormat1;
315
316
317struct  HB_ChainSubClassRule_
318{
319  HB_UShort*              Backtrack;  /* array of backtrack classes      */
320  HB_UShort*              Input;      /* array of context classes        */
321  HB_UShort*              Lookahead;  /* array of lookahead classes      */
322  HB_SubstLookupRecord*  SubstLookupRecord;
323				      /* array of substitution lookups   */
324  HB_UShort               BacktrackGlyphCount;
325				      /* total number of backtrack
326					 classes                         */
327  HB_UShort               InputGlyphCount;
328				      /* total number of context classes */
329  HB_UShort               LookaheadGlyphCount;
330				      /* total number of lookahead
331					 classes                         */
332  HB_UShort               SubstCount; /* number of SubstLookupRecords    */
333};
334
335typedef struct HB_ChainSubClassRule_  HB_ChainSubClassRule;
336
337
338struct  HB_ChainSubClassSet_
339{
340  HB_ChainSubClassRule*  ChainSubClassRule;
341				      /* array of ChainSubClassRule
342					 tables                      */
343  HB_UShort               ChainSubClassRuleCount;
344				      /* number of ChainSubClassRule
345					 tables                      */
346};
347
348typedef struct HB_ChainSubClassSet_  HB_ChainSubClassSet;
349
350
351/* The `MaxXXXLength' fields are not defined in the TTO specification
352   but simplifies the implementation of this format.  It holds the
353   maximal context length used in the specific context rules.         */
354
355struct  HB_ChainContextSubstFormat2_
356{
357  HB_ChainSubClassSet*  ChainSubClassSet;
358				      /* array of ChainSubClassSet
359					 tables                     */
360  HB_Coverage           Coverage;    /* Coverage table             */
361
362  HB_ClassDefinition    BacktrackClassDef;
363				      /* BacktrackClassDef table    */
364  HB_ClassDefinition    InputClassDef;
365				      /* InputClassDef table        */
366  HB_ClassDefinition    LookaheadClassDef;
367				      /* LookaheadClassDef table    */
368
369  HB_UShort              ChainSubClassSetCount;
370				      /* number of ChainSubClassSet
371					 tables                     */
372  HB_UShort              MaxBacktrackLength;
373				      /* maximal backtrack length   */
374  HB_UShort              MaxLookaheadLength;
375				      /* maximal lookahead length   */
376  HB_UShort              MaxInputLength;
377				      /* maximal input length       */
378};
379
380typedef struct HB_ChainContextSubstFormat2_  HB_ChainContextSubstFormat2;
381
382
383struct  HB_ChainContextSubstFormat3_
384{
385  HB_Coverage*           BacktrackCoverage;
386				      /* array of backtrack Coverage
387					 tables                        */
388  HB_Coverage*           InputCoverage;
389				      /* array of input coverage
390					 tables                        */
391  HB_Coverage*           LookaheadCoverage;
392				      /* array of lookahead coverage
393					 tables                        */
394  HB_SubstLookupRecord*  SubstLookupRecord;
395				      /* array of substitution lookups */
396  HB_UShort               BacktrackGlyphCount;
397				      /* number of backtrack glyphs    */
398  HB_UShort               InputGlyphCount;
399				      /* number of input glyphs        */
400  HB_UShort               LookaheadGlyphCount;
401				      /* number of lookahead glyphs    */
402  HB_UShort               SubstCount; /* number of SubstLookupRecords  */
403};
404
405typedef struct HB_ChainContextSubstFormat3_  HB_ChainContextSubstFormat3;
406
407
408struct  HB_ChainContextSubst_
409{
410  union
411  {
412    HB_ChainContextSubstFormat1  ccsf1;
413    HB_ChainContextSubstFormat2  ccsf2;
414    HB_ChainContextSubstFormat3  ccsf3;
415  } ccsf;
416
417  HB_Byte  SubstFormat;               /* 1, 2, or 3 */
418};
419
420typedef struct HB_ChainContextSubst_  HB_ChainContextSubst;
421
422
423#if 0
424/* LookupType 7 */
425struct HB_ExtensionSubst_
426{
427  HB_GSUB_SubTable *subtable;         /* referenced subtable */
428  HB_UShort      SubstFormat;         /* always 1 */
429  HB_UShort      LookuptType;         /* lookup-type of referenced subtable */
430};
431
432typedef struct HB_ExtensionSubst_  HB_ExtensionSubst;
433#endif
434
435
436/* LookupType 8 */
437struct HB_ReverseChainContextSubst_
438{
439  HB_Coverage*  LookaheadCoverage;   /* array of lookahead Coverage
440					 tables                          */
441  HB_UShort*     Substitute;          /* array of substitute Glyph ID    */
442  HB_Coverage*  BacktrackCoverage;   /* array of backtrack Coverage
443					 tables                          */
444  HB_Coverage   Coverage;	        /* coverage table for input glyphs */
445  HB_UShort      SubstFormat;         /* always 1 */
446  HB_UShort      BacktrackGlyphCount; /* number of backtrack glyphs      */
447  HB_UShort      LookaheadGlyphCount; /* number of lookahead glyphs      */
448  HB_UShort      GlyphCount;          /* number of Glyph IDs             */
449};
450
451typedef struct HB_ReverseChainContextSubst_  HB_ReverseChainContextSubst;
452
453
454union  HB_GSUB_SubTable_
455{
456  HB_SingleSubst              single;
457  HB_MultipleSubst            multiple;
458  HB_AlternateSubst           alternate;
459  HB_LigatureSubst            ligature;
460  HB_ContextSubst             context;
461  HB_ChainContextSubst        chain;
462  HB_ReverseChainContextSubst reverse;
463};
464
465
466
467
468HB_INTERNAL HB_Error
469_HB_GSUB_Load_SubTable( HB_GSUB_SubTable* st,
470				  HB_Stream     stream,
471				  HB_UShort     lookup_type );
472
473HB_INTERNAL void
474_HB_GSUB_Free_SubTable( HB_GSUB_SubTable* st,
475			      HB_UShort     lookup_type );
476
477#ifdef HB_USE_PACKED_STRUCTS
478#pragma pack(pop)
479#endif
480
481HB_END_HEADER
482
483#endif /* HARFBUZZ_GSUB_PRIVATE_H */
484