/src/harfbuzz/src/hb-ot-kern-table.hh
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2017 Google, Inc. |
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 | | * Google Author(s): Behdad Esfahbod |
25 | | */ |
26 | | |
27 | | #ifndef HB_OT_KERN_TABLE_HH |
28 | | #define HB_OT_KERN_TABLE_HH |
29 | | |
30 | | #include "hb-aat-layout-common.hh" |
31 | | #include "hb-aat-layout-kerx-table.hh" |
32 | | |
33 | | |
34 | | /* |
35 | | * kern -- Kerning |
36 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/kern |
37 | | * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6kern.html |
38 | | */ |
39 | | #define HB_OT_TAG_kern HB_TAG('k','e','r','n') |
40 | | |
41 | | |
42 | | namespace OT { |
43 | | |
44 | | |
45 | | template <typename KernSubTableHeader> |
46 | | struct KernSubTableFormat3 |
47 | | { |
48 | | int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const |
49 | 0 | { |
50 | 0 | hb_array_t<const FWORD> kernValue = kernValueZ.as_array (kernValueCount); |
51 | 0 | hb_array_t<const HBUINT8> leftClass = StructAfter<const UnsizedArrayOf<HBUINT8>> (kernValue).as_array (glyphCount); |
52 | 0 | hb_array_t<const HBUINT8> rightClass = StructAfter<const UnsizedArrayOf<HBUINT8>> (leftClass).as_array (glyphCount); |
53 | 0 | hb_array_t<const HBUINT8> kernIndex = StructAfter<const UnsizedArrayOf<HBUINT8>> (rightClass).as_array (leftClassCount * rightClassCount); |
54 | |
|
55 | 0 | unsigned int leftC = leftClass[left]; |
56 | 0 | unsigned int rightC = rightClass[right]; |
57 | 0 | if (unlikely (leftC >= leftClassCount || rightC >= rightClassCount)) |
58 | 0 | return 0; |
59 | 0 | unsigned int i = leftC * rightClassCount + rightC; |
60 | 0 | return kernValue[kernIndex[i]]; |
61 | 0 | } Unexecuted instantiation: OT::KernSubTableFormat3<OT::KernOTSubTableHeader>::get_kerning(unsigned int, unsigned int) const Unexecuted instantiation: OT::KernSubTableFormat3<OT::KernAATSubTableHeader>::get_kerning(unsigned int, unsigned int) const |
62 | | |
63 | | bool apply (AAT::hb_aat_apply_context_t *c) const |
64 | 0 | { |
65 | 0 | TRACE_APPLY (this); |
66 | |
|
67 | 0 | if (!c->plan->requested_kerning) |
68 | 0 | return false; |
69 | | |
70 | 0 | if (header.coverage & header.Backwards) |
71 | 0 | return false; |
72 | | |
73 | 0 | hb_kern_machine_t<KernSubTableFormat3> machine (*this, header.coverage & header.CrossStream); |
74 | 0 | machine.kern (c->font, c->buffer, c->plan->kern_mask); |
75 | |
|
76 | 0 | return_trace (true); |
77 | 0 | } Unexecuted instantiation: OT::KernSubTableFormat3<OT::KernOTSubTableHeader>::apply(AAT::hb_aat_apply_context_t*) const Unexecuted instantiation: OT::KernSubTableFormat3<OT::KernAATSubTableHeader>::apply(AAT::hb_aat_apply_context_t*) const |
78 | | |
79 | | bool sanitize (hb_sanitize_context_t *c) const |
80 | 0 | { |
81 | 0 | TRACE_SANITIZE (this); |
82 | 0 | return_trace (c->check_struct (this) && |
83 | 0 | hb_barrier () && |
84 | 0 | c->check_range (kernValueZ, |
85 | 0 | kernValueCount * sizeof (FWORD) + |
86 | 0 | glyphCount * 2 + |
87 | 0 | leftClassCount * rightClassCount)); |
88 | 0 | } Unexecuted instantiation: OT::KernSubTableFormat3<OT::KernOTSubTableHeader>::sanitize(hb_sanitize_context_t*) const Unexecuted instantiation: OT::KernSubTableFormat3<OT::KernAATSubTableHeader>::sanitize(hb_sanitize_context_t*) const |
89 | | |
90 | | template <typename set_t> |
91 | | void collect_glyphs (set_t &left_set, set_t &right_set, bool &second_set_gates, unsigned num_glyphs) const |
92 | 0 | { |
93 | 0 | second_set_gates = false; |
94 | 0 | if (likely (glyphCount)) |
95 | 0 | { |
96 | 0 | left_set.add_range (0, num_glyphs - 1); |
97 | 0 | right_set.add_range (0, num_glyphs - 1); |
98 | 0 | } |
99 | 0 | } Unexecuted instantiation: void OT::KernSubTableFormat3<OT::KernOTSubTableHeader>::collect_glyphs<hb_bit_set_t>(hb_bit_set_t&, hb_bit_set_t&, bool&, unsigned int) const Unexecuted instantiation: void OT::KernSubTableFormat3<OT::KernAATSubTableHeader>::collect_glyphs<hb_bit_set_t>(hb_bit_set_t&, hb_bit_set_t&, bool&, unsigned int) const |
100 | | |
101 | | protected: |
102 | | KernSubTableHeader |
103 | | header; |
104 | | HBUINT16 glyphCount; /* The number of glyphs in this font. */ |
105 | | HBUINT8 kernValueCount; /* The number of kerning values. */ |
106 | | HBUINT8 leftClassCount; /* The number of left-hand classes. */ |
107 | | HBUINT8 rightClassCount;/* The number of right-hand classes. */ |
108 | | HBUINT8 flags; /* Set to zero (reserved for future use). */ |
109 | | UnsizedArrayOf<FWORD> |
110 | | kernValueZ; /* The kerning values. |
111 | | * Length kernValueCount. */ |
112 | | #if 0 |
113 | | UnsizedArrayOf<HBUINT8> |
114 | | leftClass; /* The left-hand classes. |
115 | | * Length glyphCount. */ |
116 | | UnsizedArrayOf<HBUINT8> |
117 | | rightClass; /* The right-hand classes. |
118 | | * Length glyphCount. */ |
119 | | UnsizedArrayOf<HBUINT8>kernIndex; |
120 | | /* The indices into the kernValue array. |
121 | | * Length leftClassCount * rightClassCount */ |
122 | | #endif |
123 | | public: |
124 | | DEFINE_SIZE_ARRAY (KernSubTableHeader::static_size + 6, kernValueZ); |
125 | | }; |
126 | | |
127 | | template <typename KernSubTableHeader> |
128 | | struct KernSubTable |
129 | | { |
130 | 8.50M | size_t get_size () const { return u.header.length; }OT::KernSubTable<OT::KernOTSubTableHeader>::get_size() const Line | Count | Source | 130 | 8.50M | size_t get_size () const { return u.header.length; } |
Unexecuted instantiation: OT::KernSubTable<OT::KernAATSubTableHeader>::get_size() const |
131 | 16.3M | unsigned int get_type () const { return u.header.format; }OT::KernSubTable<OT::KernOTSubTableHeader>::get_type() const Line | Count | Source | 131 | 16.3M | unsigned int get_type () const { return u.header.format; } |
Unexecuted instantiation: OT::KernSubTable<OT::KernAATSubTableHeader>::get_type() const |
132 | 7.63M | bool is_machine_kern () const { return get_type () == 1; }OT::KernSubTable<OT::KernOTSubTableHeader>::is_machine_kern() const Line | Count | Source | 132 | 7.63M | bool is_machine_kern () const { return get_type () == 1; } |
Unexecuted instantiation: OT::KernSubTable<OT::KernAATSubTableHeader>::is_machine_kern() const |
133 | | |
134 | | int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const |
135 | 0 | { |
136 | 0 | switch (get_type ()) { |
137 | 0 | /* This method hooks up to hb_font_t's get_h_kerning. Only support Format0. */ |
138 | 0 | case 0: hb_barrier (); return u.format0.get_kerning (left, right); |
139 | 0 | default:return 0; |
140 | 0 | } |
141 | 0 | } Unexecuted instantiation: OT::KernSubTable<OT::KernOTSubTableHeader>::get_kerning(unsigned int, unsigned int) const Unexecuted instantiation: OT::KernSubTable<OT::KernAATSubTableHeader>::get_kerning(unsigned int, unsigned int) const |
142 | | |
143 | | template <typename context_t, typename ...Ts> |
144 | | typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const |
145 | 1.05M | { |
146 | 1.05M | unsigned int subtable_type = get_type (); |
147 | 1.05M | TRACE_DISPATCH (this, subtable_type); |
148 | 1.05M | switch (subtable_type) { |
149 | 1.05M | case 0: hb_barrier (); return_trace (c->dispatch (u.format0)); |
150 | 0 | #ifndef HB_NO_AAT_SHAPE |
151 | 0 | case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...)); |
152 | 0 | #endif |
153 | 0 | case 2: hb_barrier (); return_trace (c->dispatch (u.format2)); |
154 | 0 | #ifndef HB_NO_AAT_SHAPE |
155 | 0 | case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward<Ts> (ds)...)); |
156 | 0 | #endif |
157 | 0 | default: return_trace (c->default_return_value ()); |
158 | 1.05M | } |
159 | 1.05M | } AAT::hb_aat_apply_context_t::return_t OT::KernSubTable<OT::KernOTSubTableHeader>::dispatch<AAT::hb_aat_apply_context_t>(AAT::hb_aat_apply_context_t*) const Line | Count | Source | 145 | 1.04M | { | 146 | 1.04M | unsigned int subtable_type = get_type (); | 147 | 1.04M | TRACE_DISPATCH (this, subtable_type); | 148 | 1.04M | switch (subtable_type) { | 149 | 1.04M | case 0: hb_barrier (); return_trace (c->dispatch (u.format0)); | 150 | 0 | #ifndef HB_NO_AAT_SHAPE | 151 | 0 | case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...)); | 152 | 0 | #endif | 153 | 0 | case 2: hb_barrier (); return_trace (c->dispatch (u.format2)); | 154 | 0 | #ifndef HB_NO_AAT_SHAPE | 155 | 0 | case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward<Ts> (ds)...)); | 156 | 0 | #endif | 157 | 0 | default: return_trace (c->default_return_value ()); | 158 | 1.04M | } | 159 | 1.04M | } |
Unexecuted instantiation: AAT::hb_aat_apply_context_t::return_t OT::KernSubTable<OT::KernAATSubTableHeader>::dispatch<AAT::hb_aat_apply_context_t>(AAT::hb_aat_apply_context_t*) const hb_sanitize_context_t::return_t OT::KernSubTable<OT::KernOTSubTableHeader>::dispatch<hb_sanitize_context_t>(hb_sanitize_context_t*) const Line | Count | Source | 145 | 9.66k | { | 146 | 9.66k | unsigned int subtable_type = get_type (); | 147 | 9.66k | TRACE_DISPATCH (this, subtable_type); | 148 | 9.66k | switch (subtable_type) { | 149 | 9.66k | case 0: hb_barrier (); return_trace (c->dispatch (u.format0)); | 150 | 0 | #ifndef HB_NO_AAT_SHAPE | 151 | 0 | case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...)); | 152 | 0 | #endif | 153 | 0 | case 2: hb_barrier (); return_trace (c->dispatch (u.format2)); | 154 | 0 | #ifndef HB_NO_AAT_SHAPE | 155 | 0 | case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward<Ts> (ds)...)); | 156 | 0 | #endif | 157 | 0 | default: return_trace (c->default_return_value ()); | 158 | 9.66k | } | 159 | 9.66k | } |
Unexecuted instantiation: hb_sanitize_context_t::return_t OT::KernSubTable<OT::KernAATSubTableHeader>::dispatch<hb_sanitize_context_t>(hb_sanitize_context_t*) const |
160 | | |
161 | | template <typename set_t> |
162 | | void collect_glyphs (set_t &left_set, set_t &right_set, bool &second_set_gates, |
163 | | AAT::kern_pair_filter_t &filter, unsigned num_glyphs) const |
164 | 9.66k | { |
165 | 9.66k | second_set_gates = false; |
166 | 9.66k | unsigned int subtable_type = get_type (); |
167 | 9.66k | switch (subtable_type) { |
168 | 9.66k | case 0: hb_barrier (); u.format0.collect_glyphs (left_set, right_set, filter); return; |
169 | 0 | #ifndef HB_NO_AAT_SHAPE |
170 | 0 | case 1: hb_barrier (); u.format1.collect_glyphs (left_set, right_set, second_set_gates, num_glyphs); return; |
171 | 0 | #endif |
172 | 0 | case 2: hb_barrier (); u.format2.collect_glyphs (left_set, right_set, second_set_gates, num_glyphs); return; |
173 | 0 | #ifndef HB_NO_AAT_SHAPE |
174 | 0 | case 3: hb_barrier (); u.format3.collect_glyphs (left_set, right_set, second_set_gates, num_glyphs); return; |
175 | 0 | #endif |
176 | 0 | default: return; |
177 | 9.66k | } |
178 | 9.66k | } void OT::KernSubTable<OT::KernOTSubTableHeader>::collect_glyphs<hb_bit_set_t>(hb_bit_set_t&, hb_bit_set_t&, bool&, AAT::kern_pair_filter_t&, unsigned int) const Line | Count | Source | 164 | 9.66k | { | 165 | 9.66k | second_set_gates = false; | 166 | 9.66k | unsigned int subtable_type = get_type (); | 167 | 9.66k | switch (subtable_type) { | 168 | 9.66k | case 0: hb_barrier (); u.format0.collect_glyphs (left_set, right_set, filter); return; | 169 | 0 | #ifndef HB_NO_AAT_SHAPE | 170 | 0 | case 1: hb_barrier (); u.format1.collect_glyphs (left_set, right_set, second_set_gates, num_glyphs); return; | 171 | 0 | #endif | 172 | 0 | case 2: hb_barrier (); u.format2.collect_glyphs (left_set, right_set, second_set_gates, num_glyphs); return; | 173 | 0 | #ifndef HB_NO_AAT_SHAPE | 174 | 0 | case 3: hb_barrier (); u.format3.collect_glyphs (left_set, right_set, second_set_gates, num_glyphs); return; | 175 | 0 | #endif | 176 | 0 | default: return; | 177 | 9.66k | } | 178 | 9.66k | } |
Unexecuted instantiation: void OT::KernSubTable<OT::KernAATSubTableHeader>::collect_glyphs<hb_bit_set_t>(hb_bit_set_t&, hb_bit_set_t&, bool&, AAT::kern_pair_filter_t&, unsigned int) const |
179 | | |
180 | | bool sanitize (hb_sanitize_context_t *c) const |
181 | 9.66k | { |
182 | 9.66k | TRACE_SANITIZE (this); |
183 | 9.66k | if (unlikely (!(u.header.sanitize (c) && |
184 | 9.66k | hb_barrier () && |
185 | 9.66k | u.header.length >= u.header.min_size && |
186 | 9.66k | c->check_range (this, u.header.length)))) return_trace (false); |
187 | | |
188 | 9.66k | return_trace (dispatch (c)); |
189 | 9.66k | } OT::KernSubTable<OT::KernOTSubTableHeader>::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 181 | 9.66k | { | 182 | 9.66k | TRACE_SANITIZE (this); | 183 | 9.66k | if (unlikely (!(u.header.sanitize (c) && | 184 | 9.66k | hb_barrier () && | 185 | 9.66k | u.header.length >= u.header.min_size && | 186 | 9.66k | c->check_range (this, u.header.length)))) return_trace (false); | 187 | | | 188 | 9.66k | return_trace (dispatch (c)); | 189 | 9.66k | } |
Unexecuted instantiation: OT::KernSubTable<OT::KernAATSubTableHeader>::sanitize(hb_sanitize_context_t*) const |
190 | | |
191 | | public: |
192 | | union { |
193 | | KernSubTableHeader header; |
194 | | AAT::KerxSubTableFormat0<KernSubTableHeader> format0; |
195 | | #ifndef HB_NO_AAT_SHAPE |
196 | | AAT::KerxSubTableFormat1<KernSubTableHeader> format1; |
197 | | #endif |
198 | | AAT::KerxSubTableFormat2<KernSubTableHeader> format2; |
199 | | #ifndef HB_NO_AAT_SHAPE |
200 | | KernSubTableFormat3<KernSubTableHeader> format3; |
201 | | #endif |
202 | | } u; |
203 | | public: |
204 | | DEFINE_SIZE_MIN (KernSubTableHeader::static_size); |
205 | | }; |
206 | | |
207 | | |
208 | | struct KernOTSubTableHeader |
209 | | { |
210 | | static constexpr bool apple = false; |
211 | | typedef AAT::ObsoleteTypes Types; |
212 | | |
213 | 1.97k | unsigned tuple_count () const { return 0; } |
214 | 7.64M | bool is_horizontal () const { return (coverage & Horizontal); } |
215 | | |
216 | | enum Coverage |
217 | | { |
218 | | Horizontal = 0x01u, |
219 | | Minimum = 0x02u, |
220 | | CrossStream = 0x04u, |
221 | | Override = 0x08u, |
222 | | |
223 | | /* Not supported: */ |
224 | | Backwards = 0x00u, |
225 | | Variation = 0x00u, |
226 | | }; |
227 | | |
228 | | bool sanitize (hb_sanitize_context_t *c) const |
229 | 19.3k | { |
230 | 19.3k | TRACE_SANITIZE (this); |
231 | 19.3k | return_trace (c->check_struct (this)); |
232 | 19.3k | } |
233 | | |
234 | | public: |
235 | | HBUINT16 versionZ; /* Unused. */ |
236 | | HBUINT16 length; /* Length of the subtable (including this header). */ |
237 | | HBUINT8 format; /* Subtable format. */ |
238 | | HBUINT8 coverage; /* Coverage bits. */ |
239 | | public: |
240 | | DEFINE_SIZE_STATIC (6); |
241 | | }; |
242 | | |
243 | | struct KernOT : AAT::KerxTable<KernOT> |
244 | | { |
245 | | friend struct AAT::KerxTable<KernOT>; |
246 | | |
247 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_kern; |
248 | | static constexpr unsigned minVersion = 0u; |
249 | | |
250 | | typedef KernOTSubTableHeader SubTableHeader; |
251 | | typedef SubTableHeader::Types Types; |
252 | | typedef KernSubTable<SubTableHeader> SubTable; |
253 | | |
254 | | protected: |
255 | | HBUINT16 version; /* Version--0x0000u */ |
256 | | HBUINT16 tableCount; /* Number of subtables in the kerning table. */ |
257 | | SubTable firstSubTable; /* Subtables. */ |
258 | | public: |
259 | | DEFINE_SIZE_MIN (4); |
260 | | }; |
261 | | |
262 | | |
263 | | struct KernAATSubTableHeader |
264 | | { |
265 | | static constexpr bool apple = true; |
266 | | typedef AAT::ObsoleteTypes Types; |
267 | | |
268 | 0 | unsigned tuple_count () const { return 0; } |
269 | 0 | bool is_horizontal () const { return !(coverage & Vertical); } |
270 | | |
271 | | enum Coverage |
272 | | { |
273 | | Vertical = 0x80u, |
274 | | CrossStream = 0x40u, |
275 | | Variation = 0x20u, |
276 | | |
277 | | /* Not supported: */ |
278 | | Backwards = 0x00u, |
279 | | }; |
280 | | |
281 | | bool sanitize (hb_sanitize_context_t *c) const |
282 | 0 | { |
283 | 0 | TRACE_SANITIZE (this); |
284 | 0 | return_trace (c->check_struct (this)); |
285 | 0 | } |
286 | | |
287 | | public: |
288 | | HBUINT32 length; /* Length of the subtable (including this header). */ |
289 | | HBUINT8 coverage; /* Coverage bits. */ |
290 | | HBUINT8 format; /* Subtable format. */ |
291 | | HBUINT16 tupleIndex; /* The tuple index (used for variations fonts). |
292 | | * This value specifies which tuple this subtable covers. |
293 | | * Note: We don't implement. */ |
294 | | public: |
295 | | DEFINE_SIZE_STATIC (8); |
296 | | }; |
297 | | |
298 | | struct KernAAT : AAT::KerxTable<KernAAT> |
299 | | { |
300 | | friend struct AAT::KerxTable<KernAAT>; |
301 | | |
302 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_kern; |
303 | | static constexpr unsigned minVersion = 0x00010000u; |
304 | | |
305 | | typedef KernAATSubTableHeader SubTableHeader; |
306 | | typedef SubTableHeader::Types Types; |
307 | | typedef KernSubTable<SubTableHeader> SubTable; |
308 | | |
309 | | protected: |
310 | | HBUINT32 version; /* Version--0x00010000u */ |
311 | | HBUINT32 tableCount; /* Number of subtables in the kerning table. */ |
312 | | SubTable firstSubTable; /* Subtables. */ |
313 | | public: |
314 | | DEFINE_SIZE_MIN (8); |
315 | | }; |
316 | | |
317 | | struct kern |
318 | | { |
319 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_kern; |
320 | | |
321 | 8.89k | bool has_data () const { return u.version32.v; } |
322 | 2.31M | unsigned get_type () const { return u.major.v; } |
323 | | |
324 | | bool has_state_machine () const |
325 | 7.54k | { |
326 | 7.54k | switch (get_type ()) { |
327 | 7.54k | case 0: hb_barrier (); return u.ot.has_state_machine (); |
328 | 0 | #ifndef HB_NO_AAT_SHAPE |
329 | 0 | case 1: hb_barrier (); return u.aat.has_state_machine (); |
330 | 0 | #endif |
331 | 0 | default:return false; |
332 | 7.54k | } |
333 | 7.54k | } |
334 | | |
335 | | bool has_cross_stream () const |
336 | 37 | { |
337 | 37 | switch (get_type ()) { |
338 | 37 | case 0: hb_barrier (); return u.ot.has_cross_stream (); |
339 | 0 | #ifndef HB_NO_AAT_SHAPE |
340 | 0 | case 1: hb_barrier (); return u.aat.has_cross_stream (); |
341 | 0 | #endif |
342 | 0 | default:return false; |
343 | 37 | } |
344 | 37 | } |
345 | | |
346 | | int get_h_kerning (hb_codepoint_t left, hb_codepoint_t right) const |
347 | 0 | { |
348 | 0 | switch (get_type ()) { |
349 | 0 | case 0: hb_barrier (); return u.ot.get_h_kerning (left, right); |
350 | 0 | #ifndef HB_NO_AAT_SHAPE |
351 | 0 | case 1: hb_barrier (); return u.aat.get_h_kerning (left, right); |
352 | 0 | #endif |
353 | 0 | default:return 0; |
354 | 0 | } |
355 | 0 | } |
356 | | |
357 | | bool apply (AAT::hb_aat_apply_context_t *c, |
358 | | const AAT::kern_accelerator_data_t &accel_data) const |
359 | 2.29M | { return dispatch (c, accel_data); } |
360 | | |
361 | | template <typename context_t, typename ...Ts> |
362 | | typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const |
363 | 2.29M | { |
364 | 2.29M | unsigned int subtable_type = get_type (); |
365 | 2.29M | TRACE_DISPATCH (this, subtable_type); |
366 | 2.29M | switch (subtable_type) { |
367 | 2.29M | case 0: hb_barrier (); return_trace (c->dispatch (u.ot, std::forward<Ts> (ds)...)); |
368 | 0 | #ifndef HB_NO_AAT_SHAPE |
369 | 0 | case 1: hb_barrier (); return_trace (c->dispatch (u.aat, std::forward<Ts> (ds)...)); |
370 | 0 | #endif |
371 | 0 | default: return_trace (c->default_return_value ()); |
372 | 2.29M | } |
373 | 2.29M | } AAT::hb_aat_apply_context_t::return_t OT::kern::dispatch<AAT::hb_aat_apply_context_t, AAT::kern_accelerator_data_t const&>(AAT::hb_aat_apply_context_t*, AAT::kern_accelerator_data_t const&) const Line | Count | Source | 363 | 2.29M | { | 364 | 2.29M | unsigned int subtable_type = get_type (); | 365 | 2.29M | TRACE_DISPATCH (this, subtable_type); | 366 | 2.29M | switch (subtable_type) { | 367 | 2.29M | case 0: hb_barrier (); return_trace (c->dispatch (u.ot, std::forward<Ts> (ds)...)); | 368 | 0 | #ifndef HB_NO_AAT_SHAPE | 369 | 0 | case 1: hb_barrier (); return_trace (c->dispatch (u.aat, std::forward<Ts> (ds)...)); | 370 | 0 | #endif | 371 | 0 | default: return_trace (c->default_return_value ()); | 372 | 2.29M | } | 373 | 2.29M | } |
hb_sanitize_context_t::return_t OT::kern::dispatch<hb_sanitize_context_t>(hb_sanitize_context_t*) const Line | Count | Source | 363 | 4.51k | { | 364 | 4.51k | unsigned int subtable_type = get_type (); | 365 | 4.51k | TRACE_DISPATCH (this, subtable_type); | 366 | 4.51k | switch (subtable_type) { | 367 | 4.51k | case 0: hb_barrier (); return_trace (c->dispatch (u.ot, std::forward<Ts> (ds)...)); | 368 | 0 | #ifndef HB_NO_AAT_SHAPE | 369 | 0 | case 1: hb_barrier (); return_trace (c->dispatch (u.aat, std::forward<Ts> (ds)...)); | 370 | 0 | #endif | 371 | 0 | default: return_trace (c->default_return_value ()); | 372 | 4.51k | } | 373 | 4.51k | } |
|
374 | | |
375 | | bool sanitize (hb_sanitize_context_t *c) const |
376 | 4.51k | { |
377 | 4.51k | TRACE_SANITIZE (this); |
378 | 4.51k | if (!u.version32.v.sanitize (c)) return_trace (false); |
379 | 4.51k | hb_barrier (); |
380 | 4.51k | return_trace (dispatch (c)); |
381 | 4.51k | } |
382 | | |
383 | | AAT::kern_accelerator_data_t create_accelerator_data (unsigned num_glyphs) const |
384 | 4.53k | { |
385 | 4.53k | switch (get_type ()) { |
386 | 4.53k | case 0: hb_barrier (); return u.ot.create_accelerator_data (num_glyphs); |
387 | 0 | #ifndef HB_NO_AAT_SHAPE |
388 | 0 | case 1: hb_barrier (); return u.aat.create_accelerator_data (num_glyphs); |
389 | 0 | #endif |
390 | 0 | default:return AAT::kern_accelerator_data_t (); |
391 | 4.53k | } |
392 | 4.53k | } |
393 | | |
394 | | struct accelerator_t |
395 | | { |
396 | | accelerator_t (hb_face_t *face) |
397 | 4.53k | { |
398 | 4.53k | hb_sanitize_context_t sc; |
399 | 4.53k | this->table = sc.reference_table<kern> (face); |
400 | 4.53k | this->accel_data = this->table->create_accelerator_data (face->get_num_glyphs ()); |
401 | 4.53k | } |
402 | | ~accelerator_t () |
403 | 4.53k | { |
404 | 4.53k | this->table.destroy (); |
405 | 4.53k | } |
406 | | |
407 | 2.29M | hb_blob_t *get_blob () const { return table.get_blob (); } |
408 | | |
409 | | bool apply (AAT::hb_aat_apply_context_t *c) const |
410 | 2.29M | { |
411 | 2.29M | return table->apply (c, accel_data); |
412 | 2.29M | } |
413 | | |
414 | | hb_blob_ptr_t<kern> table; |
415 | | AAT::kern_accelerator_data_t accel_data; |
416 | | }; |
417 | | |
418 | | protected: |
419 | | union { |
420 | | struct { HBUINT32 v; } version32; |
421 | | struct { HBUINT16 v; } major; |
422 | | KernOT ot; |
423 | | #ifndef HB_NO_AAT_SHAPE |
424 | | KernAAT aat; |
425 | | #endif |
426 | | } u; |
427 | | public: |
428 | | DEFINE_SIZE_UNION (4, version32.v); |
429 | | }; |
430 | | |
431 | | struct kern_accelerator_t : kern::accelerator_t { |
432 | 4.53k | kern_accelerator_t (hb_face_t *face) : kern::accelerator_t (face) {} |
433 | | }; |
434 | | |
435 | | } /* namespace OT */ |
436 | | |
437 | | |
438 | | #endif /* HB_OT_KERN_TABLE_HH */ |