2 * Copyright (C) 2007,2008,2009 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_COMMON_PRIVATE_HH
28 #define HB_OT_LAYOUT_COMMON_PRIVATE_HH
30 #include "hb-ot-layout-private.h"
32 #include "hb-open-types-private.hh"
37 * OpenType Layout Common Table Formats
43 * Script, ScriptList, LangSys, Feature, FeatureList, Lookup, LookupList
46 template <typename Type>
49 Tag tag; /* 4-byte Tag identifier */
51 offset; /* Offset from beginning of object holding
55 template <typename Type>
56 struct RecordListOf : ArrayOf<Record<Type> >
58 inline const Type& operator [] (unsigned int i) const
60 if (HB_UNLIKELY (i >= this->len)) return Null(Type);
61 return this+this->array[i].offset;
63 inline const Tag& get_tag (unsigned int i) const
65 if (HB_UNLIKELY (i >= this->len)) return Null(Tag);
66 return this->array[i].tag;
72 typedef Record<Script> ScriptRecord;
73 ASSERT_SIZE (ScriptRecord, 6);
75 typedef Record<LangSys> LangSysRecord;
76 ASSERT_SIZE (LangSysRecord, 6);
78 typedef Record<Feature> FeatureRecord;
79 ASSERT_SIZE (FeatureRecord, 6);
84 inline const unsigned int get_feature_index (unsigned int i) const { return featureIndex[i]; }
85 inline unsigned int get_feature_count (void) const { return featureIndex.len; }
87 inline bool has_required_feature (void) const { return reqFeatureIndex != 0xffff; }
88 inline int get_required_feature_index (void) const
90 if (reqFeatureIndex == 0xffff)
92 return reqFeatureIndex;;
95 Offset lookupOrder; /* = Null (reserved for an offset to a
96 * reordering table) */
97 USHORT reqFeatureIndex;/* Index of a feature required for this
98 * language system--if no required features
101 featureIndex; /* Array of indices into the FeatureList */
103 ASSERT_SIZE_DATA (LangSys, 6, "\0\0\xFF\xFF");
108 inline const LangSys& get_lang_sys (unsigned int i) const
110 if (i == NO_INDEX) return get_default_lang_sys ();
111 return this+langSys[i].offset;
113 inline unsigned int get_lang_sys_count (void) const { return langSys.len; }
114 inline const Tag& get_lang_sys_tag (unsigned int i) const { return langSys[i].tag; }
116 // LONGTERMTODO bsearch
117 DEFINE_TAG_FIND_INTERFACE (LangSys, lang_sys); /* find_lang_sys_index (), get_lang_sys_by_tag (tag) */
119 inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; }
120 inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; }
124 defaultLangSys; /* Offset to DefaultLangSys table--from
125 * beginning of Script table--may be Null */
126 ArrayOf<LangSysRecord>
127 langSys; /* Array of LangSysRecords--listed
128 * alphabetically by LangSysTag */
130 ASSERT_SIZE (Script, 4);
132 typedef RecordListOf<Script> ScriptList;
133 ASSERT_SIZE (ScriptList, 2);
138 inline const unsigned int get_lookup_index (unsigned int i) const { return lookupIndex[i]; }
139 inline unsigned int get_lookup_count (void) const { return lookupIndex.len; }
141 /* TODO: implement get_feature_parameters() */
142 /* TODO: implement FeatureSize and other special features? */
143 Offset featureParams; /* Offset to Feature Parameters table (if one
144 * has been defined for the feature), relative
145 * to the beginning of the Feature Table; = Null
148 lookupIndex; /* Array of LookupList indices */
150 ASSERT_SIZE (Feature, 4);
152 typedef RecordListOf<Feature> FeatureList;
153 ASSERT_SIZE (FeatureList, 2);
156 struct LookupFlag : USHORT
159 RightToLeft = 0x0001u,
160 IgnoreBaseGlyphs = 0x0002u,
161 IgnoreLigatures = 0x0004u,
162 IgnoreMarks = 0x0008u,
163 UseMarkFilteringSet = 0x0010u,
165 MarkAttachmentType = 0xFF00u,
168 ASSERT_SIZE (LookupFlag, 2);
170 struct LookupSubTable
173 USHORT format; /* Subtable format. Different for GSUB and GPOS */
175 ASSERT_SIZE (LookupSubTable, 2);
179 inline const LookupSubTable& get_subtable (unsigned int i) const { return this+subTable[i]; }
180 inline unsigned int get_subtable_count (void) const { return subTable.len; }
182 inline unsigned int get_type (void) const { return lookupType; }
183 inline unsigned int get_flag (void) const
185 unsigned int flag = lookupFlag;
186 if (HB_UNLIKELY (flag & LookupFlag::UseMarkFilteringSet))
188 const USHORT &markFilteringSet = *(const USHORT*)
189 ((const char *) &subTable + subTable.get_size ());
190 flag += (markFilteringSet << 16);
195 USHORT lookupType; /* Different enumerations for GSUB and GPOS */
196 USHORT lookupFlag; /* Lookup qualifiers */
197 OffsetArrayOf<LookupSubTable>
198 subTable; /* Array of SubTables */
199 USHORT markFilteringSetX[0]; /* Index (base 0) into GDEF mark glyph sets
200 * structure. This field is only present if bit
201 * UseMarkFilteringSet of lookup flags is set. */
203 ASSERT_SIZE (Lookup, 6);
205 template <typename Type>
206 struct OffsetListOf : OffsetArrayOf<Type>
208 inline const Type& operator [] (unsigned int i) const
210 if (HB_UNLIKELY (i >= this->len)) return Null(Type);
211 return this+this->array[i];
215 typedef OffsetListOf<Lookup> LookupList;
216 ASSERT_SIZE (LookupList, 2);
223 struct CoverageFormat1
225 friend struct Coverage;
228 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
230 if (HB_UNLIKELY (glyph_id > 0xFFFF))
235 unsigned int num_glyphs = glyphArray.len;
236 for (unsigned int i = 0; i < num_glyphs; i++)
237 if (gid == glyphArray[i])
242 inline bool sanitize (SANITIZE_ARG_DEF) {
243 return SANITIZE (glyphArray);
247 USHORT coverageFormat; /* Format identifier--format = 1 */
249 glyphArray; /* Array of GlyphIDs--in numerical order */
251 ASSERT_SIZE (CoverageFormat1, 4);
253 struct CoverageRangeRecord
255 friend struct CoverageFormat2;
258 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
260 if (glyph_id >= start && glyph_id <= end)
261 return (unsigned int) startCoverageIndex + (glyph_id - start);
265 inline bool sanitize (SANITIZE_ARG_DEF) {
266 return SANITIZE_SELF ();
270 GlyphID start; /* First GlyphID in the range */
271 GlyphID end; /* Last GlyphID in the range */
272 USHORT startCoverageIndex; /* Coverage Index of first GlyphID in
275 ASSERT_SIZE_DATA (CoverageRangeRecord, 6, "\000\001");
277 struct CoverageFormat2
279 friend struct Coverage;
282 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
285 unsigned int count = rangeRecord.len;
286 for (unsigned int i = 0; i < count; i++)
288 unsigned int coverage = rangeRecord[i].get_coverage (glyph_id);
289 if (coverage != NOT_COVERED)
295 inline bool sanitize (SANITIZE_ARG_DEF) {
296 return SANITIZE (rangeRecord);
300 USHORT coverageFormat; /* Format identifier--format = 2 */
301 ArrayOf<CoverageRangeRecord>
302 rangeRecord; /* Array of glyph ranges--ordered by
303 * Start GlyphID. rangeCount entries
306 ASSERT_SIZE (CoverageFormat2, 4);
310 inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_coverage (glyph_id); }
312 unsigned int get_coverage (hb_codepoint_t glyph_id) const
315 case 1: return u.format1->get_coverage(glyph_id);
316 case 2: return u.format2->get_coverage(glyph_id);
317 default:return NOT_COVERED;
321 inline bool sanitize (SANITIZE_ARG_DEF) {
322 if (!SANITIZE (u.format)) return false;
324 case 1: return u.format1->sanitize (SANITIZE_ARG);
325 case 2: return u.format2->sanitize (SANITIZE_ARG);
332 USHORT format; /* Format identifier */
333 CoverageFormat1 format1[];
334 CoverageFormat2 format2[];
337 ASSERT_SIZE (Coverage, 2);
341 * Class Definition Table
344 struct ClassDefFormat1
346 friend struct ClassDef;
349 inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
351 if ((unsigned int) (glyph_id - startGlyph) < classValue.len)
352 return classValue[glyph_id - startGlyph];
356 inline bool sanitize (SANITIZE_ARG_DEF) {
357 return SANITIZE_SELF () && SANITIZE (classValue);
360 USHORT classFormat; /* Format identifier--format = 1 */
361 GlyphID startGlyph; /* First GlyphID of the classValueArray */
363 classValue; /* Array of Class Values--one per GlyphID */
365 ASSERT_SIZE (ClassDefFormat1, 6);
367 struct ClassRangeRecord
369 friend struct ClassDefFormat2;
372 inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
374 if (glyph_id >= start && glyph_id <= end)
379 inline bool sanitize (SANITIZE_ARG_DEF) {
380 return SANITIZE_SELF ();
384 GlyphID start; /* First GlyphID in the range */
385 GlyphID end; /* Last GlyphID in the range */
386 USHORT classValue; /* Applied to all glyphs in the range */
388 ASSERT_SIZE_DATA (ClassRangeRecord, 6, "\000\001");
390 struct ClassDefFormat2
392 friend struct ClassDef;
395 inline hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
398 unsigned int count = rangeRecord.len;
399 for (unsigned int i = 0; i < count; i++)
401 int classValue = rangeRecord[i].get_class (glyph_id);
408 inline bool sanitize (SANITIZE_ARG_DEF) {
409 return SANITIZE (rangeRecord);
412 USHORT classFormat; /* Format identifier--format = 2 */
413 ArrayOf<ClassRangeRecord>
414 rangeRecord; /* Array of glyph ranges--ordered by
417 ASSERT_SIZE (ClassDefFormat2, 4);
421 inline unsigned int operator() (hb_codepoint_t glyph_id) const { return get_class (glyph_id); }
423 hb_ot_layout_class_t get_class (hb_codepoint_t glyph_id) const
426 case 1: return u.format1->get_class(glyph_id);
427 case 2: return u.format2->get_class(glyph_id);
432 inline bool sanitize (SANITIZE_ARG_DEF) {
433 if (!SANITIZE (u.format)) return false;
435 case 1: return u.format1->sanitize (SANITIZE_ARG);
436 case 2: return u.format2->sanitize (SANITIZE_ARG);
443 USHORT format; /* Format identifier */
444 ClassDefFormat1 format1[];
445 ClassDefFormat2 format2[];
448 ASSERT_SIZE (ClassDef, 2);
457 int get_delta (unsigned int ppem_size) const
459 unsigned int f = deltaFormat;
460 if (HB_UNLIKELY (f < 1 || f > 3))
463 if (ppem_size < startSize || ppem_size > endSize)
466 unsigned int s = ppem_size - startSize;
468 unsigned int byte = deltaValue[s >> (4 - f)];
469 unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f)));
470 unsigned int mask = (0xFFFF >> (16 - (1 << f)));
472 int delta = bits & mask;
474 if (delta >= ((mask + 1) >> 1))
480 inline int operator() (unsigned int ppem_size) const { return get_delta (ppem_size); }
483 USHORT startSize; /* Smallest size to correct--in ppem */
484 USHORT endSize; /* Largest size to correct--in ppem */
485 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 */
486 USHORT deltaValue[]; /* Array of compressed data */
488 ASSERT_SIZE (Device, 6);
491 #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */