/src/harfbuzz/src/OT/glyf/Glyph.hh
Line | Count | Source |
1 | | #ifndef OT_GLYF_GLYPH_HH |
2 | | #define OT_GLYF_GLYPH_HH |
3 | | |
4 | | |
5 | | #include "../../hb-open-type.hh" |
6 | | |
7 | | #include "GlyphHeader.hh" |
8 | | #include "SimpleGlyph.hh" |
9 | | #include "CompositeGlyph.hh" |
10 | | |
11 | | |
12 | | namespace OT { |
13 | | |
14 | | struct glyf_accelerator_t; |
15 | | |
16 | | namespace glyf_impl { |
17 | | |
18 | | |
19 | | enum phantom_point_index_t |
20 | | { |
21 | | PHANTOM_LEFT = 0, |
22 | | PHANTOM_RIGHT = 1, |
23 | | PHANTOM_TOP = 2, |
24 | | PHANTOM_BOTTOM = 3, |
25 | | PHANTOM_COUNT = 4 |
26 | | }; |
27 | | |
28 | | struct Glyph |
29 | | { |
30 | | enum glyph_type_t { |
31 | | EMPTY, |
32 | | SIMPLE, |
33 | | COMPOSITE, |
34 | | }; |
35 | | |
36 | | public: |
37 | | composite_iter_t get_composite_iterator () const |
38 | 0 | { |
39 | 0 | if (type != COMPOSITE) return composite_iter_t (); |
40 | 0 | return CompositeGlyph (*header, bytes, extended).iter (); |
41 | 0 | } |
42 | | |
43 | | const hb_bytes_t trim_padding () const |
44 | 0 | { |
45 | 0 | switch (type) { |
46 | 0 | case COMPOSITE: return CompositeGlyph (*header, bytes, extended).trim_padding (); |
47 | 0 | case SIMPLE: return SimpleGlyph (*header, bytes).trim_padding (); |
48 | 0 | case EMPTY: return bytes; |
49 | 0 | default: return bytes; |
50 | 0 | } |
51 | 0 | } |
52 | | |
53 | | void drop_hints () |
54 | 0 | { |
55 | 0 | switch (type) { |
56 | 0 | case COMPOSITE: CompositeGlyph (*header, bytes, extended).drop_hints (); return; |
57 | 0 | case SIMPLE: SimpleGlyph (*header, bytes).drop_hints (); return; |
58 | 0 | case EMPTY: |
59 | 0 | if (bytes.length >= GlyphHeader::static_size) |
60 | 0 | SimpleGlyph (*header, bytes).drop_hints (); |
61 | 0 | return; |
62 | 0 | } |
63 | 0 | } |
64 | | |
65 | | void set_overlaps_flag () |
66 | 0 | { |
67 | 0 | switch (type) { |
68 | 0 | case COMPOSITE: CompositeGlyph (*header, bytes, extended).set_overlaps_flag (); return; |
69 | 0 | case SIMPLE: SimpleGlyph (*header, bytes).set_overlaps_flag (); return; |
70 | 0 | case EMPTY: return; |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | | void drop_hints_bytes (hb_bytes_t &dest_start, hb_bytes_t &dest_end) const |
75 | 0 | { |
76 | 0 | switch (type) { |
77 | 0 | case COMPOSITE: CompositeGlyph (*header, bytes, extended).drop_hints_bytes (dest_start); return; |
78 | 0 | case SIMPLE: SimpleGlyph (*header, bytes).drop_hints_bytes (dest_start, dest_end); return; |
79 | 0 | case EMPTY: |
80 | 0 | dest_start = bytes; |
81 | 0 | dest_end = hb_bytes_t (); |
82 | 0 | if (bytes.length >= GlyphHeader::static_size && |
83 | 0 | SimpleGlyph (*header, bytes).has_instructions_length ()) |
84 | 0 | SimpleGlyph (*header, bytes).drop_hints_bytes (dest_start, dest_end); |
85 | 0 | return; |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | bool is_composite () const |
90 | 0 | { return type == COMPOSITE; } |
91 | | |
92 | | bool get_all_points_without_var (const hb_face_t *face, |
93 | | contour_point_vector_t &points /* OUT */) const |
94 | 0 | { |
95 | 0 | switch (type) { |
96 | 0 | case SIMPLE: |
97 | 0 | if (unlikely (!SimpleGlyph (*header, bytes).get_contour_points (points, extended))) |
98 | 0 | return false; |
99 | 0 | break; |
100 | 0 | case COMPOSITE: |
101 | 0 | { |
102 | 0 | for (auto &item : get_composite_iterator ()) |
103 | 0 | if (unlikely (!item.get_points (points, extended))) return false; |
104 | 0 | break; |
105 | 0 | } |
106 | 0 | case EMPTY: |
107 | 0 | break; |
108 | 0 | } |
109 | 0 |
|
110 | 0 | /* Init phantom points */ |
111 | 0 | if (unlikely (!points.resize (points.length + PHANTOM_COUNT))) return false; |
112 | 0 | hb_array_t<contour_point_t> phantoms = points.as_array ().sub_array (points.length - PHANTOM_COUNT, PHANTOM_COUNT); |
113 | 0 | { |
114 | 0 | // Duplicated code. |
115 | 0 | int lsb = 0; |
116 | 0 | face->table.hmtx->get_leading_bearing_without_var_unscaled (gid, &lsb); |
117 | 0 | int h_delta = (int) header->xMin - lsb; |
118 | 0 | HB_UNUSED int tsb = 0; |
119 | 0 | #ifndef HB_NO_VERTICAL |
120 | 0 | face->table.vmtx->get_leading_bearing_without_var_unscaled (gid, &tsb); |
121 | 0 | #endif |
122 | 0 | int v_orig = (int) header->yMax + tsb; |
123 | 0 | unsigned h_adv = face->table.hmtx->get_advance_without_var_unscaled (gid); |
124 | 0 | unsigned v_adv = |
125 | 0 | #ifndef HB_NO_VERTICAL |
126 | 0 | face->table.vmtx->get_advance_without_var_unscaled (gid) |
127 | 0 | #else |
128 | 0 | - face->get_upem () |
129 | 0 | #endif |
130 | 0 | ; |
131 | 0 | phantoms[PHANTOM_LEFT].x = h_delta; |
132 | 0 | phantoms[PHANTOM_RIGHT].x = (int) h_adv + h_delta; |
133 | 0 | phantoms[PHANTOM_TOP].y = v_orig; |
134 | 0 | phantoms[PHANTOM_BOTTOM].y = v_orig - (int) v_adv; |
135 | 0 | } |
136 | 0 | return true; |
137 | 0 | } |
138 | | |
139 | | void update_mtx (const hb_subset_plan_t *plan, |
140 | | int xMin, int xMax, |
141 | | int yMin, int yMax, |
142 | | const contour_point_vector_t &all_points) const |
143 | 0 | { |
144 | 0 | hb_codepoint_t new_gid = 0; |
145 | 0 | if (!plan->new_gid_for_old_gid (gid, &new_gid)) |
146 | 0 | return; |
147 | 0 |
|
148 | 0 | if (type != EMPTY) |
149 | 0 | { |
150 | 0 | plan->bounds_width_vec[new_gid] = xMax - xMin; |
151 | 0 | plan->bounds_height_vec[new_gid] = yMax - yMin; |
152 | 0 | } |
153 | 0 |
|
154 | 0 | unsigned len = all_points.length; |
155 | 0 | float leftSideX = all_points[len - 4].x; |
156 | 0 | float rightSideX = all_points[len - 3].x; |
157 | 0 | float topSideY = all_points[len - 2].y; |
158 | 0 | float bottomSideY = all_points[len - 1].y; |
159 | 0 |
|
160 | 0 | uint32_t hash = hb_hash (new_gid); |
161 | 0 |
|
162 | 0 | signed hori_aw = roundf (rightSideX - leftSideX); |
163 | 0 | if (hori_aw < 0) hori_aw = 0; |
164 | 0 | int lsb = roundf (xMin - leftSideX); |
165 | 0 | plan->hmtx_map.set_with_hash (new_gid, hash, hb_pair ((unsigned) hori_aw, lsb)); |
166 | 0 | //flag value should be computed using non-empty glyphs |
167 | 0 | if (type != EMPTY && lsb != xMin) |
168 | 0 | plan->head_maxp_info.allXMinIsLsb = false; |
169 | 0 |
|
170 | 0 | signed vert_aw = roundf (topSideY - bottomSideY); |
171 | 0 | if (vert_aw < 0) vert_aw = 0; |
172 | 0 | int tsb = roundf (topSideY - yMax); |
173 | 0 | plan->vmtx_map.set_with_hash (new_gid, hash, hb_pair ((unsigned) vert_aw, tsb)); |
174 | 0 | } |
175 | | |
176 | | bool compile_header_bytes (const hb_subset_plan_t *plan, |
177 | | const contour_point_vector_t &all_points, |
178 | | hb_bytes_t &dest_bytes /* OUT */) const |
179 | 0 | { |
180 | 0 | GlyphHeader *glyph_header = nullptr; |
181 | 0 | if (!plan->pinned_at_default && type != EMPTY && all_points.length >= 4) |
182 | 0 | { |
183 | 0 | glyph_header = (GlyphHeader *) hb_calloc (1, GlyphHeader::static_size); |
184 | 0 | if (unlikely (!glyph_header)) return false; |
185 | 0 | } |
186 | 0 |
|
187 | 0 | float xMin = 0, xMax = 0; |
188 | 0 | float yMin = 0, yMax = 0; |
189 | 0 | if (all_points.length > 4) |
190 | 0 | { |
191 | 0 | xMin = xMax = all_points[0].x; |
192 | 0 | yMin = yMax = all_points[0].y; |
193 | 0 |
|
194 | 0 | unsigned count = all_points.length - 4; |
195 | 0 | for (unsigned i = 1; i < count; i++) |
196 | 0 | { |
197 | 0 | float x = all_points[i].x; |
198 | 0 | float y = all_points[i].y; |
199 | 0 | xMin = hb_min (xMin, x); |
200 | 0 | xMax = hb_max (xMax, x); |
201 | 0 | yMin = hb_min (yMin, y); |
202 | 0 | yMax = hb_max (yMax, y); |
203 | 0 | } |
204 | 0 | } |
205 | 0 |
|
206 | 0 |
|
207 | 0 | // These are destined for storage in a 16 bit field to clamp the values to |
208 | 0 | // fit into a 16 bit signed integer. |
209 | 0 | int rounded_xMin = hb_clamp (roundf (xMin), -32768.0f, 32767.0f); |
210 | 0 | int rounded_xMax = hb_clamp (roundf (xMax), -32768.0f, 32767.0f); |
211 | 0 | int rounded_yMin = hb_clamp (roundf (yMin), -32768.0f, 32767.0f); |
212 | 0 | int rounded_yMax = hb_clamp (roundf (yMax), -32768.0f, 32767.0f); |
213 | 0 |
|
214 | 0 | update_mtx (plan, rounded_xMin, rounded_xMax, rounded_yMin, rounded_yMax, all_points); |
215 | 0 |
|
216 | 0 | if (type != EMPTY) |
217 | 0 | { |
218 | 0 | plan->head_maxp_info.xMin = hb_min (plan->head_maxp_info.xMin, rounded_xMin); |
219 | 0 | plan->head_maxp_info.yMin = hb_min (plan->head_maxp_info.yMin, rounded_yMin); |
220 | 0 | plan->head_maxp_info.xMax = hb_max (plan->head_maxp_info.xMax, rounded_xMax); |
221 | 0 | plan->head_maxp_info.yMax = hb_max (plan->head_maxp_info.yMax, rounded_yMax); |
222 | 0 | } |
223 | 0 |
|
224 | 0 | /* when pinned at default, no need to compile glyph header |
225 | 0 | * and for empty glyphs: all_points only include phantom points. |
226 | 0 | * just update metrics and then return */ |
227 | 0 | if (!glyph_header) |
228 | 0 | return true; |
229 | 0 |
|
230 | 0 | glyph_header->numberOfContours = header->numberOfContours; |
231 | 0 |
|
232 | 0 | glyph_header->xMin = rounded_xMin; |
233 | 0 | glyph_header->yMin = rounded_yMin; |
234 | 0 | glyph_header->xMax = rounded_xMax; |
235 | 0 | glyph_header->yMax = rounded_yMax; |
236 | 0 |
|
237 | 0 | dest_bytes = hb_bytes_t ((const char *)glyph_header, GlyphHeader::static_size); |
238 | 0 | return true; |
239 | 0 | } |
240 | | |
241 | | bool compile_bytes_with_deltas (const hb_subset_plan_t *plan, |
242 | | hb_font_t *font, |
243 | | const glyf_accelerator_t &glyf, |
244 | | hb_bytes_t &dest_start, /* IN/OUT */ |
245 | | hb_bytes_t &dest_end /* OUT */) |
246 | 0 | { |
247 | 0 | contour_point_vector_t all_points, points_with_deltas; |
248 | 0 | unsigned composite_contours = 0; |
249 | 0 | head_maxp_info_t *head_maxp_info_p = &plan->head_maxp_info; |
250 | 0 | unsigned *composite_contours_p = &composite_contours; |
251 | 0 |
|
252 | 0 | // don't compute head/maxp values when glyph has no contours(type is EMPTY) |
253 | 0 | // also ignore .notdef glyph when --notdef-outline is not enabled |
254 | 0 | if (type == EMPTY || |
255 | 0 | (gid == 0 && !(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE))) |
256 | 0 | { |
257 | 0 | head_maxp_info_p = nullptr; |
258 | 0 | composite_contours_p = nullptr; |
259 | 0 | } |
260 | 0 |
|
261 | 0 | hb_glyf_scratch_t scratch; |
262 | 0 | if (!get_points (font, glyf, all_points, scratch, &points_with_deltas, head_maxp_info_p, composite_contours_p, false, false)) |
263 | 0 | return false; |
264 | 0 |
|
265 | 0 | // .notdef, set type to empty so we only update metrics and don't compile bytes for |
266 | 0 | // it |
267 | 0 | if (gid == 0 && |
268 | 0 | !(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE)) |
269 | 0 | { |
270 | 0 | type = EMPTY; |
271 | 0 | dest_start = hb_bytes_t (); |
272 | 0 | dest_end = hb_bytes_t (); |
273 | 0 | } |
274 | 0 |
|
275 | 0 | //dont compile bytes when pinned at default, just recalculate bounds |
276 | 0 | if (!plan->pinned_at_default) |
277 | 0 | { |
278 | 0 | switch (type) |
279 | 0 | { |
280 | 0 | case COMPOSITE: |
281 | 0 | if (!CompositeGlyph (*header, bytes, extended).compile_bytes_with_deltas (dest_start, |
282 | 0 | points_with_deltas, |
283 | 0 | dest_end)) |
284 | 0 | return false; |
285 | 0 | break; |
286 | 0 | case SIMPLE: |
287 | 0 | if (!SimpleGlyph (*header, bytes).compile_bytes_with_deltas (all_points, |
288 | 0 | plan->flags & HB_SUBSET_FLAGS_NO_HINTING, |
289 | 0 | dest_end)) |
290 | 0 | return false; |
291 | 0 | break; |
292 | 0 | case EMPTY: |
293 | 0 | dest_start = hb_bytes_t (); |
294 | 0 | dest_end = hb_bytes_t (); |
295 | 0 | /* Zero-contour glyphs may carry instructions for phantom points. |
296 | 0 | * Copy them into owned memory like the other compiled glyphs. */ |
297 | 0 | if (!(plan->flags & HB_SUBSET_FLAGS_NO_HINTING) && |
298 | 0 | bytes.length >= GlyphHeader::static_size && |
299 | 0 | header->numberOfContours == 0) |
300 | 0 | { |
301 | 0 | SimpleGlyph simple (*header, bytes); |
302 | 0 | unsigned length = simple.instructions_length (); |
303 | 0 | if (length) |
304 | 0 | { |
305 | 0 | length = simple.length (length); |
306 | 0 | char *p = (char *) hb_malloc (length); |
307 | 0 | if (unlikely (!p)) return false; |
308 | 0 | hb_memcpy (p, bytes.arrayZ, length); |
309 | 0 | dest_start = hb_bytes_t (p, length); |
310 | 0 | } |
311 | 0 | } |
312 | 0 | break; |
313 | 0 | } |
314 | 0 | } |
315 | 0 |
|
316 | 0 | if (!compile_header_bytes (plan, all_points, dest_start)) |
317 | 0 | { |
318 | 0 | dest_end.fini (); |
319 | 0 | return false; |
320 | 0 | } |
321 | 0 | return true; |
322 | 0 | } |
323 | | |
324 | | |
325 | | /* Note: Recursively calls itself. |
326 | | * all_points includes phantom points |
327 | | */ |
328 | | template <typename accelerator_t> |
329 | | bool get_points (hb_font_t *font, const accelerator_t &glyf_accelerator, |
330 | | contour_point_vector_t &all_points /* OUT */, |
331 | | hb_glyf_scratch_t &scratch, |
332 | | contour_point_vector_t *points_with_deltas = nullptr, /* OUT */ |
333 | | head_maxp_info_t * head_maxp_info = nullptr, /* OUT */ |
334 | | unsigned *composite_contours = nullptr, /* OUT */ |
335 | | bool shift_points_hori = true, |
336 | | bool use_my_metrics = true, |
337 | | bool phantom_only = false, |
338 | | hb_array_t<const int> coords = hb_array_t<const int> (), |
339 | | hb_scalar_cache_t *gvar_cache = nullptr, |
340 | | unsigned int depth = 0, |
341 | | unsigned *edge_count = nullptr, |
342 | | int64_t *budget = nullptr) const |
343 | 0 | { |
344 | 0 | if (unlikely (depth > HB_MAX_NESTING_LEVEL)) return false; |
345 | 0 | unsigned stack_edge_count = 0; |
346 | 0 | if (!edge_count) edge_count = &stack_edge_count; |
347 | 0 | if (unlikely (*edge_count > HB_MAX_GRAPH_EDGE_COUNT)) return false; |
348 | 0 | (*edge_count)++; |
349 | |
|
350 | 0 | int64_t stack_budget = HB_BUDGET_GLYPH; |
351 | 0 | if (!budget) budget = &stack_budget; |
352 | 0 | if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_16))) return false; |
353 | | |
354 | 0 | if (head_maxp_info) |
355 | 0 | { |
356 | 0 | head_maxp_info->maxComponentDepth = hb_max (head_maxp_info->maxComponentDepth, depth); |
357 | 0 | } |
358 | |
|
359 | 0 | if (!coords && font->has_nonzero_coords) |
360 | 0 | coords = hb_array (font->coords, font->num_coords); |
361 | |
|
362 | 0 | contour_point_vector_t &points = type == SIMPLE ? all_points : scratch.comp_points; |
363 | 0 | unsigned old_length = points.length; |
364 | |
|
365 | 0 | switch (type) { |
366 | 0 | case SIMPLE: |
367 | 0 | if (depth == 0 && head_maxp_info) |
368 | 0 | head_maxp_info->maxContours = hb_max (head_maxp_info->maxContours, (unsigned) header->numberOfContours); |
369 | 0 | if (depth > 0 && composite_contours) |
370 | 0 | *composite_contours += (unsigned) header->numberOfContours; |
371 | 0 | if (unlikely (!SimpleGlyph (*header, bytes).get_contour_points (all_points, extended, phantom_only, budget))) |
372 | 0 | return false; |
373 | 0 | break; |
374 | 0 | case COMPOSITE: |
375 | 0 | { |
376 | 0 | for (auto &item : get_composite_iterator ()) |
377 | 0 | if (unlikely (!item.get_points (points, extended))) return false; |
378 | 0 | break; |
379 | 0 | } |
380 | 0 | case EMPTY: |
381 | 0 | break; |
382 | 0 | } |
383 | | |
384 | | /* Init phantom points */ |
385 | 0 | if (unlikely (!points.resize (points.length + PHANTOM_COUNT))) return false; |
386 | 0 | hb_array_t<contour_point_t> phantoms = points.as_array ().sub_array (points.length - PHANTOM_COUNT, PHANTOM_COUNT); |
387 | 0 | { |
388 | | // Duplicated code. |
389 | 0 | int lsb = 0; |
390 | 0 | glyf_accelerator.hmtx->get_leading_bearing_without_var_unscaled (gid, &lsb); |
391 | 0 | int h_delta = (int) header->xMin - lsb; |
392 | 0 | HB_UNUSED int tsb = 0; |
393 | 0 | #ifndef HB_NO_VERTICAL |
394 | 0 | glyf_accelerator.vmtx->get_leading_bearing_without_var_unscaled (gid, &tsb); |
395 | 0 | #endif |
396 | 0 | int v_orig = (int) header->yMax + tsb; |
397 | 0 | unsigned h_adv = glyf_accelerator.hmtx->get_advance_without_var_unscaled (gid); |
398 | 0 | unsigned v_adv = |
399 | 0 | #ifndef HB_NO_VERTICAL |
400 | 0 | glyf_accelerator.vmtx->get_advance_without_var_unscaled (gid) |
401 | | #else |
402 | | - font->face->get_upem () |
403 | | #endif |
404 | 0 | ; |
405 | 0 | phantoms[PHANTOM_LEFT].x = h_delta; |
406 | 0 | phantoms[PHANTOM_RIGHT].x = (int) h_adv + h_delta; |
407 | 0 | phantoms[PHANTOM_TOP].y = v_orig; |
408 | 0 | phantoms[PHANTOM_BOTTOM].y = v_orig - (int) v_adv; |
409 | 0 | } |
410 | |
|
411 | 0 | #ifndef HB_NO_VAR |
412 | 0 | if (hb_any (coords)) |
413 | 0 | { |
414 | 0 | if (!glyf_accelerator.gvar->apply_deltas_to_points (gid, |
415 | 0 | coords, |
416 | 0 | points.as_array ().sub_array (old_length), |
417 | 0 | scratch, |
418 | 0 | gvar_cache, |
419 | 0 | phantom_only && type == SIMPLE, |
420 | 0 | budget)) |
421 | 0 | return false; |
422 | 0 | } |
423 | 0 | #endif |
424 | | |
425 | | // mainly used by CompositeGlyph calculating new X/Y offset value so no need to extend it |
426 | | // with child glyphs' points |
427 | 0 | if (points_with_deltas != nullptr && depth == 0 && type == COMPOSITE) |
428 | 0 | { |
429 | 0 | assert (old_length == 0); |
430 | 0 | *points_with_deltas = points; |
431 | 0 | } |
432 | | |
433 | 0 | float shift = 0; |
434 | 0 | switch (type) { |
435 | 0 | case SIMPLE: |
436 | 0 | if (depth == 0 && head_maxp_info) |
437 | 0 | head_maxp_info->maxPoints = hb_max (head_maxp_info->maxPoints, all_points.length - old_length - 4); |
438 | 0 | shift = phantoms[PHANTOM_LEFT].x; |
439 | 0 | break; |
440 | 0 | case COMPOSITE: |
441 | 0 | { |
442 | 0 | hb_decycler_node_t decycler_node (scratch.decycler); |
443 | |
|
444 | 0 | unsigned int comp_index = 0; |
445 | 0 | for (auto &item : get_composite_iterator ()) |
446 | 0 | { |
447 | 0 | hb_codepoint_t item_gid = item.get_gid (extended); |
448 | |
|
449 | 0 | if (unlikely (!decycler_node.visit (item_gid))) |
450 | 0 | { |
451 | 0 | comp_index++; |
452 | 0 | continue; |
453 | 0 | } |
454 | | |
455 | 0 | unsigned old_count = all_points.length; |
456 | |
|
457 | 0 | if (unlikely ((!phantom_only || (use_my_metrics && item.is_use_my_metrics ())) && |
458 | 0 | !glyf_accelerator.glyph_for_gid (item_gid) |
459 | 0 | .get_points (font, |
460 | 0 | glyf_accelerator, |
461 | 0 | all_points, |
462 | 0 | scratch, |
463 | 0 | points_with_deltas, |
464 | 0 | head_maxp_info, |
465 | 0 | composite_contours, |
466 | 0 | shift_points_hori, |
467 | 0 | use_my_metrics, |
468 | 0 | phantom_only, |
469 | 0 | coords, |
470 | 0 | gvar_cache, |
471 | 0 | depth + 1, |
472 | 0 | edge_count, |
473 | 0 | budget))) |
474 | 0 | { |
475 | 0 | points.resize (old_length); |
476 | 0 | return false; |
477 | 0 | } |
478 | | |
479 | | // points might have been reallocated. Relocate phantoms. |
480 | 0 | phantoms = points.as_array ().sub_array (points.length - PHANTOM_COUNT, PHANTOM_COUNT); |
481 | |
|
482 | 0 | auto comp_points = all_points.as_array ().sub_array (old_count); |
483 | | |
484 | | /* Copy phantom points from component if USE_MY_METRICS flag set */ |
485 | 0 | if (use_my_metrics && item.is_use_my_metrics ()) |
486 | 0 | for (unsigned int i = 0; i < PHANTOM_COUNT; i++) |
487 | 0 | phantoms[i] = comp_points[comp_points.length - PHANTOM_COUNT + i]; |
488 | | |
489 | | /* Each composite level transforms the whole subtree below it; |
490 | | * charge that work here so deep nesting is bounded by the budget |
491 | | * rather than by the per-draw point cap alone. */ |
492 | 0 | if (unlikely (!hb_budget_spend (*budget, HB_BUDGET_1, comp_points.length))) |
493 | 0 | { |
494 | 0 | points.resize (old_length); |
495 | 0 | return false; |
496 | 0 | } |
497 | | |
498 | 0 | if (comp_points) // Empty in case of phantom_only |
499 | 0 | { |
500 | 0 | float matrix[4]; |
501 | 0 | contour_point_t default_trans; |
502 | 0 | item.get_transformation (matrix, default_trans, extended); |
503 | | |
504 | | /* Apply component transformation & translation (with deltas applied) */ |
505 | 0 | item.transform_points (comp_points, matrix, points[old_length + comp_index]); |
506 | 0 | } |
507 | |
|
508 | 0 | if (item.is_anchored () && !phantom_only) |
509 | 0 | { |
510 | 0 | unsigned int p1, p2; |
511 | 0 | item.get_anchor_points (p1, p2, extended); |
512 | 0 | if (likely (p1 < all_points.length && p2 < comp_points.length)) |
513 | 0 | { |
514 | 0 | contour_point_t delta; |
515 | 0 | delta.init (all_points[p1].x - comp_points[p2].x, |
516 | 0 | all_points[p1].y - comp_points[p2].y); |
517 | |
|
518 | 0 | item.translate (delta, comp_points); |
519 | 0 | } |
520 | 0 | } |
521 | |
|
522 | 0 | all_points.resize (all_points.length - PHANTOM_COUNT); |
523 | |
|
524 | 0 | if (all_points.length > HB_GLYF_MAX_POINTS) |
525 | 0 | { |
526 | 0 | points.resize (old_length); |
527 | 0 | return false; |
528 | 0 | } |
529 | | |
530 | 0 | comp_index++; |
531 | 0 | } |
532 | | |
533 | 0 | if (head_maxp_info && depth == 0) |
534 | 0 | { |
535 | 0 | if (composite_contours) |
536 | 0 | head_maxp_info->maxCompositeContours = hb_max (head_maxp_info->maxCompositeContours, *composite_contours); |
537 | 0 | head_maxp_info->maxCompositePoints = hb_max (head_maxp_info->maxCompositePoints, all_points.length); |
538 | 0 | head_maxp_info->maxComponentElements = hb_max (head_maxp_info->maxComponentElements, comp_index); |
539 | 0 | } |
540 | 0 | all_points.extend (phantoms); |
541 | 0 | shift = phantoms[PHANTOM_LEFT].x; |
542 | 0 | points.resize (old_length); |
543 | 0 | } break; |
544 | 0 | case EMPTY: |
545 | 0 | all_points.extend (phantoms); |
546 | 0 | shift = phantoms[PHANTOM_LEFT].x; |
547 | 0 | points.resize (old_length); |
548 | 0 | break; |
549 | 0 | } |
550 | | |
551 | 0 | if (depth == 0 && shift_points_hori) /* Apply at top level */ |
552 | 0 | { |
553 | | /* Undocumented rasterizer behavior: |
554 | | * Shift points horizontally by the updated left side bearing |
555 | | */ |
556 | 0 | if (shift) |
557 | 0 | for (auto &point : all_points) |
558 | 0 | point.x -= shift; |
559 | 0 | } |
560 | |
|
561 | 0 | return !all_points.in_error (); |
562 | 0 | } |
563 | | |
564 | | bool get_extents_without_var_scaled (hb_font_t *font, const glyf_accelerator_t &glyf_accelerator, |
565 | | hb_glyph_extents_t *extents) const |
566 | 0 | { |
567 | 0 | if (type == EMPTY) |
568 | 0 | { |
569 | 0 | *extents = {0, 0, 0, 0}; |
570 | 0 | return true; /* Empty glyph; zero extents. */ |
571 | 0 | } |
572 | 0 | return header->get_extents_without_var_scaled (font, glyf_accelerator, gid, extents); |
573 | 0 | } |
574 | | |
575 | 0 | hb_bytes_t get_bytes () const { return bytes; } |
576 | 0 | glyph_type_t get_type () const { return type; } |
577 | 0 | const GlyphHeader *get_header () const { return header; } |
578 | 0 | bool is_extended () const { return extended; } |
579 | | |
580 | 0 | Glyph () : bytes (), |
581 | 0 | header (bytes.as<GlyphHeader> ()), |
582 | 0 | gid (-1), |
583 | 0 | type(EMPTY), |
584 | 0 | extended (false) |
585 | 0 | {} |
586 | | |
587 | | Glyph (hb_bytes_t bytes_, |
588 | | hb_codepoint_t gid_, |
589 | 0 | bool extended_) : bytes (bytes_), |
590 | 0 | header (bytes.as<GlyphHeader> ()), |
591 | 0 | gid (gid_), |
592 | 0 | extended (extended_) |
593 | 0 | { |
594 | 0 | int num_contours = header->numberOfContours; |
595 | 0 | if (unlikely (num_contours == 0)) type = EMPTY; |
596 | 0 | else if (num_contours > 0) type = SIMPLE; |
597 | 0 | else if (num_contours <= -1) type = COMPOSITE; |
598 | 0 | else type = EMPTY; // Spec deviation; Spec says COMPOSITE, but not seen in the wild. |
599 | 0 | } |
600 | | |
601 | | protected: |
602 | | hb_bytes_t bytes; |
603 | | const GlyphHeader *header; |
604 | | hb_codepoint_t gid; |
605 | | glyph_type_t type; |
606 | | bool extended; |
607 | | }; |
608 | | |
609 | | |
610 | | } /* namespace glyf_impl */ |
611 | | } /* namespace OT */ |
612 | | |
613 | | |
614 | | #endif /* OT_GLYF_GLYPH_HH */ |