2 * Copyright © 2007,2008,2009 Red Hat, Inc.
3 * Copyright © 2010,2011 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
29 #ifndef HB_OT_LAYOUT_GDEF_PRIVATE_HH
30 #define HB_OT_LAYOUT_GDEF_PRIVATE_HH
32 #include "hb-ot-layout-common-private.hh"
34 #include "hb-font-private.hh"
40 * Attachment List Table
43 typedef ArrayOf<USHORT> AttachPoint; /* Array of contour point indices--in
44 * increasing numerical order */
48 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
49 unsigned int start_offset,
50 unsigned int *point_count /* IN/OUT */,
51 unsigned int *point_array /* OUT */) const
53 unsigned int index = (this+coverage) (glyph_id);
54 if (index == NOT_COVERED)
61 const AttachPoint &points = this+attachPoint[index];
64 const USHORT *array = points.sub_array (start_offset, point_count);
65 unsigned int count = *point_count;
66 for (unsigned int i = 0; i < count; i++)
67 point_array[i] = array[i];
73 inline bool sanitize (hb_sanitize_context_t *c) {
75 return coverage.sanitize (c, this)
76 && attachPoint.sanitize (c, this);
81 coverage; /* Offset to Coverage table -- from
82 * beginning of AttachList table */
83 OffsetArrayOf<AttachPoint>
84 attachPoint; /* Array of AttachPoint tables
85 * in Coverage Index order */
87 DEFINE_SIZE_ARRAY (4, attachPoint);
91 * Ligature Caret Table
94 struct CaretValueFormat1
96 friend struct CaretValue;
99 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const
101 return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate);
104 inline bool sanitize (hb_sanitize_context_t *c) {
106 return c->check_struct (this);
110 USHORT caretValueFormat; /* Format identifier--format = 1 */
111 SHORT coordinate; /* X or Y value, in design units */
113 DEFINE_SIZE_STATIC (4);
116 struct CaretValueFormat2
118 friend struct CaretValue;
121 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
124 if (hb_font_get_glyph_contour_point_for_origin (font, glyph_id, caretValuePoint, direction, &x, &y))
125 return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
130 inline bool sanitize (hb_sanitize_context_t *c) {
132 return c->check_struct (this);
136 USHORT caretValueFormat; /* Format identifier--format = 2 */
137 USHORT caretValuePoint; /* Contour point index on glyph */
139 DEFINE_SIZE_STATIC (4);
142 struct CaretValueFormat3
144 friend struct CaretValue;
146 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
148 return HB_DIRECTION_IS_HORIZONTAL (direction) ?
149 font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font) :
150 font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font);
153 inline bool sanitize (hb_sanitize_context_t *c) {
155 return c->check_struct (this)
156 && deviceTable.sanitize (c, this);
160 USHORT caretValueFormat; /* Format identifier--format = 3 */
161 SHORT coordinate; /* X or Y value, in design units */
163 deviceTable; /* Offset to Device table for X or Y
164 * value--from beginning of CaretValue
167 DEFINE_SIZE_STATIC (6);
172 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
175 case 1: return u.format1.get_caret_value (font, direction, glyph_id);
176 case 2: return u.format2.get_caret_value (font, direction, glyph_id);
177 case 3: return u.format3.get_caret_value (font, direction, glyph_id);
182 inline bool sanitize (hb_sanitize_context_t *c) {
184 if (!u.format.sanitize (c)) return false;
186 case 1: return u.format1.sanitize (c);
187 case 2: return u.format2.sanitize (c);
188 case 3: return u.format3.sanitize (c);
195 USHORT format; /* Format identifier */
196 CaretValueFormat1 format1;
197 CaretValueFormat2 format2;
198 CaretValueFormat3 format3;
201 DEFINE_SIZE_UNION (2, format);
206 inline unsigned int get_lig_carets (hb_font_t *font,
207 hb_direction_t direction,
208 hb_codepoint_t glyph_id,
209 unsigned int start_offset,
210 unsigned int *caret_count /* IN/OUT */,
211 hb_position_t *caret_array /* OUT */) const
214 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
215 unsigned int count = *caret_count;
216 for (unsigned int i = 0; i < count; i++)
217 caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id);
223 inline bool sanitize (hb_sanitize_context_t *c) {
225 return carets.sanitize (c, this);
229 OffsetArrayOf<CaretValue>
230 carets; /* Offset array of CaretValue tables
231 * --from beginning of LigGlyph table
232 * --in increasing coordinate order */
234 DEFINE_SIZE_ARRAY (2, carets);
239 inline unsigned int get_lig_carets (hb_font_t *font,
240 hb_direction_t direction,
241 hb_codepoint_t glyph_id,
242 unsigned int start_offset,
243 unsigned int *caret_count /* IN/OUT */,
244 hb_position_t *caret_array /* OUT */) const
246 unsigned int index = (this+coverage) (glyph_id);
247 if (index == NOT_COVERED)
253 const LigGlyph &lig_glyph = this+ligGlyph[index];
254 return lig_glyph.get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array);
257 inline bool sanitize (hb_sanitize_context_t *c) {
259 return coverage.sanitize (c, this)
260 && ligGlyph.sanitize (c, this);
265 coverage; /* Offset to Coverage table--from
266 * beginning of LigCaretList table */
267 OffsetArrayOf<LigGlyph>
268 ligGlyph; /* Array of LigGlyph tables
269 * in Coverage Index order */
271 DEFINE_SIZE_ARRAY (4, ligGlyph);
275 struct MarkGlyphSetsFormat1
277 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
278 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
280 inline bool sanitize (hb_sanitize_context_t *c) {
282 return coverage.sanitize (c, this);
286 USHORT format; /* Format identifier--format = 1 */
287 LongOffsetArrayOf<Coverage>
288 coverage; /* Array of long offsets to mark set
291 DEFINE_SIZE_ARRAY (4, coverage);
296 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
299 case 1: return u.format1.covers (set_index, glyph_id);
300 default:return false;
304 inline bool sanitize (hb_sanitize_context_t *c) {
306 if (!u.format.sanitize (c)) return false;
308 case 1: return u.format1.sanitize (c);
315 USHORT format; /* Format identifier */
316 MarkGlyphSetsFormat1 format1;
319 DEFINE_SIZE_UNION (2, format);
329 static const hb_tag_t Tag = HB_OT_TAG_GDEF;
332 UnclassifiedGlyph = 0,
339 inline bool has_glyph_classes (void) const { return glyphClassDef != 0; }
340 inline unsigned int get_glyph_class (hb_codepoint_t glyph) const
341 { return (this+glyphClassDef).get_class (glyph); }
343 inline bool has_mark_attachment_types (void) const { return markAttachClassDef != 0; }
344 inline unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const
345 { return (this+markAttachClassDef).get_class (glyph); }
347 inline bool has_attach_points (void) const { return attachList != 0; }
348 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
349 unsigned int start_offset,
350 unsigned int *point_count /* IN/OUT */,
351 unsigned int *point_array /* OUT */) const
352 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
354 inline bool has_lig_carets (void) const { return ligCaretList != 0; }
355 inline unsigned int get_lig_carets (hb_font_t *font,
356 hb_direction_t direction,
357 hb_codepoint_t glyph_id,
358 unsigned int start_offset,
359 unsigned int *caret_count /* IN/OUT */,
360 hb_position_t *caret_array /* OUT */) const
361 { return (this+ligCaretList).get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array); }
363 inline bool has_mark_sets (void) const { return version >= 0x00010002 && markGlyphSetsDef[0] != 0; }
364 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
365 { return version >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
367 inline bool sanitize (hb_sanitize_context_t *c) {
369 return version.sanitize (c) && likely (version.major == 1)
370 && glyphClassDef.sanitize (c, this)
371 && attachList.sanitize (c, this)
372 && ligCaretList.sanitize (c, this)
373 && markAttachClassDef.sanitize (c, this)
374 && (version < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this));
378 /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
379 * glyph class and other bits, and high 8-bit gthe mark attachment type (if any).
380 * Not to be confused with lookup_props which is very similar. */
381 inline unsigned int get_glyph_props (hb_codepoint_t glyph) const
383 unsigned int klass = get_glyph_class (glyph);
387 case UnclassifiedGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED;
388 case BaseGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH;
389 case LigatureGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE;
390 case ComponentGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT;
392 klass = get_mark_attachment_type (glyph);
393 return HB_OT_LAYOUT_GLYPH_CLASS_MARK | (klass << 8);
399 FixedVersion version; /* Version of the GDEF table--currently
402 glyphClassDef; /* Offset to class definition table
403 * for glyph type--from beginning of
404 * GDEF header (may be Null) */
406 attachList; /* Offset to list of glyphs with
407 * attachment points--from beginning
408 * of GDEF header (may be Null) */
409 OffsetTo<LigCaretList>
410 ligCaretList; /* Offset to list of positioning points
411 * for ligature carets--from beginning
412 * of GDEF header (may be Null) */
414 markAttachClassDef; /* Offset to class definition table for
415 * mark attachment type--from beginning
416 * of GDEF header (may be Null) */
417 OffsetTo<MarkGlyphSets>
418 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
419 * definitions--from beginning of GDEF
420 * header (may be NULL). Introduced
421 * in version 00010002. */
423 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef);
429 #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */