2 * Copyright (C) 2007,2008 Red Hat, Inc.
4 * This is part of HarfBuzz, an OpenType Layout engine library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Red Hat Author(s): Behdad Esfahbod
27 #ifndef HB_OT_LAYOUT_OPEN_PRIVATE_H
28 #define HB_OT_LAYOUT_OPEN_PRIVATE_H
30 #include "hb-private.h"
31 #include "hb-ot-layout.h"
38 #define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN) \
39 inline NAME& operator = (TYPE i) { v = BIG_ENDIAN(i); return *this; } \
40 inline operator TYPE(void) const { return BIG_ENDIAN(v); } \
41 inline bool operator== (NAME o) const { return v == o.v; } \
44 #define DEFINE_INT_TYPE0(NAME, type) DEFINE_INT_TYPE1 (NAME, type, hb_be_##type)
45 #define DEFINE_INT_TYPE(NAME, u, w) DEFINE_INT_TYPE0 (NAME, u##int##w##_t)
46 #define DEFINE_INT_TYPE_STRUCT(NAME, u, w) \
48 DEFINE_INT_TYPE(NAME, u, w) \
55 /* get_len() is a method returning the number of items in an array-like object */
56 #define DEFINE_LEN(Type, array, num) \
57 inline unsigned int get_len(void) const { return num; } \
59 /* get_size() is a method returning the size in bytes of an array-like object */
60 #define DEFINE_SIZE(Type, array, num) \
61 inline unsigned int get_size(void) const { return sizeof (*this) + sizeof (Type) * num; }
63 #define DEFINE_LEN_AND_SIZE(Type, array, num) \
64 DEFINE_LEN(Type, array, num) \
65 DEFINE_SIZE(Type, array, num)
67 /* An array type is one that contains a variable number of objects
68 * as its last item. An array object is extended with len() and size()
69 * methods, as well as overloaded [] operator. */
70 #define DEFINE_ARRAY_TYPE(Type, array, num) \
71 DEFINE_INDEX_OPERATOR(Type, array, num) \
72 DEFINE_LEN_AND_SIZE(Type, array, num)
73 #define DEFINE_INDEX_OPERATOR(Type, array, num) \
74 inline const Type& operator[] (unsigned int i) const { \
75 if (HB_UNLIKELY (i >= num)) return Null##Type; \
79 /* An offset array type is like an array type, but it contains a table
80 * of offsets to the objects, relative to the beginning of the current
82 #define DEFINE_OFFSET_ARRAY_TYPE(Type, array, num) \
83 DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
84 DEFINE_LEN_AND_SIZE(Offset, array, num)
85 #define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
86 inline const Type& operator[] (unsigned int i) const { \
87 if (HB_UNLIKELY (i >= num)) return Null##Type; \
88 if (HB_UNLIKELY (!array[i])) return Null##Type; \
89 return *(const Type *)((const char*)this + array[i]); \
92 #define DEFINE_RECORD_ARRAY_TYPE(Type, array, num) \
93 DEFINE_RECORD_ACCESSOR(Type, array, num) \
94 DEFINE_LEN_AND_SIZE(Record, array, num)
95 #define DEFINE_RECORD_ACCESSOR(Type, array, num) \
96 inline const Type& operator[] (unsigned int i) const { \
97 if (HB_UNLIKELY (i >= num)) return Null##Type; \
98 if (HB_UNLIKELY (!array[i].offset)) return Null##Type; \
99 return *(const Type *)((const char*)this + array[i].offset); \
101 inline const Tag& get_tag (unsigned int i) const { \
102 if (HB_UNLIKELY (i >= num)) return NullTag; \
103 return array[i].tag; \
105 /* TODO: implement find_tag() */
111 #define DEFINE_LIST_ACCESSOR(Type, name) \
112 inline const Type##List& get_##name##_list (void) const { \
113 if (HB_UNLIKELY (!name##List)) return Null##Type##List; \
114 return *(const Type##List *)((const char*)this + name##List); \
116 inline const Type& get_##name (unsigned int i) const { \
117 return get_##name##_list()[i]; \
124 /* makes class uninstantiable. should be used for union classes that don't
125 * contain any complete type */
126 #define DEFINE_NON_INSTANTIABLE(Type) \
127 private: inline Type() {} /* cannot be instantiated */ \
130 /* defines Null##Type as a safe nil instance of Type */
131 #define DEFINE_NULL_DATA(Type, size, data) \
132 static const unsigned char Null##Type##Data[size] = data; \
133 DEFINE_NULL_ALIAS (Type, Type)
134 #define DEFINE_NULL(Type, size) \
135 DEFINE_NULL_DATA(Type, size, "")
136 #define DEFINE_NULL_ASSERT_SIZE(Type, size) \
137 DEFINE_NULL_ASSERT_SIZE_DATA(Type, size, "")
138 #define DEFINE_NULL_ASSERT_SIZE_DATA(Type, size, data) \
139 ASSERT_SIZE (Type, size); \
140 DEFINE_NULL_DATA (Type, size, data)
141 #define DEFINE_NULL_ALIAS(NewType, OldType) \
142 static const NewType &Null##NewType = *(NewType *)Null##OldType##Data
144 /* get_for_data() is a static class method returning a reference to an
145 * instance of Type located at the input data location. It's just a
147 #define STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
148 static inline const Type& get_for_data (const char *data) { \
149 return *(const Type*)data; \
151 #define STATIC_DEFINE_GET_FOR_DATA(Type) \
152 STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
153 STATIC_DEFINE_GET_FOR_DATA0( , Type)
156 #define DEFINE_ACCESSOR(Type, name, Name) \
157 inline const Type& name (void) const { \
158 if (HB_UNLIKELY (!Name)) return Null##Type; \
159 return *(const Type*)((const char*)this + Name); \
166 * The OpenType Font File
177 /* "The following data types are used in the OpenType font file.
178 * All OpenType fonts use Motorola-style byte ordering (Big Endian):" */
181 DEFINE_INT_TYPE_STRUCT (BYTE, u, 8); /* 8-bit unsigned integer. */
182 DEFINE_NULL_ASSERT_SIZE (BYTE, 1);
183 DEFINE_INT_TYPE_STRUCT (CHAR, , 8); /* 8-bit signed integer. */
184 DEFINE_NULL_ASSERT_SIZE (CHAR, 1);
185 DEFINE_INT_TYPE_STRUCT (USHORT, u, 16); /* 16-bit unsigned integer. */
186 DEFINE_NULL_ASSERT_SIZE (USHORT, 2);
187 DEFINE_INT_TYPE_STRUCT (SHORT, , 16); /* 16-bit signed integer. */
188 DEFINE_NULL_ASSERT_SIZE (SHORT, 2);
189 DEFINE_INT_TYPE_STRUCT (ULONG, u, 32); /* 32-bit unsigned integer. */
190 DEFINE_NULL_ASSERT_SIZE (ULONG, 4);
191 DEFINE_INT_TYPE_STRUCT (LONG, , 32); /* 32-bit signed integer. */
192 DEFINE_NULL_ASSERT_SIZE (LONG, 4);
194 /* Date represented in number of seconds since 12:00 midnight, January 1,
195 * 1904. The value is represented as a signed 64-bit integer. */
196 DEFINE_INT_TYPE_STRUCT (LONGDATETIME, , 64);
198 /* 32-bit signed fixed-point number (16.16) */
200 inline Fixed& operator = (int32_t v) { i = (int16_t) (v >> 16); f = (uint16_t) v; return *this; } \
201 inline operator int32_t(void) const { return (((int32_t) i) << 16) + (uint16_t) f; } \
202 inline bool operator== (Fixed o) const { return i == o.i && f == o.f; } \
204 inline operator double(void) const { return (uint32_t) this / 65536.; }
205 inline int16_t int_part (void) const { return i; }
206 inline uint16_t frac_part (void) const { return f; }
212 DEFINE_NULL_ASSERT_SIZE (Fixed, 4);
214 /* Smallest measurable distance in the em space. */
217 /* 16-bit signed integer (SHORT) that describes a quantity in FUnits. */
218 struct FWORD : SHORT {
220 DEFINE_NULL_ASSERT_SIZE (FWORD, 2);
222 /* 16-bit unsigned integer (USHORT) that describes a quantity in FUnits. */
223 struct UFWORD : USHORT {
225 DEFINE_NULL_ASSERT_SIZE (UFWORD, 2);
227 /* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */
228 struct F2DOT14 : SHORT {
229 inline operator double() const { return (uint32_t) this / 16384.; }
231 DEFINE_NULL_ASSERT_SIZE (F2DOT14, 2);
233 /* Array of four uint8s (length = 32 bits) used to identify a script, language
234 * system, feature, or baseline */
236 inline Tag (void) { v[0] = v[1] = v[2] = v[3] = 0; }
237 inline Tag (uint32_t v) { (ULONG&)(*this) = v; }
238 inline Tag (const char *c) { v[0] = c[0]; v[1] = c[1]; v[2] = c[2]; v[3] = c[3]; }
239 inline bool operator== (Tag o) const { return v[0]==o.v[0]&&v[1]==o.v[1]&&v[2]==o.v[2]&&v[3]==o.v[3]; }
240 inline bool operator== (const char *c) const { return v[0]==c[0]&&v[1]==c[1]&&v[2]==c[2]&&v[3]==c[3]; }
241 inline bool operator== (uint32_t i) const { return i == (uint32_t) *this; }
242 inline operator uint32_t(void) const { return (v[0]<<24)+(v[1]<<16) +(v[2]<<8)+v[3]; }
243 /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */
244 inline operator const char* (void) const { return (const char *)this; }
245 inline operator char* (void) { return (char *)this; }
250 ASSERT_SIZE (Tag, 4);
251 DEFINE_NULL_DATA (Tag, 5, " ");
253 /* Glyph index number, same as uint16 (length = 16 bits) */
254 DEFINE_INT_TYPE_STRUCT (GlyphID, u, 16);
255 DEFINE_NULL_ASSERT_SIZE (GlyphID, 2);
257 /* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */
258 DEFINE_INT_TYPE_STRUCT (Offset, u, 16);
259 DEFINE_NULL_ASSERT_SIZE (Offset, 2);
262 struct CheckSum : ULONG {
263 static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length) {
265 ULONG *EndPtr = Table+((Length+3) & ~3) / sizeof(ULONG);
267 while (Table < EndPtr)
272 DEFINE_NULL_ASSERT_SIZE (CheckSum, 4);
279 struct USHORT_Version : USHORT {
281 DEFINE_NULL_ASSERT_SIZE (USHORT_Version, 2);
283 struct Fixed_Version : Fixed {
284 inline int16_t major (void) const { return this->int_part(); }
285 inline int16_t minor (void) const { return this->frac_part(); }
287 DEFINE_NULL_ASSERT_SIZE (Fixed_Version, 4);
291 * Organization of an OpenType Font
294 struct OpenTypeFontFile;
298 typedef struct TableDirectory {
300 friend struct OpenTypeFontFile;
302 inline const Tag& get_tag (void) const { return tag; }
303 inline unsigned long get_checksum (void) const { return checkSum; }
304 inline unsigned long get_offset (void) const { return offset; }
305 inline unsigned long get_length (void) const { return length; }
308 Tag tag; /* 4-byte identifier. */
309 CheckSum checkSum; /* CheckSum for this table. */
310 ULONG offset; /* Offset from beginning of TrueType font
312 ULONG length; /* Length of this table. */
314 DEFINE_NULL_ASSERT_SIZE (TableDirectory, 16);
316 typedef struct OffsetTable {
317 /* OpenTypeTables, in no particular order */
318 DEFINE_ARRAY_TYPE (TableDirectory, tableDir, numTables);
319 // TODO: Implement find_table
322 Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
323 USHORT numTables; /* Number of tables. */
324 USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
325 USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
326 USHORT rangeShift; /* NumTables x 16-searchRange. */
327 TableDirectory tableDir[]; /* TableDirectory entries. numTables items */
329 DEFINE_NULL_ASSERT_SIZE (OffsetTable, 12);
330 DEFINE_NULL_ALIAS (OpenTypeFontFace, OffsetTable);
333 * TrueType Collections
337 /* OpenTypeFontFaces, in no particular order */
338 DEFINE_OFFSET_ARRAY_TYPE (OffsetTable, offsetTable, numFonts);
339 /* XXX check version here */
342 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
343 ULONG version; /* Version of the TTC Header (1.0 or 2.0),
344 * 0x00010000 or 0x00020000 */
345 ULONG numFonts; /* Number of fonts in TTC */
346 ULONG offsetTable[]; /* Array of offsets to the OffsetTable for each font
347 * from the beginning of the file */
349 DEFINE_NULL_ASSERT_SIZE (TTCHeader, 12);
356 struct OpenTypeFontFile {
357 DEFINE_NON_INSTANTIABLE(OpenTypeFontFile);
358 static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 );
359 static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O');
360 static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f');
362 STATIC_DEFINE_GET_FOR_DATA (OpenTypeFontFile);
364 /* This is how you get a table */
365 inline const char* get_table (const OpenTypeTable& table) const {
366 return ((const char*)this) + table.offset;
368 inline char* get_table (const OpenTypeTable& table) {
369 return ((char*)this) + table.offset;
371 inline const char* operator[] (const OpenTypeTable& table) const {
372 return ((const char*)this) + table.offset;
374 inline char* operator[] (const OpenTypeTable& table) {
375 return ((char*)this) + table.offset;
378 /* Array interface sans get_size() */
379 inline unsigned int get_len (void) const {
382 case TrueTypeTag: case CFFTag: return 1;
383 case TTCTag: return ((const TTCHeader&)*this).get_len();
386 inline const OpenTypeFontFace& operator[] (unsigned int i) const {
387 if (HB_UNLIKELY (i >= get_len ())) return NullOpenTypeFontFace;
389 default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this;
390 case TTCTag: return ((const TTCHeader&)*this)[i];
393 inline const Tag& get_tag (void) const { return tag; }
396 Tag tag; /* 4-byte identifier. */
398 DEFINE_NULL_ASSERT_SIZE (OpenTypeFontFile, 4);
404 * OpenType Layout Common Table Formats
409 * Script, ScriptList, LangSys, Feature, FeatureList, Lookup, LookupList
412 typedef struct Record {
413 Tag tag; /* 4-byte Tag identifier */
414 Offset offset; /* Offset from beginning of object holding
416 } ScriptRecord, LangSysRecord, FeatureRecord;
417 DEFINE_NULL_ASSERT_SIZE (Record, 6);
420 /* Feature indices, in no particular order */
421 DEFINE_ARRAY_TYPE (USHORT, featureIndex, featureCount);
423 /* Returns -1 if none */
424 inline int get_required_feature_index (void) const {
425 if (reqFeatureIndex == 0xffff)
427 return reqFeatureIndex;;
430 /* TODO implement find_feature */
433 Offset lookupOrder; /* = Null (reserved for an offset to a
434 * reordering table) */
435 USHORT reqFeatureIndex;/* Index of a feature required for this
436 * language system--if no required features
438 USHORT featureCount; /* Number of FeatureIndex values for this
439 * language system--excludes the required
441 USHORT featureIndex[]; /* Array of indices into the FeatureList--in
442 * arbitrary order. featureCount entires long */
444 DEFINE_NULL_ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF");
447 /* LangSys', in sorted alphabetical tag order */
448 DEFINE_RECORD_ARRAY_TYPE (LangSys, langSysRecord, langSysCount);
450 inline const bool has_default_language_system (void) const {
451 return defaultLangSys != 0;
453 inline const LangSys& get_default_language_system (void) const {
454 if (HB_UNLIKELY (!defaultLangSys))
456 return *(LangSys*)((const char*)this + defaultLangSys);
459 /* TODO implement find_language_system based on find_tag */
462 Offset defaultLangSys; /* Offset to DefaultLangSys table--from
463 * beginning of Script table--may be Null */
464 USHORT langSysCount; /* Number of LangSysRecords for this script--
465 * excluding the DefaultLangSys */
466 LangSysRecord langSysRecord[];/* Array of LangSysRecords--listed
467 * alphabetically by LangSysTag */
469 DEFINE_NULL_ASSERT_SIZE (Script, 4);
472 /* Scripts, in sorted alphabetical tag order */
473 DEFINE_RECORD_ARRAY_TYPE (Script, scriptRecord, scriptCount);
476 USHORT scriptCount; /* Number of ScriptRecords */
477 ScriptRecord scriptRecord[]; /* Array of ScriptRecords--listed alphabetically
480 DEFINE_NULL_ASSERT_SIZE (ScriptList, 2);
483 /* LookupList indices, in no particular order */
484 DEFINE_ARRAY_TYPE (USHORT, lookupIndex, lookupCount);
487 Offset featureParams; /* Offset to Feature Parameters table (if one
488 * has been defined for the feature), relative
489 * to the beginning of the Feature Table; = Null
491 USHORT lookupCount; /* Number of LookupList indices for this
493 USHORT lookupIndex[]; /* Array of LookupList indices for this
494 * feature--zero-based (first lookup is
495 * LookupListIndex = 0) */
497 DEFINE_NULL_ASSERT_SIZE (Feature, 4);
500 /* Feature indices, in sorted alphabetical tag order */
501 DEFINE_RECORD_ARRAY_TYPE (Feature, featureRecord, featureCount);
504 USHORT featureCount; /* Number of FeatureRecords in this table */
505 FeatureRecord featureRecord[];/* Array of FeatureRecords--zero-based (first
506 * feature has FeatureIndex = 0)--listed
507 * alphabetically by FeatureTag */
509 DEFINE_NULL_ASSERT_SIZE (FeatureList, 2);
511 struct LookupFlag : USHORT {
512 static const uint16_t RightToLeft = 0x0001u;
513 static const uint16_t IgnoreBaseGlyphs = 0x0002u;
514 static const uint16_t IgnoreLigatures = 0x0004u;
515 static const uint16_t IgnoreMarks = 0x0008u;
516 static const uint16_t Reserved = 0x00F0u;
517 static const uint16_t MarkAttachmentType = 0xFF00u;
519 DEFINE_NULL_ASSERT_SIZE (LookupFlag, 2);
521 struct LookupSubTable {
522 DEFINE_NON_INSTANTIABLE(LookupSubTable);
525 USHORT format; /* Subtable format. Different for GSUB and GPOS */
527 DEFINE_NULL_ASSERT_SIZE (LookupSubTable, 2);
531 /* SubTables, in the desired order */
532 DEFINE_OFFSET_ARRAY_TYPE (LookupSubTable, subTableOffset, subTableCount);
534 inline bool is_right_to_left (void) const { return lookupFlag & LookupFlag::RightToLeft; }
535 inline bool ignore_base_glyphs(void) const { return lookupFlag & LookupFlag::IgnoreBaseGlyphs; }
536 inline bool ignore_ligatures (void) const { return lookupFlag & LookupFlag::IgnoreLigatures; }
537 inline bool ignore_marks (void) const { return lookupFlag & LookupFlag::IgnoreMarks; }
538 inline bool get_mark_attachment_type (void) const { return lookupFlag & LookupFlag::MarkAttachmentType; }
540 inline uint16_t get_type (void) const { return lookupType; }
541 inline uint16_t get_flag (void) const { return lookupFlag; }
544 USHORT lookupType; /* Different enumerations for GSUB and GPOS */
545 USHORT lookupFlag; /* Lookup qualifiers */
546 USHORT subTableCount; /* Number of SubTables for this lookup */
547 Offset subTableOffset[];/* Array of offsets to SubTables-from
548 * beginning of Lookup table */
550 DEFINE_NULL_ASSERT_SIZE (Lookup, 6);
553 /* Lookup indices, in sorted alphabetical tag order */
554 DEFINE_OFFSET_ARRAY_TYPE (Lookup, lookupOffset, lookupCount);
557 USHORT lookupCount; /* Number of lookups in this table */
558 Offset lookupOffset[]; /* Array of offsets to Lookup tables--from
559 * beginning of LookupList--zero based (first
560 * lookup is Lookup index = 0) */
562 DEFINE_NULL_ASSERT_SIZE (LookupList, 2);
568 struct CoverageFormat1 {
569 /* GlyphIDs, in sorted numerical order */
570 DEFINE_ARRAY_TYPE (GlyphID, glyphArray, glyphCount);
572 inline int get_coverage (uint16_t glyph_id) const {
576 for (unsigned int i = 0; i < glyphCount; i++)
577 if (gid == glyphArray[i])
583 USHORT coverageFormat; /* Format identifier--format = 1 */
584 USHORT glyphCount; /* Number of glyphs in the GlyphArray */
585 GlyphID glyphArray[]; /* Array of GlyphIDs--in numerical order */
587 ASSERT_SIZE (CoverageFormat1, 4);
589 struct CoverageRangeRecord {
591 inline int get_coverage (uint16_t glyph_id) const {
592 if (glyph_id >= start && glyph_id <= end)
593 return startCoverageIndex + (glyph_id - start);
598 GlyphID start; /* First GlyphID in the range */
599 GlyphID end; /* Last GlyphID in the range */
600 USHORT startCoverageIndex; /* Coverage Index of first GlyphID in
603 DEFINE_NULL_ASSERT_SIZE_DATA (CoverageRangeRecord, 6, "\001");
605 struct CoverageFormat2 {
606 /* CoverageRangeRecords, in sorted numerical start order */
607 DEFINE_ARRAY_TYPE (CoverageRangeRecord, rangeRecord, rangeCount);
609 inline int get_coverage (uint16_t glyph_id) const {
611 for (unsigned int i = 0; i < rangeCount; i++) {
612 int coverage = rangeRecord[i].get_coverage (glyph_id);
620 USHORT coverageFormat; /* Format identifier--format = 2 */
621 USHORT rangeCount; /* Number of CoverageRangeRecords */
622 CoverageRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
623 * Start GlyphID. rangeCount entries
626 ASSERT_SIZE (CoverageFormat2, 4);
629 DEFINE_NON_INSTANTIABLE(Coverage);
631 inline unsigned int get_size (void) const {
632 switch (u.coverageFormat) {
633 case 1: return u.format1.get_size ();
634 case 2: return u.format2.get_size ();
635 default:return sizeof (u.coverageFormat);
639 /* Returns -1 if not covered. */
640 inline int get_coverage (uint16_t glyph_id) const {
641 switch (u.coverageFormat) {
642 case 1: return u.format1.get_coverage(glyph_id);
643 case 2: return u.format2.get_coverage(glyph_id);
650 USHORT coverageFormat; /* Format identifier */
651 CoverageFormat1 format1;
652 CoverageFormat2 format2;
655 DEFINE_NULL (Coverage, 2);
658 * Class Definition Table
661 struct ClassDefFormat1 {
662 /* GlyphIDs, in sorted numerical order */
663 DEFINE_ARRAY_TYPE (USHORT, classValueArray, glyphCount);
665 inline int get_class (uint16_t glyph_id) const {
666 if (glyph_id >= startGlyph && glyph_id < startGlyph + glyphCount)
667 return classValueArray[glyph_id - startGlyph];
672 USHORT classFormat; /* Format identifier--format = 1 */
673 GlyphID startGlyph; /* First GlyphID of the classValueArray */
674 USHORT glyphCount; /* Size of the classValueArray */
675 USHORT classValueArray[]; /* Array of Class Values--one per GlyphID */
677 ASSERT_SIZE (ClassDefFormat1, 6);
679 struct ClassRangeRecord {
681 inline int get_class (uint16_t glyph_id) const {
682 if (glyph_id >= start && glyph_id <= end)
688 GlyphID start; /* First GlyphID in the range */
689 GlyphID end; /* Last GlyphID in the range */
690 USHORT classValue; /* Applied to all glyphs in the range */
692 DEFINE_NULL_ASSERT_SIZE_DATA (ClassRangeRecord, 6, "\001");
694 struct ClassDefFormat2 {
695 /* ClassRangeRecords, in sorted numerical start order */
696 DEFINE_ARRAY_TYPE (ClassRangeRecord, rangeRecord, rangeCount);
698 inline int get_class (uint16_t glyph_id) const {
700 for (int i = 0; i < rangeCount; i++) {
701 int classValue = rangeRecord[i].get_class (glyph_id);
709 USHORT classFormat; /* Format identifier--format = 2 */
710 USHORT rangeCount; /* Number of Number of ClassRangeRecords */
711 ClassRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
714 ASSERT_SIZE (ClassDefFormat2, 4);
717 DEFINE_NON_INSTANTIABLE(ClassDef);
719 inline unsigned int get_size (void) const {
720 switch (u.classFormat) {
721 case 1: return u.format1.get_size ();
722 case 2: return u.format2.get_size ();
723 default:return sizeof (u.classFormat);
727 /* Returns 0 if not found. */
728 inline int get_class (uint16_t glyph_id) const {
729 switch (u.classFormat) {
730 case 1: return u.format1.get_class(glyph_id);
731 case 2: return u.format2.get_class(glyph_id);
738 USHORT classFormat; /* Format identifier */
739 ClassDefFormat1 format1;
740 ClassDefFormat2 format2;
743 DEFINE_NULL (ClassDef, 2);
751 inline unsigned int get_size (void) const {
752 int count = endSize - startSize + 1;
753 if (count < 0) count = 0;
754 switch (deltaFormat) {
755 case 1: return sizeof (Device) + sizeof (USHORT) * ((count+7)/8);
756 case 2: return sizeof (Device) + sizeof (USHORT) * ((count+3)/4);
757 case 3: return sizeof (Device) + sizeof (USHORT) * ((count+1)/2);
758 default:return sizeof (Device);
762 inline int get_delta (int ppem_size) const {
763 if (ppem_size >= startSize && ppem_size <= endSize &&
764 deltaFormat >= 1 && deltaFormat <= 3) {
765 int s = ppem_size - startSize;
768 uint16_t byte = deltaValue[s >> (4 - f)];
769 uint16_t bits = byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f));
770 uint16_t mask = 0xFFFF >> (16 - (1 << f));
772 int delta = bits & mask;
774 if (delta >= ((mask + 1) >> 1))
783 USHORT startSize; /* Smallest size to correct--in ppem */
784 USHORT endSize; /* Largest size to correct--in ppem */
785 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 */
786 USHORT deltaValue[]; /* Array of compressed data */
788 DEFINE_NULL_ASSERT_SIZE (Device, 6);
794 typedef struct GSUBGPOSHeader {
795 static const hb_tag_t GSUBTag = HB_TAG ('G','S','U','B');
796 static const hb_tag_t GPOSTag = HB_TAG ('G','P','O','S');
798 STATIC_DEFINE_GET_FOR_DATA (GSUBGPOSHeader);
799 /* XXX check version here */
801 DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list, get_script(i) */
802 DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list, get_feature(i) */
803 DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list, get_lookup(i) */
805 /* TODO implement find_script */
808 Fixed_Version version; /* Version of the GSUB/GPOS table--initially set
810 Offset scriptList; /* Offset to ScriptList table--from beginning of
812 Offset featureList; /* Offset to FeatureList table--from beginning of
814 Offset lookupList; /* Offset to LookupList table--from beginning of
816 } GSUBHeader, GPOSHeader;
817 DEFINE_NULL_ASSERT_SIZE (GSUBGPOSHeader, 10);
818 DEFINE_NULL_ALIAS (GSUBHeader, GSUBGPOSHeader);
819 DEFINE_NULL_ALIAS (GPOSHeader, GSUBGPOSHeader);
821 #endif /* HB_OT_LAYOUT_OPEN_PRIVATE_H */