michael@0: /* michael@0: * Copyright © 2007,2008,2009 Red Hat, Inc. michael@0: * Copyright © 2010,2011,2012 Google, Inc. michael@0: * michael@0: * This is part of HarfBuzz, a text shaping library. michael@0: * michael@0: * Permission is hereby granted, without written agreement and without michael@0: * license or royalty fees, to use, copy, modify, and distribute this michael@0: * software and its documentation for any purpose, provided that the michael@0: * above copyright notice and the following two paragraphs appear in michael@0: * all copies of this software. michael@0: * michael@0: * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR michael@0: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES michael@0: * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN michael@0: * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH michael@0: * DAMAGE. michael@0: * michael@0: * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, michael@0: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS michael@0: * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO michael@0: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. michael@0: * michael@0: * Red Hat Author(s): Behdad Esfahbod michael@0: * Google Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #ifndef HB_OT_LAYOUT_GDEF_TABLE_HH michael@0: #define HB_OT_LAYOUT_GDEF_TABLE_HH michael@0: michael@0: #include "hb-ot-layout-common-private.hh" michael@0: michael@0: #include "hb-font-private.hh" michael@0: michael@0: michael@0: namespace OT { michael@0: michael@0: michael@0: /* michael@0: * Attachment List Table michael@0: */ michael@0: michael@0: typedef ArrayOf AttachPoint; /* Array of contour point indices--in michael@0: * increasing numerical order */ michael@0: michael@0: struct AttachList michael@0: { michael@0: inline unsigned int get_attach_points (hb_codepoint_t glyph_id, michael@0: unsigned int start_offset, michael@0: unsigned int *point_count /* IN/OUT */, michael@0: unsigned int *point_array /* OUT */) const michael@0: { michael@0: unsigned int index = (this+coverage).get_coverage (glyph_id); michael@0: if (index == NOT_COVERED) michael@0: { michael@0: if (point_count) michael@0: *point_count = 0; michael@0: return 0; michael@0: } michael@0: michael@0: const AttachPoint &points = this+attachPoint[index]; michael@0: michael@0: if (point_count) { michael@0: const USHORT *array = points.sub_array (start_offset, point_count); michael@0: unsigned int count = *point_count; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: point_array[i] = array[i]; michael@0: } michael@0: michael@0: return points.len; michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (coverage.sanitize (c, this) && attachPoint.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: OffsetTo michael@0: coverage; /* Offset to Coverage table -- from michael@0: * beginning of AttachList table */ michael@0: OffsetArrayOf michael@0: attachPoint; /* Array of AttachPoint tables michael@0: * in Coverage Index order */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (4, attachPoint); michael@0: }; michael@0: michael@0: /* michael@0: * Ligature Caret Table michael@0: */ michael@0: michael@0: struct CaretValueFormat1 michael@0: { michael@0: friend struct CaretValue; michael@0: michael@0: private: michael@0: 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: { michael@0: return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (c->check_struct (this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT caretValueFormat; /* Format identifier--format = 1 */ michael@0: SHORT coordinate; /* X or Y value, in design units */ michael@0: public: michael@0: DEFINE_SIZE_STATIC (4); michael@0: }; michael@0: michael@0: struct CaretValueFormat2 michael@0: { michael@0: friend struct CaretValue; michael@0: michael@0: private: michael@0: inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const michael@0: { michael@0: hb_position_t x, y; michael@0: if (font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y)) michael@0: return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y; michael@0: else michael@0: return 0; michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (c->check_struct (this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT caretValueFormat; /* Format identifier--format = 2 */ michael@0: USHORT caretValuePoint; /* Contour point index on glyph */ michael@0: public: michael@0: DEFINE_SIZE_STATIC (4); michael@0: }; michael@0: michael@0: struct CaretValueFormat3 michael@0: { michael@0: friend struct CaretValue; michael@0: michael@0: 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: { michael@0: return HB_DIRECTION_IS_HORIZONTAL (direction) ? michael@0: font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font) : michael@0: font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (c->check_struct (this) && deviceTable.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT caretValueFormat; /* Format identifier--format = 3 */ michael@0: SHORT coordinate; /* X or Y value, in design units */ michael@0: OffsetTo michael@0: deviceTable; /* Offset to Device table for X or Y michael@0: * value--from beginning of CaretValue michael@0: * table */ michael@0: public: michael@0: DEFINE_SIZE_STATIC (6); michael@0: }; michael@0: michael@0: struct CaretValue michael@0: { michael@0: inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const michael@0: { michael@0: switch (u.format) { michael@0: case 1: return u.format1.get_caret_value (font, direction, glyph_id); michael@0: case 2: return u.format2.get_caret_value (font, direction, glyph_id); michael@0: case 3: return u.format3.get_caret_value (font, direction, glyph_id); michael@0: default:return 0; michael@0: } michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!u.format.sanitize (c)) return TRACE_RETURN (false); michael@0: switch (u.format) { michael@0: case 1: return TRACE_RETURN (u.format1.sanitize (c)); michael@0: case 2: return TRACE_RETURN (u.format2.sanitize (c)); michael@0: case 3: return TRACE_RETURN (u.format3.sanitize (c)); michael@0: default:return TRACE_RETURN (true); michael@0: } michael@0: } michael@0: michael@0: protected: michael@0: union { michael@0: USHORT format; /* Format identifier */ michael@0: CaretValueFormat1 format1; michael@0: CaretValueFormat2 format2; michael@0: CaretValueFormat3 format3; michael@0: } u; michael@0: public: michael@0: DEFINE_SIZE_UNION (2, format); michael@0: }; michael@0: michael@0: struct LigGlyph michael@0: { michael@0: inline unsigned int get_lig_carets (hb_font_t *font, michael@0: hb_direction_t direction, michael@0: hb_codepoint_t glyph_id, michael@0: unsigned int start_offset, michael@0: unsigned int *caret_count /* IN/OUT */, michael@0: hb_position_t *caret_array /* OUT */) const michael@0: { michael@0: if (caret_count) { michael@0: const OffsetTo *array = carets.sub_array (start_offset, caret_count); michael@0: unsigned int count = *caret_count; michael@0: for (unsigned int i = 0; i < count; i++) michael@0: caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id); michael@0: } michael@0: michael@0: return carets.len; michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (carets.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: OffsetArrayOf michael@0: carets; /* Offset array of CaretValue tables michael@0: * --from beginning of LigGlyph table michael@0: * --in increasing coordinate order */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (2, carets); michael@0: }; michael@0: michael@0: struct LigCaretList michael@0: { michael@0: inline unsigned int get_lig_carets (hb_font_t *font, michael@0: hb_direction_t direction, michael@0: hb_codepoint_t glyph_id, michael@0: unsigned int start_offset, michael@0: unsigned int *caret_count /* IN/OUT */, michael@0: hb_position_t *caret_array /* OUT */) const michael@0: { michael@0: unsigned int index = (this+coverage).get_coverage (glyph_id); michael@0: if (index == NOT_COVERED) michael@0: { michael@0: if (caret_count) michael@0: *caret_count = 0; michael@0: return 0; michael@0: } michael@0: const LigGlyph &lig_glyph = this+ligGlyph[index]; michael@0: return lig_glyph.get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array); michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: OffsetTo michael@0: coverage; /* Offset to Coverage table--from michael@0: * beginning of LigCaretList table */ michael@0: OffsetArrayOf michael@0: ligGlyph; /* Array of LigGlyph tables michael@0: * in Coverage Index order */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (4, ligGlyph); michael@0: }; michael@0: michael@0: michael@0: struct MarkGlyphSetsFormat1 michael@0: { michael@0: inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const michael@0: { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (coverage.sanitize (c, this)); michael@0: } michael@0: michael@0: protected: michael@0: USHORT format; /* Format identifier--format = 1 */ michael@0: LongOffsetArrayOf michael@0: coverage; /* Array of long offsets to mark set michael@0: * coverage tables */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (4, coverage); michael@0: }; michael@0: michael@0: struct MarkGlyphSets michael@0: { michael@0: inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const michael@0: { michael@0: switch (u.format) { michael@0: case 1: return u.format1.covers (set_index, glyph_id); michael@0: default:return false; michael@0: } michael@0: } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: if (!u.format.sanitize (c)) return TRACE_RETURN (false); michael@0: switch (u.format) { michael@0: case 1: return TRACE_RETURN (u.format1.sanitize (c)); michael@0: default:return TRACE_RETURN (true); michael@0: } michael@0: } michael@0: michael@0: protected: michael@0: union { michael@0: USHORT format; /* Format identifier */ michael@0: MarkGlyphSetsFormat1 format1; michael@0: } u; michael@0: public: michael@0: DEFINE_SIZE_UNION (2, format); michael@0: }; michael@0: michael@0: michael@0: /* michael@0: * GDEF -- The Glyph Definition Table michael@0: */ michael@0: michael@0: struct GDEF michael@0: { michael@0: static const hb_tag_t tableTag = HB_OT_TAG_GDEF; michael@0: michael@0: enum GlyphClasses { michael@0: UnclassifiedGlyph = 0, michael@0: BaseGlyph = 1, michael@0: LigatureGlyph = 2, michael@0: MarkGlyph = 3, michael@0: ComponentGlyph = 4 michael@0: }; michael@0: michael@0: inline bool has_glyph_classes (void) const { return glyphClassDef != 0; } michael@0: inline unsigned int get_glyph_class (hb_codepoint_t glyph) const michael@0: { return (this+glyphClassDef).get_class (glyph); } michael@0: inline void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const michael@0: { (this+glyphClassDef).add_class (glyphs, klass); } michael@0: michael@0: inline bool has_mark_attachment_types (void) const { return markAttachClassDef != 0; } michael@0: inline unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const michael@0: { return (this+markAttachClassDef).get_class (glyph); } michael@0: michael@0: inline bool has_attach_points (void) const { return attachList != 0; } michael@0: inline unsigned int get_attach_points (hb_codepoint_t glyph_id, michael@0: unsigned int start_offset, michael@0: unsigned int *point_count /* IN/OUT */, michael@0: unsigned int *point_array /* OUT */) const michael@0: { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); } michael@0: michael@0: inline bool has_lig_carets (void) const { return ligCaretList != 0; } michael@0: inline unsigned int get_lig_carets (hb_font_t *font, michael@0: hb_direction_t direction, michael@0: hb_codepoint_t glyph_id, michael@0: unsigned int start_offset, michael@0: unsigned int *caret_count /* IN/OUT */, michael@0: hb_position_t *caret_array /* OUT */) const michael@0: { return (this+ligCaretList).get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array); } michael@0: michael@0: inline bool has_mark_sets (void) const { return version.to_int () >= 0x00010002 && markGlyphSetsDef[0] != 0; } michael@0: inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const michael@0: { return version.to_int () >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); } michael@0: michael@0: inline bool sanitize (hb_sanitize_context_t *c) { michael@0: TRACE_SANITIZE (this); michael@0: return TRACE_RETURN (version.sanitize (c) && michael@0: likely (version.major == 1) && michael@0: glyphClassDef.sanitize (c, this) && michael@0: attachList.sanitize (c, this) && michael@0: ligCaretList.sanitize (c, this) && michael@0: markAttachClassDef.sanitize (c, this) && michael@0: (version.to_int () < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this))); michael@0: } michael@0: michael@0: michael@0: /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing michael@0: * glyph class and other bits, and high 8-bit gthe mark attachment type (if any). michael@0: * Not to be confused with lookup_props which is very similar. */ michael@0: inline unsigned int get_glyph_props (hb_codepoint_t glyph) const michael@0: { michael@0: unsigned int klass = get_glyph_class (glyph); michael@0: michael@0: ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs); michael@0: ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures); michael@0: ASSERT_STATIC ((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks); michael@0: michael@0: switch (klass) { michael@0: default: return 0; michael@0: case BaseGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH; michael@0: case LigatureGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE; michael@0: case MarkGlyph: michael@0: klass = get_mark_attachment_type (glyph); michael@0: return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8); michael@0: } michael@0: } michael@0: michael@0: michael@0: protected: michael@0: FixedVersion version; /* Version of the GDEF table--currently michael@0: * 0x00010002 */ michael@0: OffsetTo michael@0: glyphClassDef; /* Offset to class definition table michael@0: * for glyph type--from beginning of michael@0: * GDEF header (may be Null) */ michael@0: OffsetTo michael@0: attachList; /* Offset to list of glyphs with michael@0: * attachment points--from beginning michael@0: * of GDEF header (may be Null) */ michael@0: OffsetTo michael@0: ligCaretList; /* Offset to list of positioning points michael@0: * for ligature carets--from beginning michael@0: * of GDEF header (may be Null) */ michael@0: OffsetTo michael@0: markAttachClassDef; /* Offset to class definition table for michael@0: * mark attachment type--from beginning michael@0: * of GDEF header (may be Null) */ michael@0: OffsetTo michael@0: markGlyphSetsDef[VAR]; /* Offset to the table of mark set michael@0: * definitions--from beginning of GDEF michael@0: * header (may be NULL). Introduced michael@0: * in version 00010002. */ michael@0: public: michael@0: DEFINE_SIZE_ARRAY (12, markGlyphSetsDef); michael@0: }; michael@0: michael@0: michael@0: } /* namespace OT */ michael@0: michael@0: michael@0: #endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */