1 #ifndef HB_OT_LAYOUT_OPEN_PRIVATE_H
2 #define HB_OT_LAYOUT_OPEN_PRIVATE_H
4 #include "hb-private.h"
5 #include "hb-ot-layout.h"
11 #define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN) \
12 inline NAME& operator = (TYPE i) { v = BIG_ENDIAN(i); return *this; } \
13 inline operator TYPE(void) const { return BIG_ENDIAN(v); } \
14 inline bool operator== (NAME o) const { return v == o.v; } \
17 #define DEFINE_INT_TYPE0(NAME, type) DEFINE_INT_TYPE1 (NAME, type, hb_be_##type)
18 #define DEFINE_INT_TYPE(NAME, u, w) DEFINE_INT_TYPE0 (NAME, u##int##w##_t)
19 #define DEFINE_INT_TYPE_STRUCT(NAME, u, w) \
21 DEFINE_INT_TYPE(NAME, u, w) \
28 /* get_len() is a method returning the number of items in an array-like object */
29 #define DEFINE_LEN(Type, array, num) \
30 inline unsigned int get_len(void) const { return num; } \
32 /* get_size() is a method returning the size in bytes of an array-like object */
33 #define DEFINE_SIZE(Type, array, num) \
34 inline unsigned int get_size(void) const { return sizeof (*this) + sizeof (Type) * num; }
36 #define DEFINE_LEN_AND_SIZE(Type, array, num) \
37 DEFINE_LEN(Type, array, num) \
38 DEFINE_SIZE(Type, array, num)
40 /* An array type is one that contains a variable number of objects
41 * as its last item. An array object is extended with len() and size()
42 * methods, as well as overloaded [] operator. */
43 #define DEFINE_ARRAY_TYPE(Type, array, num) \
44 DEFINE_INDEX_OPERATOR(Type, array, num) \
45 DEFINE_LEN_AND_SIZE(Type, array, num)
46 #define DEFINE_INDEX_OPERATOR(Type, array, num) \
47 inline const Type& operator[] (unsigned int i) const { \
48 if (HB_UNLIKELY (i >= num)) return Null##Type; \
52 /* An offset array type is like an array type, but it contains a table
53 * of offsets to the objects, relative to the beginning of the current
55 #define DEFINE_OFFSET_ARRAY_TYPE(Type, array, num) \
56 DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
57 DEFINE_LEN_AND_SIZE(Offset, array, num)
58 #define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
59 inline const Type& operator[] (unsigned int i) const { \
60 if (HB_UNLIKELY (i >= num)) return Null##Type; \
61 if (HB_UNLIKELY (!array[i])) return Null##Type; \
62 return *(const Type *)((const char*)this + array[i]); \
65 #define DEFINE_RECORD_ARRAY_TYPE(Type, array, num) \
66 DEFINE_RECORD_ACCESSOR(Type, array, num) \
67 DEFINE_LEN_AND_SIZE(Record, array, num)
68 #define DEFINE_RECORD_ACCESSOR(Type, array, num) \
69 inline const Type& operator[] (unsigned int i) const { \
70 if (HB_UNLIKELY (i >= num)) return Null##Type; \
71 if (HB_UNLIKELY (!array[i].offset)) return Null##Type; \
72 return *(const Type *)((const char*)this + array[i].offset); \
74 inline const Tag& get_tag (unsigned int i) const { \
75 if (HB_UNLIKELY (i >= num)) return NullTag; \
76 return array[i].tag; \
78 /* TODO: implement find_tag() */
84 #define DEFINE_LIST_ACCESSOR(Type, name) \
85 inline const Type##List& get_##name##_list (void) const { \
86 if (HB_UNLIKELY (!name##List)) return Null##Type##List; \
87 return *(const Type##List *)((const char*)this + name##List); \
89 inline const Type& get_##name (unsigned int i) const { \
90 return get_##name##_list()[i]; \
97 /* makes class uninstantiable. should be used for union classes that don't
98 * contain any complete type */
99 #define DEFINE_NON_INSTANTIABLE(Type) \
100 private: inline Type() {} /* cannot be instantiated */ \
103 /* defines Null##Type as a safe nil instance of Type */
104 #define DEFINE_NULL_DATA(Type, size, data) \
105 static const unsigned char Null##Type##Data[size] = data; \
106 DEFINE_NULL_ALIAS (Type, Type)
107 #define DEFINE_NULL(Type, size) \
108 DEFINE_NULL_DATA(Type, size, "")
109 #define DEFINE_NULL_ASSERT_SIZE(Type, size) \
110 DEFINE_NULL_ASSERT_SIZE_DATA(Type, size, "")
111 #define DEFINE_NULL_ASSERT_SIZE_DATA(Type, size, data) \
112 ASSERT_SIZE (Type, size); \
113 DEFINE_NULL_DATA (Type, size, data)
114 #define DEFINE_NULL_ALIAS(NewType, OldType) \
115 static const NewType &Null##NewType = *(NewType *)Null##OldType##Data
117 /* get_for_data() is a static class method returning a reference to an
118 * instance of Type located at the input data location. It's just a
120 #define STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
121 static inline const Type& get_for_data (const char *data) { \
122 return *(const Type*)data; \
124 #define STATIC_DEFINE_GET_FOR_DATA(Type) \
125 STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
126 STATIC_DEFINE_GET_FOR_DATA0( , Type)
129 #define DEFINE_ACCESSOR(Type, name, Name) \
130 inline const Type& name (void) const { \
131 if (HB_UNLIKELY (!Name)) return Null##Type; \
132 return *(const Type*)((const char*)this + Name); \
139 * The OpenType Font File
150 /* "The following data types are used in the OpenType font file.
151 * All OpenType fonts use Motorola-style byte ordering (Big Endian):" */
154 DEFINE_INT_TYPE_STRUCT (BYTE, u, 8); /* 8-bit unsigned integer. */
155 DEFINE_NULL_ASSERT_SIZE (BYTE, 1);
156 DEFINE_INT_TYPE_STRUCT (CHAR, , 8); /* 8-bit signed integer. */
157 DEFINE_NULL_ASSERT_SIZE (CHAR, 1);
158 DEFINE_INT_TYPE_STRUCT (USHORT, u, 16); /* 16-bit unsigned integer. */
159 DEFINE_NULL_ASSERT_SIZE (USHORT, 2);
160 DEFINE_INT_TYPE_STRUCT (SHORT, , 16); /* 16-bit signed integer. */
161 DEFINE_NULL_ASSERT_SIZE (SHORT, 2);
162 DEFINE_INT_TYPE_STRUCT (ULONG, u, 32); /* 32-bit unsigned integer. */
163 DEFINE_NULL_ASSERT_SIZE (ULONG, 4);
164 DEFINE_INT_TYPE_STRUCT (LONG, , 32); /* 32-bit signed integer. */
165 DEFINE_NULL_ASSERT_SIZE (LONG, 4);
167 /* Date represented in number of seconds since 12:00 midnight, January 1,
168 * 1904. The value is represented as a signed 64-bit integer. */
169 DEFINE_INT_TYPE_STRUCT (LONGDATETIME, , 64);
171 /* 32-bit signed fixed-point number (16.16) */
173 inline Fixed& operator = (int32_t v) { i = (int16_t) (v >> 16); f = (uint16_t) v; return *this; } \
174 inline operator int32_t(void) const { return (((int32_t) i) << 16) + (uint16_t) f; } \
175 inline bool operator== (Fixed o) const { return i == o.i && f == o.f; } \
177 inline operator double(void) const { return (uint32_t) this / 65536.; }
178 inline int16_t int_part (void) const { return i; }
179 inline uint16_t frac_part (void) const { return f; }
185 DEFINE_NULL_ASSERT_SIZE (Fixed, 4);
187 /* Smallest measurable distance in the em space. */
190 /* 16-bit signed integer (SHORT) that describes a quantity in FUnits. */
191 struct FWORD : SHORT {
193 DEFINE_NULL_ASSERT_SIZE (FWORD, 2);
195 /* 16-bit unsigned integer (USHORT) that describes a quantity in FUnits. */
196 struct UFWORD : USHORT {
198 DEFINE_NULL_ASSERT_SIZE (UFWORD, 2);
200 /* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */
201 struct F2DOT14 : SHORT {
202 inline operator double() const { return (uint32_t) this / 16384.; }
204 DEFINE_NULL_ASSERT_SIZE (F2DOT14, 2);
206 /* Array of four uint8s (length = 32 bits) used to identify a script, language
207 * system, feature, or baseline */
209 inline Tag (void) { v[0] = v[1] = v[2] = v[3] = 0; }
210 inline Tag (uint32_t v) { (ULONG&)(*this) = v; }
211 inline Tag (const char *c) { v[0] = c[0]; v[1] = c[1]; v[2] = c[2]; v[3] = c[3]; }
212 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]; }
213 inline bool operator== (const char *c) const { return v[0]==c[0]&&v[1]==c[1]&&v[2]==c[2]&&v[3]==c[3]; }
214 inline bool operator== (uint32_t i) const { return i == (uint32_t) *this; }
215 inline operator uint32_t(void) const { return (v[0]<<24)+(v[1]<<16) +(v[2]<<8)+v[3]; }
216 /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */
217 inline operator const char* (void) const { return (const char *)this; }
218 inline operator char* (void) { return (char *)this; }
223 ASSERT_SIZE (Tag, 4);
224 DEFINE_NULL_DATA (Tag, 5, " ");
226 /* Glyph index number, same as uint16 (length = 16 bits) */
227 DEFINE_INT_TYPE_STRUCT (GlyphID, u, 16);
228 DEFINE_NULL_ASSERT_SIZE (GlyphID, 2);
230 /* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */
231 DEFINE_INT_TYPE_STRUCT (Offset, u, 16);
232 DEFINE_NULL_ASSERT_SIZE (Offset, 2);
235 struct CheckSum : ULONG {
236 static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length) {
238 ULONG *EndPtr = Table+((Length+3) & ~3) / sizeof(ULONG);
240 while (Table < EndPtr)
245 DEFINE_NULL_ASSERT_SIZE (CheckSum, 4);
252 struct USHORT_Version : USHORT {
254 DEFINE_NULL_ASSERT_SIZE (USHORT_Version, 2);
256 struct Fixed_Version : Fixed {
257 inline int16_t major (void) const { return this->int_part(); }
258 inline int16_t minor (void) const { return this->frac_part(); }
260 DEFINE_NULL_ASSERT_SIZE (Fixed_Version, 4);
264 * Organization of an OpenType Font
267 struct OpenTypeFontFile;
271 typedef struct TableDirectory {
273 friend struct OpenTypeFontFile;
275 inline const Tag& get_tag (void) const { return tag; }
276 inline unsigned long get_checksum (void) const { return checkSum; }
277 inline unsigned long get_offset (void) const { return offset; }
278 inline unsigned long get_length (void) const { return length; }
281 Tag tag; /* 4-byte identifier. */
282 CheckSum checkSum; /* CheckSum for this table. */
283 ULONG offset; /* Offset from beginning of TrueType font
285 ULONG length; /* Length of this table. */
287 DEFINE_NULL_ASSERT_SIZE (TableDirectory, 16);
289 typedef struct OffsetTable {
290 /* OpenTypeTables, in no particular order */
291 DEFINE_ARRAY_TYPE (TableDirectory, tableDir, numTables);
292 // TODO: Implement find_table
295 Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
296 USHORT numTables; /* Number of tables. */
297 USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
298 USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
299 USHORT rangeShift; /* NumTables x 16-searchRange. */
300 TableDirectory tableDir[]; /* TableDirectory entries. numTables items */
302 DEFINE_NULL_ASSERT_SIZE (OffsetTable, 12);
303 DEFINE_NULL_ALIAS (OpenTypeFontFace, OffsetTable);
306 * TrueType Collections
310 /* OpenTypeFontFaces, in no particular order */
311 DEFINE_OFFSET_ARRAY_TYPE (OffsetTable, offsetTable, numFonts);
314 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
315 ULONG version; /* Version of the TTC Header (1.0 or 2.0),
316 * 0x00010000 or 0x00020000 */
317 ULONG numFonts; /* Number of fonts in TTC */
318 ULONG offsetTable[]; /* Array of offsets to the OffsetTable for each font
319 * from the beginning of the file */
321 DEFINE_NULL_ASSERT_SIZE (TTCHeader, 12);
328 struct OpenTypeFontFile {
329 DEFINE_NON_INSTANTIABLE(OpenTypeFontFile);
330 static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 );
331 static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O');
332 static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f');
334 STATIC_DEFINE_GET_FOR_DATA (OpenTypeFontFile);
336 /* This is how you get a table */
337 inline const char* get_table (const OpenTypeTable& table) const {
338 return ((const char*)this) + table.offset;
340 inline char* get_table (const OpenTypeTable& table) {
341 return ((char*)this) + table.offset;
343 inline const char* operator[] (const OpenTypeTable& table) const {
344 return ((const char*)this) + table.offset;
346 inline char* operator[] (const OpenTypeTable& table) {
347 return ((char*)this) + table.offset;
350 /* Array interface sans get_size() */
351 inline unsigned int get_len (void) const {
354 case TrueTypeTag: case CFFTag: return 1;
355 case TTCTag: return ((const TTCHeader&)*this).get_len();
358 inline const OpenTypeFontFace& operator[] (unsigned int i) const {
359 if (HB_UNLIKELY (i >= get_len ())) return NullOpenTypeFontFace;
361 default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this;
362 case TTCTag: return ((const TTCHeader&)*this)[i];
365 inline const Tag& get_tag (void) const { return tag; }
368 Tag tag; /* 4-byte identifier. */
370 DEFINE_NULL_ASSERT_SIZE (OpenTypeFontFile, 4);
376 * OpenType Layout Common Table Formats
381 * Script, ScriptList, LangSys, Feature, FeatureList, Lookup, LookupList
384 typedef struct Record {
385 Tag tag; /* 4-byte Tag identifier */
386 Offset offset; /* Offset from beginning of object holding
388 } ScriptRecord, LangSysRecord, FeatureRecord;
389 DEFINE_NULL_ASSERT_SIZE (Record, 6);
392 /* Feature indices, in no particular order */
393 DEFINE_ARRAY_TYPE (USHORT, featureIndex, featureCount);
395 /* Returns -1 if none */
396 inline int get_required_feature_index (void) const {
397 if (reqFeatureIndex == 0xffff)
399 return reqFeatureIndex;;
402 /* TODO implement find_feature */
405 Offset lookupOrder; /* = Null (reserved for an offset to a
406 * reordering table) */
407 USHORT reqFeatureIndex;/* Index of a feature required for this
408 * language system--if no required features
410 USHORT featureCount; /* Number of FeatureIndex values for this
411 * language system--excludes the required
413 USHORT featureIndex[]; /* Array of indices into the FeatureList--in
414 * arbitrary order. featureCount entires long */
416 DEFINE_NULL_ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF");
419 /* LangSys', in sorted alphabetical tag order */
420 DEFINE_RECORD_ARRAY_TYPE (LangSys, langSysRecord, langSysCount);
422 inline const bool has_default_language_system (void) const {
423 return defaultLangSys != 0;
425 inline const LangSys& get_default_language_system (void) const {
426 if (HB_UNLIKELY (!defaultLangSys))
428 return *(LangSys*)((const char*)this + defaultLangSys);
431 /* TODO implement find_language_system based on find_tag */
434 Offset defaultLangSys; /* Offset to DefaultLangSys table--from
435 * beginning of Script table--may be Null */
436 USHORT langSysCount; /* Number of LangSysRecords for this script--
437 * excluding the DefaultLangSys */
438 LangSysRecord langSysRecord[];/* Array of LangSysRecords--listed
439 * alphabetically by LangSysTag */
441 DEFINE_NULL_ASSERT_SIZE (Script, 4);
444 /* Scripts, in sorted alphabetical tag order */
445 DEFINE_RECORD_ARRAY_TYPE (Script, scriptRecord, scriptCount);
448 USHORT scriptCount; /* Number of ScriptRecords */
449 ScriptRecord scriptRecord[]; /* Array of ScriptRecords--listed alphabetically
452 DEFINE_NULL_ASSERT_SIZE (ScriptList, 2);
455 /* LookupList indices, in no particular order */
456 DEFINE_ARRAY_TYPE (USHORT, lookupIndex, lookupCount);
459 Offset featureParams; /* Offset to Feature Parameters table (if one
460 * has been defined for the feature), relative
461 * to the beginning of the Feature Table; = Null
463 USHORT lookupCount; /* Number of LookupList indices for this
465 USHORT lookupIndex[]; /* Array of LookupList indices for this
466 * feature--zero-based (first lookup is
467 * LookupListIndex = 0) */
469 DEFINE_NULL_ASSERT_SIZE (Feature, 4);
472 /* Feature indices, in sorted alphabetical tag order */
473 DEFINE_RECORD_ARRAY_TYPE (Feature, featureRecord, featureCount);
476 USHORT featureCount; /* Number of FeatureRecords in this table */
477 FeatureRecord featureRecord[];/* Array of FeatureRecords--zero-based (first
478 * feature has FeatureIndex = 0)--listed
479 * alphabetically by FeatureTag */
481 DEFINE_NULL_ASSERT_SIZE (FeatureList, 2);
483 struct LookupFlag : USHORT {
484 static const uint16_t RightToLeft = 0x0001u;
485 static const uint16_t IgnoreBaseGlyphs = 0x0002u;
486 static const uint16_t IgnoreLigatures = 0x0004u;
487 static const uint16_t IgnoreMarks = 0x0008u;
488 static const uint16_t Reserved = 0x00F0u;
489 static const uint16_t MarkAttachmentType = 0xFF00u;
491 DEFINE_NULL_ASSERT_SIZE (LookupFlag, 2);
493 struct LookupSubTable {
494 DEFINE_NON_INSTANTIABLE(LookupSubTable);
497 USHORT format; /* Subtable format. Different for GSUB and GPOS */
499 DEFINE_NULL_ASSERT_SIZE (LookupSubTable, 2);
503 /* SubTables, in the desired order */
504 DEFINE_OFFSET_ARRAY_TYPE (LookupSubTable, subTableOffset, subTableCount);
506 inline bool is_right_to_left (void) const { return lookupFlag & LookupFlag::RightToLeft; }
507 inline bool ignore_base_glyphs(void) const { return lookupFlag & LookupFlag::IgnoreBaseGlyphs; }
508 inline bool ignore_ligatures (void) const { return lookupFlag & LookupFlag::IgnoreLigatures; }
509 inline bool ignore_marks (void) const { return lookupFlag & LookupFlag::IgnoreMarks; }
510 inline bool get_mark_attachment_type (void) const { return lookupFlag & LookupFlag::MarkAttachmentType; }
512 inline uint16_t get_type (void) const { return lookupType; }
513 inline uint16_t get_flag (void) const { return lookupFlag; }
516 USHORT lookupType; /* Different enumerations for GSUB and GPOS */
517 USHORT lookupFlag; /* Lookup qualifiers */
518 USHORT subTableCount; /* Number of SubTables for this lookup */
519 Offset subTableOffset[];/* Array of offsets to SubTables-from
520 * beginning of Lookup table */
522 DEFINE_NULL_ASSERT_SIZE (Lookup, 6);
525 /* Lookup indices, in sorted alphabetical tag order */
526 DEFINE_OFFSET_ARRAY_TYPE (Lookup, lookupOffset, lookupCount);
529 USHORT lookupCount; /* Number of lookups in this table */
530 Offset lookupOffset[]; /* Array of offsets to Lookup tables--from
531 * beginning of LookupList--zero based (first
532 * lookup is Lookup index = 0) */
534 DEFINE_NULL_ASSERT_SIZE (LookupList, 2);
540 struct CoverageFormat1 {
541 /* GlyphIDs, in sorted numerical order */
542 DEFINE_ARRAY_TYPE (GlyphID, glyphArray, glyphCount);
544 inline int get_coverage (uint16_t glyph_id) const {
548 for (unsigned int i = 0; i < glyphCount; i++)
549 if (gid == glyphArray[i])
555 USHORT coverageFormat; /* Format identifier--format = 1 */
556 USHORT glyphCount; /* Number of glyphs in the GlyphArray */
557 GlyphID glyphArray[]; /* Array of GlyphIDs--in numerical order */
559 ASSERT_SIZE (CoverageFormat1, 4);
561 struct CoverageRangeRecord {
563 inline int get_coverage (uint16_t glyph_id) const {
564 if (glyph_id >= start && glyph_id <= end)
565 return startCoverageIndex + (glyph_id - start);
570 GlyphID start; /* First GlyphID in the range */
571 GlyphID end; /* Last GlyphID in the range */
572 USHORT startCoverageIndex; /* Coverage Index of first GlyphID in
575 DEFINE_NULL_ASSERT_SIZE_DATA (CoverageRangeRecord, 6, "\001");
577 struct CoverageFormat2 {
578 /* CoverageRangeRecords, in sorted numerical start order */
579 DEFINE_ARRAY_TYPE (CoverageRangeRecord, rangeRecord, rangeCount);
581 inline int get_coverage (uint16_t glyph_id) const {
583 for (unsigned int i = 0; i < rangeCount; i++) {
584 int coverage = rangeRecord[i].get_coverage (glyph_id);
592 USHORT coverageFormat; /* Format identifier--format = 2 */
593 USHORT rangeCount; /* Number of CoverageRangeRecords */
594 CoverageRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
595 * Start GlyphID. rangeCount entries
598 ASSERT_SIZE (CoverageFormat2, 4);
601 DEFINE_NON_INSTANTIABLE(Coverage);
603 inline unsigned int get_size (void) const {
604 switch (u.coverageFormat) {
605 case 1: return u.format1.get_size ();
606 case 2: return u.format2.get_size ();
607 default:return sizeof (u.coverageFormat);
611 /* Returns -1 if not covered. */
612 inline int get_coverage (uint16_t glyph_id) const {
613 switch (u.coverageFormat) {
614 case 1: return u.format1.get_coverage(glyph_id);
615 case 2: return u.format2.get_coverage(glyph_id);
622 USHORT coverageFormat; /* Format identifier */
623 CoverageFormat1 format1;
624 CoverageFormat2 format2;
627 DEFINE_NULL (Coverage, 2);
630 * Class Definition Table
633 struct ClassDefFormat1 {
634 /* GlyphIDs, in sorted numerical order */
635 DEFINE_ARRAY_TYPE (USHORT, classValueArray, glyphCount);
637 inline int get_class (uint16_t glyph_id) const {
638 if (glyph_id >= startGlyph && glyph_id < startGlyph + glyphCount)
639 return classValueArray[glyph_id - startGlyph];
644 USHORT classFormat; /* Format identifier--format = 1 */
645 GlyphID startGlyph; /* First GlyphID of the classValueArray */
646 USHORT glyphCount; /* Size of the classValueArray */
647 USHORT classValueArray[]; /* Array of Class Values--one per GlyphID */
649 ASSERT_SIZE (ClassDefFormat1, 6);
651 struct ClassRangeRecord {
653 inline int get_class (uint16_t glyph_id) const {
654 if (glyph_id >= start && glyph_id <= end)
660 GlyphID start; /* First GlyphID in the range */
661 GlyphID end; /* Last GlyphID in the range */
662 USHORT classValue; /* Applied to all glyphs in the range */
664 DEFINE_NULL_ASSERT_SIZE_DATA (ClassRangeRecord, 6, "\001");
666 struct ClassDefFormat2 {
667 /* ClassRangeRecords, in sorted numerical start order */
668 DEFINE_ARRAY_TYPE (ClassRangeRecord, rangeRecord, rangeCount);
670 inline int get_class (uint16_t glyph_id) const {
672 for (int i = 0; i < rangeCount; i++) {
673 int classValue = rangeRecord[i].get_class (glyph_id);
681 USHORT classFormat; /* Format identifier--format = 2 */
682 USHORT rangeCount; /* Number of Number of ClassRangeRecords */
683 ClassRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
686 ASSERT_SIZE (ClassDefFormat2, 4);
689 DEFINE_NON_INSTANTIABLE(ClassDef);
691 inline unsigned int get_size (void) const {
692 switch (u.classFormat) {
693 case 1: return u.format1.get_size ();
694 case 2: return u.format2.get_size ();
695 default:return sizeof (u.classFormat);
699 /* Returns 0 if not found. */
700 inline int get_class (uint16_t glyph_id) const {
701 switch (u.classFormat) {
702 case 1: return u.format1.get_class(glyph_id);
703 case 2: return u.format2.get_class(glyph_id);
710 USHORT classFormat; /* Format identifier */
711 ClassDefFormat1 format1;
712 ClassDefFormat2 format2;
715 DEFINE_NULL (ClassDef, 2);
723 inline unsigned int get_size (void) const {
724 int count = endSize - startSize + 1;
725 if (count < 0) count = 0;
726 switch (deltaFormat) {
727 case 1: return sizeof (Device) + sizeof (USHORT) * ((count+7)/8);
728 case 2: return sizeof (Device) + sizeof (USHORT) * ((count+3)/4);
729 case 3: return sizeof (Device) + sizeof (USHORT) * ((count+1)/2);
730 default:return sizeof (Device);
734 inline int get_delta (int ppem_size) const {
735 if (ppem_size >= startSize && ppem_size <= endSize &&
736 deltaFormat >= 1 && deltaFormat <= 3) {
737 int s = ppem_size - startSize;
740 uint16_t byte = deltaValue[s >> (4 - f)];
741 uint16_t bits = byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f));
742 uint16_t mask = 0xFFFF >> (16 - (1 << f));
744 int delta = bits & mask;
746 if (delta >= ((mask + 1) >> 1))
755 USHORT startSize; /* Smallest size to correct--in ppem */
756 USHORT endSize; /* Largest size to correct--in ppem */
757 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 */
758 USHORT deltaValue[]; /* Array of compressed data */
760 DEFINE_NULL_ASSERT_SIZE (Device, 6);
766 typedef struct GSUBGPOSHeader {
767 static const hb_tag_t GSUBTag = HB_TAG ('G','S','U','B');
768 static const hb_tag_t GPOSTag = HB_TAG ('G','P','O','S');
770 STATIC_DEFINE_GET_FOR_DATA (GSUBGPOSHeader);
772 DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list, get_script(i) */
773 DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list, get_feature(i) */
774 DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list, get_lookup(i) */
776 /* TODO implement find_script */
779 Fixed_Version version; /* Version of the GSUB/GPOS table--initially set
781 Offset scriptList; /* Offset to ScriptList table--from beginning of
783 Offset featureList; /* Offset to FeatureList table--from beginning of
785 Offset lookupList; /* Offset to LookupList table--from beginning of
787 } GSUBHeader, GPOSHeader;
788 DEFINE_NULL_ASSERT_SIZE (GSUBGPOSHeader, 10);
789 DEFINE_NULL_ALIAS (GSUBHeader, GSUBGPOSHeader);
790 DEFINE_NULL_ALIAS (GPOSHeader, GSUBGPOSHeader);
792 #endif /* HB_OT_LAYOUT_OPEN_PRIVATE_H */