/work/workdir/UnpackedTarball/harfbuzz/src/hb-subset-plan.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2018 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): Garret Rieger, Roderick Sheeter |
25 | | */ |
26 | | |
27 | | #include "hb-subset-plan.hh" |
28 | | #include "hb-subset-accelerator.hh" |
29 | | #include "hb-map.hh" |
30 | | #include "hb-multimap.hh" |
31 | | #include "hb-set.hh" |
32 | | #include "hb-subset.h" |
33 | | #include "hb-unicode.h" |
34 | | |
35 | | #include "hb-ot-cmap-table.hh" |
36 | | #include "hb-ot-glyf-table.hh" |
37 | | #include "hb-ot-layout-base-table.hh" |
38 | | #include "hb-ot-cff1-table.hh" |
39 | | #include "hb-ot-cff2-table.hh" |
40 | | #include "OT/Color/COLR/COLR.hh" |
41 | | #include "OT/Color/COLR/colrv1-closure.hh" |
42 | | #include "OT/Color/CPAL/CPAL.hh" |
43 | | #include "hb-ot-var-fvar-table.hh" |
44 | | #include "hb-ot-var-varc-table.hh" |
45 | | #include "hb-ot-stat-table.hh" |
46 | | #include "hb-ot-math-table.hh" |
47 | | |
48 | | hb_subset_accelerator_t::~hb_subset_accelerator_t () |
49 | 0 | { |
50 | 0 | if (cmap_cache && destroy_cmap_cache) |
51 | 0 | destroy_cmap_cache ((void*) cmap_cache); |
52 | |
|
53 | 0 | #ifndef HB_NO_SUBSET_CFF |
54 | 0 | cff1_accel.fini (); |
55 | 0 | cff2_accel.fini (); |
56 | 0 | #endif |
57 | 0 | hb_face_destroy (source); |
58 | 0 | } |
59 | | |
60 | | |
61 | | #ifndef HB_NO_SUBSET_CFF |
62 | | static inline bool |
63 | | _add_cff_seac_components (const OT::cff1::accelerator_subset_t &cff, |
64 | | hb_codepoint_t gid, |
65 | | hb_set_t *gids_to_retain) |
66 | 0 | { |
67 | 0 | hb_codepoint_t base_gid, accent_gid; |
68 | 0 | if (cff.get_seac_components (gid, &base_gid, &accent_gid)) |
69 | 0 | { |
70 | 0 | gids_to_retain->add (base_gid); |
71 | 0 | gids_to_retain->add (accent_gid); |
72 | 0 | return true; |
73 | 0 | } |
74 | 0 | return false; |
75 | 0 | } |
76 | | #endif |
77 | | |
78 | | static void |
79 | | _remap_palette_indexes (const hb_set_t *palette_indexes, |
80 | | hb_map_t *mapping /* OUT */) |
81 | 0 | { |
82 | 0 | unsigned new_idx = 0; |
83 | 0 | for (unsigned palette_index : palette_indexes->iter ()) |
84 | 0 | { |
85 | 0 | if (palette_index == 0xFFFF) |
86 | 0 | { |
87 | 0 | mapping->set (palette_index, palette_index); |
88 | 0 | continue; |
89 | 0 | } |
90 | 0 | mapping->set (palette_index, new_idx); |
91 | 0 | new_idx++; |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | | void |
96 | | remap_indexes (const hb_set_t *indexes, |
97 | | hb_map_t *mapping /* OUT */) |
98 | 0 | { |
99 | 0 | for (auto _ : + hb_enumerate (indexes->iter ())) |
100 | 0 | mapping->set (_.second, _.first); |
101 | 0 | } |
102 | | |
103 | | static inline void |
104 | | _cmap_closure (hb_face_t *face, |
105 | | const hb_set_t *unicodes, |
106 | | hb_set_t *glyphset) |
107 | 20.3k | { |
108 | 20.3k | OT::cmap_accelerator_t cmap (face); |
109 | 20.3k | cmap.closure_glyphs (unicodes, glyphset); |
110 | 20.3k | } |
111 | | |
112 | | static void _colr_closure (hb_subset_plan_t* plan, |
113 | | hb_set_t *glyphs_colred) |
114 | 0 | { |
115 | 0 | OT::COLR::accelerator_t colr (plan->source); |
116 | 0 | if (!colr.is_valid ()) return; |
117 | | |
118 | 0 | hb_set_t palette_indices, layer_indices; |
119 | | // Collect all glyphs referenced by COLRv0 |
120 | 0 | hb_set_t glyphset_colrv0; |
121 | 0 | for (hb_codepoint_t gid : *glyphs_colred) |
122 | 0 | colr.closure_glyphs (gid, &glyphset_colrv0); |
123 | |
|
124 | 0 | glyphs_colred->union_ (glyphset_colrv0); |
125 | | |
126 | | //closure for COLRv1 |
127 | 0 | hb_set_t variation_indices, delta_set_indices; |
128 | 0 | colr.closure_forV1 (glyphs_colred, &layer_indices, &palette_indices, &variation_indices, &delta_set_indices); |
129 | |
|
130 | 0 | colr.closure_V0palette_indices (glyphs_colred, &palette_indices); |
131 | 0 | remap_indexes (&layer_indices, &plan->colrv1_layers); |
132 | 0 | _remap_palette_indexes (&palette_indices, &plan->colr_palettes); |
133 | |
|
134 | 0 | #ifndef HB_NO_VAR |
135 | | /* colr variation indices mapping during planning phase: |
136 | | * generate colrv1_variation_idx_delta_map. When delta set index map is not |
137 | | * included, it's a mapping from varIdx-> (new varIdx,delta). Otherwise, it's |
138 | | * a mapping from old delta set idx-> (new delta set idx, delta). Mapping |
139 | | * delta set indices is the same as gid mapping. |
140 | | * Besides, we need to generate a delta set idx-> new var_idx map for updating |
141 | | * delta set index map if exists. This map will be updated again after |
142 | | * instancing. */ |
143 | 0 | if (colr.has_var_store () && variation_indices) |
144 | 0 | { |
145 | 0 | const OT::ItemVariationStore &var_store = colr.get_var_store (); |
146 | | // generated inner_maps is used by ItemVariationStore serialize(), which is subset only |
147 | 0 | unsigned subtable_count = var_store.get_sub_table_count (); |
148 | 0 | generate_varstore_inner_maps (variation_indices, subtable_count, plan->colrv1_varstore_inner_maps); |
149 | |
|
150 | 0 | if (!plan->all_axes_pinned) |
151 | 0 | remap_variation_indices (var_store, |
152 | 0 | variation_indices, |
153 | 0 | plan->normalized_coords, |
154 | 0 | false, /* no need to calculate delta for COLR during planning */ |
155 | 0 | plan->all_axes_pinned, |
156 | 0 | plan->colrv1_variation_idx_delta_map); |
157 | 0 | } |
158 | | |
159 | | /* Sentinel-only maps still need their delta-set indices remapped, even |
160 | | * when there are no live variation rows or no variation store. */ |
161 | 0 | if (!plan->all_axes_pinned && colr.has_delta_set_index_map ()) |
162 | 0 | remap_colrv1_delta_set_index_indices (colr.get_delta_set_index_map (), |
163 | 0 | delta_set_indices, |
164 | 0 | plan->colrv1_variation_idx_delta_map, |
165 | 0 | plan->colrv1_new_deltaset_idx_varidx_map); |
166 | 0 | #endif |
167 | 0 | } |
168 | | |
169 | | static inline void |
170 | | _math_closure (hb_subset_plan_t *plan, |
171 | | hb_set_t *glyphset) |
172 | 0 | { |
173 | 0 | hb_blob_ptr_t<OT::MATH> math = plan->source_table<OT::MATH> (); |
174 | 0 | if (math->has_data ()) |
175 | 0 | math->closure_glyphs (glyphset); |
176 | 0 | math.destroy (); |
177 | 0 | } |
178 | | |
179 | | static inline void |
180 | | _remove_invalid_gids (hb_set_t *glyphs, |
181 | | unsigned int num_glyphs) |
182 | 40.6k | { |
183 | 40.6k | glyphs->del_range (num_glyphs, HB_SET_VALUE_INVALID); |
184 | 40.6k | } |
185 | | |
186 | | template<bool GID_ALWAYS_EXISTS = false, typename I, typename F, typename G, hb_requires (hb_is_iterator (I))> |
187 | | static void |
188 | | _fill_unicode_and_glyph_map(hb_subset_plan_t *plan, |
189 | | I unicode_iterator, |
190 | | F unicode_to_gid_for_iterator, |
191 | | G unicode_to_gid_general) |
192 | 1.51M | { |
193 | 1.51M | for (hb_codepoint_t cp : unicode_iterator) |
194 | 208M | { |
195 | 208M | hb_codepoint_t gid = unicode_to_gid_for_iterator(cp); |
196 | 208M | if (!GID_ALWAYS_EXISTS && gid == HB_MAP_VALUE_INVALID) |
197 | 200M | { |
198 | 200M | DEBUG_MSG(SUBSET, nullptr, "Drop U+%04X; no gid", cp); |
199 | 200M | continue; |
200 | 200M | } |
201 | | |
202 | 7.71M | plan->codepoint_to_glyph->set (cp, gid); |
203 | 7.71M | plan->unicode_to_new_gid_list.push (hb_pair (cp, gid)); |
204 | 7.71M | } |
205 | 1.51M | } Unexecuted instantiation: hb-subset-plan.cc:_ZL27_fill_unicode_and_glyph_mapILb0EN23hb_bit_set_invertible_t6iter_tEZL28_populate_unicodes_to_retainPK8hb_set_tS4_P16hb_subset_plan_tE3$_0S7_TnPN12hb_enable_ifIXsr17hb_is_iterator_ofIT0_NS9_6item_tEEE5valueEvE4typeELPv0EEvS6_S9_T1_T2_ Unexecuted instantiation: hb-subset-plan.cc:_ZL27_fill_unicode_and_glyph_mapILb0EN23hb_bit_set_invertible_t6iter_tEZL28_populate_unicodes_to_retainPK8hb_set_tS4_P16hb_subset_plan_tE3$_1S7_TnPN12hb_enable_ifIXsr17hb_is_iterator_ofIT0_NS9_6item_tEEE5valueEvE4typeELPv0EEvS6_S9_T1_T2_ Unexecuted instantiation: hb-subset-plan.cc:_ZL27_fill_unicode_and_glyph_mapILb1E10hb_array_tIKjEZL28_populate_unicodes_to_retainPK8hb_set_tS5_P16hb_subset_plan_tE3$_2ZL28_populate_unicodes_to_retainS5_S5_S7_E3$_3TnPN12hb_enable_ifIXsr17hb_is_iterator_ofIT0_NSB_6item_tEEE5valueEvE4typeELPv0EEvS7_SB_T1_T2_ Unexecuted instantiation: hb-subset-plan.cc:_ZL27_fill_unicode_and_glyph_mapILb0EN23hb_bit_set_invertible_t6iter_tEZL28_populate_unicodes_to_retainPK8hb_set_tS4_P16hb_subset_plan_tE3$_4ZL28_populate_unicodes_to_retainS4_S4_S6_E3$_5TnPN12hb_enable_ifIXsr17hb_is_iterator_ofIT0_NSA_6item_tEEE5valueEvE4typeELPv0EEvS6_SA_T1_T2_ hb-subset-plan.cc:_ZL27_fill_unicode_and_glyph_mapILb0E15hb_range_iter_tIjjEZL28_populate_unicodes_to_retainPK8hb_set_tS4_P16hb_subset_plan_tE3$_6ZL28_populate_unicodes_to_retainS4_S4_S6_E3$_7TnPN12hb_enable_ifIXsr17hb_is_iterator_ofIT0_NSA_6item_tEEE5valueEvE4typeELPv0EEvS6_SA_T1_T2_ Line | Count | Source | 192 | 1.51M | { | 193 | 1.51M | for (hb_codepoint_t cp : unicode_iterator) | 194 | 208M | { | 195 | 208M | hb_codepoint_t gid = unicode_to_gid_for_iterator(cp); | 196 | 208M | if (!GID_ALWAYS_EXISTS && gid == HB_MAP_VALUE_INVALID) | 197 | 200M | { | 198 | 200M | DEBUG_MSG(SUBSET, nullptr, "Drop U+%04X; no gid", cp); | 199 | 200M | continue; | 200 | 200M | } | 201 | | | 202 | 7.71M | plan->codepoint_to_glyph->set (cp, gid); | 203 | 7.71M | plan->unicode_to_new_gid_list.push (hb_pair (cp, gid)); | 204 | 7.71M | } | 205 | 1.51M | } |
|
206 | | |
207 | | template<bool GID_ALWAYS_EXISTS = false, typename I, typename F, hb_requires (hb_is_iterator (I))> |
208 | | static void |
209 | | _fill_unicode_and_glyph_map(hb_subset_plan_t *plan, |
210 | | I unicode_iterator, |
211 | | F unicode_to_gid_for_iterator) |
212 | 0 | { |
213 | 0 | _fill_unicode_and_glyph_map(plan, unicode_iterator, unicode_to_gid_for_iterator, unicode_to_gid_for_iterator); |
214 | 0 | } Unexecuted instantiation: hb-subset-plan.cc:_ZL27_fill_unicode_and_glyph_mapILb0EN23hb_bit_set_invertible_t6iter_tEZL28_populate_unicodes_to_retainPK8hb_set_tS4_P16hb_subset_plan_tE3$_0TnPN12hb_enable_ifIXsr17hb_is_iterator_ofIT0_NS9_6item_tEEE5valueEvE4typeELPv0EEvS6_S9_T1_ Unexecuted instantiation: hb-subset-plan.cc:_ZL27_fill_unicode_and_glyph_mapILb0EN23hb_bit_set_invertible_t6iter_tEZL28_populate_unicodes_to_retainPK8hb_set_tS4_P16hb_subset_plan_tE3$_1TnPN12hb_enable_ifIXsr17hb_is_iterator_ofIT0_NS9_6item_tEEE5valueEvE4typeELPv0EEvS6_S9_T1_ |
215 | | |
216 | | /* |
217 | | * Finds additional unicode codepoints which are reachable from the input unicode set. |
218 | | * Currently this adds in mirrored variants (needed for bidi) of any input unicodes. |
219 | | */ |
220 | | static hb_set_t |
221 | 20.3k | _unicode_closure (const hb_set_t* unicodes, bool bidi_closure) { |
222 | | // TODO: we may want to also consider pulling in reachable unicode composition and decompositions. |
223 | | // see: https://github.com/harfbuzz/harfbuzz/issues/2283 |
224 | 20.3k | hb_set_t out = *unicodes; |
225 | 20.3k | if (!bidi_closure) return out; |
226 | | |
227 | 20.3k | if (out.is_inverted()) { |
228 | | // don't closure inverted sets, they are asking to specifically exclude certain codepoints. |
229 | | // otherwise everything is already included. |
230 | 0 | return out; |
231 | 0 | } |
232 | | |
233 | 20.3k | auto unicode_funcs = hb_unicode_funcs_get_default (); |
234 | 20.3k | for (hb_codepoint_t cp : *unicodes) { |
235 | 0 | hb_codepoint_t mirror = hb_unicode_mirroring(unicode_funcs, cp); |
236 | 0 | if (unlikely (mirror != cp)) { |
237 | 0 | out.add(mirror); |
238 | 0 | } |
239 | 0 | } |
240 | | |
241 | 20.3k | return out; |
242 | 20.3k | } |
243 | | |
244 | | static void |
245 | | _populate_unicodes_to_retain (const hb_set_t *unicodes_in, |
246 | | const hb_set_t *glyphs, |
247 | | hb_subset_plan_t *plan) |
248 | 20.3k | { |
249 | 20.3k | hb_set_t unicodes = _unicode_closure(unicodes_in, |
250 | 20.3k | !(plan->flags & HB_SUBSET_FLAGS_NO_BIDI_CLOSURE)); |
251 | | |
252 | 20.3k | OT::cmap_accelerator_t cmap (plan->source); |
253 | 20.3k | unsigned size_threshold = plan->source->get_num_glyphs (); |
254 | | |
255 | 20.3k | if (glyphs->is_empty () && unicodes.get_population () < size_threshold) |
256 | 0 | { |
257 | |
|
258 | 0 | const hb_map_t* unicode_to_gid = nullptr; |
259 | 0 | if (plan->accelerator) |
260 | 0 | unicode_to_gid = &plan->accelerator->unicode_to_gid; |
261 | | |
262 | | // This is approach to collection is faster, but can only be used if glyphs |
263 | | // are not being explicitly added to the subset and the input unicodes set is |
264 | | // not excessively large (eg. an inverted set). |
265 | 0 | plan->unicode_to_new_gid_list.alloc (unicodes.get_population ()); |
266 | 0 | if (!unicode_to_gid) { |
267 | 0 | _fill_unicode_and_glyph_map(plan, unicodes.iter(), [&] (hb_codepoint_t cp) { |
268 | 0 | hb_codepoint_t gid; |
269 | 0 | if (!cmap.get_nominal_glyph (cp, &gid)) { |
270 | 0 | return HB_MAP_VALUE_INVALID; |
271 | 0 | } |
272 | 0 | return gid; |
273 | 0 | }); |
274 | 0 | } else { |
275 | | // Use in memory unicode to gid map it's faster then looking up from |
276 | | // the map. This code is mostly duplicated from above to avoid doing |
277 | | // conditionals on the presence of the unicode_to_gid map each |
278 | | // iteration. |
279 | 0 | _fill_unicode_and_glyph_map(plan, unicodes.iter(), [&] (hb_codepoint_t cp) { |
280 | 0 | return unicode_to_gid->get (cp); |
281 | 0 | }); |
282 | 0 | } |
283 | 0 | } |
284 | 20.3k | else |
285 | 20.3k | { |
286 | | // This approach is slower, but can handle adding in glyphs to the subset and will match |
287 | | // them with cmap entries. |
288 | | |
289 | 20.3k | hb_map_t unicode_glyphid_map_storage; |
290 | 20.3k | hb_set_t cmap_unicodes_storage; |
291 | 20.3k | const hb_map_t* unicode_glyphid_map = &unicode_glyphid_map_storage; |
292 | 20.3k | const hb_set_t* cmap_unicodes = &cmap_unicodes_storage; |
293 | | |
294 | 20.3k | if (!plan->accelerator) { |
295 | 20.3k | cmap.collect_mapping (&cmap_unicodes_storage, &unicode_glyphid_map_storage); |
296 | 20.3k | plan->unicode_to_new_gid_list.alloc (hb_min(unicodes.get_population () |
297 | 20.3k | + glyphs->get_population (), |
298 | 20.3k | cmap_unicodes->get_population ())); |
299 | 20.3k | } else { |
300 | 0 | unicode_glyphid_map = &plan->accelerator->unicode_to_gid; |
301 | 0 | cmap_unicodes = &plan->accelerator->unicodes; |
302 | 0 | } |
303 | | |
304 | 20.3k | if (plan->accelerator && |
305 | 0 | unicodes.get_population () < cmap_unicodes->get_population () && |
306 | 0 | glyphs->get_population () < cmap_unicodes->get_population ()) |
307 | 0 | { |
308 | 0 | plan->codepoint_to_glyph->alloc (unicodes.get_population () + glyphs->get_population ()); |
309 | |
|
310 | 0 | auto &gid_to_unicodes = plan->accelerator->gid_to_unicodes; |
311 | |
|
312 | 0 | for (hb_codepoint_t gid : *glyphs) |
313 | 0 | { |
314 | 0 | auto unicodes = gid_to_unicodes.get (gid); |
315 | 0 | _fill_unicode_and_glyph_map<true>(plan, unicodes, [&] (hb_codepoint_t cp) { |
316 | 0 | return gid; |
317 | 0 | }, |
318 | 0 | [&] (hb_codepoint_t cp) { |
319 | 0 | return unicode_glyphid_map->get(cp); |
320 | 0 | }); |
321 | 0 | } |
322 | |
|
323 | 0 | _fill_unicode_and_glyph_map(plan, unicodes.iter(), [&] (hb_codepoint_t cp) { |
324 | | /* Don't double-add entry. */ |
325 | 0 | if (plan->codepoint_to_glyph->has (cp)) |
326 | 0 | return HB_MAP_VALUE_INVALID; |
327 | | |
328 | 0 | return unicode_glyphid_map->get(cp); |
329 | 0 | }, |
330 | 0 | [&] (hb_codepoint_t cp) { |
331 | 0 | return unicode_glyphid_map->get(cp); |
332 | 0 | }); |
333 | |
|
334 | 0 | plan->unicode_to_new_gid_list.qsort (); |
335 | 0 | } |
336 | 20.3k | else |
337 | 20.3k | { |
338 | 20.3k | plan->codepoint_to_glyph->alloc (cmap_unicodes->get_population ()); |
339 | 20.3k | hb_codepoint_t first = HB_SET_VALUE_INVALID, last = HB_SET_VALUE_INVALID; |
340 | 1.53M | for (; cmap_unicodes->next_range (&first, &last); ) |
341 | 1.51M | { |
342 | 208M | _fill_unicode_and_glyph_map(plan, hb_range(first, last + 1), [&] (hb_codepoint_t cp) { |
343 | 208M | hb_codepoint_t gid = (*unicode_glyphid_map)[cp]; |
344 | 208M | if (!unicodes.has (cp) && !glyphs->has (gid)) |
345 | 200M | return HB_MAP_VALUE_INVALID; |
346 | 7.71M | return gid; |
347 | 208M | }, |
348 | 1.51M | [&] (hb_codepoint_t cp) { |
349 | 1.51M | return unicode_glyphid_map->get(cp); |
350 | 1.51M | }); |
351 | 1.51M | } |
352 | 20.3k | } |
353 | | |
354 | | /* Add gids which where requested, but not mapped in cmap */ |
355 | 20.3k | unsigned num_glyphs = plan->source->get_num_glyphs (); |
356 | 20.3k | hb_codepoint_t first = HB_SET_VALUE_INVALID, last = HB_SET_VALUE_INVALID; |
357 | 186k | for (; glyphs->next_range (&first, &last); ) |
358 | 167k | { |
359 | 167k | if (first >= num_glyphs) |
360 | 1.19k | break; |
361 | 166k | if (last >= num_glyphs) |
362 | 135 | last = num_glyphs - 1; |
363 | 166k | plan->_glyphset_gsub.add_range (first, last); |
364 | 166k | } |
365 | 20.3k | } |
366 | | |
367 | 20.3k | auto &arr = plan->unicode_to_new_gid_list; |
368 | 20.3k | if (arr.length) |
369 | 12.3k | { |
370 | 12.3k | plan->unicodes.add_sorted_array (&arr.arrayZ->first, arr.length, sizeof (*arr.arrayZ)); |
371 | 12.3k | plan->_glyphset_gsub.add_array (&arr.arrayZ->second, arr.length, sizeof (*arr.arrayZ)); |
372 | 12.3k | } |
373 | | |
374 | | // Variation selectors don't have glyphs associated with them in the cmap so they will have been filtered out above |
375 | | // but should still be retained. Add them back here. |
376 | | |
377 | | // However, the min and max codepoints for OS/2 should be calculated without considering variation selectors, |
378 | | // so record those first. |
379 | 20.3k | plan->os2_info.min_cmap_codepoint = plan->unicodes.get_min(); |
380 | 20.3k | plan->os2_info.max_cmap_codepoint = plan->unicodes.get_max(); |
381 | | |
382 | 20.3k | hb_set_t variation_selectors_to_retain; |
383 | 20.3k | cmap.collect_variation_selectors(&variation_selectors_to_retain); |
384 | 20.3k | + variation_selectors_to_retain.iter() |
385 | 20.3k | | hb_filter(unicodes) |
386 | 20.3k | | hb_sink(&plan->unicodes) |
387 | 20.3k | ; |
388 | 20.3k | } |
389 | | |
390 | | static unsigned |
391 | | _glyf_add_gid_and_children (const OT::glyf_accelerator_t &glyf, |
392 | | hb_codepoint_t gid, |
393 | | hb_set_t *gids_to_retain, |
394 | | int operation_count, |
395 | | unsigned depth = 0) |
396 | 414k | { |
397 | | /* Check if is already visited */ |
398 | 414k | if (gids_to_retain->has (gid)) return operation_count; |
399 | | |
400 | 399k | gids_to_retain->add (gid); |
401 | | |
402 | 399k | if (unlikely (depth++ > HB_MAX_NESTING_LEVEL)) return operation_count; |
403 | 399k | if (unlikely (--operation_count < 0)) return operation_count; |
404 | | |
405 | 399k | auto glyph = glyf.glyph_for_gid (gid); |
406 | | |
407 | 399k | for (auto &item : glyph.get_composite_iterator ()) |
408 | 36.0k | operation_count = |
409 | 36.0k | _glyf_add_gid_and_children (glyf, |
410 | 36.0k | item.get_gid (glyph.is_extended ()), |
411 | 36.0k | gids_to_retain, |
412 | 36.0k | operation_count, |
413 | 36.0k | depth); |
414 | | |
415 | 399k | return operation_count; |
416 | 399k | } |
417 | | |
418 | | static void |
419 | | _nameid_closure (hb_subset_plan_t* plan, |
420 | | hb_set_t* drop_tables) |
421 | 20.3k | { |
422 | 20.3k | #ifndef HB_NO_STYLE |
423 | 20.3k | if (!drop_tables->has (HB_OT_TAG_STAT)) |
424 | 0 | plan->source->table.STAT->collect_name_ids (&plan->user_axes_location, &plan->name_ids); |
425 | 20.3k | #endif |
426 | 20.3k | #ifndef HB_NO_VAR |
427 | 20.3k | if (!plan->all_axes_pinned) |
428 | 20.3k | plan->source->table.fvar->collect_name_ids (&plan->user_axes_location, &plan->axes_old_index_tag_map, &plan->name_ids); |
429 | 20.3k | #endif |
430 | 20.3k | #ifndef HB_NO_COLOR |
431 | 20.3k | if (!drop_tables->has (HB_OT_TAG_CPAL)) |
432 | 0 | plan->source->table.CPAL->collect_name_ids (&plan->colr_palettes, &plan->name_ids); |
433 | 20.3k | #endif |
434 | | |
435 | 20.3k | #ifndef HB_NO_SUBSET_LAYOUT |
436 | 20.3k | layout_nameid_closure(plan, drop_tables); |
437 | 20.3k | #endif |
438 | 20.3k | } |
439 | | |
440 | | static void |
441 | | _populate_gids_to_retain (hb_subset_plan_t* plan, |
442 | | hb_set_t* drop_tables) |
443 | 20.3k | { |
444 | 20.3k | OT::glyf_accelerator_t glyf (plan->source); |
445 | 20.3k | #ifndef HB_NO_SUBSET_CFF |
446 | | // Note: we cannot use inprogress_accelerator here, since it has not been |
447 | | // created yet. So in case of preprocessed-face (and otherwise), we do an |
448 | | // extra sanitize pass here, which is not ideal. |
449 | 20.3k | OT::cff1::accelerator_subset_t stack_cff (plan->accelerator ? nullptr : plan->source); |
450 | 20.3k | const OT::cff1::accelerator_subset_t *cff (plan->accelerator ? plan->accelerator->cff1_accel.get () : &stack_cff); |
451 | 20.3k | #endif |
452 | | |
453 | 20.3k | plan->_glyphset_gsub.add (0); // Not-def |
454 | | |
455 | 20.3k | _cmap_closure (plan->source, &plan->unicodes, &plan->_glyphset_gsub); |
456 | 20.3k | plan->_glyphset_cmaped = plan->_glyphset_gsub; |
457 | | |
458 | 20.3k | if (!drop_tables->has (HB_OT_TAG_MATH)) |
459 | 0 | { |
460 | 0 | _math_closure (plan, &plan->_glyphset_gsub); |
461 | 0 | _remove_invalid_gids (&plan->_glyphset_gsub, plan->source->get_num_glyphs ()); |
462 | 0 | } |
463 | 20.3k | plan->_glyphset_mathed = plan->_glyphset_gsub; |
464 | | |
465 | 20.3k | #ifndef HB_NO_SUBSET_LAYOUT |
466 | 20.3k | layout_populate_gids_to_retain(plan, drop_tables); |
467 | 20.3k | #endif |
468 | | |
469 | 20.3k | _remove_invalid_gids (&plan->_glyphset_gsub, plan->source->get_num_glyphs ()); |
470 | | |
471 | 20.3k | hb_set_t cur_glyphset = plan->_glyphset_gsub; |
472 | 20.3k | if (!drop_tables->has (HB_OT_TAG_COLR)) |
473 | 0 | { |
474 | 0 | _colr_closure (plan, &cur_glyphset); |
475 | 0 | _remove_invalid_gids (&cur_glyphset, plan->source->get_num_glyphs ()); |
476 | 0 | } |
477 | | |
478 | 20.3k | plan->_glyphset_colred = cur_glyphset; |
479 | | |
480 | 20.3k | #ifndef HB_NO_VAR_COMPOSITES |
481 | 20.3k | if (!drop_tables->has (OT::VARC::tableTag)) |
482 | 0 | { |
483 | 0 | if (unlikely (!plan->source->table.VARC->closure_glyphs (&cur_glyphset))) |
484 | 0 | { |
485 | 0 | plan->check_success (false); |
486 | 0 | return; |
487 | 0 | } |
488 | 0 | _remove_invalid_gids (&cur_glyphset, plan->source->get_num_glyphs ()); |
489 | 0 | } |
490 | 20.3k | #endif |
491 | | |
492 | 20.3k | plan->_glyphset_varced = cur_glyphset; |
493 | | |
494 | 20.3k | _nameid_closure (plan, drop_tables); |
495 | | /* Populate a full set of glyphs to retain by adding all referenced |
496 | | * composite glyphs. */ |
497 | 20.3k | if (glyf.has_data ()) |
498 | 19.5k | for (hb_codepoint_t gid : cur_glyphset) |
499 | 378k | _glyf_add_gid_and_children (glyf, gid, &plan->_glyphset, |
500 | 378k | cur_glyphset.get_population () * HB_MAX_COMPOSITE_OPERATIONS_PER_GLYPH); |
501 | 775 | else |
502 | 775 | plan->_glyphset.union_ (cur_glyphset); |
503 | 20.3k | #ifndef HB_NO_SUBSET_CFF |
504 | 20.3k | if (!plan->accelerator || plan->accelerator->has_seac) |
505 | 20.3k | { |
506 | 20.3k | bool has_seac = false; |
507 | 20.3k | if (cff->is_valid ()) |
508 | 0 | for (hb_codepoint_t gid : cur_glyphset) |
509 | 0 | if (_add_cff_seac_components (*cff, gid, &plan->_glyphset)) |
510 | 0 | has_seac = true; |
511 | 20.3k | plan->has_seac = has_seac; |
512 | 20.3k | } |
513 | 20.3k | #endif |
514 | | |
515 | 20.3k | _remove_invalid_gids (&plan->_glyphset, plan->source->get_num_glyphs ()); |
516 | | |
517 | 20.3k | #ifndef HB_NO_VAR |
518 | 20.3k | #ifndef HB_NO_SUBSET_LAYOUT |
519 | 20.3k | if (!drop_tables->has (HB_OT_TAG_GDEF)) |
520 | 0 | collect_layout_variation_indices (plan); |
521 | 20.3k | #endif |
522 | 20.3k | #endif |
523 | 20.3k | } |
524 | | |
525 | | static bool |
526 | | _create_glyph_map_gsub (const hb_set_t* glyph_set_gsub, |
527 | | const hb_map_t* glyph_map, |
528 | | hb_map_t* out, |
529 | | hb_vector_t<hb_codepoint_t>* out_flat) |
530 | 20.3k | { |
531 | 20.3k | if (unlikely (glyph_set_gsub->in_error ())) |
532 | 0 | return false; |
533 | | |
534 | 20.3k | hb_codepoint_t max_gid = HB_SET_VALUE_INVALID; |
535 | 20.3k | hb_set_previous (glyph_set_gsub, &max_gid); |
536 | 20.3k | unsigned flat_size = max_gid == HB_SET_VALUE_INVALID ? 0 : max_gid + 1; |
537 | 20.3k | if (unlikely (!out_flat->resize_dirty (flat_size))) |
538 | 0 | return false; |
539 | 20.3k | hb_memset (out_flat->arrayZ, 0xFF, flat_size * sizeof (hb_codepoint_t)); |
540 | | |
541 | 20.3k | out->alloc (glyph_set_gsub->get_population ()); |
542 | 20.3k | for (auto gid : *glyph_set_gsub) |
543 | 381k | { |
544 | 381k | hb_codepoint_t new_gid = glyph_map->get (gid); |
545 | 381k | out->set (gid, new_gid); |
546 | 381k | out_flat->arrayZ[gid] = new_gid; |
547 | 381k | } |
548 | 20.3k | return !out->in_error (); |
549 | 20.3k | } |
550 | | |
551 | | static bool |
552 | | _create_old_gid_to_new_gid_map (const hb_face_t *face, |
553 | | bool retain_gids, |
554 | | const hb_set_t *all_gids_to_retain, |
555 | | const hb_map_t *requested_glyph_map, |
556 | | hb_map_t *glyph_map, /* OUT */ |
557 | | hb_map_t *reverse_glyph_map, /* OUT */ |
558 | | hb_sorted_vector_t<hb_codepoint_pair_t> *new_to_old_gid_list /* OUT */, |
559 | | unsigned int *num_glyphs /* OUT */) |
560 | 20.3k | { |
561 | 20.3k | unsigned pop = all_gids_to_retain->get_population (); |
562 | 20.3k | reverse_glyph_map->alloc (pop); |
563 | 20.3k | glyph_map->alloc (pop); |
564 | 20.3k | new_to_old_gid_list->alloc (pop); |
565 | | |
566 | 20.3k | if (*requested_glyph_map) |
567 | 20.3k | { |
568 | 20.3k | hb_set_t new_gids(requested_glyph_map->values()); |
569 | 20.3k | if (new_gids.get_population() != requested_glyph_map->get_population()) |
570 | 0 | { |
571 | 0 | DEBUG_MSG (SUBSET, nullptr, "The provided custom glyph mapping is not unique."); |
572 | 0 | return false; |
573 | 0 | } |
574 | | |
575 | 20.3k | if (retain_gids) |
576 | 0 | { |
577 | 0 | DEBUG_MSG (SUBSET, nullptr, |
578 | 0 | "HB_SUBSET_FLAGS_RETAIN_GIDS cannot be set if " |
579 | 0 | "a custom glyph mapping has been provided."); |
580 | 0 | return false; |
581 | 0 | } |
582 | | |
583 | 20.3k | hb_codepoint_t max_glyph = 0; |
584 | 20.3k | hb_set_t remaining; |
585 | 20.3k | for (auto old_gid : all_gids_to_retain->iter ()) |
586 | 401k | { |
587 | 401k | if (old_gid == 0) { |
588 | 20.3k | new_to_old_gid_list->push (hb_pair<hb_codepoint_t, hb_codepoint_t> (0u, 0u)); |
589 | 20.3k | continue; |
590 | 20.3k | } |
591 | | |
592 | 381k | hb_codepoint_t* new_gid; |
593 | 381k | if (!requested_glyph_map->has (old_gid, &new_gid)) |
594 | 20.3k | { |
595 | 20.3k | remaining.add(old_gid); |
596 | 20.3k | continue; |
597 | 20.3k | } |
598 | | |
599 | 360k | if (*new_gid > max_glyph) |
600 | 49.0k | max_glyph = *new_gid; |
601 | 360k | new_to_old_gid_list->push (hb_pair (*new_gid, old_gid)); |
602 | 360k | } |
603 | 20.3k | new_to_old_gid_list->qsort (); |
604 | | |
605 | | // Anything that wasn't mapped by the requested mapping should |
606 | | // be placed after the requested mapping. |
607 | 20.3k | for (auto old_gid : remaining) |
608 | 20.3k | new_to_old_gid_list->push (hb_pair (++max_glyph, old_gid)); |
609 | | |
610 | 20.3k | *num_glyphs = max_glyph + 1; |
611 | 20.3k | } |
612 | 0 | else if (!retain_gids) |
613 | 0 | { |
614 | 0 | + hb_enumerate (hb_iter (all_gids_to_retain), (hb_codepoint_t) 0) |
615 | 0 | | hb_sink (new_to_old_gid_list) |
616 | 0 | ; |
617 | 0 | *num_glyphs = new_to_old_gid_list->length; |
618 | 0 | } |
619 | 0 | else |
620 | 0 | { |
621 | 0 | + hb_iter (all_gids_to_retain) |
622 | 0 | | hb_map ([] (hb_codepoint_t _) { |
623 | 0 | return hb_codepoint_pair_t (_, _); |
624 | 0 | }) |
625 | 0 | | hb_sink (new_to_old_gid_list) |
626 | 0 | ; |
627 | |
|
628 | 0 | hb_codepoint_t max_glyph = HB_SET_VALUE_INVALID; |
629 | 0 | hb_set_previous (all_gids_to_retain, &max_glyph); |
630 | |
|
631 | 0 | *num_glyphs = max_glyph + 1; |
632 | 0 | } |
633 | | |
634 | 20.3k | reverse_glyph_map->alloc (reverse_glyph_map->get_population () + new_to_old_gid_list->length); |
635 | 20.3k | + hb_iter (new_to_old_gid_list) |
636 | 20.3k | | hb_sink (reverse_glyph_map) |
637 | 20.3k | ; |
638 | 20.3k | glyph_map->alloc (glyph_map->get_population () + new_to_old_gid_list->length); |
639 | 20.3k | + hb_iter (new_to_old_gid_list) |
640 | 20.3k | | hb_map (&hb_codepoint_pair_t::reverse) |
641 | 20.3k | | hb_sink (glyph_map) |
642 | 20.3k | ; |
643 | | |
644 | 20.3k | return true; |
645 | 20.3k | } |
646 | | |
647 | | hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face, |
648 | | const hb_subset_input_t *input) |
649 | 20.3k | { |
650 | 20.3k | successful = true; |
651 | 20.3k | flags = input->flags; |
652 | | |
653 | 20.3k | unicode_to_new_gid_list.init (); |
654 | | |
655 | 20.3k | name_ids = *input->sets.name_ids; |
656 | 20.3k | name_languages = *input->sets.name_languages; |
657 | 20.3k | layout_features = *input->sets.layout_features; |
658 | 20.3k | layout_scripts = *input->sets.layout_scripts; |
659 | 20.3k | glyphs_requested = *input->sets.glyphs; |
660 | 20.3k | drop_tables = *input->sets.drop_tables; |
661 | 20.3k | no_subset_tables = *input->sets.no_subset_tables; |
662 | 20.3k | source = hb_face_reference (face); |
663 | 20.3k | dest = hb_face_builder_create (); |
664 | | |
665 | 20.3k | codepoint_to_glyph = hb_map_create (); |
666 | 20.3k | glyph_map = hb_map_create (); |
667 | 20.3k | reverse_glyph_map = hb_map_create (); |
668 | | |
669 | 20.3k | gsub_insert_catch_all_feature_variation_rec = false; |
670 | 20.3k | gpos_insert_catch_all_feature_variation_rec = false; |
671 | 20.3k | gdef_varstore_inner_maps.init (); |
672 | | |
673 | 20.3k | user_axes_location = input->axes_location; |
674 | 20.3k | all_axes_pinned = false; |
675 | 20.3k | pinned_at_default = true; |
676 | 20.3k | has_gdef_varstore = false; |
677 | 20.3k | has_avar2 = false; |
678 | | |
679 | | #ifdef HB_EXPERIMENTAL_API |
680 | | for (auto _ : input->name_table_overrides) |
681 | | { |
682 | | hb_bytes_t name_bytes = _.second; |
683 | | unsigned len = name_bytes.length; |
684 | | char *name_str = (char *) hb_malloc (len); |
685 | | if (unlikely (!check_success (name_str))) |
686 | | break; |
687 | | |
688 | | hb_memcpy (name_str, name_bytes.arrayZ, len); |
689 | | name_table_overrides.set (_.first, hb_bytes_t (name_str, len)); |
690 | | } |
691 | | #endif |
692 | | |
693 | 20.3k | void* accel = hb_face_get_user_data(face, hb_subset_accelerator_t::user_data_key()); |
694 | | |
695 | 20.3k | attach_accelerator_data = input->attach_accelerator_data; |
696 | 20.3k | force_long_loca = input->force_long_loca; |
697 | | #ifdef HB_EXPERIMENTAL_API |
698 | | force_long_loca = force_long_loca || (flags & HB_SUBSET_FLAGS_IFTB_REQUIREMENTS); |
699 | | #endif |
700 | | |
701 | 20.3k | if (accel) |
702 | 0 | accelerator = (hb_subset_accelerator_t*) accel; |
703 | | |
704 | 20.3k | if (unlikely (in_error ())) |
705 | 0 | return; |
706 | | |
707 | 20.3k | #ifndef HB_NO_VAR_COMPOSITES |
708 | 20.3k | if (!input->sets.drop_tables->has (OT::VARC::tableTag) && |
709 | 0 | input->sets.no_subset_tables->has (OT::VARC::tableTag) && |
710 | 0 | !(input->flags & HB_SUBSET_FLAGS_RETAIN_GIDS) && |
711 | 0 | face->table.VARC->has_data ()) |
712 | 0 | { |
713 | 0 | check_success (false); |
714 | 0 | return; |
715 | 0 | } |
716 | 20.3k | #endif |
717 | | |
718 | 20.3k | #ifndef HB_NO_VAR |
719 | 20.3k | if (!check_success (normalize_axes_location (face, this))) |
720 | 0 | return; |
721 | 20.3k | #endif |
722 | 20.3k | #ifndef HB_NO_VAR_COMPOSITES |
723 | 20.3k | if (!user_axes_location.is_empty () && |
724 | 0 | !input->sets.drop_tables->has (OT::VARC::tableTag) && |
725 | 0 | input->sets.no_subset_tables->has (OT::VARC::tableTag) && |
726 | 0 | face->table.VARC->has_data ()) |
727 | 0 | { |
728 | 0 | check_success (false); |
729 | 0 | return; |
730 | 0 | } |
731 | 20.3k | #endif |
732 | | |
733 | 20.3k | _populate_unicodes_to_retain (input->sets.unicodes, input->sets.glyphs, this); |
734 | | |
735 | 20.3k | _populate_gids_to_retain (this, input->sets.drop_tables); |
736 | 20.3k | if (unlikely (in_error ())) |
737 | 0 | return; |
738 | | |
739 | 20.3k | if (!check_success(_create_old_gid_to_new_gid_map( |
740 | 20.3k | face, |
741 | 20.3k | input->flags & HB_SUBSET_FLAGS_RETAIN_GIDS, |
742 | 20.3k | &_glyphset, |
743 | 20.3k | &input->glyph_map, |
744 | 20.3k | glyph_map, |
745 | 20.3k | reverse_glyph_map, |
746 | 20.3k | &new_to_old_gid_list, |
747 | 20.3k | &_num_output_glyphs))) { |
748 | 0 | return; |
749 | 0 | } |
750 | | |
751 | | #ifdef HB_EXPERIMENTAL_API |
752 | | if ((input->flags & HB_SUBSET_FLAGS_RETAIN_GIDS) && |
753 | | (input->flags & HB_SUBSET_FLAGS_RETAIN_NUM_GLYPHS)) { |
754 | | // We've been requested to maintain the num glyphs count from the |
755 | | // input face. |
756 | | _num_output_glyphs = source->get_num_glyphs (); |
757 | | } |
758 | | #endif |
759 | | |
760 | 20.3k | if (!check_success (_create_glyph_map_gsub ( |
761 | 20.3k | &_glyphset_gsub, |
762 | 20.3k | glyph_map, |
763 | 20.3k | &glyph_map_gsub, |
764 | 20.3k | &glyph_map_gsub_flat))) |
765 | 0 | return; |
766 | | |
767 | | // Now that we have old to new gid map update the unicode to new gid list. |
768 | 7.73M | for (unsigned i = 0; i < unicode_to_new_gid_list.length; i++) |
769 | 7.71M | { |
770 | | // Use raw array access for performance. |
771 | 7.71M | unicode_to_new_gid_list.arrayZ[i].second = |
772 | 7.71M | glyph_map->get(unicode_to_new_gid_list.arrayZ[i].second); |
773 | 7.71M | } |
774 | | |
775 | 20.3k | bounds_width_vec.resize_dirty (_num_output_glyphs); |
776 | 20.3k | for (auto &v : bounds_width_vec) |
777 | 423k | v = 0xFFFFFFFF; |
778 | 20.3k | bounds_height_vec.resize_dirty (_num_output_glyphs); |
779 | 20.3k | for (auto &v : bounds_height_vec) |
780 | 423k | v = 0xFFFFFFFF; |
781 | | |
782 | 20.3k | #ifndef HB_NO_SUBSET_LAYOUT |
783 | 20.3k | if (!drop_tables.has (HB_OT_TAG_GDEF)) |
784 | 0 | remap_used_mark_sets (this, used_mark_sets_map); |
785 | 20.3k | #endif |
786 | | |
787 | 20.3k | #ifndef HB_NO_VAR |
788 | 20.3k | #ifndef HB_NO_BASE |
789 | 20.3k | if (!drop_tables.has (HB_OT_TAG_BASE)) |
790 | 0 | collect_base_variation_indices (this); |
791 | 20.3k | #endif |
792 | 20.3k | #endif |
793 | | |
794 | 20.3k | if (unlikely (in_error ())) |
795 | 0 | return; |
796 | | |
797 | 20.3k | #if !defined(HB_NO_VAR) && !defined(HB_NO_OT_FONT_CFF) |
798 | 20.3k | update_instance_metrics_map_from_cff2 (this); |
799 | 20.3k | #endif |
800 | 20.3k | #ifndef HB_NO_VAR |
801 | 20.3k | if (!check_success (get_instance_glyphs_contour_points (this))) |
802 | 0 | return; |
803 | 20.3k | #endif |
804 | | |
805 | 20.3k | if (attach_accelerator_data) |
806 | 0 | { |
807 | 0 | inprogress_accelerator = |
808 | 0 | hb_subset_accelerator_t::create (source, |
809 | 0 | *codepoint_to_glyph, |
810 | 0 | unicodes, |
811 | 0 | has_seac); |
812 | |
|
813 | 0 | check_success (inprogress_accelerator); |
814 | 0 | } |
815 | | |
816 | 1.32M | #define HB_SUBSET_PLAN_MEMBER(Type, Name) check_success (!Name.in_error ()); |
817 | 20.3k | #include "hb-subset-plan-member-list.hh" |
818 | 20.3k | #undef HB_SUBSET_PLAN_MEMBER |
819 | 20.3k | } |
820 | | |
821 | | hb_subset_plan_t::~hb_subset_plan_t() |
822 | 20.3k | { |
823 | 20.3k | hb_face_destroy (dest); |
824 | | |
825 | 20.3k | hb_map_destroy (codepoint_to_glyph); |
826 | 20.3k | hb_map_destroy (glyph_map); |
827 | 20.3k | hb_map_destroy (reverse_glyph_map); |
828 | 20.3k | #ifndef HB_NO_SUBSET_CFF |
829 | 20.3k | cff1_accel.fini (); |
830 | 20.3k | cff2_accel.fini (); |
831 | 20.3k | #endif |
832 | 20.3k | hb_face_destroy (source); |
833 | | |
834 | | #ifdef HB_EXPERIMENTAL_API |
835 | | for (auto _ : name_table_overrides.iter_ref ()) |
836 | | _.second.fini (); |
837 | | #endif |
838 | | |
839 | 20.3k | if (inprogress_accelerator) |
840 | 0 | hb_subset_accelerator_t::destroy ((void*) inprogress_accelerator); |
841 | 20.3k | } |
842 | | |
843 | | |
844 | | /** |
845 | | * hb_subset_plan_create_or_fail: |
846 | | * @face: font face to create the plan for. |
847 | | * @input: a #hb_subset_input_t input. |
848 | | * |
849 | | * Computes a plan for subsetting the supplied face according |
850 | | * to a provided input. The plan describes |
851 | | * which tables and glyphs should be retained. |
852 | | * |
853 | | * Return value: (transfer full): New subset plan. Destroy with |
854 | | * hb_subset_plan_destroy(). If there is a failure creating the plan |
855 | | * nullptr will be returned. |
856 | | * |
857 | | * Since: 4.0.0 |
858 | | **/ |
859 | | hb_subset_plan_t * |
860 | | hb_subset_plan_create_or_fail (hb_face_t *face, |
861 | | const hb_subset_input_t *input) |
862 | 20.3k | { |
863 | 20.3k | hb_subset_plan_t *plan; |
864 | 20.3k | if (unlikely (!(plan = hb_object_create<hb_subset_plan_t> (face, input)))) |
865 | 0 | return nullptr; |
866 | | |
867 | 20.3k | if (unlikely (plan->in_error ())) |
868 | 0 | { |
869 | 0 | hb_subset_plan_destroy (plan); |
870 | 0 | return nullptr; |
871 | 0 | } |
872 | | |
873 | 20.3k | return plan; |
874 | 20.3k | } |
875 | | |
876 | | /** |
877 | | * hb_subset_plan_destroy: |
878 | | * @plan: a #hb_subset_plan_t |
879 | | * |
880 | | * Decreases the reference count on @plan, and if it reaches zero, destroys |
881 | | * @plan, freeing all memory. |
882 | | * |
883 | | * Since: 4.0.0 |
884 | | **/ |
885 | | void |
886 | | hb_subset_plan_destroy (hb_subset_plan_t *plan) |
887 | 20.3k | { |
888 | 20.3k | if (!hb_object_destroy (plan)) return; |
889 | | |
890 | 20.3k | hb_free (plan); |
891 | 20.3k | } |
892 | | |
893 | | /** |
894 | | * hb_subset_plan_old_to_new_glyph_mapping: |
895 | | * @plan: a subsetting plan. |
896 | | * |
897 | | * Returns the mapping between glyphs in the original font to glyphs in the |
898 | | * subset that will be produced by @plan |
899 | | * |
900 | | * Return value: (transfer none): |
901 | | * A pointer to the #hb_map_t of the mapping. |
902 | | * |
903 | | * Since: 4.0.0 |
904 | | **/ |
905 | | hb_map_t * |
906 | | hb_subset_plan_old_to_new_glyph_mapping (const hb_subset_plan_t *plan) |
907 | 0 | { |
908 | 0 | return plan->glyph_map; |
909 | 0 | } |
910 | | |
911 | | /** |
912 | | * hb_subset_plan_new_to_old_glyph_mapping: |
913 | | * @plan: a subsetting plan. |
914 | | * |
915 | | * Returns the mapping between glyphs in the subset that will be produced by |
916 | | * @plan and the glyph in the original font. |
917 | | * |
918 | | * Return value: (transfer none): |
919 | | * A pointer to the #hb_map_t of the mapping. |
920 | | * |
921 | | * Since: 4.0.0 |
922 | | **/ |
923 | | hb_map_t * |
924 | | hb_subset_plan_new_to_old_glyph_mapping (const hb_subset_plan_t *plan) |
925 | 0 | { |
926 | 0 | return plan->reverse_glyph_map; |
927 | 0 | } |
928 | | |
929 | | /** |
930 | | * hb_subset_plan_unicode_to_old_glyph_mapping: |
931 | | * @plan: a subsetting plan. |
932 | | * |
933 | | * Returns the mapping between codepoints in the original font and the |
934 | | * associated glyph id in the original font. |
935 | | * |
936 | | * Return value: (transfer none): |
937 | | * A pointer to the #hb_map_t of the mapping. |
938 | | * |
939 | | * Since: 4.0.0 |
940 | | **/ |
941 | | hb_map_t * |
942 | | hb_subset_plan_unicode_to_old_glyph_mapping (const hb_subset_plan_t *plan) |
943 | 0 | { |
944 | 0 | return plan->codepoint_to_glyph; |
945 | 0 | } |
946 | | |
947 | | /** |
948 | | * hb_subset_plan_reference: (skip) |
949 | | * @plan: a #hb_subset_plan_t object. |
950 | | * |
951 | | * Increases the reference count on @plan. |
952 | | * |
953 | | * Return value: @plan. |
954 | | * |
955 | | * Since: 4.0.0 |
956 | | **/ |
957 | | hb_subset_plan_t * |
958 | | hb_subset_plan_reference (hb_subset_plan_t *plan) |
959 | 0 | { |
960 | 0 | return hb_object_reference (plan); |
961 | 0 | } |
962 | | |
963 | | /** |
964 | | * hb_subset_plan_set_user_data: (skip) |
965 | | * @plan: a #hb_subset_plan_t object. |
966 | | * @key: The user-data key to set |
967 | | * @data: A pointer to the user data |
968 | | * @destroy: (nullable): A callback to call when @data is not needed anymore |
969 | | * @replace: Whether to replace an existing data with the same key |
970 | | * |
971 | | * Attaches a user-data key/data pair to the given subset plan object. |
972 | | * |
973 | | * Return value: `true` if success, `false` otherwise |
974 | | * |
975 | | * Since: 4.0.0 |
976 | | **/ |
977 | | hb_bool_t |
978 | | hb_subset_plan_set_user_data (hb_subset_plan_t *plan, |
979 | | hb_user_data_key_t *key, |
980 | | void *data, |
981 | | hb_destroy_func_t destroy, |
982 | | hb_bool_t replace) |
983 | 0 | { |
984 | 0 | return hb_object_set_user_data (plan, key, data, destroy, replace); |
985 | 0 | } |
986 | | |
987 | | /** |
988 | | * hb_subset_plan_get_user_data: (skip) |
989 | | * @plan: a #hb_subset_plan_t object. |
990 | | * @key: The user-data key to query |
991 | | * |
992 | | * Fetches the user data associated with the specified key, |
993 | | * attached to the specified subset plan object. |
994 | | * |
995 | | * Return value: (transfer none): A pointer to the user data |
996 | | * |
997 | | * Since: 4.0.0 |
998 | | **/ |
999 | | void * |
1000 | | hb_subset_plan_get_user_data (const hb_subset_plan_t *plan, |
1001 | | hb_user_data_key_t *key) |
1002 | 0 | { |
1003 | 0 | return hb_object_get_user_data (plan, key); |
1004 | 0 | } |