blob: 20b8bd762239c8e189e03e2edf939ccd88655ae9 [file] [log] [blame]
Elie Rouxf748e112017-02-18 19:54:33 +01001/*
2 * Copyright © 2016 Elie Roux <elie.roux@telecom-bretagne.eu>
Behdad Esfahbod7a70c202018-02-27 12:45:26 -08003 * Copyright © 2018 Google, Inc.
Elie Rouxf748e112017-02-18 19:54:33 +01004 *
5 * This is part of HarfBuzz, a text shaping library.
6 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
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 *
Behdad Esfahbod7a70c202018-02-27 12:45:26 -080025 * Google Author(s): Behdad Esfahbod
Elie Rouxf748e112017-02-18 19:54:33 +010026 */
27
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +033028#ifndef HB_OT_LAYOUT_BASE_TABLE_HH
29#define HB_OT_LAYOUT_BASE_TABLE_HH
Elie Rouxf748e112017-02-18 19:54:33 +010030
31#include "hb-open-type-private.hh"
32#include "hb-ot-layout-common-private.hh"
Elie Rouxf748e112017-02-18 19:54:33 +010033
34namespace OT {
35
Elie Roux39633152017-02-26 15:07:53 +010036#define NOT_INDEXED ((unsigned int) -1)
Elie Rouxd34e35b2017-02-25 20:41:05 +010037
Elie Rouxf748e112017-02-18 19:54:33 +010038/*
39 * BASE -- The BASE Table
40 */
41
Behdad Esfahbod7a70c202018-02-27 12:45:26 -080042struct BaseCoordFormat1
43{
44 inline int get_coord (void) const { return coordinate; }
Elie Rouxd34e35b2017-02-25 20:41:05 +010045
Elie Roux1d30c6d2017-02-25 16:19:35 +010046 inline bool sanitize (hb_sanitize_context_t *c) const
47 {
48 TRACE_SANITIZE (this);
49 return_trace (c->check_struct (this));
50 }
51
Elie Rouxf748e112017-02-18 19:54:33 +010052 protected:
Behdad Esfahbod7a70c202018-02-27 12:45:26 -080053 HBUINT16 format; /* Format identifier--format = 1 */
54 HBINT16 coordinate; /* X or Y value, in design units */
Elie Rouxf748e112017-02-18 19:54:33 +010055 public:
56 DEFINE_SIZE_STATIC (4);
57};
58
Behdad Esfahbod7a70c202018-02-27 12:45:26 -080059struct BaseCoordFormat2
60{
61 inline int get_coord (void) const
62 {
63 /* TODO */
64 return coordinate;
65 }
Elie Rouxd34e35b2017-02-25 20:41:05 +010066
Elie Roux1d30c6d2017-02-25 16:19:35 +010067 inline bool sanitize (hb_sanitize_context_t *c) const
68 {
69 TRACE_SANITIZE (this);
70 return_trace (c->check_struct (this));
71 }
72
Elie Rouxf748e112017-02-18 19:54:33 +010073 protected:
Behdad Esfahbod7a70c202018-02-27 12:45:26 -080074 HBUINT16 format; /* Format identifier--format = 2 */
75 HBINT16 coordinate; /* X or Y value, in design units */
76 GlyphID referenceGlyph; /* Glyph ID of control glyph */
77 HBUINT16 coordPoint; /* Index of contour point on the
78 * reference glyph */
Elie Rouxf748e112017-02-18 19:54:33 +010079 public:
80 DEFINE_SIZE_STATIC (8);
81};
82
Behdad Esfahbod7a70c202018-02-27 12:45:26 -080083struct BaseCoordFormat3
84{
85 inline int get_coord (void) const
86 {
87 /* TODO */
88 return coordinate;
89 }
Elie Rouxd34e35b2017-02-25 20:41:05 +010090
Elie Roux1d30c6d2017-02-25 16:19:35 +010091 inline bool sanitize (hb_sanitize_context_t *c) const
92 {
93 TRACE_SANITIZE (this);
94 return_trace (c->check_struct (this) && deviceTable.sanitize (c, this));
95 }
96
Elie Rouxf748e112017-02-18 19:54:33 +010097 protected:
Behdad Esfahbod7a70c202018-02-27 12:45:26 -080098 HBUINT16 format; /* Format identifier--format = 3 */
99 HBINT16 coordinate; /* X or Y value, in design units */
100 OffsetTo<Device> deviceTable; /* Offset to Device table for X or
101 * Y value, from beginning of
102 * BaseCoord table (may be NULL). */
Elie Rouxf748e112017-02-18 19:54:33 +0100103 public:
104 DEFINE_SIZE_STATIC (6);
105};
106
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800107struct BaseCoord
108{
109 inline int get_coord (void) const
110 {
111 switch (u.format) {
112 case 1: return u.format1.get_coord ();
113 case 2: return u.format2.get_coord ();
114 case 3: return u.format3.get_coord ();
115 default:return 0;
116 }
117 }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100118
Elie Roux1d30c6d2017-02-25 16:19:35 +0100119 inline bool sanitize (hb_sanitize_context_t *c) const
120 {
121 TRACE_SANITIZE (this);
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800122 if (!u.format.sanitize (c)) return_trace (false);
123 switch (u.format) {
Elie Roux1d30c6d2017-02-25 16:19:35 +0100124 case 1: return_trace (u.format1.sanitize (c));
125 case 2: return_trace (u.format2.sanitize (c));
126 case 3: return_trace (u.format3.sanitize (c));
Elie Roux39633152017-02-26 15:07:53 +0100127 default:return_trace (false);
Elie Roux1d30c6d2017-02-25 16:19:35 +0100128 }
129 }
130
Elie Rouxf748e112017-02-18 19:54:33 +0100131 protected:
132 union {
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800133 HBUINT16 format;
134 BaseCoordFormat1 format1;
135 BaseCoordFormat2 format2;
136 BaseCoordFormat3 format3;
Elie Rouxf748e112017-02-18 19:54:33 +0100137 } u;
Elie Rouxf748e112017-02-18 19:54:33 +0100138 public:
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800139 DEFINE_SIZE_UNION (2, format);
Elie Rouxf748e112017-02-18 19:54:33 +0100140};
141
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800142struct FeatMinMaxRecord
143{
144 inline int get_min_value (void) const
145 { return (this+minCoord).get_coord(); }
Elie Roux1d30c6d2017-02-25 16:19:35 +0100146
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800147 inline int get_max_value (void) const
148 { return (this+maxCoord).get_coord(); }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100149
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800150 inline const Tag &get_tag () const
151 { return tag; }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100152
Elie Roux1d30c6d2017-02-25 16:19:35 +0100153 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
154 {
155 TRACE_SANITIZE (this);
156 return_trace (c->check_struct (this) &&
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800157 minCoord.sanitize (c, base) &&
158 maxCoord.sanitize (c, base));
Elie Roux1d30c6d2017-02-25 16:19:35 +0100159 }
160
Elie Rouxf748e112017-02-18 19:54:33 +0100161 protected:
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800162 Tag tag; /* 4-byte feature identification tag--must
163 * match feature tag in FeatureList */
164 OffsetTo<BaseCoord> minCoord; /* Offset to BaseCoord table that defines
165 * the minimum extent value, from beginning
166 * of MinMax table (may be NULL) */
167 OffsetTo<BaseCoord> maxCoord; /* Offset to BaseCoord table that defines
168 * the maximum extent value, from beginning
169 * of MinMax table (may be NULL) */
Elie Rouxf748e112017-02-18 19:54:33 +0100170 public:
171 DEFINE_SIZE_STATIC (8);
172
173};
174
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800175struct MinMax
176{
Elie Roux39633152017-02-26 15:07:53 +0100177 inline unsigned int get_feature_tag_index (Tag featureTableTag) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100178 {
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800179 /* TODO bsearch */
180 unsigned int count = featMinMaxRecords.len;
181 for (unsigned int i = 0; i < count; i++)
182 {
183 Tag tag = featMinMaxRecords[i].get_tag();
184 int cmp = tag.cmp(featureTableTag);
Elie Roux39633152017-02-26 15:07:53 +0100185 if (cmp == 0) return i;
186 if (cmp > 0) return NOT_INDEXED;
Elie Rouxd34e35b2017-02-25 20:41:05 +0100187 }
Elie Roux39633152017-02-26 15:07:53 +0100188 return NOT_INDEXED;
Elie Rouxd34e35b2017-02-25 20:41:05 +0100189 }
190
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800191 inline int get_min_value (unsigned int featureTableTagIndex) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100192 {
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800193 if (featureTableTagIndex == NOT_INDEXED)
Elie Roux39633152017-02-26 15:07:53 +0100194 return (this+minCoord).get_coord();
Elie Roux39633152017-02-26 15:07:53 +0100195 return featMinMaxRecords[featureTableTagIndex].get_min_value();
196 }
197
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800198 inline int get_max_value (unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100199 {
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800200 if (featureTableTagIndex == NOT_INDEXED)
Elie Roux39633152017-02-26 15:07:53 +0100201 return (this+maxCoord).get_coord();
Elie Roux39633152017-02-26 15:07:53 +0100202 return featMinMaxRecords[featureTableTagIndex].get_max_value();
203 }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100204
Elie Roux1d30c6d2017-02-25 16:19:35 +0100205 inline bool sanitize (hb_sanitize_context_t *c) const
206 {
207 TRACE_SANITIZE (this);
208 return_trace (c->check_struct (this) &&
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800209 minCoord.sanitize (c, this) &&
210 maxCoord.sanitize (c, this) &&
211 featMinMaxRecords.sanitize (c, this));
Elie Roux1d30c6d2017-02-25 16:19:35 +0100212 }
213
Elie Rouxf748e112017-02-18 19:54:33 +0100214 protected:
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800215 OffsetTo<BaseCoord> minCoord; /* Offset to BaseCoord table that defines
216 * minimum extent value, from the beginning
217 * of MinMax table (may be NULL) */
218 OffsetTo<BaseCoord> maxCoord; /* Offset to BaseCoord table that defines
219 * maximum extent value, from the beginning
220 * of MinMax table (may be NULL) */
221 ArrayOf<FeatMinMaxRecord>
222 featMinMaxRecords; /* Array of FeatMinMaxRecords, in alphabetical
223 * order by featureTableTag */
Elie Rouxf748e112017-02-18 19:54:33 +0100224 public:
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800225 DEFINE_SIZE_ARRAY (6, featMinMaxRecords);
Elie Rouxf748e112017-02-18 19:54:33 +0100226};
227
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800228/* TODO... */
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800229struct BaseLangSysRecord
230{
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800231 inline const Tag& get_tag(void) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100232 { return baseLangSysTag; }
233
Elie Roux39633152017-02-26 15:07:53 +0100234 inline unsigned int get_feature_tag_index (Tag featureTableTag) const
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800235 { return (this+minMax).get_feature_tag_index(featureTableTag); }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100236
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800237 inline int get_min_value (unsigned int featureTableTagIndex) const
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800238 { return (this+minMax).get_min_value(featureTableTagIndex); }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100239
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800240 inline int get_max_value (unsigned int featureTableTagIndex) const
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800241 { return (this+minMax).get_max_value(featureTableTagIndex); }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100242
Elie Roux1d30c6d2017-02-25 16:19:35 +0100243 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
244 {
245 TRACE_SANITIZE (this);
246 return_trace (c->check_struct (this) &&
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800247 minMax.sanitize (c, base));
Elie Roux1d30c6d2017-02-25 16:19:35 +0100248 }
249
Elie Rouxf748e112017-02-18 19:54:33 +0100250 protected:
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800251 Tag baseLangSysTag;
252 OffsetTo<MinMax> minMax;
Elie Rouxf748e112017-02-18 19:54:33 +0100253 public:
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800254 DEFINE_SIZE_STATIC (6);
Elie Rouxf748e112017-02-18 19:54:33 +0100255
256};
257
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800258struct BaseValues
259{
260 inline unsigned int get_default_base_tag_index (void) const
Elie Roux39633152017-02-26 15:07:53 +0100261 { return defaultIndex; }
262
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800263 inline int get_base_coord (unsigned int baselineTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100264 {
Elie Roux39633152017-02-26 15:07:53 +0100265 return (this+baseCoords[baselineTagIndex]).get_coord();
266 }
267
Elie Roux1d30c6d2017-02-25 16:19:35 +0100268 inline bool sanitize (hb_sanitize_context_t *c) const
269 {
270 TRACE_SANITIZE (this);
271 return_trace (c->check_struct (this) &&
Elie Roux39633152017-02-26 15:07:53 +0100272 defaultIndex <= baseCoordCount &&
Elie Roux499b4be2017-02-25 16:48:22 +0100273 baseCoords.sanitize (c, this));
Elie Roux1d30c6d2017-02-25 16:19:35 +0100274 }
275
Elie Rouxf748e112017-02-18 19:54:33 +0100276 protected:
Behdad Esfahbod551fa2d2018-02-25 16:32:17 -0800277 Index defaultIndex;
278 HBUINT16 baseCoordCount;
279 OffsetArrayOf<BaseCoord> baseCoords;
Elie Rouxf748e112017-02-18 19:54:33 +0100280 public:
Elie Roux499b4be2017-02-25 16:48:22 +0100281 DEFINE_SIZE_ARRAY (6, baseCoords);
Elie Rouxf748e112017-02-18 19:54:33 +0100282
283};
284
Elie Roux499b4be2017-02-25 16:48:22 +0100285struct BaseScript {
Elie Roux1d30c6d2017-02-25 16:19:35 +0100286
Elie Roux39633152017-02-26 15:07:53 +0100287 inline unsigned int get_lang_tag_index (Tag baseLangSysTag) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100288 {
Elie Roux39633152017-02-26 15:07:53 +0100289 Tag tag;
290 int cmp;
291 for (unsigned int i = 0; i < baseLangSysCount; i++) {
292 tag = baseLangSysRecords[i].get_tag();
293 // taking advantage of alphabetical order
294 cmp = tag.cmp(baseLangSysTag);
295 if (cmp == 0) return i;
296 if (cmp > 0) return NOT_INDEXED;
Elie Rouxd34e35b2017-02-25 20:41:05 +0100297 }
Elie Roux39633152017-02-26 15:07:53 +0100298 return NOT_INDEXED;
Elie Rouxd34e35b2017-02-25 20:41:05 +0100299 }
300
Elie Roux39633152017-02-26 15:07:53 +0100301 inline unsigned int get_feature_tag_index (unsigned int baseLangSysIndex, Tag featureTableTag) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100302 {
Elie Roux39633152017-02-26 15:07:53 +0100303 if (baseLangSysIndex == NOT_INDEXED) {
304 if (unlikely(defaultMinMax)) return NOT_INDEXED;
305 return (this+defaultMinMax).get_feature_tag_index(featureTableTag);
Elie Rouxd34e35b2017-02-25 20:41:05 +0100306 }
Elie Roux39633152017-02-26 15:07:53 +0100307 if (unlikely(baseLangSysIndex >= baseLangSysCount)) return NOT_INDEXED;
308 return baseLangSysRecords[baseLangSysIndex].get_feature_tag_index(featureTableTag);
Elie Rouxd34e35b2017-02-25 20:41:05 +0100309 }
310
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800311 inline int get_min_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100312 {
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800313 if (baseLangSysIndex == NOT_INDEXED)
Elie Roux39633152017-02-26 15:07:53 +0100314 return (this+defaultMinMax).get_min_value(featureTableTagIndex);
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +0330315 return baseLangSysRecords[baseLangSysIndex].get_max_value(featureTableTagIndex);
Elie Rouxd34e35b2017-02-25 20:41:05 +0100316 }
317
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800318 inline int get_max_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100319 {
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800320 if (baseLangSysIndex == NOT_INDEXED)
Elie Roux39633152017-02-26 15:07:53 +0100321 return (this+defaultMinMax).get_min_value(featureTableTagIndex);
Elie Roux39633152017-02-26 15:07:53 +0100322 return baseLangSysRecords[baseLangSysIndex].get_max_value(featureTableTagIndex);
Elie Rouxd34e35b2017-02-25 20:41:05 +0100323 }
324
Elie Roux39633152017-02-26 15:07:53 +0100325 inline unsigned int get_default_base_tag_index (void) const
326 { return (this+baseValues).get_default_base_tag_index(); }
327
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800328 inline int get_base_coord (unsigned int baselineTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100329 { return (this+baseValues).get_base_coord(baselineTagIndex); }
330
Elie Roux1d30c6d2017-02-25 16:19:35 +0100331 inline bool sanitize (hb_sanitize_context_t *c) const
332 {
333 TRACE_SANITIZE (this);
334 return_trace (c->check_struct (this) &&
335 baseValues.sanitize (c, this) &&
336 defaultMinMax.sanitize (c, this) &&
Elie Roux499b4be2017-02-25 16:48:22 +0100337 baseLangSysRecords.sanitize (c, this));
Elie Roux1d30c6d2017-02-25 16:19:35 +0100338 }
339
Elie Rouxf748e112017-02-18 19:54:33 +0100340 protected:
Elie Rouxbd155672017-02-25 17:08:01 +0100341 OffsetTo<BaseValues> baseValues;
342 OffsetTo<MinMax> defaultMinMax;
Behdad Esfahbod05699fd2018-02-24 12:01:54 -0800343 HBUINT16 baseLangSysCount;
Elie Rouxbd155672017-02-25 17:08:01 +0100344 ArrayOf<BaseLangSysRecord> baseLangSysRecords;
Elie Rouxf748e112017-02-18 19:54:33 +0100345
346 public:
Elie Roux499b4be2017-02-25 16:48:22 +0100347 DEFINE_SIZE_ARRAY (8, baseLangSysRecords);
Elie Rouxf748e112017-02-18 19:54:33 +0100348};
349
350
351struct BaseScriptRecord {
352
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800353 inline const Tag& get_tag (void) const
Elie Roux39633152017-02-26 15:07:53 +0100354 { return baseScriptTag; }
355
356 inline unsigned int get_default_base_tag_index(void) const
357 { return (this+baseScript).get_default_base_tag_index(); }
358
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800359 inline int get_base_coord(unsigned int baselineTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100360 { return (this+baseScript).get_base_coord(baselineTagIndex); }
361
362 inline unsigned int get_lang_tag_index (Tag baseLangSysTag) const
363 { return (this+baseScript).get_lang_tag_index(baseLangSysTag); }
364
365 inline unsigned int get_feature_tag_index (unsigned int baseLangSysIndex, Tag featureTableTag) const
366 { return (this+baseScript).get_feature_tag_index(baseLangSysIndex, featureTableTag); }
367
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800368 inline int get_max_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100369 { return (this+baseScript).get_max_value(baseLangSysIndex, featureTableTagIndex); }
370
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800371 inline int get_min_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100372 { return (this+baseScript).get_min_value(baseLangSysIndex, featureTableTagIndex); }
Elie Rouxd34e35b2017-02-25 20:41:05 +0100373
Elie Roux1d30c6d2017-02-25 16:19:35 +0100374 inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
375 {
376 TRACE_SANITIZE (this);
377 return_trace (c->check_struct (this) &&
Elie Roux39633152017-02-26 15:07:53 +0100378 baseScript != Null(OffsetTo<BaseScript>) &&
Elie Roux1d30c6d2017-02-25 16:19:35 +0100379 baseScript.sanitize (c, base));
380 }
381
Elie Rouxf748e112017-02-18 19:54:33 +0100382 protected:
Elie Rouxbd155672017-02-25 17:08:01 +0100383 Tag baseScriptTag;
384 OffsetTo<BaseScript> baseScript;
Elie Rouxf748e112017-02-18 19:54:33 +0100385
386 public:
Elie Rouxf131f002017-02-19 10:12:22 +0100387 DEFINE_SIZE_STATIC (6);
Elie Rouxf748e112017-02-18 19:54:33 +0100388};
389
390struct BaseScriptList {
391
Elie Roux39633152017-02-26 15:07:53 +0100392 inline unsigned int get_base_script_index (Tag baseScriptTag) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100393 {
394 for (unsigned int i = 0; i < baseScriptCount; i++)
395 if (baseScriptRecords[i].get_tag() == baseScriptTag)
Elie Roux39633152017-02-26 15:07:53 +0100396 return i;
397 return NOT_INDEXED;
Elie Rouxd34e35b2017-02-25 20:41:05 +0100398 }
399
Elie Roux39633152017-02-26 15:07:53 +0100400 inline unsigned int get_default_base_tag_index (unsigned int baseScriptIndex) const
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +0330401 {
Elie Roux39633152017-02-26 15:07:53 +0100402 if (unlikely(baseScriptIndex >= baseScriptCount)) return NOT_INDEXED;
403 return baseScriptRecords[baseScriptIndex].get_default_base_tag_index();
404 }
405
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800406 inline int get_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100407 {
Elie Roux39633152017-02-26 15:07:53 +0100408 return baseScriptRecords[baseScriptIndex].get_base_coord(baselineTagIndex);
409 }
410
411 inline unsigned int get_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const
412 {
413 if (unlikely(baseScriptIndex >= baseScriptCount)) return NOT_INDEXED;
414 return baseScriptRecords[baseScriptIndex].get_lang_tag_index(baseLangSysTag);
415 }
416
417 inline unsigned int get_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const
418 {
419 if (unlikely(baseScriptIndex >= baseScriptCount)) return NOT_INDEXED;
420 return baseScriptRecords[baseScriptIndex].get_feature_tag_index(baseLangSysIndex, featureTableTag);
421 }
422
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800423 inline int get_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100424 {
Elie Roux39633152017-02-26 15:07:53 +0100425 return baseScriptRecords[baseScriptIndex].get_max_value(baseLangSysIndex, featureTableTagIndex);
426 }
427
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800428 inline int get_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100429 {
Elie Roux39633152017-02-26 15:07:53 +0100430 return baseScriptRecords[baseScriptIndex].get_min_value(baseLangSysIndex, featureTableTagIndex);
Elie Rouxd34e35b2017-02-25 20:41:05 +0100431 }
432
Elie Roux1d30c6d2017-02-25 16:19:35 +0100433 inline bool sanitize (hb_sanitize_context_t *c) const
434 {
435 TRACE_SANITIZE (this);
436 return_trace (c->check_struct (this) &&
Elie Roux499b4be2017-02-25 16:48:22 +0100437 baseScriptRecords.sanitize (c, this));
Elie Roux1d30c6d2017-02-25 16:19:35 +0100438 }
439
Elie Rouxf748e112017-02-18 19:54:33 +0100440 protected:
Behdad Esfahbod05699fd2018-02-24 12:01:54 -0800441 HBUINT16 baseScriptCount;
Elie Roux499b4be2017-02-25 16:48:22 +0100442 ArrayOf<BaseScriptRecord> baseScriptRecords;
Elie Rouxf748e112017-02-18 19:54:33 +0100443
444 public:
Elie Roux499b4be2017-02-25 16:48:22 +0100445 DEFINE_SIZE_ARRAY (4, baseScriptRecords);
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +0330446
Elie Rouxf748e112017-02-18 19:54:33 +0100447};
448
Elie Rouxd34e35b2017-02-25 20:41:05 +0100449struct BaseTagList
450{
Elie Rouxf748e112017-02-18 19:54:33 +0100451
Elie Roux39633152017-02-26 15:07:53 +0100452 inline unsigned int get_tag_index(Tag baselineTag) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100453 {
454 for (unsigned int i = 0; i < baseTagCount; i++)
Elie Roux39633152017-02-26 15:07:53 +0100455 if (baselineTags[i] == baselineTag)
456 return i;
457 return NOT_INDEXED;
Elie Rouxd34e35b2017-02-25 20:41:05 +0100458 }
459
460 inline bool sanitize (hb_sanitize_context_t *c) const
Elie Roux1d30c6d2017-02-25 16:19:35 +0100461 {
462 TRACE_SANITIZE (this);
463 return_trace (c->check_struct (this));
464 }
465
Elie Rouxf748e112017-02-18 19:54:33 +0100466 protected:
Behdad Esfahbod05699fd2018-02-24 12:01:54 -0800467 HBUINT16 baseTagCount;
Elie Roux39633152017-02-26 15:07:53 +0100468 SortedArrayOf<Tag> baselineTags;
Elie Rouxf748e112017-02-18 19:54:33 +0100469
470 public:
Elie Roux499b4be2017-02-25 16:48:22 +0100471 DEFINE_SIZE_ARRAY (4, baselineTags);
Elie Rouxf748e112017-02-18 19:54:33 +0100472};
473
Elie Rouxa0bdd542017-02-25 16:34:58 +0100474struct Axis
Elie Rouxf748e112017-02-18 19:54:33 +0100475{
476
Elie Roux39633152017-02-26 15:07:53 +0100477 inline unsigned int get_base_tag_index(Tag baselineTag) const
Elie Rouxd34e35b2017-02-25 20:41:05 +0100478 {
Elie Roux39633152017-02-26 15:07:53 +0100479 if (unlikely(baseTagList == Null(OffsetTo<BaseTagList>))) return NOT_INDEXED;
480 return (this+baseTagList).get_tag_index(baselineTag);
481 }
482
483 inline unsigned int get_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +0330484 {
Elie Roux39633152017-02-26 15:07:53 +0100485 if (unlikely(baseScriptList == Null(OffsetTo<BaseScriptList>))) return NOT_INDEXED;
486 return (this+baseScriptList).get_default_base_tag_index(baseScriptIndex);
487 }
488
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800489 inline int get_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100490 {
Elie Roux39633152017-02-26 15:07:53 +0100491 return (this+baseScriptList).get_base_coord(baseScriptIndex, baselineTagIndex);
492 }
493
494 inline unsigned int get_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const
495 {
496 if (unlikely(baseScriptList == Null(OffsetTo<BaseScriptList>))) return NOT_INDEXED;
497 return (this+baseScriptList).get_lang_tag_index(baseScriptIndex, baseLangSysTag);
498 }
499
500 inline unsigned int get_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const
501 {
502 if (unlikely(baseScriptList == Null(OffsetTo<BaseScriptList>))) return NOT_INDEXED;
503 return (this+baseScriptList).get_feature_tag_index(baseScriptIndex, baseLangSysIndex, featureTableTag);
504 }
505
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800506 inline int get_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100507 {
Elie Roux39633152017-02-26 15:07:53 +0100508 return (this+baseScriptList).get_max_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex);
509 }
510
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800511 inline int get_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100512 {
Elie Roux39633152017-02-26 15:07:53 +0100513 return (this+baseScriptList).get_min_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex);
Elie Rouxd34e35b2017-02-25 20:41:05 +0100514 }
515
Elie Roux1d30c6d2017-02-25 16:19:35 +0100516 inline bool sanitize (hb_sanitize_context_t *c) const
517 {
518 TRACE_SANITIZE (this);
519 return_trace (c->check_struct (this) &&
520 baseTagList.sanitize (c, this) &&
521 baseScriptList.sanitize (c, this));
522 }
523
Elie Rouxf748e112017-02-18 19:54:33 +0100524 protected:
Elie Rouxbd155672017-02-25 17:08:01 +0100525 OffsetTo<BaseTagList> baseTagList;
526 OffsetTo<BaseScriptList> baseScriptList;
Elie Rouxf748e112017-02-18 19:54:33 +0100527
528 public:
529 DEFINE_SIZE_STATIC (4);
530};
531
Behdad Esfahbodd7633d02018-02-27 12:50:57 -0800532struct BASE
Elie Rouxf131f002017-02-19 10:12:22 +0100533{
Behdad Esfahbodd7633d02018-02-27 12:50:57 -0800534 static const hb_tag_t tableTag = HB_OT_TAG_BASE;
Elie Rouxf131f002017-02-19 10:12:22 +0100535
Elie Roux39633152017-02-26 15:07:53 +0100536 inline bool has_vert_axis(void)
537 { return vertAxis != Null(OffsetTo<Axis>); }
538
539 inline bool has_horiz_axis(void)
540 { return horizAxis != Null(OffsetTo<Axis>); }
541
542 // horizontal axis base coords:
543
544 inline unsigned int get_horiz_base_tag_index(Tag baselineTag) const
545 {
546 if (unlikely(horizAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
547 return (this+horizAxis).get_base_tag_index(baselineTag);
548 }
549
550 inline unsigned int get_horiz_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +0330551 {
Elie Roux39633152017-02-26 15:07:53 +0100552 if (unlikely(horizAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
553 return (this+horizAxis).get_default_base_tag_index_for_script_index(baseScriptIndex);
554 }
555
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800556 inline int get_horiz_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100557 {
Elie Roux39633152017-02-26 15:07:53 +0100558 return (this+horizAxis).get_base_coord(baseScriptIndex, baselineTagIndex);
559 }
560
561 // vertical axis base coords:
562
563 inline unsigned int get_vert_base_tag_index(Tag baselineTag) const
564 {
565 if (unlikely(vertAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
566 return (this+vertAxis).get_base_tag_index(baselineTag);
567 }
568
569 inline unsigned int get_vert_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +0330570 {
Elie Roux39633152017-02-26 15:07:53 +0100571 if (unlikely(vertAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
572 return (this+vertAxis).get_default_base_tag_index_for_script_index(baseScriptIndex);
573 }
574
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800575 inline int get_vert_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100576 {
Elie Roux39633152017-02-26 15:07:53 +0100577 return (this+vertAxis).get_base_coord(baseScriptIndex, baselineTagIndex);
578 }
579
580 // horizontal axis min/max coords:
581
582 inline unsigned int get_horiz_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const
583 {
584 if (unlikely(horizAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
585 return (this+horizAxis).get_lang_tag_index (baseScriptIndex, baseLangSysTag);
586 }
587
588 inline unsigned int get_horiz_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const
589 {
590 if (unlikely(horizAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
591 return (this+horizAxis).get_feature_tag_index (baseScriptIndex, baseLangSysIndex, featureTableTag);
592 }
593
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800594 inline int get_horiz_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100595 {
Elie Roux39633152017-02-26 15:07:53 +0100596 return (this+horizAxis).get_max_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex);
597 }
598
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800599 inline int get_horiz_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100600 {
Elie Roux39633152017-02-26 15:07:53 +0100601 return (this+horizAxis).get_min_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex);
602 }
603
604 // vertical axis min/max coords:
605
606 inline unsigned int get_vert_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const
607 {
608 if (unlikely(vertAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
609 return (this+vertAxis).get_lang_tag_index (baseScriptIndex, baseLangSysTag);
610 }
611
612 inline unsigned int get_vert_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const
613 {
614 if (unlikely(vertAxis == Null(OffsetTo<Axis>))) return NOT_INDEXED;
615 return (this+vertAxis).get_feature_tag_index (baseScriptIndex, baseLangSysIndex, featureTableTag);
616 }
617
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800618 inline int get_vert_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100619 {
Elie Roux39633152017-02-26 15:07:53 +0100620 return (this+vertAxis).get_max_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex);
621 }
622
Behdad Esfahbod7a70c202018-02-27 12:45:26 -0800623 inline int get_vert_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const
Elie Roux39633152017-02-26 15:07:53 +0100624 {
Elie Roux39633152017-02-26 15:07:53 +0100625 return (this+vertAxis).get_min_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex);
626 }
627
Elie Roux1d30c6d2017-02-25 16:19:35 +0100628 inline bool sanitize (hb_sanitize_context_t *c) const
629 {
630 TRACE_SANITIZE (this);
631 return_trace (c->check_struct (this) &&
Behdad Esfahbodd7633d02018-02-27 12:50:57 -0800632 likely (version.major == 1) &&
633 horizAxis.sanitize (c, this) &&
634 vertAxis.sanitize (c, this) &&
635 (version.to_int () < 0x00010001u || varStore.sanitize (c, this)));
Elie Roux1d30c6d2017-02-25 16:19:35 +0100636 }
637
Elie Rouxf131f002017-02-19 10:12:22 +0100638 protected:
Elie Rouxbd155672017-02-25 17:08:01 +0100639 FixedVersion<> version;
640 OffsetTo<Axis> horizAxis;
641 OffsetTo<Axis> vertAxis;
Behdad Esfahbodd7633d02018-02-27 12:50:57 -0800642 LOffsetTo<VariationStore>
643 varStore; /* Offset to the table of Item Variation
644 * Store--from beginning of BASE
645 * header (may be NULL). Introduced
646 * in version 0x00010001. */
Elie Rouxf131f002017-02-19 10:12:22 +0100647 public:
Behdad Esfahbodd7633d02018-02-27 12:50:57 -0800648 DEFINE_SIZE_MIN (8);
Elie Rouxf748e112017-02-18 19:54:33 +0100649};
650
651
652} /* namespace OT */
653
654
Ebrahim Byagowi0ad8c662018-02-26 12:45:08 +0330655#endif /* HB_OT_LAYOUT_BASE_TABLE_HH */