blob: 8565a486233c64f5fbbea353e6813c42e6bb72ed [file] [log] [blame]
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05001/*
Behdad Esfahbodee58aae2009-05-17 05:14:33 -04002 * Copyright (C) 2007,2008,2009 Red Hat, Inc.
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05003 *
4 * This is part of HarfBuzz, an OpenType Layout engine library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Red Hat Author(s): Behdad Esfahbod
25 */
26
Behdad Esfahbod8dd1c8b2008-01-23 05:00:30 -050027#ifndef HB_OT_LAYOUT_GDEF_PRIVATE_H
28#define HB_OT_LAYOUT_GDEF_PRIVATE_H
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -050029
Behdad Esfahbod6f20f722009-05-17 20:28:01 -040030#include "hb-ot-layout-common-private.h"
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -050031
Behdad Esfahbod12360f72008-01-23 15:50:38 -050032
Behdad Esfahbod5f810362009-05-17 00:54:25 -040033#define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, array, name) \
Behdad Esfahbod2d15e722009-04-15 19:50:16 -040034 inline const Type& name (hb_codepoint_t glyph) { \
Behdad Esfahbod5f810362009-05-17 00:54:25 -040035 return this+array[(this+coverage)(glyph)]; \
Behdad Esfahbod12360f72008-01-23 15:50:38 -050036 }
37
38
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040039struct GlyphClassDef : ClassDef {
Behdad Esfahbod2d15e722009-04-15 19:50:16 -040040 static const unsigned int BaseGlyph = 0x0001u;
41 static const unsigned int LigatureGlyph = 0x0002u;
42 static const unsigned int MarkGlyph = 0x0003u;
43 static const unsigned int ComponentGlyph = 0x0004u;
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040044};
45
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050046/*
47 * Attachment List Table
48 */
49
50struct AttachPoint {
Behdad Esfahbodc9a7cbe2009-05-17 01:22:51 -040051 ArrayOf<USHORT>
52 pointIndex; /* Array of contour point indices--in
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050053 * increasing numerical order */
54};
Behdad Esfahbod8b835802009-05-16 22:48:14 -040055ASSERT_SIZE (AttachPoint, 2);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040056
57struct AttachList {
Behdad Esfahbod75860892008-01-23 18:02:28 -050058
Behdad Esfahbod2d15e722009-04-15 19:50:16 -040059 /* const AttachPoint& get_attach_points (hb_codepoint_t glyph); */
Behdad Esfahbod5f810362009-05-17 00:54:25 -040060 DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, attachPoint, get_attach_points);
Behdad Esfahbod303fe622008-01-23 00:20:48 -050061
Behdad Esfahbod12360f72008-01-23 15:50:38 -050062 private:
Behdad Esfahbod3d54bd12009-05-17 00:15:51 -040063 OffsetTo<Coverage>
64 coverage; /* Offset to Coverage table -- from
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040065 * beginning of AttachList table */
Behdad Esfahbod5f810362009-05-17 00:54:25 -040066 OffsetArrayOf<AttachPoint>
67 attachPoint; /* Array of AttachPoint tables
68 * in Coverage Index order */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040069};
Behdad Esfahbod8b835802009-05-16 22:48:14 -040070ASSERT_SIZE (AttachList, 4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040071
72/*
73 * Ligature Caret Table
74 */
75
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040076struct CaretValueFormat1 {
Behdad Esfahbod303fe622008-01-23 00:20:48 -050077
Behdad Esfahbod75860892008-01-23 18:02:28 -050078 friend struct CaretValue;
79
80 private:
Behdad Esfahbod303fe622008-01-23 00:20:48 -050081 inline int get_caret_value (int ppem) const {
82 return /* TODO garbage */ coordinate / ppem;
83 }
84
85 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040086 USHORT caretValueFormat; /* Format identifier--format = 1 */
87 SHORT coordinate; /* X or Y value, in design units */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040088};
Behdad Esfahbod12360f72008-01-23 15:50:38 -050089ASSERT_SIZE (CaretValueFormat1, 4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040090
91struct CaretValueFormat2 {
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040092
Behdad Esfahbod75860892008-01-23 18:02:28 -050093 friend struct CaretValue;
94
95 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040096 inline int get_caret_value (int ppem) const {
Behdad Esfahbod303fe622008-01-23 00:20:48 -050097 return /* TODO garbage */ 0 / ppem;
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040098 }
Behdad Esfahbod303fe622008-01-23 00:20:48 -050099
100 private:
101 USHORT caretValueFormat; /* Format identifier--format = 2 */
102 USHORT caretValuePoint; /* Contour point index on glyph */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400103};
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500104ASSERT_SIZE (CaretValueFormat2, 4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400105
106struct CaretValueFormat3 {
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500107
Behdad Esfahbod75860892008-01-23 18:02:28 -0500108 friend struct CaretValue;
109
110 private:
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500111 inline const Device& get_device (void) const {
Behdad Esfahbod8b835802009-05-16 22:48:14 -0400112 if (HB_UNLIKELY (!deviceTable)) return Null(Device);
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500113 return *(const Device*)((const char*)this + deviceTable);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400114 }
115
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500116 inline int get_caret_value (int ppem) const {
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500117 return /* TODO garbage */ (coordinate + get_device().get_delta (ppem)) / ppem;
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500118 }
119
120 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400121 USHORT caretValueFormat; /* Format identifier--format = 3 */
122 SHORT coordinate; /* X or Y value, in design units */
123 Offset deviceTable; /* Offset to Device table for X or Y
124 * value--from beginning of CaretValue
125 * table */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400126};
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500127ASSERT_SIZE (CaretValueFormat3, 6);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400128
129struct CaretValue {
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400130 /* XXX we need access to a load-contour-point vfunc here */
Behdad Esfahbod75860892008-01-23 18:02:28 -0500131 int get_caret_value (int ppem) const {
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -0400132 switch (u.format) {
133 case 1: return u.format1->get_caret_value(ppem);
134 case 2: return u.format2->get_caret_value(ppem);
135 case 3: return u.format3->get_caret_value(ppem);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400136 default:return 0;
137 }
138 }
139
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500140 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400141 union {
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -0400142 USHORT format; /* Format identifier */
143 CaretValueFormat1 format1[];
144 CaretValueFormat2 format2[];
145 CaretValueFormat3 format3[];
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400146 } u;
147};
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -0400148ASSERT_SIZE (CaretValue, 2);
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -0500149
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500150struct LigGlyph {
Behdad Esfahbod75860892008-01-23 18:02:28 -0500151
152 friend struct LigCaretList;
153
Behdad Esfahbod5f810362009-05-17 00:54:25 -0400154 OffsetArrayOf<CaretValue>
155 caret; /* Array of CaretValue tables
156 * in increasing coordinate order */
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500157};
Behdad Esfahbod8b835802009-05-16 22:48:14 -0400158ASSERT_SIZE (LigGlyph, 2);
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500159
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500160struct LigCaretList {
Behdad Esfahbod75860892008-01-23 18:02:28 -0500161
162 friend struct GDEF;
163
164 private:
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400165 /* const LigGlyph& get_lig_glyph (hb_codepoint_t glyph); */
Behdad Esfahbod5f810362009-05-17 00:54:25 -0400166 DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, ligGlyph, get_lig_glyph);
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500167
168 private:
Behdad Esfahbod3d54bd12009-05-17 00:15:51 -0400169 OffsetTo<Coverage>
170 coverage; /* Offset to Coverage table--from
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500171 * beginning of LigCaretList table */
Behdad Esfahbod5f810362009-05-17 00:54:25 -0400172 OffsetArrayOf<LigGlyph>
173 ligGlyph; /* Array of LigGlyph tables
174 * in Coverage Index order */
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500175};
Behdad Esfahbod8b835802009-05-16 22:48:14 -0400176ASSERT_SIZE (LigCaretList, 4);
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500177
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500178/*
Behdad Esfahbodaefaafe2008-01-23 17:25:29 -0500179 * GDEF
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500180 */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500181
Behdad Esfahbodaefaafe2008-01-23 17:25:29 -0500182struct GDEF {
Behdad Esfahbod75860892008-01-23 18:02:28 -0500183 static const hb_tag_t Tag = HB_TAG ('G','D','E','F');
Behdad Esfahbod600e5eb2008-01-23 02:01:37 -0500184
Behdad Esfahbodaff831e2008-01-24 06:03:45 -0500185 static const hb_ot_layout_class_t UnclassifiedGlyph = 0;
186 static const hb_ot_layout_class_t BaseGlyph = 1;
187 static const hb_ot_layout_class_t LigatureGlyph = 2;
188 static const hb_ot_layout_class_t MarkGlyph = 3;
189 static const hb_ot_layout_class_t ComponentGlyph = 4;
190
Behdad Esfahbodaefaafe2008-01-23 17:25:29 -0500191 STATIC_DEFINE_GET_FOR_DATA (GDEF);
192 /* XXX check version here? */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500193
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400194 inline bool has_glyph_classes () const { return glyphClassDef != 0; }
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400195 inline hb_ot_layout_class_t get_glyph_class (hb_codepoint_t glyph) const {
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400196 return glyphClassDef(this).get_class (glyph);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500197 }
198
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400199 inline bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
Behdad Esfahbod2d15e722009-04-15 19:50:16 -0400200 inline hb_ot_layout_class_t get_mark_attachment_type (hb_codepoint_t glyph) const {
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400201 return markAttachClassDef(this).get_class (glyph);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500202 }
203
204 /* TODO get_attach and get_lig_caret */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400205 inline bool has_attach_list () const { return attachList != 0; }
206 inline bool has_lig_caret_list () const { return ligCaretList != 0; }
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500207
Behdad Esfahbod238c8552009-05-17 00:22:37 -0400208 private:
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500209 Fixed version; /* Version of the GDEF table--initially
210 * 0x00010000 */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400211 OffsetTo<ClassDef>
212 glyphClassDef; /* Offset to class definition table
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500213 * for glyph type--from beginning of
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500214 * GDEF header (may be Null) */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400215 OffsetTo<AttachList>
216 attachList; /* Offset to list of glyphs with
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500217 * attachment points--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500218 * of GDEF header (may be Null) */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400219 OffsetTo<LigCaretList>
220 ligCaretList; /* Offset to list of positioning points
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500221 * for ligature carets--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500222 * of GDEF header (may be Null) */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400223 OffsetTo<ClassDef>
224 markAttachClassDef; /* Offset to class definition table for
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500225 * mark attachment type--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500226 * of GDEF header (may be Null) */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500227};
Behdad Esfahbod8b835802009-05-16 22:48:14 -0400228ASSERT_SIZE (GDEF, 12);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500229
Behdad Esfahbod6f20f722009-05-17 20:28:01 -0400230
Behdad Esfahbod8dd1c8b2008-01-23 05:00:30 -0500231#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_H */