< prev index next >

src/java.desktop/share/native/libfontmanager/harfbuzz/hb-ot-layout-gdef-table.hh

Print this page




  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
  26  * Google Author(s): Behdad Esfahbod
  27  */
  28 
  29 #ifndef HB_OT_LAYOUT_GDEF_TABLE_HH
  30 #define HB_OT_LAYOUT_GDEF_TABLE_HH
  31 
  32 #include "hb-ot-layout-common-private.hh"
  33 
  34 #include "hb-font-private.hh"
  35 
  36 
  37 namespace OT {
  38 
  39 
  40 /*
  41  * Attachment List Table
  42  */
  43 
  44 typedef ArrayOf<HBUINT16> AttachPoint;  /* Array of contour point indices--in
  45                                          * increasing numerical order */
  46 
  47 struct AttachList
  48 {
  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
  53   {
  54     unsigned int index = (this+coverage).get_coverage (glyph_id);
  55     if (index == NOT_COVERED)
  56     {
  57       if (point_count)
  58         *point_count = 0;
  59       return 0;
  60     }
  61 
  62     const AttachPoint &points = this+attachPoint[index];
  63 
  64     if (point_count) {
  65       const HBUINT16 *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];
  69     }
  70 
  71     return points.len;
  72   }
  73 
  74   inline bool sanitize (hb_sanitize_context_t *c) const
  75   {
  76     TRACE_SANITIZE (this);
  77     return_trace (coverage.sanitize (c, this) && attachPoint.sanitize (c, this));
  78   }
  79 
  80   protected:
  81   OffsetTo<Coverage>
  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 */
  87   public:
  88   DEFINE_SIZE_ARRAY (4, attachPoint);
  89 };
  90 
  91 /*
  92  * Ligature Caret Table
  93  */
  94 
  95 struct CaretValueFormat1
  96 {
  97   friend struct CaretValue;
  98 
  99   private:
 100   inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction) const
 101   {
 102     return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate);
 103   }
 104 
 105   inline bool sanitize (hb_sanitize_context_t *c) const
 106   {
 107     TRACE_SANITIZE (this);
 108     return_trace (c->check_struct (this));
 109   }
 110 
 111   protected:
 112   HBUINT16      caretValueFormat;       /* Format identifier--format = 1 */
 113   FWORD         coordinate;             /* X or Y value, in design units */
 114   public:
 115   DEFINE_SIZE_STATIC (4);
 116 };
 117 
 118 struct CaretValueFormat2
 119 {
 120   friend struct CaretValue;
 121 
 122   private:
 123   inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
 124   {
 125     hb_position_t x, y;
 126     if (font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y))
 127       return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
 128     else
 129       return 0;
 130   }
 131 
 132   inline bool sanitize (hb_sanitize_context_t *c) const
 133   {
 134     TRACE_SANITIZE (this);
 135     return_trace (c->check_struct (this));
 136   }
 137 
 138   protected:
 139   HBUINT16      caretValueFormat;       /* Format identifier--format = 2 */
 140   HBUINT16      caretValuePoint;        /* Contour point index on glyph */
 141   public:
 142   DEFINE_SIZE_STATIC (4);
 143 };
 144 
 145 struct CaretValueFormat3
 146 {
 147   friend struct CaretValue;
 148 
 149   inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, const VariationStore &var_store) const

 150   {
 151     return HB_DIRECTION_IS_HORIZONTAL (direction) ?
 152            font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font, var_store) :
 153            font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font, var_store);
 154   }
 155 
 156   inline bool sanitize (hb_sanitize_context_t *c) const
 157   {
 158     TRACE_SANITIZE (this);
 159     return_trace (c->check_struct (this) && deviceTable.sanitize (c, this));
 160   }
 161 
 162   protected:
 163   HBUINT16      caretValueFormat;       /* Format identifier--format = 3 */
 164   FWORD         coordinate;             /* X or Y value, in design units */
 165   OffsetTo<Device>
 166                 deviceTable;            /* Offset to Device table for X or Y
 167                                          * value--from beginning of CaretValue
 168                                          * table */
 169   public:
 170   DEFINE_SIZE_STATIC (6);
 171 };
 172 
 173 struct CaretValue
 174 {
 175   inline hb_position_t get_caret_value (hb_font_t *font,
 176                                         hb_direction_t direction,
 177                                         hb_codepoint_t glyph_id,
 178                                         const VariationStore &var_store) const
 179   {
 180     switch (u.format) {
 181     case 1: return u.format1.get_caret_value (font, direction);
 182     case 2: return u.format2.get_caret_value (font, direction, glyph_id);
 183     case 3: return u.format3.get_caret_value (font, direction, var_store);
 184     default:return 0;
 185     }
 186   }
 187 
 188   inline bool sanitize (hb_sanitize_context_t *c) const
 189   {
 190     TRACE_SANITIZE (this);
 191     if (!u.format.sanitize (c)) return_trace (false);
 192     switch (u.format) {
 193     case 1: return_trace (u.format1.sanitize (c));
 194     case 2: return_trace (u.format2.sanitize (c));
 195     case 3: return_trace (u.format3.sanitize (c));
 196     default:return_trace (true);
 197     }
 198   }
 199 
 200   protected:
 201   union {
 202   HBUINT16              format;         /* Format identifier */
 203   CaretValueFormat1     format1;
 204   CaretValueFormat2     format2;
 205   CaretValueFormat3     format3;
 206   } u;
 207   public:
 208   DEFINE_SIZE_UNION (2, format);
 209 };
 210 
 211 struct LigGlyph
 212 {
 213   inline unsigned int get_lig_carets (hb_font_t *font,
 214                                       hb_direction_t direction,
 215                                       hb_codepoint_t glyph_id,
 216                                       const VariationStore &var_store,
 217                                       unsigned int start_offset,
 218                                       unsigned int *caret_count /* IN/OUT */,
 219                                       hb_position_t *caret_array /* OUT */) const
 220   {
 221     if (caret_count) {
 222       const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count);
 223       unsigned int count = *caret_count;

 224       for (unsigned int i = 0; i < count; i++)
 225         caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id, var_store);
 226     }
 227 
 228     return carets.len;
 229   }
 230 
 231   inline bool sanitize (hb_sanitize_context_t *c) const
 232   {
 233     TRACE_SANITIZE (this);
 234     return_trace (carets.sanitize (c, this));
 235   }
 236 
 237   protected:
 238   OffsetArrayOf<CaretValue>
 239                 carets;                 /* Offset array of CaretValue tables
 240                                          * --from beginning of LigGlyph table
 241                                          * --in increasing coordinate order */
 242   public:
 243   DEFINE_SIZE_ARRAY (2, carets);
 244 };
 245 
 246 struct LigCaretList
 247 {
 248   inline unsigned int get_lig_carets (hb_font_t *font,
 249                                       hb_direction_t direction,
 250                                       hb_codepoint_t glyph_id,
 251                                       const VariationStore &var_store,
 252                                       unsigned int start_offset,
 253                                       unsigned int *caret_count /* IN/OUT */,
 254                                       hb_position_t *caret_array /* OUT */) const
 255   {
 256     unsigned int index = (this+coverage).get_coverage (glyph_id);
 257     if (index == NOT_COVERED)
 258     {
 259       if (caret_count)
 260         *caret_count = 0;
 261       return 0;
 262     }
 263     const LigGlyph &lig_glyph = this+ligGlyph[index];
 264     return lig_glyph.get_lig_carets (font, direction, glyph_id, var_store, start_offset, caret_count, caret_array);
 265   }
 266 
 267   inline bool sanitize (hb_sanitize_context_t *c) const
 268   {
 269     TRACE_SANITIZE (this);
 270     return_trace (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this));
 271   }
 272 
 273   protected:
 274   OffsetTo<Coverage>
 275                 coverage;               /* Offset to Coverage table--from
 276                                          * beginning of LigCaretList table */
 277   OffsetArrayOf<LigGlyph>
 278                 ligGlyph;               /* Array of LigGlyph tables
 279                                          * in Coverage Index order */
 280   public:
 281   DEFINE_SIZE_ARRAY (4, ligGlyph);
 282 };
 283 
 284 
 285 struct MarkGlyphSetsFormat1
 286 {
 287   inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
 288   { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
 289 
 290   inline bool sanitize (hb_sanitize_context_t *c) const
 291   {
 292     TRACE_SANITIZE (this);
 293     return_trace (coverage.sanitize (c, this));
 294   }
 295 
 296   protected:
 297   HBUINT16      format;                 /* Format identifier--format = 1 */
 298   ArrayOf<LOffsetTo<Coverage> >
 299                 coverage;               /* Array of long offsets to mark set
 300                                          * coverage tables */
 301   public:
 302   DEFINE_SIZE_ARRAY (4, coverage);
 303 };
 304 
 305 struct MarkGlyphSets
 306 {
 307   inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
 308   {
 309     switch (u.format) {
 310     case 1: return u.format1.covers (set_index, glyph_id);
 311     default:return false;
 312     }
 313   }
 314 
 315   inline bool sanitize (hb_sanitize_context_t *c) const
 316   {
 317     TRACE_SANITIZE (this);
 318     if (!u.format.sanitize (c)) return_trace (false);
 319     switch (u.format) {
 320     case 1: return_trace (u.format1.sanitize (c));
 321     default:return_trace (true);
 322     }
 323   }
 324 
 325   protected:
 326   union {
 327   HBUINT16              format;         /* Format identifier */
 328   MarkGlyphSetsFormat1  format1;
 329   } u;
 330   public:
 331   DEFINE_SIZE_UNION (2, format);
 332 };
 333 
 334 
 335 /*
 336  * GDEF -- Glyph Definition
 337  * https://docs.microsoft.com/en-us/typography/opentype/spec/gdef
 338  */
 339 

 340 struct GDEF
 341 {
 342   static const hb_tag_t tableTag        = HB_OT_TAG_GDEF;
 343 
 344   enum GlyphClasses {
 345     UnclassifiedGlyph   = 0,
 346     BaseGlyph           = 1,
 347     LigatureGlyph       = 2,
 348     MarkGlyph           = 3,
 349     ComponentGlyph      = 4
 350   };
 351 
 352   inline bool has_glyph_classes (void) const { return glyphClassDef != 0; }
 353   inline unsigned int get_glyph_class (hb_codepoint_t glyph) const

 354   { return (this+glyphClassDef).get_class (glyph); }
 355   inline void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const
 356   { (this+glyphClassDef).add_class (glyphs, klass); }
 357 
 358   inline bool has_mark_attachment_types (void) const { return markAttachClassDef != 0; }
 359   inline unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const
 360   { return (this+markAttachClassDef).get_class (glyph); }
 361 
 362   inline bool has_attach_points (void) const { return attachList != 0; }
 363   inline unsigned int get_attach_points (hb_codepoint_t glyph_id,
 364                                          unsigned int start_offset,
 365                                          unsigned int *point_count /* IN/OUT */,
 366                                          unsigned int *point_array /* OUT */) const
 367   { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
 368 
 369   inline bool has_lig_carets (void) const { return ligCaretList != 0; }
 370   inline unsigned int get_lig_carets (hb_font_t *font,
 371                                       hb_direction_t direction,
 372                                       hb_codepoint_t glyph_id,
 373                                       unsigned int start_offset,
 374                                       unsigned int *caret_count /* IN/OUT */,
 375                                       hb_position_t *caret_array /* OUT */) const
 376   { return (this+ligCaretList).get_lig_carets (font,
 377                                                direction, glyph_id, get_var_store(),
 378                                                start_offset, caret_count, caret_array); }
 379 
 380   inline bool has_mark_sets (void) const { return version.to_int () >= 0x00010002u && markGlyphSetsDef != 0; }
 381   inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
 382   { return version.to_int () >= 0x00010002u && (this+markGlyphSetsDef).covers (set_index, glyph_id); }
 383 
 384   inline bool has_var_store (void) const { return version.to_int () >= 0x00010003u && varStore != 0; }
 385   inline const VariationStore &get_var_store (void) const
 386   { return version.to_int () >= 0x00010003u ? this+varStore : Null(VariationStore); }
 387 
 388   inline bool sanitize (hb_sanitize_context_t *c) const
 389   {
 390     TRACE_SANITIZE (this);
 391     return_trace (version.sanitize (c) &&
 392                   likely (version.major == 1) &&
 393                   glyphClassDef.sanitize (c, this) &&
 394                   attachList.sanitize (c, this) &&
 395                   ligCaretList.sanitize (c, this) &&
 396                   markAttachClassDef.sanitize (c, this) &&
 397                   (version.to_int () < 0x00010002u || markGlyphSetsDef.sanitize (c, this)) &&
 398                   (version.to_int () < 0x00010003u || varStore.sanitize (c, this)));
 399   }
 400 
 401   /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
 402    * glyph class and other bits, and high 8-bit gthe mark attachment type (if any).
 403    * Not to be confused with lookup_props which is very similar. */
 404   inline unsigned int get_glyph_props (hb_codepoint_t glyph) const
 405   {
 406     unsigned int klass = get_glyph_class (glyph);
 407 
 408     static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs), "");
 409     static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures), "");
 410     static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks), "");
 411 
 412     switch (klass) {
 413     default:                    return 0;
 414     case BaseGlyph:             return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH;
 415     case LigatureGlyph:         return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
 416     case MarkGlyph:
 417           klass = get_mark_attachment_type (glyph);
 418           return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8);
 419     }
 420   }
 421 



























































 422 
 423   protected:
 424   FixedVersion<>version;                /* Version of the GDEF table--currently
 425                                          * 0x00010003u */
 426   OffsetTo<ClassDef>
 427                 glyphClassDef;          /* Offset to class definition table
 428                                          * for glyph type--from beginning of
 429                                          * GDEF header (may be Null) */
 430   OffsetTo<AttachList>
 431                 attachList;             /* Offset to list of glyphs with
 432                                          * attachment points--from beginning
 433                                          * of GDEF header (may be Null) */
 434   OffsetTo<LigCaretList>
 435                 ligCaretList;           /* Offset to list of positioning points
 436                                          * for ligature carets--from beginning
 437                                          * of GDEF header (may be Null) */
 438   OffsetTo<ClassDef>
 439                 markAttachClassDef;     /* Offset to class definition table for
 440                                          * mark attachment type--from beginning
 441                                          * of GDEF header (may be Null) */
 442   OffsetTo<MarkGlyphSets>
 443                 markGlyphSetsDef;       /* Offset to the table of mark set
 444                                          * definitions--from beginning of GDEF
 445                                          * header (may be NULL).  Introduced
 446                                          * in version 0x00010002. */
 447   LOffsetTo<VariationStore>
 448                 varStore;               /* Offset to the table of Item Variation
 449                                          * Store--from beginning of GDEF
 450                                          * header (may be NULL).  Introduced
 451                                          * in version 0x00010003. */
 452   public:
 453   DEFINE_SIZE_MIN (12);
 454 };
 455 

 456 
 457 } /* namespace OT */
 458 
 459 
 460 #endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */


  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
  26  * Google Author(s): Behdad Esfahbod
  27  */
  28 
  29 #ifndef HB_OT_LAYOUT_GDEF_TABLE_HH
  30 #define HB_OT_LAYOUT_GDEF_TABLE_HH
  31 
  32 #include "hb-ot-layout-common.hh"
  33 
  34 #include "hb-font.hh"
  35 
  36 
  37 namespace OT {
  38 
  39 
  40 /*
  41  * Attachment List Table
  42  */
  43 
  44 typedef ArrayOf<HBUINT16> AttachPoint;  /* Array of contour point indices--in
  45                                          * increasing numerical order */
  46 
  47 struct AttachList
  48 {
  49   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
  53   {
  54     unsigned int index = (this+coverage).get_coverage (glyph_id);
  55     if (index == NOT_COVERED)
  56     {
  57       if (point_count)
  58         *point_count = 0;
  59       return 0;
  60     }
  61 
  62     const AttachPoint &points = this+attachPoint[index];
  63 
  64     if (point_count)
  65     {
  66       hb_array_t<const HBUINT16> array = points.sub_array (start_offset, point_count);
  67       unsigned int count = array.length;
  68       for (unsigned int i = 0; i < count; i++)
  69         point_array[i] = array[i];
  70     }
  71 
  72     return points.len;
  73   }
  74 
  75   bool sanitize (hb_sanitize_context_t *c) const
  76   {
  77     TRACE_SANITIZE (this);
  78     return_trace (coverage.sanitize (c, this) && attachPoint.sanitize (c, this));
  79   }
  80 
  81   protected:
  82   OffsetTo<Coverage>
  83                 coverage;               /* Offset to Coverage table -- from
  84                                          * beginning of AttachList table */
  85   OffsetArrayOf<AttachPoint>
  86                 attachPoint;            /* Array of AttachPoint tables
  87                                          * in Coverage Index order */
  88   public:
  89   DEFINE_SIZE_ARRAY (4, attachPoint);
  90 };
  91 
  92 /*
  93  * Ligature Caret Table
  94  */
  95 
  96 struct CaretValueFormat1
  97 {
  98   friend struct CaretValue;
  99 
 100   private:
 101   hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction) const
 102   {
 103     return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate);
 104   }
 105 
 106   bool sanitize (hb_sanitize_context_t *c) const
 107   {
 108     TRACE_SANITIZE (this);
 109     return_trace (c->check_struct (this));
 110   }
 111 
 112   protected:
 113   HBUINT16      caretValueFormat;       /* Format identifier--format = 1 */
 114   FWORD         coordinate;             /* X or Y value, in design units */
 115   public:
 116   DEFINE_SIZE_STATIC (4);
 117 };
 118 
 119 struct CaretValueFormat2
 120 {
 121   friend struct CaretValue;
 122 
 123   private:
 124   hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
 125   {
 126     hb_position_t x, y;
 127     font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y);
 128     return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;


 129   }
 130 
 131   bool sanitize (hb_sanitize_context_t *c) const
 132   {
 133     TRACE_SANITIZE (this);
 134     return_trace (c->check_struct (this));
 135   }
 136 
 137   protected:
 138   HBUINT16      caretValueFormat;       /* Format identifier--format = 2 */
 139   HBUINT16      caretValuePoint;        /* Contour point index on glyph */
 140   public:
 141   DEFINE_SIZE_STATIC (4);
 142 };
 143 
 144 struct CaretValueFormat3
 145 {
 146   friend struct CaretValue;
 147 
 148   hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction,
 149                                  const VariationStore &var_store) const
 150   {
 151     return HB_DIRECTION_IS_HORIZONTAL (direction) ?
 152            font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font, var_store) :
 153            font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font, var_store);
 154   }
 155 
 156   bool sanitize (hb_sanitize_context_t *c) const
 157   {
 158     TRACE_SANITIZE (this);
 159     return_trace (c->check_struct (this) && deviceTable.sanitize (c, this));
 160   }
 161 
 162   protected:
 163   HBUINT16      caretValueFormat;       /* Format identifier--format = 3 */
 164   FWORD         coordinate;             /* X or Y value, in design units */
 165   OffsetTo<Device>
 166                 deviceTable;            /* Offset to Device table for X or Y
 167                                          * value--from beginning of CaretValue
 168                                          * table */
 169   public:
 170   DEFINE_SIZE_STATIC (6);
 171 };
 172 
 173 struct CaretValue
 174 {
 175   hb_position_t get_caret_value (hb_font_t *font,
 176                                         hb_direction_t direction,
 177                                         hb_codepoint_t glyph_id,
 178                                         const VariationStore &var_store) const
 179   {
 180     switch (u.format) {
 181     case 1: return u.format1.get_caret_value (font, direction);
 182     case 2: return u.format2.get_caret_value (font, direction, glyph_id);
 183     case 3: return u.format3.get_caret_value (font, direction, var_store);
 184     default:return 0;
 185     }
 186   }
 187 
 188   bool sanitize (hb_sanitize_context_t *c) const
 189   {
 190     TRACE_SANITIZE (this);
 191     if (!u.format.sanitize (c)) return_trace (false);
 192     switch (u.format) {
 193     case 1: return_trace (u.format1.sanitize (c));
 194     case 2: return_trace (u.format2.sanitize (c));
 195     case 3: return_trace (u.format3.sanitize (c));
 196     default:return_trace (true);
 197     }
 198   }
 199 
 200   protected:
 201   union {
 202   HBUINT16              format;         /* Format identifier */
 203   CaretValueFormat1     format1;
 204   CaretValueFormat2     format2;
 205   CaretValueFormat3     format3;
 206   } u;
 207   public:
 208   DEFINE_SIZE_UNION (2, format);
 209 };
 210 
 211 struct LigGlyph
 212 {
 213   unsigned int get_lig_carets (hb_font_t *font,
 214                                hb_direction_t direction,
 215                                hb_codepoint_t glyph_id,
 216                                const VariationStore &var_store,
 217                                unsigned int start_offset,
 218                                unsigned int *caret_count /* IN/OUT */,
 219                                hb_position_t *caret_array /* OUT */) const
 220   {
 221     if (caret_count)
 222     {
 223       hb_array_t <const OffsetTo<CaretValue> > array = carets.sub_array (start_offset, caret_count);
 224       unsigned int count = array.length;
 225       for (unsigned int i = 0; i < count; i++)
 226         caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id, var_store);
 227     }
 228 
 229     return carets.len;
 230   }
 231 
 232   bool sanitize (hb_sanitize_context_t *c) const
 233   {
 234     TRACE_SANITIZE (this);
 235     return_trace (carets.sanitize (c, this));
 236   }
 237 
 238   protected:
 239   OffsetArrayOf<CaretValue>
 240                 carets;                 /* Offset array of CaretValue tables
 241                                          * --from beginning of LigGlyph table
 242                                          * --in increasing coordinate order */
 243   public:
 244   DEFINE_SIZE_ARRAY (2, carets);
 245 };
 246 
 247 struct LigCaretList
 248 {
 249   unsigned int get_lig_carets (hb_font_t *font,
 250                                hb_direction_t direction,
 251                                hb_codepoint_t glyph_id,
 252                                const VariationStore &var_store,
 253                                unsigned int start_offset,
 254                                unsigned int *caret_count /* IN/OUT */,
 255                                hb_position_t *caret_array /* OUT */) const
 256   {
 257     unsigned int index = (this+coverage).get_coverage (glyph_id);
 258     if (index == NOT_COVERED)
 259     {
 260       if (caret_count)
 261         *caret_count = 0;
 262       return 0;
 263     }
 264     const LigGlyph &lig_glyph = this+ligGlyph[index];
 265     return lig_glyph.get_lig_carets (font, direction, glyph_id, var_store, start_offset, caret_count, caret_array);
 266   }
 267 
 268   bool sanitize (hb_sanitize_context_t *c) const
 269   {
 270     TRACE_SANITIZE (this);
 271     return_trace (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this));
 272   }
 273 
 274   protected:
 275   OffsetTo<Coverage>
 276                 coverage;               /* Offset to Coverage table--from
 277                                          * beginning of LigCaretList table */
 278   OffsetArrayOf<LigGlyph>
 279                 ligGlyph;               /* Array of LigGlyph tables
 280                                          * in Coverage Index order */
 281   public:
 282   DEFINE_SIZE_ARRAY (4, ligGlyph);
 283 };
 284 
 285 
 286 struct MarkGlyphSetsFormat1
 287 {
 288   bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
 289   { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; }
 290 
 291   bool sanitize (hb_sanitize_context_t *c) const
 292   {
 293     TRACE_SANITIZE (this);
 294     return_trace (coverage.sanitize (c, this));
 295   }
 296 
 297   protected:
 298   HBUINT16      format;                 /* Format identifier--format = 1 */
 299   ArrayOf<LOffsetTo<Coverage> >
 300                 coverage;               /* Array of long offsets to mark set
 301                                          * coverage tables */
 302   public:
 303   DEFINE_SIZE_ARRAY (4, coverage);
 304 };
 305 
 306 struct MarkGlyphSets
 307 {
 308   bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
 309   {
 310     switch (u.format) {
 311     case 1: return u.format1.covers (set_index, glyph_id);
 312     default:return false;
 313     }
 314   }
 315 
 316   bool sanitize (hb_sanitize_context_t *c) const
 317   {
 318     TRACE_SANITIZE (this);
 319     if (!u.format.sanitize (c)) return_trace (false);
 320     switch (u.format) {
 321     case 1: return_trace (u.format1.sanitize (c));
 322     default:return_trace (true);
 323     }
 324   }
 325 
 326   protected:
 327   union {
 328   HBUINT16              format;         /* Format identifier */
 329   MarkGlyphSetsFormat1  format1;
 330   } u;
 331   public:
 332   DEFINE_SIZE_UNION (2, format);
 333 };
 334 
 335 
 336 /*
 337  * GDEF -- Glyph Definition
 338  * https://docs.microsoft.com/en-us/typography/opentype/spec/gdef
 339  */
 340 
 341 
 342 struct GDEF
 343 {
 344   static constexpr hb_tag_t tableTag = HB_OT_TAG_GDEF;
 345 
 346   enum GlyphClasses {
 347     UnclassifiedGlyph   = 0,
 348     BaseGlyph           = 1,
 349     LigatureGlyph       = 2,
 350     MarkGlyph           = 3,
 351     ComponentGlyph      = 4
 352   };
 353 
 354   bool has_data () const { return version.to_int (); }
 355   bool has_glyph_classes () const { return glyphClassDef != 0; }
 356   unsigned int get_glyph_class (hb_codepoint_t glyph) const
 357   { return (this+glyphClassDef).get_class (glyph); }
 358   void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const
 359   { (this+glyphClassDef).add_class (glyphs, klass); }
 360 
 361   bool has_mark_attachment_types () const { return markAttachClassDef != 0; }
 362   unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const
 363   { return (this+markAttachClassDef).get_class (glyph); }
 364 
 365   bool has_attach_points () const { return attachList != 0; }
 366   unsigned int get_attach_points (hb_codepoint_t glyph_id,
 367                                   unsigned int start_offset,
 368                                   unsigned int *point_count /* IN/OUT */,
 369                                   unsigned int *point_array /* OUT */) const
 370   { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); }
 371 
 372   bool has_lig_carets () const { return ligCaretList != 0; }
 373   unsigned int get_lig_carets (hb_font_t *font,
 374                                hb_direction_t direction,
 375                                hb_codepoint_t glyph_id,
 376                                unsigned int start_offset,
 377                                unsigned int *caret_count /* IN/OUT */,
 378                                hb_position_t *caret_array /* OUT */) const
 379   { return (this+ligCaretList).get_lig_carets (font,
 380                                                direction, glyph_id, get_var_store(),
 381                                                start_offset, caret_count, caret_array); }
 382 
 383   bool has_mark_sets () const { return version.to_int () >= 0x00010002u && markGlyphSetsDef != 0; }
 384   bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
 385   { return version.to_int () >= 0x00010002u && (this+markGlyphSetsDef).covers (set_index, glyph_id); }
 386 
 387   bool has_var_store () const { return version.to_int () >= 0x00010003u && varStore != 0; }
 388   const VariationStore &get_var_store () const
 389   { return version.to_int () >= 0x00010003u ? this+varStore : Null(VariationStore); }
 390 













 391   /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing
 392    * glyph class and other bits, and high 8-bit the mark attachment type (if any).
 393    * Not to be confused with lookup_props which is very similar. */
 394   unsigned int get_glyph_props (hb_codepoint_t glyph) const
 395   {
 396     unsigned int klass = get_glyph_class (glyph);
 397 
 398     static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH == (unsigned int) LookupFlag::IgnoreBaseGlyphs), "");
 399     static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE == (unsigned int) LookupFlag::IgnoreLigatures), "");
 400     static_assert (((unsigned int) HB_OT_LAYOUT_GLYPH_PROPS_MARK == (unsigned int) LookupFlag::IgnoreMarks), "");
 401 
 402     switch (klass) {
 403     default:                    return 0;
 404     case BaseGlyph:             return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH;
 405     case LigatureGlyph:         return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE;
 406     case MarkGlyph:
 407           klass = get_mark_attachment_type (glyph);
 408           return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8);
 409     }
 410   }
 411 
 412   HB_INTERNAL bool is_blacklisted (hb_blob_t *blob,
 413                                    hb_face_t *face) const;
 414 
 415   struct accelerator_t
 416   {
 417     void init (hb_face_t *face)
 418     {
 419       this->table = hb_sanitize_context_t().reference_table<GDEF> (face);
 420       if (unlikely (this->table->is_blacklisted (this->table.get_blob (), face)))
 421       {
 422         hb_blob_destroy (this->table.get_blob ());
 423         this->table = hb_blob_get_empty ();
 424       }
 425     }
 426 
 427     void fini () { this->table.destroy (); }
 428 
 429     hb_blob_ptr_t<GDEF> table;
 430   };
 431 
 432   unsigned int get_size () const
 433   {
 434     return min_size +
 435            (version.to_int () >= 0x00010002u ? markGlyphSetsDef.static_size : 0) +
 436            (version.to_int () >= 0x00010003u ? varStore.static_size : 0);
 437   }
 438 
 439   bool subset (hb_subset_context_t *c) const
 440   {
 441     TRACE_SUBSET (this);
 442     struct GDEF *out = c->serializer->embed (*this);
 443     if (unlikely (!out)) return_trace (false);
 444 
 445     out->glyphClassDef.serialize_subset (c, this+glyphClassDef, out);
 446     out->attachList.set (0);//TODO(subset) serialize_subset (c, this+attachList, out);
 447     out->ligCaretList.set (0);//TODO(subset) serialize_subset (c, this+ligCaretList, out);
 448     out->markAttachClassDef.serialize_subset (c, this+markAttachClassDef, out);
 449 
 450     if (version.to_int () >= 0x00010002u)
 451       out->markGlyphSetsDef.set (0);// TODO(subset) serialize_subset (c, this+markGlyphSetsDef, out);
 452 
 453     if (version.to_int () >= 0x00010003u)
 454       out->varStore.set (0);// TODO(subset) serialize_subset (c, this+varStore, out);
 455 
 456     return_trace (true);
 457   }
 458 
 459   bool sanitize (hb_sanitize_context_t *c) const
 460   {
 461     TRACE_SANITIZE (this);
 462     return_trace (version.sanitize (c) &&
 463                   likely (version.major == 1) &&
 464                   glyphClassDef.sanitize (c, this) &&
 465                   attachList.sanitize (c, this) &&
 466                   ligCaretList.sanitize (c, this) &&
 467                   markAttachClassDef.sanitize (c, this) &&
 468                   (version.to_int () < 0x00010002u || markGlyphSetsDef.sanitize (c, this)) &&
 469                   (version.to_int () < 0x00010003u || varStore.sanitize (c, this)));
 470   }
 471 
 472   protected:
 473   FixedVersion<>version;                /* Version of the GDEF table--currently
 474                                          * 0x00010003u */
 475   OffsetTo<ClassDef>
 476                 glyphClassDef;          /* Offset to class definition table
 477                                          * for glyph type--from beginning of
 478                                          * GDEF header (may be Null) */
 479   OffsetTo<AttachList>
 480                 attachList;             /* Offset to list of glyphs with
 481                                          * attachment points--from beginning
 482                                          * of GDEF header (may be Null) */
 483   OffsetTo<LigCaretList>
 484                 ligCaretList;           /* Offset to list of positioning points
 485                                          * for ligature carets--from beginning
 486                                          * of GDEF header (may be Null) */
 487   OffsetTo<ClassDef>
 488                 markAttachClassDef;     /* Offset to class definition table for
 489                                          * mark attachment type--from beginning
 490                                          * of GDEF header (may be Null) */
 491   OffsetTo<MarkGlyphSets>
 492                 markGlyphSetsDef;       /* Offset to the table of mark set
 493                                          * definitions--from beginning of GDEF
 494                                          * header (may be NULL).  Introduced
 495                                          * in version 0x00010002. */
 496   LOffsetTo<VariationStore>
 497                 varStore;               /* Offset to the table of Item Variation
 498                                          * Store--from beginning of GDEF
 499                                          * header (may be NULL).  Introduced
 500                                          * in version 0x00010003. */
 501   public:
 502   DEFINE_SIZE_MIN (12);
 503 };
 504 
 505 struct GDEF_accelerator_t : GDEF::accelerator_t {};
 506 
 507 } /* namespace OT */
 508 
 509 
 510 #endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */
< prev index next >