2 * Copyright © 2007,2008,2009 Red Hat, Inc.
3 * Copyright © 2010,2011,2012 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_TABLE_HH
30 #define HB_OT_LAYOUT_GDEF_TABLE_HH
32 #include "hb-ot-layout-common-private.hh"
34 #include "hb-font-private.hh"
41 * Attachment List Table
44 typedef ArrayOf
<USHORT
> AttachPoint
; /* Array of contour point indices--in
45 * increasing numerical order */
49 inline unsigned int get_attach_points (hb_codepoint_t glyph_id
,
50 unsigned int start_offset
,
51 unsigned int *point_count
/* IN/OUT */,
52 unsigned int *point_array
/* OUT */) const
54 unsigned int index
= (this+coverage
).get_coverage (glyph_id
);
55 if (index
== NOT_COVERED
)
62 const AttachPoint
&points
= this+attachPoint
[index
];
65 const USHORT
*array
= points
.sub_array (start_offset
, point_count
);
66 unsigned int count
= *point_count
;
67 for (unsigned int i
= 0; i
< count
; i
++)
68 point_array
[i
] = array
[i
];
74 inline bool sanitize (hb_sanitize_context_t
*c
) const
76 TRACE_SANITIZE (this);
77 return TRACE_RETURN (coverage
.sanitize (c
, this) && attachPoint
.sanitize (c
, this));
82 coverage
; /* Offset to Coverage table -- from
83 * beginning of AttachList table */
84 OffsetArrayOf
<AttachPoint
>
85 attachPoint
; /* Array of AttachPoint tables
86 * in Coverage Index order */
88 DEFINE_SIZE_ARRAY (4, attachPoint
);
92 * Ligature Caret Table
95 struct CaretValueFormat1
97 friend struct CaretValue
;
100 inline hb_position_t
get_caret_value (hb_font_t
*font
, hb_direction_t direction
, hb_codepoint_t glyph_id HB_UNUSED
) const
102 return HB_DIRECTION_IS_HORIZONTAL (direction
) ? font
->em_scale_x (coordinate
) : font
->em_scale_y (coordinate
);
105 inline bool sanitize (hb_sanitize_context_t
*c
) const
107 TRACE_SANITIZE (this);
108 return TRACE_RETURN (c
->check_struct (this));
112 USHORT caretValueFormat
; /* Format identifier--format = 1 */
113 SHORT coordinate
; /* X or Y value, in design units */
115 DEFINE_SIZE_STATIC (4);
118 struct CaretValueFormat2
120 friend struct CaretValue
;
123 inline hb_position_t
get_caret_value (hb_font_t
*font
, hb_direction_t direction
, hb_codepoint_t glyph_id
) const
126 if (font
->get_glyph_contour_point_for_origin (glyph_id
, caretValuePoint
, direction
, &x
, &y
))
127 return HB_DIRECTION_IS_HORIZONTAL (direction
) ? x
: y
;
132 inline bool sanitize (hb_sanitize_context_t
*c
) const
134 TRACE_SANITIZE (this);
135 return TRACE_RETURN (c
->check_struct (this));
139 USHORT caretValueFormat
; /* Format identifier--format = 2 */
140 USHORT caretValuePoint
; /* Contour point index on glyph */
142 DEFINE_SIZE_STATIC (4);
145 struct CaretValueFormat3
147 friend struct CaretValue
;
149 inline hb_position_t
get_caret_value (hb_font_t
*font
, hb_direction_t direction
, hb_codepoint_t glyph_id HB_UNUSED
) const
151 return HB_DIRECTION_IS_HORIZONTAL (direction
) ?
152 font
->em_scale_x (coordinate
) + (this+deviceTable
).get_x_delta (font
) :
153 font
->em_scale_y (coordinate
) + (this+deviceTable
).get_y_delta (font
);
156 inline bool sanitize (hb_sanitize_context_t
*c
) const
158 TRACE_SANITIZE (this);
159 return TRACE_RETURN (c
->check_struct (this) && deviceTable
.sanitize (c
, this));
163 USHORT caretValueFormat
; /* Format identifier--format = 3 */
164 SHORT coordinate
; /* X or Y value, in design units */
166 deviceTable
; /* Offset to Device table for X or Y
167 * value--from beginning of CaretValue
170 DEFINE_SIZE_STATIC (6);
175 inline hb_position_t
get_caret_value (hb_font_t
*font
, hb_direction_t direction
, hb_codepoint_t glyph_id
) const
178 case 1: return u
.format1
.get_caret_value (font
, direction
, glyph_id
);
179 case 2: return u
.format2
.get_caret_value (font
, direction
, glyph_id
);
180 case 3: return u
.format3
.get_caret_value (font
, direction
, glyph_id
);
185 inline bool sanitize (hb_sanitize_context_t
*c
) const
187 TRACE_SANITIZE (this);
188 if (!u
.format
.sanitize (c
)) return TRACE_RETURN (false);
190 case 1: return TRACE_RETURN (u
.format1
.sanitize (c
));
191 case 2: return TRACE_RETURN (u
.format2
.sanitize (c
));
192 case 3: return TRACE_RETURN (u
.format3
.sanitize (c
));
193 default:return TRACE_RETURN (true);
199 USHORT format
; /* Format identifier */
200 CaretValueFormat1 format1
;
201 CaretValueFormat2 format2
;
202 CaretValueFormat3 format3
;
205 DEFINE_SIZE_UNION (2, format
);
210 inline unsigned int get_lig_carets (hb_font_t
*font
,
211 hb_direction_t direction
,
212 hb_codepoint_t glyph_id
,
213 unsigned int start_offset
,
214 unsigned int *caret_count
/* IN/OUT */,
215 hb_position_t
*caret_array
/* OUT */) const
218 const OffsetTo
<CaretValue
> *array
= carets
.sub_array (start_offset
, caret_count
);
219 unsigned int count
= *caret_count
;
220 for (unsigned int i
= 0; i
< count
; i
++)
221 caret_array
[i
] = (this+array
[i
]).get_caret_value (font
, direction
, glyph_id
);
227 inline bool sanitize (hb_sanitize_context_t
*c
) const
229 TRACE_SANITIZE (this);
230 return TRACE_RETURN (carets
.sanitize (c
, this));
234 OffsetArrayOf
<CaretValue
>
235 carets
; /* Offset array of CaretValue tables
236 * --from beginning of LigGlyph table
237 * --in increasing coordinate order */
239 DEFINE_SIZE_ARRAY (2, carets
);
244 inline unsigned int get_lig_carets (hb_font_t
*font
,
245 hb_direction_t direction
,
246 hb_codepoint_t glyph_id
,
247 unsigned int start_offset
,
248 unsigned int *caret_count
/* IN/OUT */,
249 hb_position_t
*caret_array
/* OUT */) const
251 unsigned int index
= (this+coverage
).get_coverage (glyph_id
);
252 if (index
== NOT_COVERED
)
258 const LigGlyph
&lig_glyph
= this+ligGlyph
[index
];
259 return lig_glyph
.get_lig_carets (font
, direction
, glyph_id
, start_offset
, caret_count
, caret_array
);
262 inline bool sanitize (hb_sanitize_context_t
*c
) const
264 TRACE_SANITIZE (this);
265 return TRACE_RETURN (coverage
.sanitize (c
, this) && ligGlyph
.sanitize (c
, this));
270 coverage
; /* Offset to Coverage table--from
271 * beginning of LigCaretList table */
272 OffsetArrayOf
<LigGlyph
>
273 ligGlyph
; /* Array of LigGlyph tables
274 * in Coverage Index order */
276 DEFINE_SIZE_ARRAY (4, ligGlyph
);
280 struct MarkGlyphSetsFormat1
282 inline bool covers (unsigned int set_index
, hb_codepoint_t glyph_id
) const
283 { return (this+coverage
[set_index
]).get_coverage (glyph_id
) != NOT_COVERED
; }
285 inline bool sanitize (hb_sanitize_context_t
*c
) const
287 TRACE_SANITIZE (this);
288 return TRACE_RETURN (coverage
.sanitize (c
, this));
292 USHORT format
; /* Format identifier--format = 1 */
293 ArrayOf
<OffsetTo
<Coverage
, ULONG
> >
294 coverage
; /* Array of long offsets to mark set
297 DEFINE_SIZE_ARRAY (4, coverage
);
302 inline bool covers (unsigned int set_index
, hb_codepoint_t glyph_id
) const
305 case 1: return u
.format1
.covers (set_index
, glyph_id
);
306 default:return false;
310 inline bool sanitize (hb_sanitize_context_t
*c
) const
312 TRACE_SANITIZE (this);
313 if (!u
.format
.sanitize (c
)) return TRACE_RETURN (false);
315 case 1: return TRACE_RETURN (u
.format1
.sanitize (c
));
316 default:return TRACE_RETURN (true);
322 USHORT format
; /* Format identifier */
323 MarkGlyphSetsFormat1 format1
;
326 DEFINE_SIZE_UNION (2, format
);
331 * GDEF -- The Glyph Definition Table
336 static const hb_tag_t tableTag
= HB_OT_TAG_GDEF
;
339 UnclassifiedGlyph
= 0,
346 inline bool has_glyph_classes (void) const { return glyphClassDef
!= 0; }
347 inline unsigned int get_glyph_class (hb_codepoint_t glyph
) const
348 { return (this+glyphClassDef
).get_class (glyph
); }
349 inline void get_glyphs_in_class (unsigned int klass
, hb_set_t
*glyphs
) const
350 { (this+glyphClassDef
).add_class (glyphs
, klass
); }
352 inline bool has_mark_attachment_types (void) const { return markAttachClassDef
!= 0; }
353 inline unsigned int get_mark_attachment_type (hb_codepoint_t glyph
) const
354 { return (this+markAttachClassDef
).get_class (glyph
); }
356 inline bool has_attach_points (void) const { return attachList
!= 0; }
357 inline unsigned int get_attach_points (hb_codepoint_t glyph_id
,
358 unsigned int start_offset
,
359 unsigned int *point_count
/* IN/OUT */,
360 unsigned int *point_array
/* OUT */) const
361 { return (this+attachList
).get_attach_points (glyph_id
, start_offset
, point_count
, point_array
); }
363 inline bool has_lig_carets (void) const { return ligCaretList
!= 0; }
364 inline unsigned int get_lig_carets (hb_font_t
*font
,
365 hb_direction_t direction
,
366 hb_codepoint_t glyph_id
,
367 unsigned int start_offset
,
368 unsigned int *caret_count
/* IN/OUT */,
369 hb_position_t
*caret_array
/* OUT */) const
370 { return (this+ligCaretList
).get_lig_carets (font
, direction
, glyph_id
, start_offset
, caret_count
, caret_array
); }
372 inline bool has_mark_sets (void) const { return version
.to_int () >= 0x00010002u
&& markGlyphSetsDef
[0] != 0; }
373 inline bool mark_set_covers (unsigned int set_index
, hb_codepoint_t glyph_id
) const
374 { return version
.to_int () >= 0x00010002u
&& (this+markGlyphSetsDef
[0]).covers (set_index
, glyph_id
); }
376 inline bool sanitize (hb_sanitize_context_t
*c
) const
378 TRACE_SANITIZE (this);
379 return TRACE_RETURN (version
.sanitize (c
) &&
380 likely (version
.major
== 1) &&
381 glyphClassDef
.sanitize (c
, this) &&
382 attachList
.sanitize (c
, this) &&
383 ligCaretList
.sanitize (c
, this) &&
384 markAttachClassDef
.sanitize (c
, this) &&
385 (version
.to_int () < 0x00010002u
|| markGlyphSetsDef
[0].sanitize (c
, this)));
389 /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
390 * glyph class and other bits, and high 8-bit gthe mark attachment type (if any).
391 * Not to be confused with lookup_props which is very similar. */
392 inline unsigned int get_glyph_props (hb_codepoint_t glyph
) const
394 unsigned int klass
= get_glyph_class (glyph
);
396 ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH
== (unsigned int) LookupFlag::IgnoreBaseGlyphs
);
397 ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE
== (unsigned int) LookupFlag::IgnoreLigatures
);
398 ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK
== (unsigned int) LookupFlag::IgnoreMarks
);
402 case BaseGlyph
: return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH
;
403 case LigatureGlyph
: return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE
;
405 klass
= get_mark_attachment_type (glyph
);
406 return HB_OT_LAYOUT_GLYPH_PROPS_MARK
| (klass
<< 8);
412 FixedVersion version
; /* Version of the GDEF table--currently
415 glyphClassDef
; /* Offset to class definition table
416 * for glyph type--from beginning of
417 * GDEF header (may be Null) */
419 attachList
; /* Offset to list of glyphs with
420 * attachment points--from beginning
421 * of GDEF header (may be Null) */
422 OffsetTo
<LigCaretList
>
423 ligCaretList
; /* Offset to list of positioning points
424 * for ligature carets--from beginning
425 * of GDEF header (may be Null) */
427 markAttachClassDef
; /* Offset to class definition table for
428 * mark attachment type--from beginning
429 * of GDEF header (may be Null) */
430 OffsetTo
<MarkGlyphSets
>
431 markGlyphSetsDef
[VAR
]; /* Offset to the table of mark set
432 * definitions--from beginning of GDEF
433 * header (may be NULL). Introduced
434 * in version 00010002. */
436 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef
);
443 #endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */