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"
37 #define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN) \
38 inline NAME& operator = (TYPE i) { v = BIG_ENDIAN(i); return *this; } \
39 inline operator TYPE(void) const { return BIG_ENDIAN(v); } \
40 inline bool operator== (NAME o) const { return v == o.v; } \
43 #define DEFINE_INT_TYPE0(NAME, type) DEFINE_INT_TYPE1 (NAME, type, hb_be_##type)
44 #define DEFINE_INT_TYPE(NAME, u, w) DEFINE_INT_TYPE0 (NAME, u##int##w##_t)
45 #define DEFINE_INT_TYPE_STRUCT(NAME, u, w) \
47 DEFINE_INT_TYPE(NAME, u, w) \
54 /* get_len() is a method returning the number of items in an array-like object */
55 #define DEFINE_LEN(Type, array, num) \
56 inline unsigned int get_len(void) const { return num; } \
58 /* get_size() is a method returning the size in bytes of an array-like object */
59 #define DEFINE_SIZE(Type, array, num) \
60 inline unsigned int get_size(void) const { return sizeof (*this) + sizeof (Type) * num; }
62 #define DEFINE_LEN_AND_SIZE(Type, array, num) \
63 DEFINE_LEN(Type, array, num) \
64 DEFINE_SIZE(Type, array, num)
66 /* An array type is one that contains a variable number of objects
67 * as its last item. An array object is extended with len() and size()
68 * methods, as well as overloaded [] operator. */
69 #define DEFINE_ARRAY_TYPE(Type, array, num) \
70 DEFINE_INDEX_OPERATOR(Type, array, num) \
71 DEFINE_LEN_AND_SIZE(Type, array, num)
72 #define DEFINE_INDEX_OPERATOR(Type, array, num) \
73 inline const Type& operator[] (unsigned int i) const { \
74 if (HB_UNLIKELY (i >= num)) return Null##Type; \
78 /* An offset array type is like an array type, but it contains a table
79 * of offsets to the objects, relative to the beginning of the current
81 #define DEFINE_OFFSET_ARRAY_TYPE(Type, array, num) \
82 DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
83 DEFINE_LEN_AND_SIZE(Offset, array, num)
84 #define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
85 inline const Type& operator[] (unsigned int i) const { \
86 if (HB_UNLIKELY (i >= num)) return Null##Type; \
87 if (HB_UNLIKELY (!array[i])) return Null##Type; \
88 return *(const Type *)((const char*)this + array[i]); \
91 #define DEFINE_RECORD_ARRAY_TYPE(Type, array, num) \
92 DEFINE_RECORD_ACCESSOR(Type, array, num) \
93 DEFINE_LEN_AND_SIZE(Record, array, num)
94 #define DEFINE_RECORD_ACCESSOR(Type, array, num) \
95 inline const Type& operator[] (unsigned int i) const { \
96 if (HB_UNLIKELY (i >= num)) return Null##Type; \
97 if (HB_UNLIKELY (!array[i].offset)) return Null##Type; \
98 return *(const Type *)((const char*)this + array[i].offset); \
100 inline const Tag& get_tag (unsigned int i) const { \
101 if (HB_UNLIKELY (i >= num)) return NullTag; \
102 return array[i].tag; \
104 /* TODO: implement find_tag() */
110 #define DEFINE_LIST_ACCESSOR(Type, name) \
111 inline const Type##List& get_##name##_list (void) const { \
112 if (HB_UNLIKELY (!name##List)) return Null##Type##List; \
113 return *(const Type##List *)((const char*)this + name##List); \
115 inline const Type& get_##name (unsigned int i) const { \
116 return get_##name##_list()[i]; \
123 /* makes class uninstantiable. should be used for union classes that don't
124 * contain any complete type */
125 #define DEFINE_NON_INSTANTIABLE(Type) \
126 private: inline Type() {} /* cannot be instantiated */ \
129 /* defines Null##Type as a safe nil instance of Type */
130 #define DEFINE_NULL_DATA(Type, size, data) \
131 static const unsigned char Null##Type##Data[size] = data; \
132 DEFINE_NULL_ALIAS (Type, Type)
133 #define DEFINE_NULL(Type, size) \
134 DEFINE_NULL_DATA(Type, size, "")
135 #define DEFINE_NULL_ASSERT_SIZE(Type, size) \
136 DEFINE_NULL_ASSERT_SIZE_DATA(Type, size, "")
137 #define DEFINE_NULL_ASSERT_SIZE_DATA(Type, size, data) \
138 ASSERT_SIZE (Type, size); \
139 DEFINE_NULL_DATA (Type, size, data)
140 #define DEFINE_NULL_ALIAS(NewType, OldType) \
141 static const NewType &Null##NewType = *(NewType *)Null##OldType##Data
143 /* get_for_data() is a static class method returning a reference to an
144 * instance of Type located at the input data location. It's just a
146 #define STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
147 static inline const Type& get_for_data (const char *data) { \
148 return *(const Type*)data; \
150 #define STATIC_DEFINE_GET_FOR_DATA(Type) \
151 STATIC_DEFINE_GET_FOR_DATA0(const, Type) \
152 STATIC_DEFINE_GET_FOR_DATA0( , Type)
155 #define DEFINE_ACCESSOR(Type, name, Name) \
156 inline const Type& name (void) const { \
157 if (HB_UNLIKELY (!Name)) return Null##Type; \
158 return *(const Type*)((const char*)this + Name); \
165 * The OpenType Font File
176 /* "The following data types are used in the OpenType font file.
177 * All OpenType fonts use Motorola-style byte ordering (Big Endian):" */
180 DEFINE_INT_TYPE_STRUCT (BYTE, u, 8); /* 8-bit unsigned integer. */
181 DEFINE_NULL_ASSERT_SIZE (BYTE, 1);
182 DEFINE_INT_TYPE_STRUCT (CHAR, , 8); /* 8-bit signed integer. */
183 DEFINE_NULL_ASSERT_SIZE (CHAR, 1);
184 DEFINE_INT_TYPE_STRUCT (USHORT, u, 16); /* 16-bit unsigned integer. */
185 DEFINE_NULL_ASSERT_SIZE (USHORT, 2);
186 DEFINE_INT_TYPE_STRUCT (SHORT, , 16); /* 16-bit signed integer. */
187 DEFINE_NULL_ASSERT_SIZE (SHORT, 2);
188 DEFINE_INT_TYPE_STRUCT (ULONG, u, 32); /* 32-bit unsigned integer. */
189 DEFINE_NULL_ASSERT_SIZE (ULONG, 4);
190 DEFINE_INT_TYPE_STRUCT (LONG, , 32); /* 32-bit signed integer. */
191 DEFINE_NULL_ASSERT_SIZE (LONG, 4);
193 /* Date represented in number of seconds since 12:00 midnight, January 1,
194 * 1904. The value is represented as a signed 64-bit integer. */
195 DEFINE_INT_TYPE_STRUCT (LONGDATETIME, , 64);
197 /* 32-bit signed fixed-point number (16.16) */
199 inline Fixed& operator = (int32_t v) { i = (int16_t) (v >> 16); f = (uint16_t) v; return *this; } \
200 inline operator int32_t(void) const { return (((int32_t) i) << 16) + (uint16_t) f; } \
201 inline bool operator== (Fixed o) const { return i == o.i && f == o.f; } \
203 inline operator double(void) const { return (uint32_t) this / 65536.; }
204 inline int16_t int_part (void) const { return i; }
205 inline uint16_t frac_part (void) const { return f; }
211 DEFINE_NULL_ASSERT_SIZE (Fixed, 4);
213 /* Smallest measurable distance in the em space. */
216 /* 16-bit signed integer (SHORT) that describes a quantity in FUnits. */
217 struct FWORD : SHORT {
219 DEFINE_NULL_ASSERT_SIZE (FWORD, 2);
221 /* 16-bit unsigned integer (USHORT) that describes a quantity in FUnits. */
222 struct UFWORD : USHORT {
224 DEFINE_NULL_ASSERT_SIZE (UFWORD, 2);
226 /* 16-bit signed fixed number with the low 14 bits of fraction (2.14). */
227 struct F2DOT14 : SHORT {
228 inline operator double() const { return (uint32_t) this / 16384.; }
230 DEFINE_NULL_ASSERT_SIZE (F2DOT14, 2);
232 /* Array of four uint8s (length = 32 bits) used to identify a script, language
233 * system, feature, or baseline */
235 inline Tag (void) { v[0] = v[1] = v[2] = v[3] = 0; }
236 inline Tag (uint32_t v) { (ULONG&)(*this) = v; }
237 inline Tag (const char *c) { v[0] = c[0]; v[1] = c[1]; v[2] = c[2]; v[3] = c[3]; }
238 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]; }
239 inline bool operator== (const char *c) const { return v[0]==c[0]&&v[1]==c[1]&&v[2]==c[2]&&v[3]==c[3]; }
240 inline bool operator== (uint32_t i) const { return i == (uint32_t) *this; }
241 inline operator uint32_t(void) const { return (v[0]<<24)+(v[1]<<16) +(v[2]<<8)+v[3]; }
242 /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */
243 inline operator const char* (void) const { return (const char *)this; }
244 inline operator char* (void) { return (char *)this; }
249 ASSERT_SIZE (Tag, 4);
250 DEFINE_NULL_DATA (Tag, 5, " ");
252 /* Glyph index number, same as uint16 (length = 16 bits) */
253 DEFINE_INT_TYPE_STRUCT (GlyphID, u, 16);
254 DEFINE_NULL_ASSERT_SIZE (GlyphID, 2);
256 /* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */
257 DEFINE_INT_TYPE_STRUCT (Offset, u, 16);
258 DEFINE_NULL_ASSERT_SIZE (Offset, 2);
261 struct CheckSum : ULONG {
262 static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length) {
264 ULONG *EndPtr = Table+((Length+3) & ~3) / sizeof(ULONG);
266 while (Table < EndPtr)
271 DEFINE_NULL_ASSERT_SIZE (CheckSum, 4);
278 struct USHORT_Version : USHORT {
280 DEFINE_NULL_ASSERT_SIZE (USHORT_Version, 2);
282 struct Fixed_Version : Fixed {
283 inline int16_t major (void) const { return this->int_part(); }
284 inline int16_t minor (void) const { return this->frac_part(); }
286 DEFINE_NULL_ASSERT_SIZE (Fixed_Version, 4);
290 * Organization of an OpenType Font
293 struct OpenTypeFontFile;
297 typedef struct TableDirectory {
299 friend struct OpenTypeFontFile;
301 inline const Tag& get_tag (void) const { return tag; }
302 inline unsigned long get_checksum (void) const { return checkSum; }
303 inline unsigned long get_offset (void) const { return offset; }
304 inline unsigned long get_length (void) const { return length; }
307 Tag tag; /* 4-byte identifier. */
308 CheckSum checkSum; /* CheckSum for this table. */
309 ULONG offset; /* Offset from beginning of TrueType font
311 ULONG length; /* Length of this table. */
313 DEFINE_NULL_ASSERT_SIZE (TableDirectory, 16);
315 typedef struct OffsetTable {
316 /* OpenTypeTables, in no particular order */
317 DEFINE_ARRAY_TYPE (TableDirectory, tableDir, numTables);
318 // TODO: Implement find_table
321 Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */
322 USHORT numTables; /* Number of tables. */
323 USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */
324 USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
325 USHORT rangeShift; /* NumTables x 16-searchRange. */
326 TableDirectory tableDir[]; /* TableDirectory entries. numTables items */
328 DEFINE_NULL_ASSERT_SIZE (OffsetTable, 12);
329 DEFINE_NULL_ALIAS (OpenTypeFontFace, OffsetTable);
332 * TrueType Collections
336 /* OpenTypeFontFaces, in no particular order */
337 DEFINE_OFFSET_ARRAY_TYPE (OffsetTable, offsetTable, numFonts);
340 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */
341 ULONG version; /* Version of the TTC Header (1.0 or 2.0),
342 * 0x00010000 or 0x00020000 */
343 ULONG numFonts; /* Number of fonts in TTC */
344 ULONG offsetTable[]; /* Array of offsets to the OffsetTable for each font
345 * from the beginning of the file */
347 DEFINE_NULL_ASSERT_SIZE (TTCHeader, 12);
354 struct OpenTypeFontFile {
355 DEFINE_NON_INSTANTIABLE(OpenTypeFontFile);
356 static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 );
357 static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O');
358 static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f');
360 STATIC_DEFINE_GET_FOR_DATA (OpenTypeFontFile);
362 /* This is how you get a table */
363 inline const char* get_table (const OpenTypeTable& table) const {
364 return ((const char*)this) + table.offset;
366 inline char* get_table (const OpenTypeTable& table) {
367 return ((char*)this) + table.offset;
369 inline const char* operator[] (const OpenTypeTable& table) const {
370 return ((const char*)this) + table.offset;
372 inline char* operator[] (const OpenTypeTable& table) {
373 return ((char*)this) + table.offset;
376 /* Array interface sans get_size() */
377 inline unsigned int get_len (void) const {
380 case TrueTypeTag: case CFFTag: return 1;
381 case TTCTag: return ((const TTCHeader&)*this).get_len();
384 inline const OpenTypeFontFace& operator[] (unsigned int i) const {
385 if (HB_UNLIKELY (i >= get_len ())) return NullOpenTypeFontFace;
387 default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this;
388 case TTCTag: return ((const TTCHeader&)*this)[i];
391 inline const Tag& get_tag (void) const { return tag; }
394 Tag tag; /* 4-byte identifier. */
396 DEFINE_NULL_ASSERT_SIZE (OpenTypeFontFile, 4);
402 * OpenType Layout Common Table Formats
407 * Script, ScriptList, LangSys, Feature, FeatureList, Lookup, LookupList
410 typedef struct Record {
411 Tag tag; /* 4-byte Tag identifier */
412 Offset offset; /* Offset from beginning of object holding
414 } ScriptRecord, LangSysRecord, FeatureRecord;
415 DEFINE_NULL_ASSERT_SIZE (Record, 6);
418 /* Feature indices, in no particular order */
419 DEFINE_ARRAY_TYPE (USHORT, featureIndex, featureCount);
421 /* Returns -1 if none */
422 inline int get_required_feature_index (void) const {
423 if (reqFeatureIndex == 0xffff)
425 return reqFeatureIndex;;
428 /* TODO implement find_feature */
431 Offset lookupOrder; /* = Null (reserved for an offset to a
432 * reordering table) */
433 USHORT reqFeatureIndex;/* Index of a feature required for this
434 * language system--if no required features
436 USHORT featureCount; /* Number of FeatureIndex values for this
437 * language system--excludes the required
439 USHORT featureIndex[]; /* Array of indices into the FeatureList--in
440 * arbitrary order. featureCount entires long */
442 DEFINE_NULL_ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF");
445 /* LangSys', in sorted alphabetical tag order */
446 DEFINE_RECORD_ARRAY_TYPE (LangSys, langSysRecord, langSysCount);
448 inline const bool has_default_language_system (void) const {
449 return defaultLangSys != 0;
451 inline const LangSys& get_default_language_system (void) const {
452 if (HB_UNLIKELY (!defaultLangSys))
454 return *(LangSys*)((const char*)this + defaultLangSys);
457 /* TODO implement find_language_system based on find_tag */
460 Offset defaultLangSys; /* Offset to DefaultLangSys table--from
461 * beginning of Script table--may be Null */
462 USHORT langSysCount; /* Number of LangSysRecords for this script--
463 * excluding the DefaultLangSys */
464 LangSysRecord langSysRecord[];/* Array of LangSysRecords--listed
465 * alphabetically by LangSysTag */
467 DEFINE_NULL_ASSERT_SIZE (Script, 4);
470 /* Scripts, in sorted alphabetical tag order */
471 DEFINE_RECORD_ARRAY_TYPE (Script, scriptRecord, scriptCount);
474 USHORT scriptCount; /* Number of ScriptRecords */
475 ScriptRecord scriptRecord[]; /* Array of ScriptRecords--listed alphabetically
478 DEFINE_NULL_ASSERT_SIZE (ScriptList, 2);
481 /* LookupList indices, in no particular order */
482 DEFINE_ARRAY_TYPE (USHORT, lookupIndex, lookupCount);
485 Offset featureParams; /* Offset to Feature Parameters table (if one
486 * has been defined for the feature), relative
487 * to the beginning of the Feature Table; = Null
489 USHORT lookupCount; /* Number of LookupList indices for this
491 USHORT lookupIndex[]; /* Array of LookupList indices for this
492 * feature--zero-based (first lookup is
493 * LookupListIndex = 0) */
495 DEFINE_NULL_ASSERT_SIZE (Feature, 4);
498 /* Feature indices, in sorted alphabetical tag order */
499 DEFINE_RECORD_ARRAY_TYPE (Feature, featureRecord, featureCount);
502 USHORT featureCount; /* Number of FeatureRecords in this table */
503 FeatureRecord featureRecord[];/* Array of FeatureRecords--zero-based (first
504 * feature has FeatureIndex = 0)--listed
505 * alphabetically by FeatureTag */
507 DEFINE_NULL_ASSERT_SIZE (FeatureList, 2);
509 struct LookupFlag : USHORT {
510 static const uint16_t RightToLeft = 0x0001u;
511 static const uint16_t IgnoreBaseGlyphs = 0x0002u;
512 static const uint16_t IgnoreLigatures = 0x0004u;
513 static const uint16_t IgnoreMarks = 0x0008u;
514 static const uint16_t Reserved = 0x00F0u;
515 static const uint16_t MarkAttachmentType = 0xFF00u;
517 DEFINE_NULL_ASSERT_SIZE (LookupFlag, 2);
519 struct LookupSubTable {
520 DEFINE_NON_INSTANTIABLE(LookupSubTable);
523 USHORT format; /* Subtable format. Different for GSUB and GPOS */
525 DEFINE_NULL_ASSERT_SIZE (LookupSubTable, 2);
529 /* SubTables, in the desired order */
530 DEFINE_OFFSET_ARRAY_TYPE (LookupSubTable, subTableOffset, subTableCount);
532 inline bool is_right_to_left (void) const { return lookupFlag & LookupFlag::RightToLeft; }
533 inline bool ignore_base_glyphs(void) const { return lookupFlag & LookupFlag::IgnoreBaseGlyphs; }
534 inline bool ignore_ligatures (void) const { return lookupFlag & LookupFlag::IgnoreLigatures; }
535 inline bool ignore_marks (void) const { return lookupFlag & LookupFlag::IgnoreMarks; }
536 inline bool get_mark_attachment_type (void) const { return lookupFlag & LookupFlag::MarkAttachmentType; }
538 inline uint16_t get_type (void) const { return lookupType; }
539 inline uint16_t get_flag (void) const { return lookupFlag; }
542 USHORT lookupType; /* Different enumerations for GSUB and GPOS */
543 USHORT lookupFlag; /* Lookup qualifiers */
544 USHORT subTableCount; /* Number of SubTables for this lookup */
545 Offset subTableOffset[];/* Array of offsets to SubTables-from
546 * beginning of Lookup table */
548 DEFINE_NULL_ASSERT_SIZE (Lookup, 6);
551 /* Lookup indices, in sorted alphabetical tag order */
552 DEFINE_OFFSET_ARRAY_TYPE (Lookup, lookupOffset, lookupCount);
555 USHORT lookupCount; /* Number of lookups in this table */
556 Offset lookupOffset[]; /* Array of offsets to Lookup tables--from
557 * beginning of LookupList--zero based (first
558 * lookup is Lookup index = 0) */
560 DEFINE_NULL_ASSERT_SIZE (LookupList, 2);
566 struct CoverageFormat1 {
567 /* GlyphIDs, in sorted numerical order */
568 DEFINE_ARRAY_TYPE (GlyphID, glyphArray, glyphCount);
570 inline int get_coverage (uint16_t glyph_id) const {
574 for (unsigned int i = 0; i < glyphCount; i++)
575 if (gid == glyphArray[i])
581 USHORT coverageFormat; /* Format identifier--format = 1 */
582 USHORT glyphCount; /* Number of glyphs in the GlyphArray */
583 GlyphID glyphArray[]; /* Array of GlyphIDs--in numerical order */
585 ASSERT_SIZE (CoverageFormat1, 4);
587 struct CoverageRangeRecord {
589 inline int get_coverage (uint16_t glyph_id) const {
590 if (glyph_id >= start && glyph_id <= end)
591 return startCoverageIndex + (glyph_id - start);
596 GlyphID start; /* First GlyphID in the range */
597 GlyphID end; /* Last GlyphID in the range */
598 USHORT startCoverageIndex; /* Coverage Index of first GlyphID in
601 DEFINE_NULL_ASSERT_SIZE_DATA (CoverageRangeRecord, 6, "\001");
603 struct CoverageFormat2 {
604 /* CoverageRangeRecords, in sorted numerical start order */
605 DEFINE_ARRAY_TYPE (CoverageRangeRecord, rangeRecord, rangeCount);
607 inline int get_coverage (uint16_t glyph_id) const {
609 for (unsigned int i = 0; i < rangeCount; i++) {
610 int coverage = rangeRecord[i].get_coverage (glyph_id);
618 USHORT coverageFormat; /* Format identifier--format = 2 */
619 USHORT rangeCount; /* Number of CoverageRangeRecords */
620 CoverageRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
621 * Start GlyphID. rangeCount entries
624 ASSERT_SIZE (CoverageFormat2, 4);
627 DEFINE_NON_INSTANTIABLE(Coverage);
629 inline unsigned int get_size (void) const {
630 switch (u.coverageFormat) {
631 case 1: return u.format1.get_size ();
632 case 2: return u.format2.get_size ();
633 default:return sizeof (u.coverageFormat);
637 /* Returns -1 if not covered. */
638 inline int get_coverage (uint16_t glyph_id) const {
639 switch (u.coverageFormat) {
640 case 1: return u.format1.get_coverage(glyph_id);
641 case 2: return u.format2.get_coverage(glyph_id);
648 USHORT coverageFormat; /* Format identifier */
649 CoverageFormat1 format1;
650 CoverageFormat2 format2;
653 DEFINE_NULL (Coverage, 2);
656 * Class Definition Table
659 struct ClassDefFormat1 {
660 /* GlyphIDs, in sorted numerical order */
661 DEFINE_ARRAY_TYPE (USHORT, classValueArray, glyphCount);
663 inline int get_class (uint16_t glyph_id) const {
664 if (glyph_id >= startGlyph && glyph_id < startGlyph + glyphCount)
665 return classValueArray[glyph_id - startGlyph];
670 USHORT classFormat; /* Format identifier--format = 1 */
671 GlyphID startGlyph; /* First GlyphID of the classValueArray */
672 USHORT glyphCount; /* Size of the classValueArray */
673 USHORT classValueArray[]; /* Array of Class Values--one per GlyphID */
675 ASSERT_SIZE (ClassDefFormat1, 6);
677 struct ClassRangeRecord {
679 inline int get_class (uint16_t glyph_id) const {
680 if (glyph_id >= start && glyph_id <= end)
686 GlyphID start; /* First GlyphID in the range */
687 GlyphID end; /* Last GlyphID in the range */
688 USHORT classValue; /* Applied to all glyphs in the range */
690 DEFINE_NULL_ASSERT_SIZE_DATA (ClassRangeRecord, 6, "\001");
692 struct ClassDefFormat2 {
693 /* ClassRangeRecords, in sorted numerical start order */
694 DEFINE_ARRAY_TYPE (ClassRangeRecord, rangeRecord, rangeCount);
696 inline int get_class (uint16_t glyph_id) const {
698 for (int i = 0; i < rangeCount; i++) {
699 int classValue = rangeRecord[i].get_class (glyph_id);
707 USHORT classFormat; /* Format identifier--format = 2 */
708 USHORT rangeCount; /* Number of Number of ClassRangeRecords */
709 ClassRangeRecord rangeRecord[]; /* Array of glyph ranges--ordered by
712 ASSERT_SIZE (ClassDefFormat2, 4);
715 DEFINE_NON_INSTANTIABLE(ClassDef);
717 inline unsigned int get_size (void) const {
718 switch (u.classFormat) {
719 case 1: return u.format1.get_size ();
720 case 2: return u.format2.get_size ();
721 default:return sizeof (u.classFormat);
725 /* Returns 0 if not found. */
726 inline int get_class (uint16_t glyph_id) const {
727 switch (u.classFormat) {
728 case 1: return u.format1.get_class(glyph_id);
729 case 2: return u.format2.get_class(glyph_id);
736 USHORT classFormat; /* Format identifier */
737 ClassDefFormat1 format1;
738 ClassDefFormat2 format2;
741 DEFINE_NULL (ClassDef, 2);
749 inline unsigned int get_size (void) const {
750 int count = endSize - startSize + 1;
751 if (count < 0) count = 0;
752 switch (deltaFormat) {
753 case 1: return sizeof (Device) + sizeof (USHORT) * ((count+7)/8);
754 case 2: return sizeof (Device) + sizeof (USHORT) * ((count+3)/4);
755 case 3: return sizeof (Device) + sizeof (USHORT) * ((count+1)/2);
756 default:return sizeof (Device);
760 inline int get_delta (int ppem_size) const {
761 if (ppem_size >= startSize && ppem_size <= endSize &&
762 deltaFormat >= 1 && deltaFormat <= 3) {
763 int s = ppem_size - startSize;
766 uint16_t byte = deltaValue[s >> (4 - f)];
767 uint16_t bits = byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f));
768 uint16_t mask = 0xFFFF >> (16 - (1 << f));
770 int delta = bits & mask;
772 if (delta >= ((mask + 1) >> 1))
781 USHORT startSize; /* Smallest size to correct--in ppem */
782 USHORT endSize; /* Largest size to correct--in ppem */
783 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 */
784 USHORT deltaValue[]; /* Array of compressed data */
786 DEFINE_NULL_ASSERT_SIZE (Device, 6);
792 typedef struct GSUBGPOSHeader {
793 static const hb_tag_t GSUBTag = HB_TAG ('G','S','U','B');
794 static const hb_tag_t GPOSTag = HB_TAG ('G','P','O','S');
796 STATIC_DEFINE_GET_FOR_DATA (GSUBGPOSHeader);
798 DEFINE_LIST_ACCESSOR(Script, script); /* get_script_list, get_script(i) */
799 DEFINE_LIST_ACCESSOR(Feature, feature);/* get_feature_list, get_feature(i) */
800 DEFINE_LIST_ACCESSOR(Lookup, lookup); /* get_lookup_list, get_lookup(i) */
802 /* TODO implement find_script */
805 Fixed_Version version; /* Version of the GSUB/GPOS table--initially set
807 Offset scriptList; /* Offset to ScriptList table--from beginning of
809 Offset featureList; /* Offset to FeatureList table--from beginning of
811 Offset lookupList; /* Offset to LookupList table--from beginning of
813 } GSUBHeader, GPOSHeader;
814 DEFINE_NULL_ASSERT_SIZE (GSUBGPOSHeader, 10);
815 DEFINE_NULL_ALIAS (GSUBHeader, GSUBGPOSHeader);
816 DEFINE_NULL_ALIAS (GPOSHeader, GSUBGPOSHeader);
818 #endif /* HB_OT_LAYOUT_OPEN_PRIVATE_H */