2 * Copyright © 2018 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping 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.
25 #ifndef HB_OT_STAT_TABLE_HH
26 #define HB_OT_STAT_TABLE_HH
28 #include "hb-open-type.hh"
29 #include "hb-ot-layout-common.hh"
32 * STAT -- Style Attributes
33 * https://docs.microsoft.com/en-us/typography/opentype/spec/stat
35 #define HB_OT_TAG_STAT HB_TAG('S','T','A','T')
42 OLDER_SIBLING_FONT_ATTRIBUTE = 0x0001, /* If set, this axis value table
43 * provides axis value information
44 * that is applicable to other fonts
45 * within the same font family. This
46 * is used if the other fonts were
47 * released earlier and did not include
48 * information about values for some axis.
49 * If newer versions of the other
50 * fonts include the information
51 * themselves and are present,
52 * then this record is ignored. */
53 ELIDABLE_AXIS_VALUE_NAME = 0x0002 /* If set, it indicates that the axis
54 * value represents the “normal” value
55 * for the axis and may be omitted when
56 * composing name strings. */
57 // Reserved = 0xFFFC /* Reserved for future use — set to zero. */
60 struct AxisValueFormat1
62 hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
64 bool sanitize (hb_sanitize_context_t *c) const
66 TRACE_SANITIZE (this);
67 return_trace (likely (c->check_struct (this)));
71 HBUINT16 format; /* Format identifier — set to 1. */
72 HBUINT16 axisIndex; /* Zero-base index into the axis record array
73 * identifying the axis of design variation
74 * to which the axis value record applies.
75 * Must be less than designAxisCount. */
76 HBUINT16 flags; /* Flags — see below for details. */
77 NameID valueNameID; /* The name ID for entries in the 'name' table
78 * that provide a display string for this
80 HBFixed value; /* A numeric value for this attribute value. */
82 DEFINE_SIZE_STATIC (12);
85 struct AxisValueFormat2
87 hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
89 bool sanitize (hb_sanitize_context_t *c) const
91 TRACE_SANITIZE (this);
92 return_trace (likely (c->check_struct (this)));
96 HBUINT16 format; /* Format identifier — set to 2. */
97 HBUINT16 axisIndex; /* Zero-base index into the axis record array
98 * identifying the axis of design variation
99 * to which the axis value record applies.
100 * Must be less than designAxisCount. */
101 HBUINT16 flags; /* Flags — see below for details. */
102 NameID valueNameID; /* The name ID for entries in the 'name' table
103 * that provide a display string for this
104 * attribute value. */
105 HBFixed nominalValue; /* A numeric value for this attribute value. */
106 HBFixed rangeMinValue; /* The minimum value for a range associated
107 * with the specified name ID. */
108 HBFixed rangeMaxValue; /* The maximum value for a range associated
109 * with the specified name ID. */
111 DEFINE_SIZE_STATIC (20);
114 struct AxisValueFormat3
116 hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
118 bool sanitize (hb_sanitize_context_t *c) const
120 TRACE_SANITIZE (this);
121 return_trace (likely (c->check_struct (this)));
125 HBUINT16 format; /* Format identifier — set to 3. */
126 HBUINT16 axisIndex; /* Zero-base index into the axis record array
127 * identifying the axis of design variation
128 * to which the axis value record applies.
129 * Must be less than designAxisCount. */
130 HBUINT16 flags; /* Flags — see below for details. */
131 NameID valueNameID; /* The name ID for entries in the 'name' table
132 * that provide a display string for this
133 * attribute value. */
134 HBFixed value; /* A numeric value for this attribute value. */
135 HBFixed linkedValue; /* The numeric value for a style-linked mapping
136 * from this value. */
138 DEFINE_SIZE_STATIC (16);
141 struct AxisValueRecord
143 bool sanitize (hb_sanitize_context_t *c) const
145 TRACE_SANITIZE (this);
146 return_trace (likely (c->check_struct (this)));
150 HBUINT16 axisIndex; /* Zero-base index into the axis record array
151 * identifying the axis to which this value
152 * applies. Must be less than designAxisCount. */
153 HBFixed value; /* A numeric value for this attribute value. */
155 DEFINE_SIZE_STATIC (6);
158 struct AxisValueFormat4
160 hb_ot_name_id_t get_value_name_id () const { return valueNameID; }
162 bool sanitize (hb_sanitize_context_t *c) const
164 TRACE_SANITIZE (this);
165 return_trace (likely (c->check_struct (this)));
169 HBUINT16 format; /* Format identifier — set to 4. */
170 HBUINT16 axisCount; /* The total number of axes contributing to
171 * this axis-values combination. */
172 HBUINT16 flags; /* Flags — see below for details. */
173 NameID valueNameID; /* The name ID for entries in the 'name' table
174 * that provide a display string for this
175 * attribute value. */
176 UnsizedArrayOf<AxisValueRecord>
177 axisValues; /* Array of AxisValue records that provide the
178 * combination of axis values, one for each
179 * contributing axis. */
181 DEFINE_SIZE_ARRAY (8, axisValues);
186 hb_ot_name_id_t get_value_name_id () const
190 case 1: return u.format1.get_value_name_id ();
191 case 2: return u.format2.get_value_name_id ();
192 case 3: return u.format3.get_value_name_id ();
193 case 4: return u.format4.get_value_name_id ();
194 default:return HB_OT_NAME_ID_INVALID;
198 bool sanitize (hb_sanitize_context_t *c) const
200 TRACE_SANITIZE (this);
201 if (unlikely (!c->check_struct (this)))
202 return_trace (false);
206 case 1: return_trace (u.format1.sanitize (c));
207 case 2: return_trace (u.format2.sanitize (c));
208 case 3: return_trace (u.format3.sanitize (c));
209 case 4: return_trace (u.format4.sanitize (c));
210 default:return_trace (true);
218 AxisValueFormat1 format1;
219 AxisValueFormat2 format2;
220 AxisValueFormat3 format3;
221 AxisValueFormat4 format4;
224 DEFINE_SIZE_UNION (2, format);
227 struct StatAxisRecord
229 hb_ot_name_id_t get_name_id () const { return nameID; }
231 bool sanitize (hb_sanitize_context_t *c) const
233 TRACE_SANITIZE (this);
234 return_trace (likely (c->check_struct (this)));
238 Tag tag; /* A tag identifying the axis of design variation. */
239 NameID nameID; /* The name ID for entries in the 'name' table that
240 * provide a display string for this axis. */
241 HBUINT16 ordering; /* A value that applications can use to determine
242 * primary sorting of face names, or for ordering
243 * of descriptors when composing family or face names. */
245 DEFINE_SIZE_STATIC (8);
250 static constexpr hb_tag_t tableTag = HB_OT_TAG_STAT;
252 bool has_data () const { return version.to_int (); }
254 unsigned get_design_axis_count () const { return designAxisCount; }
256 hb_ot_name_id_t get_axis_record_name_id (unsigned axis_record_index) const
258 if (unlikely (axis_record_index >= designAxisCount)) return HB_OT_NAME_ID_INVALID;
259 const StatAxisRecord &axis_record = get_design_axes ()[axis_record_index];
260 return axis_record.get_name_id ();
263 unsigned get_axis_value_count () const { return axisValueCount; }
265 hb_ot_name_id_t get_axis_value_name_id (unsigned axis_value_index) const
267 if (unlikely (axis_value_index >= axisValueCount)) return HB_OT_NAME_ID_INVALID;
268 const AxisValue &axis_value = (this + get_axis_value_offsets ()[axis_value_index]);
269 return axis_value.get_value_name_id ();
272 void collect_name_ids (hb_set_t *nameids_to_retain) const
274 if (!has_data ()) return;
277 | hb_map (&StatAxisRecord::get_name_id)
278 | hb_sink (nameids_to_retain)
281 + get_axis_value_offsets ()
282 | hb_map (hb_add (&(this + offsetToAxisValueOffsets)))
283 | hb_map (&AxisValue::get_value_name_id)
284 | hb_sink (nameids_to_retain)
288 bool sanitize (hb_sanitize_context_t *c) const
290 TRACE_SANITIZE (this);
291 return_trace (likely (c->check_struct (this) &&
292 version.major == 1 &&
294 designAxesOffset.sanitize (c, this, designAxisCount) &&
295 offsetToAxisValueOffsets.sanitize (c, this, axisValueCount, &(this+offsetToAxisValueOffsets))));
299 hb_array_t<const StatAxisRecord> const get_design_axes () const
300 { return (this+designAxesOffset).as_array (designAxisCount); }
302 hb_array_t<const OffsetTo<AxisValue>> const get_axis_value_offsets () const
303 { return (this+offsetToAxisValueOffsets).as_array (axisValueCount); }
307 FixedVersion<>version; /* Version of the stat table
308 * initially set to 0x00010002u */
309 HBUINT16 designAxisSize; /* The size in bytes of each axis record. */
310 HBUINT16 designAxisCount;/* The number of design axis records. In a
311 * font with an 'fvar' table, this value must be
312 * greater than or equal to the axisCount value
313 * in the 'fvar' table. In all fonts, must
314 * be greater than zero if axisValueCount
315 * is greater than zero. */
316 LNNOffsetTo<UnsizedArrayOf<StatAxisRecord>>
318 /* Offset in bytes from the beginning of
319 * the STAT table to the start of the design
320 * axes array. If designAxisCount is zero,
321 * set to zero; if designAxisCount is greater
322 * than zero, must be greater than zero. */
323 HBUINT16 axisValueCount; /* The number of axis value tables. */
324 LNNOffsetTo<UnsizedArrayOf<OffsetTo<AxisValue>>>
325 offsetToAxisValueOffsets;
326 /* Offset in bytes from the beginning of
327 * the STAT table to the start of the design
328 * axes value offsets array. If axisValueCount
329 * is zero, set to zero; if axisValueCount is
330 * greater than zero, must be greater than zero. */
331 NameID elidedFallbackNameID;
332 /* Name ID used as fallback when projection of
333 * names into a particular font model produces
334 * a subfamily name containing only elidable
337 DEFINE_SIZE_STATIC (20);
344 #endif /* HB_OT_STAT_TABLE_HH */