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