/src/harfbuzz/src/hb-ot-cff2-table.hh
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2018 Adobe 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 | | * Adobe Author(s): Michiharu Ariza |
25 | | */ |
26 | | |
27 | | #ifndef HB_OT_CFF2_TABLE_HH |
28 | | #define HB_OT_CFF2_TABLE_HH |
29 | | |
30 | | #include "hb-ot-cff-common.hh" |
31 | | #include "hb-subset-cff-common.hh" |
32 | | #include "hb-draw.hh" |
33 | | #include "hb-paint.hh" |
34 | | |
35 | | namespace CFF { |
36 | | |
37 | | /* |
38 | | * CFF2 -- Compact Font Format (CFF) Version 2 |
39 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/cff2 |
40 | | */ |
41 | | #define HB_OT_TAG_CFF2 HB_TAG('C','F','F','2') |
42 | | |
43 | | typedef CFF2Index CFF2CharStrings; |
44 | | typedef Subrs<HBUINT32> CFF2Subrs; |
45 | | |
46 | | typedef FDSelect3_4<HBUINT32, HBUINT16> FDSelect4; |
47 | | typedef FDSelect3_4_Range<HBUINT32, HBUINT16> FDSelect4_Range; |
48 | | |
49 | | struct CFF2FDSelect |
50 | | { |
51 | | bool serialize (hb_serialize_context_t *c, const CFF2FDSelect &src, unsigned int num_glyphs) |
52 | 0 | { |
53 | 0 | TRACE_SERIALIZE (this); |
54 | 0 | unsigned int size = src.get_size (num_glyphs); |
55 | 0 | CFF2FDSelect *dest = c->allocate_size<CFF2FDSelect> (size); |
56 | 0 | if (unlikely (!dest)) return_trace (false); |
57 | 0 | hb_memcpy (dest, &src, size); |
58 | 0 | return_trace (true); |
59 | 0 | } |
60 | | |
61 | | size_t get_size (unsigned int num_glyphs) const |
62 | 0 | { |
63 | 0 | switch (format) |
64 | 0 | { |
65 | 0 | case 0: hb_barrier (); return format.static_size + u.format0.get_size (num_glyphs); |
66 | 0 | case 3: hb_barrier (); return format.static_size + u.format3.get_size (); |
67 | 0 | case 4: hb_barrier (); return format.static_size + u.format4.get_size (); |
68 | 0 | default:return 0; |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | hb_codepoint_t get_fd (hb_codepoint_t glyph) const |
73 | 0 | { |
74 | 0 | switch (format) |
75 | 0 | { |
76 | 0 | case 0: hb_barrier (); return u.format0.get_fd (glyph); |
77 | 0 | case 3: hb_barrier (); return u.format3.get_fd (glyph); |
78 | 0 | case 4: hb_barrier (); return u.format4.get_fd (glyph); |
79 | 0 | default:return 0; |
80 | 0 | } |
81 | 0 | } |
82 | | /* Returns pair of fd and one after last glyph in range. */ |
83 | | hb_pair_t<unsigned, hb_codepoint_t> get_fd_range (hb_codepoint_t glyph) const |
84 | 0 | { |
85 | 0 | switch (format) |
86 | 0 | { |
87 | 0 | case 0: hb_barrier (); return u.format0.get_fd_range (glyph); |
88 | 0 | case 3: hb_barrier (); return u.format3.get_fd_range (glyph); |
89 | 0 | case 4: hb_barrier (); return u.format4.get_fd_range (glyph); |
90 | 0 | default:return {0, 1}; |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | | bool sanitize (hb_sanitize_context_t *c, unsigned int fdcount, |
95 | | unsigned int charstring_count = HB_CODEPOINT_INVALID) const |
96 | 0 | { |
97 | 0 | TRACE_SANITIZE (this); |
98 | 0 | if (unlikely (!c->check_struct (this))) |
99 | 0 | return_trace (false); |
100 | 0 | hb_barrier (); |
101 | |
|
102 | 0 | switch (format) |
103 | 0 | { |
104 | 0 | case 0: hb_barrier (); return_trace (u.format0.sanitize (c, fdcount, charstring_count)); |
105 | 0 | case 3: hb_barrier (); return_trace (u.format3.sanitize (c, fdcount, charstring_count)); |
106 | 0 | case 4: hb_barrier (); return_trace (u.format4.sanitize (c, fdcount, charstring_count)); |
107 | 0 | default:return_trace (false); |
108 | 0 | } |
109 | 0 | } |
110 | | |
111 | | HBUINT8 format; |
112 | | union { |
113 | | FDSelect0 format0; |
114 | | FDSelect3 format3; |
115 | | FDSelect4 format4; |
116 | | } u; |
117 | | public: |
118 | | DEFINE_SIZE_MIN (2); |
119 | | }; |
120 | | |
121 | | struct CFF2ItemVariationStore |
122 | | { |
123 | | bool sanitize (hb_sanitize_context_t *c) const |
124 | 0 | { |
125 | 0 | TRACE_SANITIZE (this); |
126 | 0 | return_trace (c->check_struct (this) && |
127 | 0 | hb_barrier () && |
128 | 0 | c->check_range (&varStore, size) && |
129 | 0 | varStore.sanitize (c)); |
130 | 0 | } |
131 | | |
132 | | bool serialize (hb_serialize_context_t *c, const CFF2ItemVariationStore *varStore) |
133 | 0 | { |
134 | 0 | TRACE_SERIALIZE (this); |
135 | 0 | unsigned int size_ = varStore->get_size (); |
136 | 0 | CFF2ItemVariationStore *dest = c->allocate_size<CFF2ItemVariationStore> (size_); |
137 | 0 | if (unlikely (!dest)) return_trace (false); |
138 | 0 | hb_memcpy (dest, varStore, size_); |
139 | 0 | return_trace (true); |
140 | 0 | } |
141 | | |
142 | 0 | size_t get_size () const { return HBUINT16::static_size + size; } |
143 | | |
144 | | HBUINT16 size; |
145 | | ItemVariationStore varStore; |
146 | | |
147 | | DEFINE_SIZE_MIN (2 + ItemVariationStore::min_size); |
148 | | }; |
149 | | |
150 | | struct cff2_top_dict_values_t : top_dict_values_t<> |
151 | | { |
152 | | void init () |
153 | 0 | { |
154 | 0 | top_dict_values_t<>::init (); |
155 | 0 | vstoreOffset = 0; |
156 | 0 | FDSelectOffset = 0; |
157 | 0 | } |
158 | 0 | void fini () { top_dict_values_t<>::fini (); } |
159 | | |
160 | | int vstoreOffset; |
161 | | int FDSelectOffset; |
162 | | }; |
163 | | |
164 | | struct cff2_top_dict_opset_t : top_dict_opset_t<> |
165 | | { |
166 | | static void process_op (op_code_t op, num_interp_env_t& env, cff2_top_dict_values_t& dictval) |
167 | 0 | { |
168 | 0 | switch (op) { |
169 | 0 | case OpCode_FontMatrix: |
170 | 0 | { |
171 | 0 | dict_val_t val; |
172 | 0 | val.init (); |
173 | 0 | dictval.add_op (op, env.str_ref); |
174 | 0 | env.clear_args (); |
175 | 0 | } |
176 | 0 | break; |
177 | | |
178 | 0 | case OpCode_vstore: |
179 | 0 | dictval.vstoreOffset = env.argStack.pop_int (); |
180 | 0 | env.clear_args (); |
181 | 0 | break; |
182 | 0 | case OpCode_FDSelect: |
183 | 0 | dictval.FDSelectOffset = env.argStack.pop_int (); |
184 | 0 | env.clear_args (); |
185 | 0 | break; |
186 | | |
187 | 0 | default: |
188 | 0 | SUPER::process_op (op, env, dictval); |
189 | | /* Record this operand below if stack is empty, otherwise done */ |
190 | 0 | if (!env.argStack.is_empty ()) return; |
191 | 0 | } |
192 | | |
193 | 0 | if (unlikely (env.in_error ())) return; |
194 | | |
195 | 0 | dictval.add_op (op, env.str_ref); |
196 | 0 | } |
197 | | |
198 | | typedef top_dict_opset_t<> SUPER; |
199 | | }; |
200 | | |
201 | | struct cff2_font_dict_values_t : dict_values_t<op_str_t> |
202 | | { |
203 | | void init () |
204 | 0 | { |
205 | 0 | dict_values_t<op_str_t>::init (); |
206 | 0 | privateDictInfo.init (); |
207 | 0 | } |
208 | 0 | void fini () { dict_values_t<op_str_t>::fini (); } |
209 | | |
210 | | table_info_t privateDictInfo; |
211 | | }; |
212 | | |
213 | | struct cff2_font_dict_opset_t : dict_opset_t |
214 | | { |
215 | | static void process_op (op_code_t op, num_interp_env_t& env, cff2_font_dict_values_t& dictval) |
216 | 0 | { |
217 | 0 | switch (op) { |
218 | 0 | case OpCode_Private: |
219 | 0 | dictval.privateDictInfo.offset = env.argStack.pop_uint (); |
220 | 0 | dictval.privateDictInfo.size = env.argStack.pop_uint (); |
221 | 0 | env.clear_args (); |
222 | 0 | break; |
223 | | |
224 | 0 | default: |
225 | 0 | SUPER::process_op (op, env); |
226 | 0 | if (!env.argStack.is_empty ()) |
227 | 0 | return; |
228 | 0 | } |
229 | | |
230 | 0 | if (unlikely (env.in_error ())) return; |
231 | | |
232 | 0 | dictval.add_op (op, env.str_ref); |
233 | 0 | } |
234 | | |
235 | | private: |
236 | | typedef dict_opset_t SUPER; |
237 | | }; |
238 | | |
239 | | template <typename VAL> |
240 | | struct cff2_private_dict_values_base_t : dict_values_t<VAL> |
241 | | { |
242 | | void init () |
243 | 0 | { |
244 | 0 | dict_values_t<VAL>::init (); |
245 | 0 | subrsOffset = 0; |
246 | 0 | localSubrs = &Null (CFF2Subrs); |
247 | 0 | ivs = 0; |
248 | 0 | } Unexecuted instantiation: CFF::cff2_private_dict_values_base_t<CFF::dict_val_t>::init() Unexecuted instantiation: CFF::cff2_private_dict_values_base_t<CFF::op_str_t>::init() |
249 | | void fini () { dict_values_t<VAL>::fini (); } |
250 | | |
251 | | int subrsOffset; |
252 | | const CFF2Subrs *localSubrs; |
253 | | unsigned int ivs; |
254 | | }; |
255 | | |
256 | | typedef cff2_private_dict_values_base_t<op_str_t> cff2_private_dict_values_subset_t; |
257 | | typedef cff2_private_dict_values_base_t<num_dict_val_t> cff2_private_dict_values_t; |
258 | | |
259 | | struct cff2_priv_dict_interp_env_t : num_interp_env_t |
260 | | { |
261 | | cff2_priv_dict_interp_env_t (const hb_ubytes_t &str) : |
262 | 0 | num_interp_env_t (str) {} |
263 | | |
264 | | void process_vsindex () |
265 | 0 | { |
266 | 0 | if (likely (!seen_vsindex)) |
267 | 0 | { |
268 | 0 | set_ivs (argStack.pop_uint ()); |
269 | 0 | } |
270 | 0 | seen_vsindex = true; |
271 | 0 | } |
272 | | |
273 | 0 | unsigned int get_ivs () const { return ivs; } |
274 | 0 | void set_ivs (unsigned int ivs_) { ivs = ivs_; } |
275 | | |
276 | | protected: |
277 | | unsigned int ivs = 0; |
278 | | bool seen_vsindex = false; |
279 | | }; |
280 | | |
281 | | struct cff2_private_dict_opset_t : dict_opset_t |
282 | | { |
283 | | static void process_op (op_code_t op, cff2_priv_dict_interp_env_t& env, cff2_private_dict_values_t& dictval) |
284 | 0 | { |
285 | 0 | switch (op) { |
286 | 0 | case OpCode_StdHW: |
287 | 0 | case OpCode_StdVW: |
288 | 0 | case OpCode_BlueScale: |
289 | 0 | case OpCode_BlueShift: |
290 | 0 | case OpCode_BlueFuzz: |
291 | 0 | case OpCode_ExpansionFactor: |
292 | 0 | case OpCode_LanguageGroup: |
293 | 0 | case OpCode_BlueValues: |
294 | 0 | case OpCode_OtherBlues: |
295 | 0 | case OpCode_FamilyBlues: |
296 | 0 | case OpCode_FamilyOtherBlues: |
297 | 0 | case OpCode_StemSnapH: |
298 | 0 | case OpCode_StemSnapV: |
299 | 0 | env.clear_args (); |
300 | 0 | break; |
301 | 0 | case OpCode_Subrs: |
302 | 0 | dictval.subrsOffset = env.argStack.pop_int (); |
303 | 0 | env.clear_args (); |
304 | 0 | break; |
305 | 0 | case OpCode_vsindexdict: |
306 | 0 | env.process_vsindex (); |
307 | 0 | dictval.ivs = env.get_ivs (); |
308 | 0 | env.clear_args (); |
309 | 0 | break; |
310 | 0 | case OpCode_blenddict: |
311 | | /* Hint values are ignored here. Discard each group so raw operands |
312 | | * from successive blends cannot overflow the stack. */ |
313 | 0 | env.clear_args (); |
314 | 0 | break; |
315 | | |
316 | 0 | default: |
317 | 0 | dict_opset_t::process_op (op, env); |
318 | 0 | break; |
319 | 0 | } |
320 | | |
321 | | /* The operators are not recorded: only the subsetter reads them back, |
322 | | * and it uses cff2_private_dict_opset_subset_t. */ |
323 | 0 | } |
324 | | }; |
325 | | |
326 | | struct cff2_private_dict_opset_subset_t : dict_opset_t |
327 | | { |
328 | | static void process_op (op_code_t op, cff2_priv_dict_interp_env_t& env, cff2_private_dict_values_subset_t& dictval) |
329 | 0 | { |
330 | 0 | switch (op) { |
331 | 0 | case OpCode_BlueValues: |
332 | 0 | case OpCode_OtherBlues: |
333 | 0 | case OpCode_FamilyBlues: |
334 | 0 | case OpCode_FamilyOtherBlues: |
335 | 0 | case OpCode_StdHW: |
336 | 0 | case OpCode_StdVW: |
337 | 0 | case OpCode_BlueScale: |
338 | 0 | case OpCode_BlueShift: |
339 | 0 | case OpCode_BlueFuzz: |
340 | 0 | case OpCode_StemSnapH: |
341 | 0 | case OpCode_StemSnapV: |
342 | 0 | case OpCode_LanguageGroup: |
343 | 0 | case OpCode_ExpansionFactor: |
344 | 0 | env.clear_args (); |
345 | 0 | break; |
346 | 0 |
|
347 | 0 | case OpCode_blenddict: |
348 | 0 | env.clear_args (); |
349 | 0 | return; |
350 | 0 |
|
351 | 0 | case OpCode_Subrs: |
352 | 0 | dictval.subrsOffset = env.argStack.pop_int (); |
353 | 0 | env.clear_args (); |
354 | 0 | break; |
355 | 0 |
|
356 | 0 | case OpCode_vsindexdict: |
357 | 0 | env.process_vsindex (); |
358 | 0 | dictval.ivs = env.get_ivs (); |
359 | 0 | env.clear_args (); |
360 | 0 | break; |
361 | 0 |
|
362 | 0 | default: |
363 | 0 | SUPER::process_op (op, env); |
364 | 0 | if (!env.argStack.is_empty ()) return; |
365 | 0 | break; |
366 | 0 | } |
367 | 0 |
|
368 | 0 | if (unlikely (env.in_error ())) return; |
369 | 0 |
|
370 | 0 | dictval.add_op (op, env.str_ref); |
371 | 0 | } |
372 | | |
373 | | private: |
374 | | typedef dict_opset_t SUPER; |
375 | | }; |
376 | | |
377 | | typedef dict_interpreter_t<cff2_top_dict_opset_t, cff2_top_dict_values_t> cff2_top_dict_interpreter_t; |
378 | | typedef dict_interpreter_t<cff2_font_dict_opset_t, cff2_font_dict_values_t> cff2_font_dict_interpreter_t; |
379 | | |
380 | | struct CFF2FDArray : FDArray<HBUINT32> |
381 | | { |
382 | | /* FDArray::serialize does not compile without this partial specialization */ |
383 | | template <typename ITER, typename OP_SERIALIZER> |
384 | | bool serialize (hb_serialize_context_t *c, ITER it, OP_SERIALIZER& opszr) |
385 | | { return FDArray<HBUINT32>::serialize<cff2_font_dict_values_t, table_info_t> (c, it, opszr); } |
386 | | }; |
387 | | |
388 | | } /* namespace CFF */ |
389 | | |
390 | | namespace OT { |
391 | | |
392 | | using namespace CFF; |
393 | | |
394 | | struct cff2 |
395 | | { |
396 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_CFF2; |
397 | | |
398 | | bool sanitize (hb_sanitize_context_t *c) const |
399 | 0 | { |
400 | 0 | TRACE_SANITIZE (this); |
401 | 0 | return_trace (c->check_struct (this) && |
402 | 0 | hb_barrier () && |
403 | 0 | likely (version.major == 2)); |
404 | 0 | } |
405 | | |
406 | | template <typename PRIVOPSET, typename PRIVDICTVAL> |
407 | | struct accelerator_templ_t |
408 | | { |
409 | | static constexpr hb_tag_t tableTag = cff2::tableTag; |
410 | | |
411 | | accelerator_templ_t (hb_face_t *face) |
412 | 0 | { |
413 | 0 | uint64_t num_priv_ops = 0; |
414 | |
|
415 | 0 | if (!face) return; |
416 | | |
417 | 0 | topDict.init (); |
418 | 0 | fontDicts.init (); |
419 | 0 | privateDicts.init (); |
420 | |
|
421 | 0 | this->blob = sc.reference_table<cff2> (face); |
422 | | |
423 | | /* setup for run-time sanitization */ |
424 | 0 | sc.init (this->blob); |
425 | 0 | sc.start_processing (); |
426 | |
|
427 | 0 | const OT::cff2 *cff2 = this->blob->template as<OT::cff2> (); |
428 | |
|
429 | 0 | if (cff2 == &Null (OT::cff2)) |
430 | 0 | goto fail; |
431 | | |
432 | 0 | { /* parse top dict */ |
433 | 0 | hb_ubytes_t topDictStr = (cff2 + cff2->topDict).as_ubytes (cff2->topDictSize); |
434 | 0 | if (unlikely (!topDictStr.sanitize (&sc))) goto fail; |
435 | 0 | hb_barrier (); |
436 | 0 | num_interp_env_t env (topDictStr); |
437 | 0 | cff2_top_dict_interpreter_t top_interp (env); |
438 | 0 | topDict.init (); |
439 | 0 | if (unlikely (!top_interp.interpret (topDict))) goto fail; |
440 | 0 | } |
441 | | |
442 | 0 | globalSubrs = &StructAtOffsetOrNull<CFF2Subrs> (cff2, cff2->topDict + cff2->topDictSize, sc); |
443 | 0 | varStore = &StructAtOffsetOrNull<CFF2ItemVariationStore> (cff2, topDict.vstoreOffset, sc); |
444 | 0 | charStrings = &StructAtOffsetOrNull<CFF2CharStrings> (cff2, topDict.charStringsOffset, sc); |
445 | 0 | fdArray = &StructAtOffsetOrNull<CFF2FDArray> (cff2, topDict.FDArrayOffset, sc); |
446 | |
|
447 | 0 | if (charStrings == &Null (CFF2CharStrings) || |
448 | 0 | globalSubrs == &Null (CFF2Subrs) || |
449 | 0 | fdArray == &Null (CFF2FDArray)) |
450 | 0 | goto fail; |
451 | | |
452 | 0 | num_glyphs = charStrings->count; |
453 | 0 | if (num_glyphs != sc.get_num_glyphs ()) |
454 | 0 | { |
455 | | /* VARC can define glyphs beyond the CFF2 CharStrings INDEX. */ |
456 | 0 | hb_blob_t *varc = face->reference_table (HB_TAG ('V','A','R','C')); |
457 | 0 | bool valid_count = num_glyphs < sc.get_num_glyphs () && |
458 | 0 | hb_blob_get_length (varc); |
459 | 0 | hb_blob_destroy (varc); |
460 | 0 | if (!valid_count) goto fail; |
461 | 0 | } |
462 | | |
463 | 0 | if (topDict.FDSelectOffset) |
464 | 0 | { |
465 | 0 | fdSelect = &StructAtOffsetOrNull<CFF2FDSelect> (cff2, topDict.FDSelectOffset, sc, |
466 | 0 | fdArray->count, num_glyphs); |
467 | 0 | if (fdSelect == &Null (CFF2FDSelect)) |
468 | 0 | goto fail; |
469 | 0 | } |
470 | | |
471 | 0 | fdCount = fdArray->count; |
472 | 0 | if (!privateDicts.resize (fdCount)) |
473 | 0 | goto fail; |
474 | | |
475 | | /* parse font dicts and gather private dicts */ |
476 | 0 | for (unsigned int i = 0; i < fdCount; i++) |
477 | 0 | { |
478 | 0 | const hb_ubytes_t fontDictStr = (*fdArray)[i]; |
479 | 0 | if (unlikely (!fontDictStr.sanitize (&sc))) goto fail; |
480 | 0 | hb_barrier (); |
481 | 0 | cff2_font_dict_values_t *font; |
482 | 0 | num_interp_env_t env (fontDictStr); |
483 | 0 | cff2_font_dict_interpreter_t font_interp (env); |
484 | 0 | font = fontDicts.push (); |
485 | 0 | if (unlikely (font == &Crap (cff2_font_dict_values_t))) goto fail; |
486 | 0 | font->init (); |
487 | 0 | if (unlikely (!font_interp.interpret (*font))) goto fail; |
488 | | |
489 | 0 | const hb_ubytes_t privDictStr = StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset, sc, font->privateDictInfo.size).as_ubytes (font->privateDictInfo.size); |
490 | 0 | if (unlikely (font->privateDictInfo.size && |
491 | 0 | privDictStr == (const unsigned char *) &Null (UnsizedByteStr))) goto fail; |
492 | 0 | cff2_priv_dict_interp_env_t env2 (privDictStr); |
493 | 0 | dict_interpreter_t<PRIVOPSET, PRIVDICTVAL, cff2_priv_dict_interp_env_t> priv_interp (env2); |
494 | 0 | privateDicts[i].init (); |
495 | 0 | if (unlikely (!priv_interp.interpret (privateDicts[i]) || privateDicts[i].values.in_error ())) goto fail; |
496 | | |
497 | | /* Font DICTs can share a Private DICT, so the size of the table does |
498 | | * not bound the operators the subset accelerator records for them. */ |
499 | 0 | num_priv_ops += privateDicts[i].get_count (); |
500 | 0 | if (unlikely (num_priv_ops > hb_max (this->blob->length, |
501 | 0 | (unsigned) HB_CFF_MAX_PRIVATE_DICT_OPS_MIN))) |
502 | 0 | goto fail; |
503 | | |
504 | 0 | privateDicts[i].localSubrs = &StructAtOffsetOrNull<CFF2Subrs> (&privDictStr[0], privateDicts[i].subrsOffset, sc); |
505 | 0 | } |
506 | | |
507 | 0 | return; |
508 | | |
509 | 0 | fail: |
510 | 0 | _fini (); |
511 | 0 | } |
512 | 0 | ~accelerator_templ_t () { _fini (); } |
513 | | void _fini () |
514 | 0 | { |
515 | 0 | sc.end_processing (); |
516 | 0 | topDict.fini (); |
517 | 0 | fontDicts.fini (); |
518 | 0 | privateDicts.fini (); |
519 | 0 | hb_blob_destroy (blob); |
520 | 0 | blob = nullptr; |
521 | |
|
522 | 0 | auto *scalars = cached_scalars_vector.get_acquire (); |
523 | 0 | if (scalars && cached_scalars_vector.cmpexch (scalars, nullptr)) |
524 | 0 | { |
525 | 0 | scalars->fini (); |
526 | 0 | hb_free (scalars); |
527 | 0 | } |
528 | 0 | } Unexecuted instantiation: OT::cff2::accelerator_templ_t<CFF::cff2_private_dict_opset_t, CFF::cff2_private_dict_values_base_t<CFF::dict_val_t> >::_fini() Unexecuted instantiation: OT::cff2::accelerator_templ_t<CFF::cff2_private_dict_opset_subset_t, CFF::cff2_private_dict_values_base_t<CFF::op_str_t> >::_fini() |
529 | | |
530 | | hb_vector_t<uint16_t> *create_glyph_to_sid_map () const |
531 | | { |
532 | | return nullptr; |
533 | | } |
534 | | |
535 | | hb_blob_t *get_blob () const { return blob; } |
536 | | |
537 | 0 | bool is_valid () const { return blob; } |
538 | | |
539 | | protected: |
540 | | hb_sanitize_context_t sc; |
541 | | |
542 | | public: |
543 | | hb_blob_t *blob = nullptr; |
544 | | cff2_top_dict_values_t topDict; |
545 | | const CFF2Subrs *globalSubrs = nullptr; |
546 | | const CFF2ItemVariationStore *varStore = nullptr; |
547 | | const CFF2CharStrings *charStrings = nullptr; |
548 | | const CFF2FDArray *fdArray = nullptr; |
549 | | /* nullptr when the font has none; not &Null(), whose address differs |
550 | | * in each library that shares this accelerator through the face. */ |
551 | | const CFF2FDSelect *fdSelect = nullptr; |
552 | | unsigned int fdCount = 0; |
553 | | |
554 | | hb_vector_t<cff2_font_dict_values_t> fontDicts; |
555 | | hb_vector_t<PRIVDICTVAL> privateDicts; |
556 | | |
557 | | mutable hb_atomic_t<hb_vector_t<float> *> cached_scalars_vector; |
558 | | |
559 | | unsigned int num_glyphs = 0; |
560 | | }; |
561 | | |
562 | | struct accelerator_t : accelerator_templ_t<cff2_private_dict_opset_t, cff2_private_dict_values_t> |
563 | | { |
564 | 0 | accelerator_t (hb_face_t *face) : accelerator_templ_t (face) {} |
565 | | |
566 | | HB_INTERNAL bool get_extents (hb_font_t *font, |
567 | | hb_codepoint_t glyph, |
568 | | hb_glyph_extents_t *extents) const; |
569 | | HB_INTERNAL bool get_extents_at (hb_font_t *font, |
570 | | hb_codepoint_t glyph, |
571 | | hb_glyph_extents_t *extents, |
572 | | hb_array_t<const int> coords, |
573 | | int64_t *budget = nullptr, |
574 | | bool scaled = true) const; |
575 | | HB_INTERNAL bool get_path (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, int64_t *budget = nullptr) const; |
576 | | HB_INTERNAL bool get_path_at (hb_font_t *font, hb_codepoint_t glyph, hb_draw_session_t &draw_session, hb_array_t<const int> coords, int64_t *budget = nullptr) const; |
577 | | }; |
578 | | |
579 | | struct accelerator_subset_t : accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> |
580 | | { |
581 | 0 | accelerator_subset_t (hb_face_t *face) : SUPER (face) {} |
582 | | ~accelerator_subset_t () |
583 | 0 | { |
584 | 0 | if (cff_accelerator) |
585 | 0 | cff_subset_accelerator_t::destroy (cff_accelerator); |
586 | 0 | } |
587 | | |
588 | | HB_INTERNAL bool subset (hb_subset_context_t *c) const; |
589 | | HB_INTERNAL bool serialize (hb_serialize_context_t *c, |
590 | | struct cff2_subset_plan &plan, |
591 | | hb_array_t<int> normalized_coords) const; |
592 | | |
593 | | mutable CFF::cff_subset_accelerator_t* cff_accelerator = nullptr; |
594 | | |
595 | | typedef accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> SUPER; |
596 | | }; |
597 | | |
598 | | public: |
599 | | FixedVersion<HBUINT8> version; /* Version of CFF2 table. set to 0x0200u */ |
600 | | NNOffsetTo<TopDict, HBUINT8> topDict; /* headerSize = Offset to Top DICT. */ |
601 | | HBUINT16 topDictSize; /* Top DICT size */ |
602 | | |
603 | | public: |
604 | | DEFINE_SIZE_STATIC (5); |
605 | | }; |
606 | | |
607 | | struct cff2_accelerator_t : cff2::accelerator_t { |
608 | 0 | cff2_accelerator_t (hb_face_t *face) : cff2::accelerator_t (face) {} |
609 | | }; |
610 | | |
611 | | struct cff2_subset_accelerator_t : cff2::accelerator_subset_t { |
612 | 0 | cff2_subset_accelerator_t (hb_face_t *face) : cff2::accelerator_subset_t (face) {} |
613 | | }; |
614 | | |
615 | | } /* namespace OT */ |
616 | | |
617 | | #endif /* HB_OT_CFF2_TABLE_HH */ |