2 * Copyright © 2017 Google, Inc.
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.
24 * Google Author(s): Behdad Esfahbod
27 #ifndef HB_OT_VAR_AVAR_TABLE_HH
28 #define HB_OT_VAR_AVAR_TABLE_HH
30 #include "hb-open-type-private.hh"
37 inline bool sanitize (hb_sanitize_context_t *c) const
39 TRACE_SANITIZE (this);
40 return_trace (c->check_struct (this));
44 F2DOT14 fromCoord; /* A normalized coordinate value obtained using
45 * default normalization. */
46 F2DOT14 toCoord; /* The modified, normalized coordinate value. */
49 DEFINE_SIZE_STATIC (4);
52 struct SegmentMaps : ArrayOf<AxisValueMap>
54 inline int map (int value) const
56 /* The following special-cases are not part of OpenType, which requires
57 * that at least -1, 0, and +1 must be mapped. But we include these as
58 * part of a better error recovery scheme. */
63 if (value <= array[0].fromCoord)
64 return value - array[0].fromCoord + array[0].toCoord;
67 unsigned int count = len;
68 for (i = 1; i < count && value > array[i].fromCoord; i++)
71 if (value >= array[i].fromCoord)
72 return value - array[i].fromCoord + array[i].toCoord;
74 if (unlikely (array[i-1].fromCoord == array[i].fromCoord))
75 return array[i-1].toCoord;
77 int denom = array[i].fromCoord - array[i-1].fromCoord;
78 return array[i-1].toCoord +
79 (array[i].toCoord - array[i-1].toCoord) *
80 (value - array[i-1].fromCoord + denom/2) / denom;
83 DEFINE_SIZE_ARRAY (2, array);
87 * avar — Axis Variations Table
90 #define HB_OT_TAG_avar HB_TAG('a','v','a','r')
94 static const hb_tag_t tableTag = HB_OT_TAG_avar;
96 inline bool sanitize (hb_sanitize_context_t *c) const
98 TRACE_SANITIZE (this);
99 if (unlikely (!(version.sanitize (c) &&
100 version.major == 1 &&
101 c->check_struct (this))))
102 return_trace (false);
104 const SegmentMaps *map = &axisSegmentMapsZ;
105 unsigned int count = axisCount;
106 for (unsigned int i = 0; i < count; i++)
108 if (unlikely (!map->sanitize (c)))
109 return_trace (false);
110 map = &StructAfter<SegmentMaps> (*map);
116 inline void map_coords (int *coords, unsigned int coords_length) const
118 unsigned int count = MIN<unsigned int> (coords_length, axisCount);
120 const SegmentMaps *map = &axisSegmentMapsZ;
121 for (unsigned int i = 0; i < count; i++)
123 coords[i] = map->map (coords[i]);
124 map = &StructAfter<SegmentMaps> (*map);
129 FixedVersion<>version; /* Version of the avar table
130 * initially set to 0x00010000u */
131 USHORT reserved; /* This field is permanently reserved. Set to 0. */
132 USHORT axisCount; /* The number of variation axes in the font. This
133 * must be the same number as axisCount in the
135 SegmentMaps axisSegmentMapsZ;
144 #endif /* HB_OT_VAR_AVAR_TABLE_HH */