blob: a5b1e87c83a4087475f1d6242f5378763f6b3e3e [file] [log] [blame]
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2007,2008,2009 Red Hat, Inc.
Behdad Esfahbod60fbb362011-05-19 18:46:15 -04003 * Copyright © 2010,2011 Google, Inc.
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05004 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04005 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -05006 *
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 * Red Hat Author(s): Behdad Esfahbod
Behdad Esfahbod98370e82010-10-27 17:39:01 -040026 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod64aef3a2008-01-23 16:14:38 -050027 */
28
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020029#ifndef HB_OT_LAYOUT_GDEF_TABLE_HH
30#define HB_OT_LAYOUT_GDEF_TABLE_HH
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -050031
Behdad Esfahbod5f5b24f2009-08-02 20:03:12 -040032#include "hb-ot-layout-common-private.hh"
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -050033
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040034#include "hb-font-private.hh"
Behdad Esfahbod23c86aa2009-08-03 21:40:20 -040035
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040036
Behdad Esfahbod12360f72008-01-23 15:50:38 -050037
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050038/*
39 * Attachment List Table
40 */
41
Behdad Esfahbode4efdd82009-05-22 18:54:24 -040042typedef ArrayOf<USHORT> AttachPoint; /* Array of contour point indices--in
Behdad Esfahbod1f437e62008-01-23 04:36:40 -050043 * increasing numerical order */
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040044
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -040045struct AttachList
46{
Behdad Esfahbode21899b2009-11-04 16:36:14 -050047 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
48 unsigned int start_offset,
49 unsigned int *point_count /* IN/OUT */,
50 unsigned int *point_array /* OUT */) const
Behdad Esfahbod855720c2009-05-26 12:00:28 -040051 {
Behdad Esfahbod79420ad2009-05-26 12:24:16 -040052 unsigned int index = (this+coverage) (glyph_id);
Behdad Esfahbod62964af2009-05-26 12:40:10 -040053 if (index == NOT_COVERED)
54 {
Behdad Esfahbode21899b2009-11-04 16:36:14 -050055 if (point_count)
56 *point_count = 0;
57 return 0;
Behdad Esfahbod62964af2009-05-26 12:40:10 -040058 }
Behdad Esfahbode21899b2009-11-04 16:36:14 -050059
Behdad Esfahbod79420ad2009-05-26 12:24:16 -040060 const AttachPoint &points = this+attachPoint[index];
61
Behdad Esfahbode21899b2009-11-04 16:36:14 -050062 if (point_count) {
Behdad Esfahbod4f5f1c32010-04-22 00:27:39 -040063 const USHORT *array = points.sub_array (start_offset, point_count);
Behdad Esfahbod48de3732009-11-04 16:59:50 -050064 unsigned int count = *point_count;
Behdad Esfahbode21899b2009-11-04 16:36:14 -050065 for (unsigned int i = 0; i < count; i++)
66 point_array[i] = array[i];
Behdad Esfahbode21899b2009-11-04 16:36:14 -050067 }
Behdad Esfahbod62964af2009-05-26 12:40:10 -040068
Behdad Esfahbode21899b2009-11-04 16:36:14 -050069 return points.len;
Behdad Esfahbod855720c2009-05-26 12:00:28 -040070 }
Behdad Esfahbod303fe622008-01-23 00:20:48 -050071
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -040072 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -040073 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -040074 return coverage.sanitize (c, this)
75 && attachPoint.sanitize (c, this);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -040076 }
77
Behdad Esfahbod855720c2009-05-26 12:00:28 -040078 private:
Behdad Esfahbod3d54bd12009-05-17 00:15:51 -040079 OffsetTo<Coverage>
80 coverage; /* Offset to Coverage table -- from
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040081 * beginning of AttachList table */
Behdad Esfahbod5f810362009-05-17 00:54:25 -040082 OffsetArrayOf<AttachPoint>
83 attachPoint; /* Array of AttachPoint tables
84 * in Coverage Index order */
Behdad Esfahbodb3651232010-05-10 16:57:29 -040085 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -040086 DEFINE_SIZE_ARRAY (4, attachPoint);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040087};
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -040088
89/*
90 * Ligature Caret Table
91 */
92
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -040093struct CaretValueFormat1
94{
Behdad Esfahbod75860892008-01-23 18:02:28 -050095 friend struct CaretValue;
96
97 private:
Behdad Esfahbod60fbb362011-05-19 18:46:15 -040098 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -040099 {
Behdad Esfahbodb6f902a2011-05-11 00:04:15 -0400100 return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate);
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500101 }
102
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400103 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400104 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400105 return c->check_struct (this);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400106 }
107
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500108 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400109 USHORT caretValueFormat; /* Format identifier--format = 1 */
110 SHORT coordinate; /* X or Y value, in design units */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400111 public:
112 DEFINE_SIZE_STATIC (4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400113};
114
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400115struct CaretValueFormat2
116{
Behdad Esfahbod75860892008-01-23 18:02:28 -0500117 friend struct CaretValue;
118
119 private:
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400120 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400121 {
Behdad Esfahbod6f729b42010-04-29 03:59:06 -0400122 hb_position_t x, y;
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400123 if (hb_font_get_glyph_contour_point_for_origin (font, glyph_id, caretValuePoint, direction, &x, &y))
Behdad Esfahbod3357d142010-10-27 12:30:46 -0400124 return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
Behdad Esfahbod6f729b42010-04-29 03:59:06 -0400125 else
126 return 0;
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400127 }
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500128
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400129 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400130 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400131 return c->check_struct (this);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400132 }
133
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500134 private:
135 USHORT caretValueFormat; /* Format identifier--format = 2 */
136 USHORT caretValuePoint; /* Contour point index on glyph */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400137 public:
138 DEFINE_SIZE_STATIC (4);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400139};
140
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400141struct CaretValueFormat3
142{
Behdad Esfahbod75860892008-01-23 18:02:28 -0500143 friend struct CaretValue;
144
Behdad Esfahbodb9452bf2011-06-14 14:47:07 -0400145 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400146 {
Behdad Esfahbod3357d142010-10-27 12:30:46 -0400147 return HB_DIRECTION_IS_HORIZONTAL (direction) ?
Behdad Esfahbodb6f902a2011-05-11 00:04:15 -0400148 font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font) :
149 font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font);
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500150 }
151
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400152 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400153 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400154 return c->check_struct (this)
155 && deviceTable.sanitize (c, this);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400156 }
157
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500158 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400159 USHORT caretValueFormat; /* Format identifier--format = 3 */
160 SHORT coordinate; /* X or Y value, in design units */
Behdad Esfahbod263bbef2009-05-20 00:00:09 -0400161 OffsetTo<Device>
162 deviceTable; /* Offset to Device table for X or Y
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400163 * value--from beginning of CaretValue
164 * table */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400165 public:
166 DEFINE_SIZE_STATIC (6);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400167};
168
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400169struct CaretValue
170{
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400171 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400172 {
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -0400173 switch (u.format) {
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400174 case 1: return u.format1.get_caret_value (font, direction, glyph_id);
175 case 2: return u.format2.get_caret_value (font, direction, glyph_id);
176 case 3: return u.format3.get_caret_value (font, direction, glyph_id);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400177 default:return 0;
178 }
179 }
180
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400181 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400182 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400183 if (!u.format.sanitize (c)) return false;
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400184 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400185 case 1: return u.format1.sanitize (c);
186 case 2: return u.format2.sanitize (c);
187 case 3: return u.format3.sanitize (c);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400188 default:return true;
189 }
190 }
191
Behdad Esfahbod303fe622008-01-23 00:20:48 -0500192 private:
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400193 union {
Behdad Esfahbodf8dc67b2009-05-17 19:47:54 -0400194 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400195 CaretValueFormat1 format1;
196 CaretValueFormat2 format2;
197 CaretValueFormat3 format3;
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400198 } u;
Behdad Esfahboded074222010-05-10 18:08:46 -0400199 public:
Behdad Esfahbod596e4712010-05-10 18:47:48 -0400200 DEFINE_SIZE_UNION (2, format);
Behdad Esfahbod4c2556c2007-07-06 11:29:21 -0400201};
Behdad Esfahbod5b3f7702006-12-28 06:42:37 -0500202
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400203struct LigGlyph
204{
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400205 inline unsigned int get_lig_carets (hb_font_t *font,
Behdad Esfahbod3357d142010-10-27 12:30:46 -0400206 hb_direction_t direction,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500207 hb_codepoint_t glyph_id,
208 unsigned int start_offset,
209 unsigned int *caret_count /* IN/OUT */,
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400210 hb_position_t *caret_array /* OUT */) const
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400211 {
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500212 if (caret_count) {
Behdad Esfahbod4f5f1c32010-04-22 00:27:39 -0400213 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
Behdad Esfahbod48de3732009-11-04 16:59:50 -0500214 unsigned int count = *caret_count;
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500215 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400216 caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id);
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500217 }
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400218
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500219 return carets.len;
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400220 }
Behdad Esfahbod75860892008-01-23 18:02:28 -0500221
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400222 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400223 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400224 return carets.sanitize (c, this);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400225 }
226
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400227 private:
Behdad Esfahbod5f810362009-05-17 00:54:25 -0400228 OffsetArrayOf<CaretValue>
Behdad Esfahbod3564ee52009-08-14 18:32:56 -0400229 carets; /* Offset array of CaretValue tables
Behdad Esfahbode4efdd82009-05-22 18:54:24 -0400230 * --from beginning of LigGlyph table
231 * --in increasing coordinate order */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400232 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400233 DEFINE_SIZE_ARRAY (2, carets);
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500234};
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500235
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400236struct LigCaretList
237{
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400238 inline unsigned int get_lig_carets (hb_font_t *font,
Behdad Esfahbod3357d142010-10-27 12:30:46 -0400239 hb_direction_t direction,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500240 hb_codepoint_t glyph_id,
241 unsigned int start_offset,
242 unsigned int *caret_count /* IN/OUT */,
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400243 hb_position_t *caret_array /* OUT */) const
Behdad Esfahbod855720c2009-05-26 12:00:28 -0400244 {
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400245 unsigned int index = (this+coverage) (glyph_id);
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400246 if (index == NOT_COVERED)
247 {
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500248 if (caret_count)
249 *caret_count = 0;
250 return 0;
Behdad Esfahbod62964af2009-05-26 12:40:10 -0400251 }
252 const LigGlyph &lig_glyph = this+ligGlyph[index];
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400253 return lig_glyph.get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array);
Behdad Esfahbod855720c2009-05-26 12:00:28 -0400254 }
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500255
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400256 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400257 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400258 return coverage.sanitize (c, this)
259 && ligGlyph.sanitize (c, this);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400260 }
261
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500262 private:
Behdad Esfahbod3d54bd12009-05-17 00:15:51 -0400263 OffsetTo<Coverage>
264 coverage; /* Offset to Coverage table--from
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500265 * beginning of LigCaretList table */
Behdad Esfahbod5f810362009-05-17 00:54:25 -0400266 OffsetArrayOf<LigGlyph>
267 ligGlyph; /* Array of LigGlyph tables
268 * in Coverage Index order */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400269 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400270 DEFINE_SIZE_ARRAY (4, ligGlyph);
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500271};
Behdad Esfahbod12360f72008-01-23 15:50:38 -0500272
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400273
274struct MarkGlyphSetsFormat1
275{
276 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
277 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
278
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400279 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400280 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400281 return coverage.sanitize (c, this);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400282 }
283
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400284 private:
285 USHORT format; /* Format identifier--format = 1 */
286 LongOffsetArrayOf<Coverage>
287 coverage; /* Array of long offsets to mark set
288 * coverage tables */
Behdad Esfahbodb3651232010-05-10 16:57:29 -0400289 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400290 DEFINE_SIZE_ARRAY (4, coverage);
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400291};
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400292
293struct MarkGlyphSets
294{
295 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
296 {
297 switch (u.format) {
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400298 case 1: return u.format1.covers (set_index, glyph_id);
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400299 default:return false;
300 }
301 }
302
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400303 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400304 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400305 if (!u.format.sanitize (c)) return false;
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400306 switch (u.format) {
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400307 case 1: return u.format1.sanitize (c);
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400308 default:return true;
309 }
310 }
311
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400312 private:
313 union {
314 USHORT format; /* Format identifier */
Behdad Esfahboddacebca2010-05-10 19:45:41 -0400315 MarkGlyphSetsFormat1 format1;
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400316 } u;
Behdad Esfahboded074222010-05-10 18:08:46 -0400317 public:
Behdad Esfahbod596e4712010-05-10 18:47:48 -0400318 DEFINE_SIZE_UNION (2, format);
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400319};
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400320
321
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500322/*
Behdad Esfahbodaefaafe2008-01-23 17:25:29 -0500323 * GDEF
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500324 */
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500325
Behdad Esfahbod60d77cf2009-05-19 23:58:54 -0400326struct GDEF
327{
Behdad Esfahboda328d662009-08-04 20:27:05 -0400328 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
Behdad Esfahbod600e5eb2008-01-23 02:01:37 -0500329
Behdad Esfahbod4fa77d32009-05-18 18:44:54 -0400330 enum {
331 UnclassifiedGlyph = 0,
332 BaseGlyph = 1,
333 LigatureGlyph = 2,
334 MarkGlyph = 3,
Behdad Esfahbod8f034d52009-08-18 16:41:59 -0400335 ComponentGlyph = 4
Behdad Esfahbod4fa77d32009-05-18 18:44:54 -0400336 };
Behdad Esfahbodaff831e2008-01-24 06:03:45 -0500337
Behdad Esfahbod7f97d2c2010-10-01 18:58:50 -0400338 inline bool has_glyph_classes (void) const { return glyphClassDef != 0; }
Behdad Esfahbod98370e82010-10-27 17:39:01 -0400339 inline unsigned int get_glyph_class (hb_codepoint_t glyph) const
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400340 { return (this+glyphClassDef).get_class (glyph); }
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500341
Behdad Esfahbod7f97d2c2010-10-01 18:58:50 -0400342 inline bool has_mark_attachment_types (void) const { return markAttachClassDef != 0; }
Behdad Esfahbod98370e82010-10-27 17:39:01 -0400343 inline unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400344 { return (this+markAttachClassDef).get_class (glyph); }
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500345
Behdad Esfahbod7f97d2c2010-10-01 18:58:50 -0400346 inline bool has_attach_points (void) const { return attachList != 0; }
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500347 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
348 unsigned int start_offset,
349 unsigned int *point_count /* IN/OUT */,
350 unsigned int *point_array /* OUT */) const
351 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
Behdad Esfahbod79420ad2009-05-26 12:24:16 -0400352
Behdad Esfahbod7f97d2c2010-10-01 18:58:50 -0400353 inline bool has_lig_carets (void) const { return ligCaretList != 0; }
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400354 inline unsigned int get_lig_carets (hb_font_t *font,
Behdad Esfahbod3357d142010-10-27 12:30:46 -0400355 hb_direction_t direction,
Behdad Esfahbode21899b2009-11-04 16:36:14 -0500356 hb_codepoint_t glyph_id,
357 unsigned int start_offset,
358 unsigned int *caret_count /* IN/OUT */,
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400359 hb_position_t *caret_array /* OUT */) const
Behdad Esfahbodabcfe9b2011-05-11 00:02:02 -0400360 { return (this+ligCaretList).get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array); }
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500361
Behdad Esfahbod4f28fbd2011-05-31 12:33:11 -0400362 inline bool has_mark_sets (void) const { return version.to_int () >= 0x00010002 && markGlyphSetsDef[0] != 0; }
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400363 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
Behdad Esfahbod4f28fbd2011-05-31 12:33:11 -0400364 { return version.to_int () >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400365
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400366 inline bool sanitize (hb_sanitize_context_t *c) {
Behdad Esfahbod3e2401f2009-08-28 17:17:11 -0400367 TRACE_SANITIZE ();
Behdad Esfahbodd7cfb3b2010-05-13 14:18:49 -0400368 return version.sanitize (c) && likely (version.major == 1)
369 && glyphClassDef.sanitize (c, this)
370 && attachList.sanitize (c, this)
371 && ligCaretList.sanitize (c, this)
372 && markAttachClassDef.sanitize (c, this)
Behdad Esfahbod4f28fbd2011-05-31 12:33:11 -0400373 && (version.to_int () < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this));
Behdad Esfahbode49a84c2009-08-04 14:33:23 -0400374 }
375
Behdad Esfahbodbf94b3a2010-10-27 22:37:59 -0400376
377 /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
378 * glyph class and other bits, and high 8-bit gthe mark attachment type (if any).
379 * Not to be confused with lookup_props which is very similar. */
380 inline unsigned int get_glyph_props (hb_codepoint_t glyph) const
381 {
382 unsigned int klass = get_glyph_class (glyph);
383
384 switch (klass) {
385 default:
386 case UnclassifiedGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED;
387 case BaseGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH;
388 case LigatureGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE;
389 case ComponentGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT;
390 case MarkGlyph:
391 klass = get_mark_attachment_type (glyph);
392 return HB_OT_LAYOUT_GLYPH_CLASS_MARK | (klass << 8);
393 }
394 }
395
396
Behdad Esfahbod238c8552009-05-17 00:22:37 -0400397 private:
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400398 FixedVersion version; /* Version of the GDEF table--currently
399 * 0x00010002 */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400400 OffsetTo<ClassDef>
401 glyphClassDef; /* Offset to class definition table
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500402 * for glyph type--from beginning of
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500403 * GDEF header (may be Null) */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400404 OffsetTo<AttachList>
405 attachList; /* Offset to list of glyphs with
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500406 * attachment points--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500407 * of GDEF header (may be Null) */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400408 OffsetTo<LigCaretList>
409 ligCaretList; /* Offset to list of positioning points
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500410 * for ligature carets--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500411 * of GDEF header (may be Null) */
Behdad Esfahbod9e4d9d72009-05-17 00:09:20 -0400412 OffsetTo<ClassDef>
413 markAttachClassDef; /* Offset to class definition table for
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500414 * mark attachment type--from beginning
Behdad Esfahbod1f437e62008-01-23 04:36:40 -0500415 * of GDEF header (may be Null) */
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400416 OffsetTo<MarkGlyphSets>
Behdad Esfahbodd3480ba2009-11-03 10:47:29 -0500417 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
Behdad Esfahbode4b92b82009-05-26 15:38:53 -0400418 * definitions--from beginning of GDEF
419 * header (may be NULL). Introduced
420 * in version 00010002. */
Behdad Esfahbod569da922010-05-10 16:38:32 -0400421 public:
Behdad Esfahbod0eb9fc62010-05-10 19:01:17 -0400422 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef);
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500423};
Behdad Esfahbodb9d76882008-01-23 01:38:10 -0500424
Behdad Esfahbod6f20f722009-05-17 20:28:01 -0400425
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400426
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +0200427#endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */