gfx/harfbuzz/src/hb-ot-layout-gdef-table.hh

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /*
michael@0 2 * Copyright © 2007,2008,2009 Red Hat, Inc.
michael@0 3 * Copyright © 2010,2011,2012 Google, Inc.
michael@0 4 *
michael@0 5 * This is part of HarfBuzz, a text shaping library.
michael@0 6 *
michael@0 7 * Permission is hereby granted, without written agreement and without
michael@0 8 * license or royalty fees, to use, copy, modify, and distribute this
michael@0 9 * software and its documentation for any purpose, provided that the
michael@0 10 * above copyright notice and the following two paragraphs appear in
michael@0 11 * all copies of this software.
michael@0 12 *
michael@0 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
michael@0 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
michael@0 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
michael@0 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
michael@0 17 * DAMAGE.
michael@0 18 *
michael@0 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
michael@0 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
michael@0 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
michael@0 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
michael@0 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
michael@0 24 *
michael@0 25 * Red Hat Author(s): Behdad Esfahbod
michael@0 26 * Google Author(s): Behdad Esfahbod
michael@0 27 */
michael@0 28
michael@0 29 #ifndef HB_OT_LAYOUT_GDEF_TABLE_HH
michael@0 30 #define HB_OT_LAYOUT_GDEF_TABLE_HH
michael@0 31
michael@0 32 #include "hb-ot-layout-common-private.hh"
michael@0 33
michael@0 34 #include "hb-font-private.hh"
michael@0 35
michael@0 36
michael@0 37 namespace OT {
michael@0 38
michael@0 39
michael@0 40 /*
michael@0 41 * Attachment List Table
michael@0 42 */
michael@0 43
michael@0 44 typedef ArrayOf<USHORT> AttachPoint; /* Array of contour point indices--in
michael@0 45 * increasing numerical order */
michael@0 46
michael@0 47 struct AttachList
michael@0 48 {
michael@0 49 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
michael@0 50 unsigned int start_offset,
michael@0 51 unsigned int *point_count /* IN/OUT */,
michael@0 52 unsigned int *point_array /* OUT */) const
michael@0 53 {
michael@0 54 unsigned int index = (this+coverage).get_coverage (glyph_id);
michael@0 55 if (index == NOT_COVERED)
michael@0 56 {
michael@0 57 if (point_count)
michael@0 58 *point_count = 0;
michael@0 59 return 0;
michael@0 60 }
michael@0 61
michael@0 62 const AttachPoint &points = this+attachPoint[index];
michael@0 63
michael@0 64 if (point_count) {
michael@0 65 const USHORT *array = points.sub_array (start_offset, point_count);
michael@0 66 unsigned int count = *point_count;
michael@0 67 for (unsigned int i = 0; i < count; i++)
michael@0 68 point_array[i] = array[i];
michael@0 69 }
michael@0 70
michael@0 71 return points.len;
michael@0 72 }
michael@0 73
michael@0 74 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 75 TRACE_SANITIZE (this);
michael@0 76 return TRACE_RETURN (coverage.sanitize (c, this) && attachPoint.sanitize (c, this));
michael@0 77 }
michael@0 78
michael@0 79 protected:
michael@0 80 OffsetTo<Coverage>
michael@0 81 coverage; /* Offset to Coverage table -- from
michael@0 82 * beginning of AttachList table */
michael@0 83 OffsetArrayOf<AttachPoint>
michael@0 84 attachPoint; /* Array of AttachPoint tables
michael@0 85 * in Coverage Index order */
michael@0 86 public:
michael@0 87 DEFINE_SIZE_ARRAY (4, attachPoint);
michael@0 88 };
michael@0 89
michael@0 90 /*
michael@0 91 * Ligature Caret Table
michael@0 92 */
michael@0 93
michael@0 94 struct CaretValueFormat1
michael@0 95 {
michael@0 96 friend struct CaretValue;
michael@0 97
michael@0 98 private:
michael@0 99 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const
michael@0 100 {
michael@0 101 return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate);
michael@0 102 }
michael@0 103
michael@0 104 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 105 TRACE_SANITIZE (this);
michael@0 106 return TRACE_RETURN (c->check_struct (this));
michael@0 107 }
michael@0 108
michael@0 109 protected:
michael@0 110 USHORT caretValueFormat; /* Format identifier--format = 1 */
michael@0 111 SHORT coordinate; /* X or Y value, in design units */
michael@0 112 public:
michael@0 113 DEFINE_SIZE_STATIC (4);
michael@0 114 };
michael@0 115
michael@0 116 struct CaretValueFormat2
michael@0 117 {
michael@0 118 friend struct CaretValue;
michael@0 119
michael@0 120 private:
michael@0 121 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
michael@0 122 {
michael@0 123 hb_position_t x, y;
michael@0 124 if (font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y))
michael@0 125 return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
michael@0 126 else
michael@0 127 return 0;
michael@0 128 }
michael@0 129
michael@0 130 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 131 TRACE_SANITIZE (this);
michael@0 132 return TRACE_RETURN (c->check_struct (this));
michael@0 133 }
michael@0 134
michael@0 135 protected:
michael@0 136 USHORT caretValueFormat; /* Format identifier--format = 2 */
michael@0 137 USHORT caretValuePoint; /* Contour point index on glyph */
michael@0 138 public:
michael@0 139 DEFINE_SIZE_STATIC (4);
michael@0 140 };
michael@0 141
michael@0 142 struct CaretValueFormat3
michael@0 143 {
michael@0 144 friend struct CaretValue;
michael@0 145
michael@0 146 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const
michael@0 147 {
michael@0 148 return HB_DIRECTION_IS_HORIZONTAL (direction) ?
michael@0 149 font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font) :
michael@0 150 font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font);
michael@0 151 }
michael@0 152
michael@0 153 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 154 TRACE_SANITIZE (this);
michael@0 155 return TRACE_RETURN (c->check_struct (this) && deviceTable.sanitize (c, this));
michael@0 156 }
michael@0 157
michael@0 158 protected:
michael@0 159 USHORT caretValueFormat; /* Format identifier--format = 3 */
michael@0 160 SHORT coordinate; /* X or Y value, in design units */
michael@0 161 OffsetTo<Device>
michael@0 162 deviceTable; /* Offset to Device table for X or Y
michael@0 163 * value--from beginning of CaretValue
michael@0 164 * table */
michael@0 165 public:
michael@0 166 DEFINE_SIZE_STATIC (6);
michael@0 167 };
michael@0 168
michael@0 169 struct CaretValue
michael@0 170 {
michael@0 171 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
michael@0 172 {
michael@0 173 switch (u.format) {
michael@0 174 case 1: return u.format1.get_caret_value (font, direction, glyph_id);
michael@0 175 case 2: return u.format2.get_caret_value (font, direction, glyph_id);
michael@0 176 case 3: return u.format3.get_caret_value (font, direction, glyph_id);
michael@0 177 default:return 0;
michael@0 178 }
michael@0 179 }
michael@0 180
michael@0 181 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 182 TRACE_SANITIZE (this);
michael@0 183 if (!u.format.sanitize (c)) return TRACE_RETURN (false);
michael@0 184 switch (u.format) {
michael@0 185 case 1: return TRACE_RETURN (u.format1.sanitize (c));
michael@0 186 case 2: return TRACE_RETURN (u.format2.sanitize (c));
michael@0 187 case 3: return TRACE_RETURN (u.format3.sanitize (c));
michael@0 188 default:return TRACE_RETURN (true);
michael@0 189 }
michael@0 190 }
michael@0 191
michael@0 192 protected:
michael@0 193 union {
michael@0 194 USHORT format; /* Format identifier */
michael@0 195 CaretValueFormat1 format1;
michael@0 196 CaretValueFormat2 format2;
michael@0 197 CaretValueFormat3 format3;
michael@0 198 } u;
michael@0 199 public:
michael@0 200 DEFINE_SIZE_UNION (2, format);
michael@0 201 };
michael@0 202
michael@0 203 struct LigGlyph
michael@0 204 {
michael@0 205 inline unsigned int get_lig_carets (hb_font_t *font,
michael@0 206 hb_direction_t direction,
michael@0 207 hb_codepoint_t glyph_id,
michael@0 208 unsigned int start_offset,
michael@0 209 unsigned int *caret_count /* IN/OUT */,
michael@0 210 hb_position_t *caret_array /* OUT */) const
michael@0 211 {
michael@0 212 if (caret_count) {
michael@0 213 const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
michael@0 214 unsigned int count = *caret_count;
michael@0 215 for (unsigned int i = 0; i < count; i++)
michael@0 216 caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id);
michael@0 217 }
michael@0 218
michael@0 219 return carets.len;
michael@0 220 }
michael@0 221
michael@0 222 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 223 TRACE_SANITIZE (this);
michael@0 224 return TRACE_RETURN (carets.sanitize (c, this));
michael@0 225 }
michael@0 226
michael@0 227 protected:
michael@0 228 OffsetArrayOf<CaretValue>
michael@0 229 carets; /* Offset array of CaretValue tables
michael@0 230 * --from beginning of LigGlyph table
michael@0 231 * --in increasing coordinate order */
michael@0 232 public:
michael@0 233 DEFINE_SIZE_ARRAY (2, carets);
michael@0 234 };
michael@0 235
michael@0 236 struct LigCaretList
michael@0 237 {
michael@0 238 inline unsigned int get_lig_carets (hb_font_t *font,
michael@0 239 hb_direction_t direction,
michael@0 240 hb_codepoint_t glyph_id,
michael@0 241 unsigned int start_offset,
michael@0 242 unsigned int *caret_count /* IN/OUT */,
michael@0 243 hb_position_t *caret_array /* OUT */) const
michael@0 244 {
michael@0 245 unsigned int index = (this+coverage).get_coverage (glyph_id);
michael@0 246 if (index == NOT_COVERED)
michael@0 247 {
michael@0 248 if (caret_count)
michael@0 249 *caret_count = 0;
michael@0 250 return 0;
michael@0 251 }
michael@0 252 const LigGlyph &lig_glyph = this+ligGlyph[index];
michael@0 253 return lig_glyph.get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array);
michael@0 254 }
michael@0 255
michael@0 256 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 257 TRACE_SANITIZE (this);
michael@0 258 return TRACE_RETURN (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this));
michael@0 259 }
michael@0 260
michael@0 261 protected:
michael@0 262 OffsetTo<Coverage>
michael@0 263 coverage; /* Offset to Coverage table--from
michael@0 264 * beginning of LigCaretList table */
michael@0 265 OffsetArrayOf<LigGlyph>
michael@0 266 ligGlyph; /* Array of LigGlyph tables
michael@0 267 * in Coverage Index order */
michael@0 268 public:
michael@0 269 DEFINE_SIZE_ARRAY (4, ligGlyph);
michael@0 270 };
michael@0 271
michael@0 272
michael@0 273 struct MarkGlyphSetsFormat1
michael@0 274 {
michael@0 275 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
michael@0 276 { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
michael@0 277
michael@0 278 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 279 TRACE_SANITIZE (this);
michael@0 280 return TRACE_RETURN (coverage.sanitize (c, this));
michael@0 281 }
michael@0 282
michael@0 283 protected:
michael@0 284 USHORT format; /* Format identifier--format = 1 */
michael@0 285 LongOffsetArrayOf<Coverage>
michael@0 286 coverage; /* Array of long offsets to mark set
michael@0 287 * coverage tables */
michael@0 288 public:
michael@0 289 DEFINE_SIZE_ARRAY (4, coverage);
michael@0 290 };
michael@0 291
michael@0 292 struct MarkGlyphSets
michael@0 293 {
michael@0 294 inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
michael@0 295 {
michael@0 296 switch (u.format) {
michael@0 297 case 1: return u.format1.covers (set_index, glyph_id);
michael@0 298 default:return false;
michael@0 299 }
michael@0 300 }
michael@0 301
michael@0 302 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 303 TRACE_SANITIZE (this);
michael@0 304 if (!u.format.sanitize (c)) return TRACE_RETURN (false);
michael@0 305 switch (u.format) {
michael@0 306 case 1: return TRACE_RETURN (u.format1.sanitize (c));
michael@0 307 default:return TRACE_RETURN (true);
michael@0 308 }
michael@0 309 }
michael@0 310
michael@0 311 protected:
michael@0 312 union {
michael@0 313 USHORT format; /* Format identifier */
michael@0 314 MarkGlyphSetsFormat1 format1;
michael@0 315 } u;
michael@0 316 public:
michael@0 317 DEFINE_SIZE_UNION (2, format);
michael@0 318 };
michael@0 319
michael@0 320
michael@0 321 /*
michael@0 322 * GDEF -- The Glyph Definition Table
michael@0 323 */
michael@0 324
michael@0 325 struct GDEF
michael@0 326 {
michael@0 327 static const hb_tag_t tableTag = HB_OT_TAG_GDEF;
michael@0 328
michael@0 329 enum GlyphClasses {
michael@0 330 UnclassifiedGlyph = 0,
michael@0 331 BaseGlyph = 1,
michael@0 332 LigatureGlyph = 2,
michael@0 333 MarkGlyph = 3,
michael@0 334 ComponentGlyph = 4
michael@0 335 };
michael@0 336
michael@0 337 inline bool has_glyph_classes (void) const { return glyphClassDef != 0; }
michael@0 338 inline unsigned int get_glyph_class (hb_codepoint_t glyph) const
michael@0 339 { return (this+glyphClassDef).get_class (glyph); }
michael@0 340 inline void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const
michael@0 341 { (this+glyphClassDef).add_class (glyphs, klass); }
michael@0 342
michael@0 343 inline bool has_mark_attachment_types (void) const { return markAttachClassDef != 0; }
michael@0 344 inline unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const
michael@0 345 { return (this+markAttachClassDef).get_class (glyph); }
michael@0 346
michael@0 347 inline bool has_attach_points (void) const { return attachList != 0; }
michael@0 348 inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
michael@0 349 unsigned int start_offset,
michael@0 350 unsigned int *point_count /* IN/OUT */,
michael@0 351 unsigned int *point_array /* OUT */) const
michael@0 352 { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
michael@0 353
michael@0 354 inline bool has_lig_carets (void) const { return ligCaretList != 0; }
michael@0 355 inline unsigned int get_lig_carets (hb_font_t *font,
michael@0 356 hb_direction_t direction,
michael@0 357 hb_codepoint_t glyph_id,
michael@0 358 unsigned int start_offset,
michael@0 359 unsigned int *caret_count /* IN/OUT */,
michael@0 360 hb_position_t *caret_array /* OUT */) const
michael@0 361 { return (this+ligCaretList).get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array); }
michael@0 362
michael@0 363 inline bool has_mark_sets (void) const { return version.to_int () >= 0x00010002 && markGlyphSetsDef[0] != 0; }
michael@0 364 inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
michael@0 365 { return version.to_int () >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); }
michael@0 366
michael@0 367 inline bool sanitize (hb_sanitize_context_t *c) {
michael@0 368 TRACE_SANITIZE (this);
michael@0 369 return TRACE_RETURN (version.sanitize (c) &&
michael@0 370 likely (version.major == 1) &&
michael@0 371 glyphClassDef.sanitize (c, this) &&
michael@0 372 attachList.sanitize (c, this) &&
michael@0 373 ligCaretList.sanitize (c, this) &&
michael@0 374 markAttachClassDef.sanitize (c, this) &&
michael@0 375 (version.to_int () < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this)));
michael@0 376 }
michael@0 377
michael@0 378
michael@0 379 /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
michael@0 380 * glyph class and other bits, and high 8-bit gthe mark attachment type (if any).
michael@0 381 * Not to be confused with lookup_props which is very similar. */
michael@0 382 inline unsigned int get_glyph_props (hb_codepoint_t glyph) const
michael@0 383 {
michael@0 384 unsigned int klass = get_glyph_class (glyph);
michael@0 385
michael@0 386 ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs);
michael@0 387 ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures);
michael@0 388 ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks);
michael@0 389
michael@0 390 switch (klass) {
michael@0 391 default: return 0;
michael@0 392 case BaseGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH;
michael@0 393 case LigatureGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
michael@0 394 case MarkGlyph:
michael@0 395 klass = get_mark_attachment_type (glyph);
michael@0 396 return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8);
michael@0 397 }
michael@0 398 }
michael@0 399
michael@0 400
michael@0 401 protected:
michael@0 402 FixedVersion version; /* Version of the GDEF table--currently
michael@0 403 * 0x00010002 */
michael@0 404 OffsetTo<ClassDef>
michael@0 405 glyphClassDef; /* Offset to class definition table
michael@0 406 * for glyph type--from beginning of
michael@0 407 * GDEF header (may be Null) */
michael@0 408 OffsetTo<AttachList>
michael@0 409 attachList; /* Offset to list of glyphs with
michael@0 410 * attachment points--from beginning
michael@0 411 * of GDEF header (may be Null) */
michael@0 412 OffsetTo<LigCaretList>
michael@0 413 ligCaretList; /* Offset to list of positioning points
michael@0 414 * for ligature carets--from beginning
michael@0 415 * of GDEF header (may be Null) */
michael@0 416 OffsetTo<ClassDef>
michael@0 417 markAttachClassDef; /* Offset to class definition table for
michael@0 418 * mark attachment type--from beginning
michael@0 419 * of GDEF header (may be Null) */
michael@0 420 OffsetTo<MarkGlyphSets>
michael@0 421 markGlyphSetsDef[VAR]; /* Offset to the table of mark set
michael@0 422 * definitions--from beginning of GDEF
michael@0 423 * header (may be NULL). Introduced
michael@0 424 * in version 00010002. */
michael@0 425 public:
michael@0 426 DEFINE_SIZE_ARRAY (12, markGlyphSetsDef);
michael@0 427 };
michael@0 428
michael@0 429
michael@0 430 } /* namespace OT */
michael@0 431
michael@0 432
michael@0 433 #endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */

mercurial