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