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_GDEF_H
27 #define HARFBUZZ_GDEF_H
28 
29 #include "harfbuzz-open.h"
30 #include "harfbuzz-stream.h"
31 
32 HB_BEGIN_HEADER
33 
34 /* GDEF glyph properties.  Note that HB_GDEF_COMPONENT has no corresponding
35  * flag in the LookupFlag field.     */
36 #define HB_GDEF_BASE_GLYPH  0x0002
37 #define HB_GDEF_LIGATURE    0x0004
38 #define HB_GDEF_MARK        0x0008
39 #define HB_GDEF_COMPONENT   0x0010
40 
41 
42 typedef struct HB_AttachPoint_  HB_AttachPoint;
43 
44 
45 struct  HB_AttachList_
46 {
47   HB_AttachPoint*   AttachPoint;      /* array of AttachPoint tables */
48   HB_Coverage       Coverage;         /* Coverage table              */
49   HB_UShort         GlyphCount;       /* number of glyphs with
50 					 attachments                 */
51   HB_Bool           loaded;
52 };
53 
54 typedef struct HB_AttachList_  HB_AttachList;
55 
56 typedef struct HB_LigGlyph_  HB_LigGlyph;
57 
58 struct  HB_LigCaretList_
59 {
60   HB_LigGlyph*   LigGlyph;            /* array of LigGlyph tables  */
61   HB_Coverage    Coverage;            /* Coverage table            */
62   HB_UShort      LigGlyphCount;       /* number of ligature glyphs */
63   HB_Bool        loaded;
64 };
65 
66 typedef struct HB_LigCaretList_  HB_LigCaretList;
67 
68 
69 
70 /* The `NewGlyphClasses' field is not defined in the TTO specification.
71    We use it for fonts with a constructed `GlyphClassDef' structure
72    (i.e., which don't have a GDEF table) to collect glyph classes
73    assigned during the lookup process.  The number of arrays in this
74    pointer array is GlyphClassDef->cd.cd2.ClassRangeCount+1; the nth
75    array then contains the glyph class values of the glyphs not covered
76    by the ClassRangeRecords structures with index n-1 and n.  We store
77    glyph class values for four glyphs in a single array element.
78 
79    `LastGlyph' is identical to the number of glyphs minus one in the
80    font; we need it only if `NewGlyphClasses' is not NULL (to have an
81    upper bound for the last array).
82 
83    Note that we first store the file offset to the `MarkAttachClassDef'
84    field (which has been introduced in OpenType 1.2) -- since the
85    `Version' field value hasn't been increased to indicate that we have
86    one more field for some obscure reason, we must parse the GSUB table
87    to find out whether class values refer to this table.  Only then we
88    can finally load the MarkAttachClassDef structure if necessary.      */
89 
90 struct  HB_GDEFHeader_
91 {
92   HB_UShort**          NewGlyphClasses;
93   HB_UInt             offset;
94   HB_UInt             MarkAttachClassDef_offset;
95 
96   HB_16Dot16             Version;
97 
98   HB_ClassDefinition   GlyphClassDef;
99   HB_AttachList        AttachList;
100   HB_LigCaretList      LigCaretList;
101   HB_ClassDefinition   MarkAttachClassDef;        /* new in OT 1.2 */
102 
103   HB_UShort            LastGlyph;
104 };
105 
106 typedef struct HB_GDEFHeader_   HB_GDEFHeader;
107 typedef struct HB_GDEFHeader_*  HB_GDEF;
108 
109 
110 HB_Error  HB_New_GDEF_Table( HB_GDEFHeader** retptr );
111 
112 
113 HB_Error  HB_Load_GDEF_Table( HB_Stream       stream,
114 			      HB_GDEFHeader** gdef );
115 
116 
117 HB_Error  HB_Done_GDEF_Table ( HB_GDEFHeader* gdef );
118 
119 
120 HB_Error  HB_GDEF_Get_Glyph_Property( HB_GDEFHeader*  gdef,
121 				      HB_UShort        glyphID,
122 				      HB_UShort*       property );
123 
124 HB_Error  HB_GDEF_Build_ClassDefinition( HB_GDEFHeader*  gdef,
125 					 HB_UShort        num_glyphs,
126 					 HB_UShort        glyph_count,
127 					 HB_UShort*       glyph_array,
128 					 HB_UShort*       class_array );
129 
130 HB_END_HEADER
131 
132 #endif /* HARFBUZZ_GDEF_H */
133