/work/workdir/UnpackedTarball/harfbuzz/src/hb-aat-layout-feat-table.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2018 Ebrahim Byagowi |
3 | | * |
4 | | * This is part of HarfBuzz, a text shaping library. |
5 | | * |
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. |
11 | | * |
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 |
16 | | * DAMAGE. |
17 | | * |
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. |
23 | | */ |
24 | | |
25 | | #ifndef HB_AAT_LAYOUT_FEAT_TABLE_HH |
26 | | #define HB_AAT_LAYOUT_FEAT_TABLE_HH |
27 | | |
28 | | #include "hb-aat-layout-common.hh" |
29 | | |
30 | | /* |
31 | | * feat -- Feature Name |
32 | | * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6feat.html |
33 | | */ |
34 | | #define HB_AAT_TAG_feat HB_TAG('f','e','a','t') |
35 | | |
36 | | |
37 | | namespace AAT { |
38 | | |
39 | | |
40 | | struct SettingName |
41 | | { |
42 | | friend struct FeatureName; |
43 | | |
44 | | int cmp (hb_aat_layout_feature_selector_t key) const |
45 | 0 | { return (int) key - (int) setting; } |
46 | | |
47 | | hb_aat_layout_feature_selector_t get_selector () const |
48 | 0 | { return (hb_aat_layout_feature_selector_t) (unsigned) setting; } |
49 | | |
50 | | hb_aat_layout_feature_selector_info_t get_info (hb_aat_layout_feature_selector_t default_selector) const |
51 | 0 | { |
52 | 0 | return { |
53 | 0 | nameIndex, |
54 | 0 | (hb_aat_layout_feature_selector_t) (unsigned int) setting, |
55 | 0 | default_selector == HB_AAT_LAYOUT_FEATURE_SELECTOR_INVALID |
56 | 0 | ? (hb_aat_layout_feature_selector_t) (setting + 1) |
57 | 0 | : default_selector, |
58 | 0 | 0 |
59 | 0 | }; |
60 | 0 | } |
61 | | |
62 | | bool sanitize (hb_sanitize_context_t *c) const |
63 | 0 | { |
64 | 0 | TRACE_SANITIZE (this); |
65 | 0 | return_trace (c->check_struct (this)); |
66 | 0 | } |
67 | | |
68 | | protected: |
69 | | HBUINT16 setting; /* The setting. */ |
70 | | NameID nameIndex; /* The name table index for the setting's name. */ |
71 | | public: |
72 | | DEFINE_SIZE_STATIC (4); |
73 | | }; |
74 | | DECLARE_NULL_NAMESPACE_BYTES (AAT, SettingName); |
75 | | |
76 | | struct feat; |
77 | | |
78 | | struct FeatureName |
79 | | { |
80 | | int cmp (hb_aat_layout_feature_type_t key) const |
81 | 0 | { return (int) key - (int) feature; } |
82 | | |
83 | | enum { |
84 | | Exclusive = 0x8000, /* If set, the feature settings are mutually exclusive. */ |
85 | | NotDefault = 0x4000, /* If clear, then the setting with an index of 0 in |
86 | | * the setting name array for this feature should |
87 | | * be taken as the default for the feature |
88 | | * (if one is required). If set, then bits 0-15 of this |
89 | | * featureFlags field contain the index of the setting |
90 | | * which is to be taken as the default. */ |
91 | | IndexMask = 0x00FF /* If bits 30 and 31 are set, then these sixteen bits |
92 | | * indicate the index of the setting in the setting name |
93 | | * array for this feature which should be taken |
94 | | * as the default. */ |
95 | | }; |
96 | | |
97 | | unsigned int get_selector_infos (unsigned int start_offset, |
98 | | unsigned int *selectors_count, /* IN/OUT. May be NULL. */ |
99 | | hb_aat_layout_feature_selector_info_t *selectors, /* OUT. May be NULL. */ |
100 | | unsigned int *pdefault_index, /* OUT. May be NULL. */ |
101 | | const void *base) const |
102 | 0 | { |
103 | 0 | hb_array_t< const SettingName> settings_table = (base+settingTableZ).as_array (nSettings); |
104 | |
|
105 | 0 | static_assert (Index::NOT_FOUND_INDEX == HB_AAT_LAYOUT_NO_SELECTOR_INDEX, ""); |
106 | |
|
107 | 0 | hb_aat_layout_feature_selector_t default_selector = HB_AAT_LAYOUT_FEATURE_SELECTOR_INVALID; |
108 | 0 | unsigned int default_index = Index::NOT_FOUND_INDEX; |
109 | 0 | if (featureFlags & Exclusive) |
110 | 0 | { |
111 | 0 | default_index = (featureFlags & NotDefault) ? featureFlags & IndexMask : 0; |
112 | 0 | default_selector = settings_table[default_index].get_selector (); |
113 | 0 | } |
114 | 0 | if (pdefault_index) |
115 | 0 | *pdefault_index = default_index; |
116 | |
|
117 | 0 | if (selectors_count) |
118 | 0 | { |
119 | 0 | + settings_table.sub_array (start_offset, selectors_count) |
120 | 0 | | hb_map ([=] (const SettingName& setting) { return setting.get_info (default_selector); }) |
121 | 0 | | hb_sink (hb_array (selectors, *selectors_count)) |
122 | 0 | ; |
123 | 0 | } |
124 | 0 | return settings_table.length; |
125 | 0 | } |
126 | | |
127 | | hb_aat_layout_feature_type_t get_feature_type () const |
128 | 0 | { return (hb_aat_layout_feature_type_t) (unsigned int) feature; } |
129 | | |
130 | 0 | hb_ot_name_id_t get_feature_name_id () const { return nameIndex; } |
131 | | |
132 | 0 | bool is_exclusive () const { return featureFlags & Exclusive; } |
133 | | |
134 | | /* A FeatureName with no settings is meaningless */ |
135 | 0 | bool has_data () const { return nSettings; } |
136 | | |
137 | | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
138 | 0 | { |
139 | 0 | TRACE_SANITIZE (this); |
140 | 0 | return_trace (likely (c->check_struct (this) && |
141 | 0 | hb_barrier () && |
142 | 0 | (base+settingTableZ).sanitize (c, nSettings))); |
143 | 0 | } |
144 | | |
145 | | protected: |
146 | | HBUINT16 feature; /* Feature type. */ |
147 | | HBUINT16 nSettings; /* The number of records in the setting name array. */ |
148 | | NNOffset32To<UnsizedArrayOf<SettingName>> |
149 | | settingTableZ; /* Offset in bytes from the beginning of this table to |
150 | | * this feature's setting name array. The actual type of |
151 | | * record this offset refers to will depend on the |
152 | | * exclusivity value, as described below. */ |
153 | | HBUINT16 featureFlags; /* Single-bit flags associated with the feature type. */ |
154 | | HBINT16 nameIndex; /* The name table index for the feature's name. |
155 | | * This index has values greater than 255 and |
156 | | * less than 32768. */ |
157 | | public: |
158 | | DEFINE_SIZE_STATIC (12); |
159 | | }; |
160 | | |
161 | | struct feat |
162 | | { |
163 | | static constexpr hb_tag_t tableTag = HB_AAT_TAG_feat; |
164 | | |
165 | 0 | bool has_data () const { return version.to_int (); } |
166 | | |
167 | | unsigned int get_feature_types (unsigned int start_offset, |
168 | | unsigned int *count, |
169 | | hb_aat_layout_feature_type_t *features) const |
170 | 0 | { |
171 | 0 | if (count) |
172 | 0 | { |
173 | 0 | + namesZ.as_array (featureNameCount).sub_array (start_offset, count) |
174 | 0 | | hb_map (&FeatureName::get_feature_type) |
175 | 0 | | hb_sink (hb_array (features, *count)) |
176 | 0 | ; |
177 | 0 | } |
178 | 0 | return featureNameCount; |
179 | 0 | } |
180 | | |
181 | | bool exposes_feature (hb_aat_layout_feature_type_t feature_type) const |
182 | 0 | { return get_feature (feature_type).has_data (); } |
183 | | |
184 | | const FeatureName& get_feature (hb_aat_layout_feature_type_t feature_type) const |
185 | 0 | { return namesZ.bsearch (featureNameCount, feature_type); } |
186 | | |
187 | | hb_ot_name_id_t get_feature_name_id (hb_aat_layout_feature_type_t feature) const |
188 | 0 | { return get_feature (feature).get_feature_name_id (); } |
189 | | |
190 | | unsigned int get_selector_infos (hb_aat_layout_feature_type_t feature_type, |
191 | | unsigned int start_offset, |
192 | | unsigned int *selectors_count, /* IN/OUT. May be NULL. */ |
193 | | hb_aat_layout_feature_selector_info_t *selectors, /* OUT. May be NULL. */ |
194 | | unsigned int *default_index /* OUT. May be NULL. */) const |
195 | 0 | { |
196 | 0 | return get_feature (feature_type).get_selector_infos (start_offset, selectors_count, selectors, |
197 | 0 | default_index, this); |
198 | 0 | } |
199 | | |
200 | | bool sanitize (hb_sanitize_context_t *c) const |
201 | 0 | { |
202 | 0 | TRACE_SANITIZE (this); |
203 | 0 | return_trace (likely (c->check_struct (this) && |
204 | 0 | hb_barrier () && |
205 | 0 | version.major == 1 && |
206 | 0 | namesZ.sanitize (c, featureNameCount, this))); |
207 | 0 | } |
208 | | |
209 | | protected: |
210 | | FixedVersion<>version; /* Version number of the feature name table |
211 | | * (0x00010000 for the current version). */ |
212 | | HBUINT16 featureNameCount; |
213 | | /* The number of entries in the feature name array. */ |
214 | | HBUINT16 reserved1; /* Reserved (set to zero). */ |
215 | | HBUINT32 reserved2; /* Reserved (set to zero). */ |
216 | | SortedUnsizedArrayOf<FeatureName> |
217 | | namesZ; /* The feature name array. */ |
218 | | public: |
219 | | DEFINE_SIZE_ARRAY (12, namesZ); |
220 | | }; |
221 | | |
222 | | } /* namespace AAT */ |
223 | | |
224 | | #endif /* HB_AAT_LAYOUT_FEAT_TABLE_HH */ |