/src/harfbuzz/src/hb-ot-cmap-table.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2014 Google, Inc. |
3 | | * |
4 | | * This is part of HarfBuzz, a text shaping library. |
5 | | * |
6 | | * Permission is hereby granted, without written agreement and without |
7 | | * license or royalty fees, to use, copy, modify, and distribute this |
8 | | * software and its documentation for any purpose, provided that the |
9 | | * above copyright notice and the following two paragraphs appear in |
10 | | * all copies of this software. |
11 | | * |
12 | | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
13 | | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
14 | | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
15 | | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
16 | | * DAMAGE. |
17 | | * |
18 | | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
19 | | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
20 | | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
21 | | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
22 | | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
23 | | * |
24 | | * Google Author(s): Behdad Esfahbod |
25 | | */ |
26 | | |
27 | | #ifndef HB_OT_CMAP_TABLE_HH |
28 | | #define HB_OT_CMAP_TABLE_HH |
29 | | |
30 | | #include "hb-ot-os2-table.hh" |
31 | | #include "hb-ot-shaper-arabic-pua.hh" |
32 | | #include "hb-open-type.hh" |
33 | | #include "hb-set.hh" |
34 | | #include "hb-cache.hh" |
35 | | |
36 | | /* |
37 | | * cmap -- Character to Glyph Index Mapping |
38 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/cmap |
39 | | */ |
40 | | #define HB_OT_TAG_cmap HB_TAG('c','m','a','p') |
41 | | |
42 | | namespace OT { |
43 | | |
44 | | |
45 | | struct CmapSubtableFormat0 |
46 | | { |
47 | | bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const |
48 | 15.5M | { |
49 | 15.5M | hb_codepoint_t gid = codepoint < 256 ? glyphIdArray[codepoint] : 0; |
50 | 15.5M | if (unlikely (!gid)) |
51 | 15.4M | return false; |
52 | 26.2k | *glyph = gid; |
53 | 26.2k | return true; |
54 | 15.5M | } |
55 | | |
56 | | unsigned get_language () const |
57 | 0 | { |
58 | 0 | return language; |
59 | 0 | } |
60 | | |
61 | | void collect_unicodes (hb_set_t *out) const |
62 | 203k | { |
63 | 52.3M | for (unsigned int i = 0; i < 256; i++) |
64 | 52.1M | if (glyphIdArray[i]) |
65 | 319k | out->add (i); |
66 | 203k | } |
67 | | |
68 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
69 | | hb_map_t *mapping /* OUT */) const |
70 | 0 | { |
71 | 0 | for (unsigned i = 0; i < 256; i++) |
72 | 0 | if (glyphIdArray[i]) |
73 | 0 | { |
74 | 0 | hb_codepoint_t glyph = glyphIdArray[i]; |
75 | 0 | unicodes->add (i); |
76 | 0 | mapping->set (i, glyph); |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | bool sanitize (hb_sanitize_context_t *c) const |
81 | 68.2k | { |
82 | 68.2k | TRACE_SANITIZE (this); |
83 | 68.2k | return_trace (c->check_struct (this)); |
84 | 68.2k | } |
85 | | |
86 | | protected: |
87 | | HBUINT16 format; /* Format number is set to 0. */ |
88 | | HBUINT16 length; /* Byte length of this subtable. */ |
89 | | HBUINT16 language; /* Ignore. */ |
90 | | HBUINT8 glyphIdArray[256];/* An array that maps character |
91 | | * code to glyph index values. */ |
92 | | public: |
93 | | DEFINE_SIZE_STATIC (6 + 256); |
94 | | }; |
95 | | |
96 | | struct CmapSubtableFormat4 |
97 | | { |
98 | | |
99 | | |
100 | | template<typename Iterator, |
101 | | typename Writer, |
102 | | hb_requires (hb_is_iterator (Iterator))> |
103 | | void to_ranges (Iterator it, Writer& range_writer) |
104 | 0 | { |
105 | 0 | hb_codepoint_t start_cp = 0, prev_run_start_cp = 0, run_start_cp = 0, end_cp = 0, last_gid = 0; |
106 | 0 | int run_length = 0 , delta = 0, prev_delta = 0; |
107 | 0 |
|
108 | 0 | enum { |
109 | 0 | FIRST_SUB_RANGE, |
110 | 0 | FOLLOWING_SUB_RANGE, |
111 | 0 | } mode; |
112 | 0 |
|
113 | 0 | while (it) { |
114 | 0 | // Start a new range |
115 | 0 | { |
116 | 0 | const auto& pair = *it; |
117 | 0 | start_cp = pair.first; |
118 | 0 | prev_run_start_cp = start_cp; |
119 | 0 | run_start_cp = start_cp; |
120 | 0 | end_cp = start_cp; |
121 | 0 | last_gid = pair.second; |
122 | 0 | run_length = 1; |
123 | 0 | prev_delta = 0; |
124 | 0 | } |
125 | 0 |
|
126 | 0 | delta = last_gid - start_cp; |
127 | 0 | mode = FIRST_SUB_RANGE; |
128 | 0 | it++; |
129 | 0 |
|
130 | 0 | while (it) { |
131 | 0 | // Process range |
132 | 0 | const auto& pair = *it; |
133 | 0 | hb_codepoint_t next_cp = pair.first; |
134 | 0 | hb_codepoint_t next_gid = pair.second; |
135 | 0 | if (next_cp != end_cp + 1) { |
136 | 0 | // Current range is over, stop processing. |
137 | 0 | break; |
138 | 0 | } |
139 | 0 |
|
140 | 0 | if (next_gid == last_gid + 1) { |
141 | 0 | // The current run continues. |
142 | 0 | end_cp = next_cp; |
143 | 0 | run_length++; |
144 | 0 | last_gid = next_gid; |
145 | 0 | it++; |
146 | 0 | continue; |
147 | 0 | } |
148 | 0 |
|
149 | 0 | // A new run is starting, decide if we want to commit the current run. |
150 | 0 | int split_cost = (mode == FIRST_SUB_RANGE) ? 8 : 16; |
151 | 0 | int run_cost = run_length * 2; |
152 | 0 | if (run_cost >= split_cost) { |
153 | 0 | commit_current_range(start_cp, |
154 | 0 | prev_run_start_cp, |
155 | 0 | run_start_cp, |
156 | 0 | end_cp, |
157 | 0 | delta, |
158 | 0 | prev_delta, |
159 | 0 | split_cost, |
160 | 0 | range_writer); |
161 | 0 | start_cp = next_cp; |
162 | 0 | } |
163 | 0 |
|
164 | 0 | // Start the new run |
165 | 0 | mode = FOLLOWING_SUB_RANGE; |
166 | 0 | prev_run_start_cp = run_start_cp; |
167 | 0 | run_start_cp = next_cp; |
168 | 0 | end_cp = next_cp; |
169 | 0 | prev_delta = delta; |
170 | 0 | delta = next_gid - run_start_cp; |
171 | 0 | run_length = 1; |
172 | 0 | last_gid = next_gid; |
173 | 0 | it++; |
174 | 0 | } |
175 | 0 |
|
176 | 0 | // Finalize range |
177 | 0 | commit_current_range (start_cp, |
178 | 0 | prev_run_start_cp, |
179 | 0 | run_start_cp, |
180 | 0 | end_cp, |
181 | 0 | delta, |
182 | 0 | prev_delta, |
183 | 0 | 8, |
184 | 0 | range_writer); |
185 | 0 | } |
186 | 0 |
|
187 | 0 | if (likely (end_cp != 0xFFFF)) { |
188 | 0 | range_writer (0xFFFF, 0xFFFF, 1); |
189 | 0 | } |
190 | 0 | } Unexecuted instantiation: void OT::CmapSubtableFormat4::to_ranges<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::CmapSubtableFormat4::serialize_find_segcount<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_array_t<hb_pair_t<unsigned int, unsigned int> const>)::Counter, (void*)0>(hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::CmapSubtableFormat4::serialize_find_segcount<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_array_t<hb_pair_t<unsigned int, unsigned int> const>)::Counter&) Unexecuted instantiation: void OT::CmapSubtableFormat4::to_ranges<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::CmapSubtableFormat4::serialize_start_end_delta_arrays<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_serialize_context_t*, hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, int)::Writer, (void*)0>(hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::CmapSubtableFormat4::serialize_start_end_delta_arrays<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_serialize_context_t*, hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, int)::Writer&) |
191 | | |
192 | | /* |
193 | | * Writes the current range as either one or two ranges depending on what is most efficient. |
194 | | */ |
195 | | template<typename Writer> |
196 | | void commit_current_range (hb_codepoint_t start, |
197 | | hb_codepoint_t prev_run_start, |
198 | | hb_codepoint_t run_start, |
199 | | hb_codepoint_t end, |
200 | | int run_delta, |
201 | | int previous_run_delta, |
202 | | int split_cost, |
203 | 0 | Writer& range_writer) { |
204 | 0 | bool should_split = false; |
205 | 0 | if (start < run_start && run_start < end) { |
206 | 0 | int run_cost = (end - run_start + 1) * 2; |
207 | 0 | if (run_cost >= split_cost) { |
208 | 0 | should_split = true; |
209 | 0 | } |
210 | 0 | } |
211 | 0 |
|
212 | 0 | // TODO(grieger): handle case where delta is legitimately 0, mark range offset array instead? |
213 | 0 | if (should_split) { |
214 | 0 | if (start == prev_run_start) |
215 | 0 | range_writer (start, run_start - 1, previous_run_delta); |
216 | 0 | else |
217 | 0 | range_writer (start, run_start - 1, 0); |
218 | 0 | range_writer (run_start, end, run_delta); |
219 | 0 | return; |
220 | 0 | } |
221 | 0 |
|
222 | 0 |
|
223 | 0 | if (start == run_start) { |
224 | 0 | // Range is only a run |
225 | 0 | range_writer (start, end, run_delta); |
226 | 0 | return; |
227 | 0 | } |
228 | 0 |
|
229 | 0 | // Write only a single non-run range. |
230 | 0 | range_writer (start, end, 0); |
231 | 0 | } Unexecuted instantiation: void OT::CmapSubtableFormat4::commit_current_range<OT::CmapSubtableFormat4::serialize_find_segcount<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_array_t<hb_pair_t<unsigned int, unsigned int> const>)::Counter>(unsigned int, unsigned int, unsigned int, unsigned int, int, int, int, OT::CmapSubtableFormat4::serialize_find_segcount<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_array_t<hb_pair_t<unsigned int, unsigned int> const>)::Counter&) Unexecuted instantiation: void OT::CmapSubtableFormat4::commit_current_range<OT::CmapSubtableFormat4::serialize_start_end_delta_arrays<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_serialize_context_t*, hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, int)::Writer>(unsigned int, unsigned int, unsigned int, unsigned int, int, int, int, OT::CmapSubtableFormat4::serialize_start_end_delta_arrays<hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, (void*)0>(hb_serialize_context_t*, hb_array_t<hb_pair_t<unsigned int, unsigned int> const>, int)::Writer&) |
232 | | |
233 | | template<typename Iterator, |
234 | | hb_requires (hb_is_iterator (Iterator))> |
235 | 0 | unsigned serialize_find_segcount (Iterator it) { |
236 | 0 | struct Counter { |
237 | 0 | unsigned segcount = 0; |
238 | 0 |
|
239 | 0 | void operator() (hb_codepoint_t start, |
240 | 0 | hb_codepoint_t end, |
241 | 0 | int delta) { |
242 | 0 | segcount++; |
243 | 0 | } |
244 | 0 | } counter; |
245 | 0 |
|
246 | 0 | to_ranges (+it, counter); |
247 | 0 | return counter.segcount; |
248 | 0 | } |
249 | | |
250 | | |
251 | | template<typename Iterator, |
252 | | hb_requires (hb_is_iterator (Iterator))> |
253 | | bool serialize_start_end_delta_arrays (hb_serialize_context_t *c, |
254 | | Iterator it, |
255 | | int segcount) |
256 | 0 | { |
257 | 0 | struct Writer { |
258 | 0 | hb_serialize_context_t *serializer_; |
259 | 0 | HBUINT16* end_code_; |
260 | 0 | HBUINT16* start_code_; |
261 | 0 | HBINT16* id_delta_; |
262 | 0 | int index_; |
263 | 0 |
|
264 | 0 | Writer(hb_serialize_context_t *serializer) |
265 | 0 | : serializer_(serializer), |
266 | 0 | end_code_(nullptr), |
267 | 0 | start_code_(nullptr), |
268 | 0 | id_delta_(nullptr), |
269 | 0 | index_ (0) {} |
270 | 0 | void operator() (hb_codepoint_t start, |
271 | 0 | hb_codepoint_t end, |
272 | 0 | int delta) { |
273 | 0 | start_code_[index_] = start; |
274 | 0 | end_code_[index_] = end; |
275 | 0 | id_delta_[index_] = delta; |
276 | 0 | index_++; |
277 | 0 | } |
278 | 0 | } writer(c); |
279 | 0 |
|
280 | 0 | writer.end_code_ = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount); |
281 | 0 | c->allocate_size<HBUINT16> (2); // padding |
282 | 0 | writer.start_code_ = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount); |
283 | 0 | writer.id_delta_ = c->allocate_size<HBINT16> (HBINT16::static_size * segcount); |
284 | 0 |
|
285 | 0 | if (unlikely (!writer.end_code_ || !writer.start_code_ || !writer.id_delta_)) return false; |
286 | 0 |
|
287 | 0 | to_ranges (+it, writer); |
288 | 0 | return true; |
289 | 0 | } |
290 | | |
291 | | template<typename Iterator, |
292 | | hb_requires (hb_is_iterator (Iterator))> |
293 | | HBUINT16* serialize_rangeoffset_glyid (hb_serialize_context_t *c, |
294 | | Iterator it, |
295 | | HBUINT16 *endCode, |
296 | | HBUINT16 *startCode, |
297 | | HBINT16 *idDelta, |
298 | | unsigned segcount) |
299 | 0 | { |
300 | 0 | hb_map_t cp_to_gid { it }; |
301 | 0 |
|
302 | 0 | HBUINT16 *idRangeOffset = c->allocate_size<HBUINT16> (HBUINT16::static_size * segcount); |
303 | 0 | if (unlikely (!c->check_success (idRangeOffset))) return nullptr; |
304 | 0 | if (unlikely ((char *)idRangeOffset - (char *)idDelta != (int) segcount * (int) HBINT16::static_size)) return nullptr; |
305 | 0 |
|
306 | 0 | for (unsigned i : + hb_range (segcount) |
307 | 0 | | hb_filter ([&] (const unsigned _) { return idDelta[_] == 0; })) |
308 | 0 | { |
309 | 0 | idRangeOffset[i] = 2 * (c->start_embed<HBUINT16> () - idRangeOffset - i); |
310 | 0 | for (hb_codepoint_t cp = startCode[i]; cp <= endCode[i]; cp++) |
311 | 0 | { |
312 | 0 | HBUINT16 gid; |
313 | 0 | gid = cp_to_gid[cp]; |
314 | 0 | c->copy<HBUINT16> (gid); |
315 | 0 | } |
316 | 0 | } |
317 | 0 |
|
318 | 0 | return idRangeOffset; |
319 | 0 | } |
320 | | |
321 | | template<typename Iterator, |
322 | | hb_requires (hb_is_iterator (Iterator))> |
323 | | void serialize (hb_serialize_context_t *c, |
324 | | Iterator it) |
325 | 0 | { |
326 | 0 | auto format4_iter = |
327 | 0 | + it |
328 | 0 | | hb_filter ([&] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> _) |
329 | 0 | { return _.first <= 0xFFFF; }) |
330 | 0 | ; |
331 | 0 |
|
332 | 0 | if (!format4_iter) return; |
333 | 0 |
|
334 | 0 | unsigned table_initpos = c->length (); |
335 | 0 | if (unlikely (!c->extend_min (this))) return; |
336 | 0 | this->format = 4; |
337 | 0 |
|
338 | 0 | hb_vector_t<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> cp_to_gid { |
339 | 0 | format4_iter |
340 | 0 | }; |
341 | 0 |
|
342 | 0 | //serialize endCode[], startCode[], idDelta[] |
343 | 0 | HBUINT16* endCode = c->start_embed<HBUINT16> (); |
344 | 0 | unsigned segcount = serialize_find_segcount (cp_to_gid.iter()); |
345 | 0 | if (unlikely (!serialize_start_end_delta_arrays (c, cp_to_gid.iter(), segcount))) |
346 | 0 | return; |
347 | 0 |
|
348 | 0 | HBUINT16 *startCode = endCode + segcount + 1; |
349 | 0 | HBINT16 *idDelta = ((HBINT16*)startCode) + segcount; |
350 | 0 |
|
351 | 0 | HBUINT16 *idRangeOffset = serialize_rangeoffset_glyid (c, |
352 | 0 | cp_to_gid.iter (), |
353 | 0 | endCode, |
354 | 0 | startCode, |
355 | 0 | idDelta, |
356 | 0 | segcount); |
357 | 0 | if (unlikely (!c->check_success (idRangeOffset))) return; |
358 | 0 |
|
359 | 0 | this->length = c->length () - table_initpos; |
360 | 0 | if ((long long) this->length != (long long) c->length () - table_initpos) |
361 | 0 | { |
362 | 0 | // Length overflowed. Discard the current object before setting the error condition, otherwise |
363 | 0 | // discard is a noop which prevents the higher level code from reverting the serializer to the |
364 | 0 | // pre-error state in cmap4 overflow handling code. |
365 | 0 | c->pop_discard (); |
366 | 0 | c->err (HB_SERIALIZE_ERROR_INT_OVERFLOW); |
367 | 0 | return; |
368 | 0 | } |
369 | 0 |
|
370 | 0 | this->segCountX2 = segcount * 2; |
371 | 0 | this->entrySelector = hb_max (1u, hb_bit_storage (segcount)) - 1; |
372 | 0 | this->searchRange = 2 * (1u << this->entrySelector); |
373 | 0 | this->rangeShift = segcount * 2 > this->searchRange |
374 | 0 | ? 2 * segcount - this->searchRange |
375 | 0 | : 0; |
376 | 0 | } Unexecuted instantiation: hb-common.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>) Unexecuted instantiation: hb-common.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>) Unexecuted instantiation: hb-face.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>) Unexecuted instantiation: hb-face.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>) Unexecuted instantiation: hb-ot-face.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>) Unexecuted instantiation: hb-ot-face.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>) Unexecuted instantiation: hb-ot-font.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>) Unexecuted instantiation: hb-ot-font.cc:void OT::CmapSubtableFormat4::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>) |
377 | | |
378 | | unsigned get_language () const |
379 | 0 | { |
380 | 0 | return language; |
381 | 0 | } |
382 | | |
383 | | struct accelerator_t |
384 | | { |
385 | 307k | accelerator_t () {} |
386 | 701k | accelerator_t (const CmapSubtableFormat4 *subtable) { init (subtable); } |
387 | | |
388 | | void init (const CmapSubtableFormat4 *subtable) |
389 | 766k | { |
390 | 766k | segCount = subtable->segCountX2 / 2; |
391 | 766k | endCount = subtable->values.arrayZ; |
392 | 766k | startCount = endCount + segCount + 1; |
393 | 766k | idDelta = startCount + segCount; |
394 | 766k | idRangeOffset = idDelta + segCount; |
395 | 766k | glyphIdArray = idRangeOffset + segCount; |
396 | 766k | glyphIdArrayLength = (subtable->length - 16 - 8 * segCount) / 2; |
397 | 766k | } |
398 | | |
399 | | bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const |
400 | 6.13M | { |
401 | 6.13M | struct CustomRange |
402 | 6.13M | { |
403 | 6.13M | int cmp (hb_codepoint_t k, |
404 | 6.13M | unsigned distance) const |
405 | 17.2M | { |
406 | 17.2M | if (k > last) return +1; |
407 | 10.3M | if (k < (&last)[distance]) return -1; |
408 | 1.42M | return 0; |
409 | 10.3M | } |
410 | 6.13M | HBUINT16 last; |
411 | 6.13M | }; |
412 | | |
413 | 6.13M | const HBUINT16 *found = hb_bsearch (codepoint, |
414 | 6.13M | this->endCount, |
415 | 6.13M | this->segCount, |
416 | 6.13M | 2, |
417 | 6.13M | _hb_cmp_method<hb_codepoint_t, CustomRange, unsigned>, |
418 | 6.13M | this->segCount + 1); |
419 | 6.13M | if (unlikely (!found)) |
420 | 4.70M | return false; |
421 | 1.42M | unsigned int i = found - endCount; |
422 | | |
423 | 1.42M | hb_codepoint_t gid; |
424 | 1.42M | unsigned int rangeOffset = this->idRangeOffset[i]; |
425 | 1.42M | if (rangeOffset == 0) |
426 | 957k | gid = codepoint + this->idDelta[i]; |
427 | 468k | else |
428 | 468k | { |
429 | | /* Somebody has been smoking... */ |
430 | 468k | unsigned int index = rangeOffset / 2 + (codepoint - this->startCount[i]) + i - this->segCount; |
431 | 468k | if (unlikely (index >= this->glyphIdArrayLength)) |
432 | 328k | return false; |
433 | 140k | gid = this->glyphIdArray[index]; |
434 | 140k | if (unlikely (!gid)) |
435 | 27.2k | return false; |
436 | 112k | gid += this->idDelta[i]; |
437 | 112k | } |
438 | 1.07M | gid &= 0xFFFFu; |
439 | 1.07M | if (unlikely (!gid)) |
440 | 17.6k | return false; |
441 | 1.05M | *glyph = gid; |
442 | 1.05M | return true; |
443 | 1.07M | } |
444 | | |
445 | | HB_INTERNAL static bool get_glyph_func (const void *obj, hb_codepoint_t codepoint, hb_codepoint_t *glyph) |
446 | 6.13M | { return ((const accelerator_t *) obj)->get_glyph (codepoint, glyph); } |
447 | | |
448 | | void collect_unicodes (hb_set_t *out) const |
449 | 66.3k | { |
450 | 66.3k | unsigned int count = this->segCount; |
451 | 66.3k | if (count && this->startCount[count - 1] == 0xFFFFu) |
452 | 56.2k | count--; /* Skip sentinel segment. */ |
453 | 1.15M | for (unsigned int i = 0; i < count; i++) |
454 | 1.09M | { |
455 | 1.09M | hb_codepoint_t start = this->startCount[i]; |
456 | 1.09M | hb_codepoint_t end = this->endCount[i]; |
457 | 1.09M | unsigned int rangeOffset = this->idRangeOffset[i]; |
458 | 1.09M | out->add_range(start, end); |
459 | 1.09M | if (rangeOffset == 0) |
460 | 651k | { |
461 | 1.09G | for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++) |
462 | 1.09G | { |
463 | 1.09G | hb_codepoint_t gid = (codepoint + this->idDelta[i]) & 0xFFFFu; |
464 | 1.09G | if (unlikely (!gid)) |
465 | 21.5k | out->del(codepoint); |
466 | 1.09G | } |
467 | 651k | } |
468 | 439k | else |
469 | 439k | { |
470 | 201M | for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++) |
471 | 201M | { |
472 | 201M | unsigned int index = rangeOffset / 2 + (codepoint - this->startCount[i]) + i - this->segCount; |
473 | 201M | if (unlikely (index >= this->glyphIdArrayLength)) |
474 | 196k | { |
475 | 196k | out->del_range (codepoint, end); |
476 | 196k | break; |
477 | 196k | } |
478 | 201M | hb_codepoint_t gid = this->glyphIdArray[index]; |
479 | 201M | if (unlikely (!gid)) |
480 | 54.4M | out->del(codepoint); |
481 | 201M | } |
482 | 439k | } |
483 | 1.09M | } |
484 | 66.3k | } |
485 | | |
486 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
487 | | hb_map_t *mapping /* OUT */) const |
488 | 0 | { |
489 | | // TODO(grieger): optimize similar to collect_unicodes |
490 | | // (ie. use add_range()) |
491 | 0 | unsigned count = this->segCount; |
492 | 0 | if (count && this->startCount[count - 1] == 0xFFFFu) |
493 | 0 | count--; /* Skip sentinel segment. */ |
494 | 0 | for (unsigned i = 0; i < count; i++) |
495 | 0 | { |
496 | 0 | hb_codepoint_t start = this->startCount[i]; |
497 | 0 | hb_codepoint_t end = this->endCount[i]; |
498 | 0 | unsigned rangeOffset = this->idRangeOffset[i]; |
499 | 0 | if (rangeOffset == 0) |
500 | 0 | { |
501 | 0 | for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++) |
502 | 0 | { |
503 | 0 | hb_codepoint_t gid = (codepoint + this->idDelta[i]) & 0xFFFFu; |
504 | 0 | if (unlikely (!gid)) |
505 | 0 | continue; |
506 | 0 | unicodes->add (codepoint); |
507 | 0 | mapping->set (codepoint, gid); |
508 | 0 | } |
509 | 0 | } |
510 | 0 | else |
511 | 0 | { |
512 | 0 | for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++) |
513 | 0 | { |
514 | 0 | unsigned index = rangeOffset / 2 + (codepoint - this->startCount[i]) + i - this->segCount; |
515 | 0 | if (unlikely (index >= this->glyphIdArrayLength)) |
516 | 0 | break; |
517 | 0 | hb_codepoint_t gid = this->glyphIdArray[index]; |
518 | 0 | if (unlikely (!gid)) |
519 | 0 | continue; |
520 | 0 | unicodes->add (codepoint); |
521 | 0 | mapping->set (codepoint, gid); |
522 | 0 | } |
523 | 0 | } |
524 | 0 | } |
525 | 0 | } |
526 | | |
527 | | const HBUINT16 *endCount; |
528 | | const HBUINT16 *startCount; |
529 | | const HBUINT16 *idDelta; |
530 | | const HBUINT16 *idRangeOffset; |
531 | | const HBUINT16 *glyphIdArray; |
532 | | unsigned int segCount; |
533 | | unsigned int glyphIdArrayLength; |
534 | | }; |
535 | | |
536 | | bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const |
537 | 635k | { |
538 | 635k | accelerator_t accel (this); |
539 | 635k | return accel.get_glyph_func (&accel, codepoint, glyph); |
540 | 635k | } |
541 | | void collect_unicodes (hb_set_t *out) const |
542 | 66.3k | { |
543 | 66.3k | accelerator_t accel (this); |
544 | 66.3k | accel.collect_unicodes (out); |
545 | 66.3k | } |
546 | | |
547 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
548 | | hb_map_t *mapping /* OUT */) const |
549 | 0 | { |
550 | 0 | accelerator_t accel (this); |
551 | 0 | accel.collect_mapping (unicodes, mapping); |
552 | 0 | } |
553 | | |
554 | | bool sanitize (hb_sanitize_context_t *c) const |
555 | 216k | { |
556 | 216k | TRACE_SANITIZE (this); |
557 | 216k | if (unlikely (!c->check_struct (this))) |
558 | 116 | return_trace (false); |
559 | | |
560 | 216k | if (unlikely (!c->check_range (this, length))) |
561 | 11.0k | { |
562 | | /* Some broken fonts have too long of a "length" value. |
563 | | * If that is the case, just change the value to truncate |
564 | | * the subtable at the end of the blob. */ |
565 | 11.0k | uint16_t new_length = (uint16_t) hb_min ((uintptr_t) 65535, |
566 | 11.0k | (uintptr_t) (c->end - |
567 | 11.0k | (char *) this)); |
568 | 11.0k | if (!c->try_set (&length, new_length)) |
569 | 5.15k | return_trace (false); |
570 | 11.0k | } |
571 | | |
572 | 216k | return_trace (16 + 4 * (unsigned int) segCountX2 <= length); |
573 | 216k | } |
574 | | |
575 | | |
576 | | |
577 | | protected: |
578 | | HBUINT16 format; /* Format number is set to 4. */ |
579 | | HBUINT16 length; /* This is the length in bytes of the |
580 | | * subtable. */ |
581 | | HBUINT16 language; /* Ignore. */ |
582 | | HBUINT16 segCountX2; /* 2 x segCount. */ |
583 | | HBUINT16 searchRange; /* 2 * (2**floor(log2(segCount))) */ |
584 | | HBUINT16 entrySelector; /* log2(searchRange/2) */ |
585 | | HBUINT16 rangeShift; /* 2 x segCount - searchRange */ |
586 | | |
587 | | UnsizedArrayOf<HBUINT16> |
588 | | values; |
589 | | #if 0 |
590 | | HBUINT16 endCount[segCount]; /* End characterCode for each segment, |
591 | | * last=0xFFFFu. */ |
592 | | HBUINT16 reservedPad; /* Set to 0. */ |
593 | | HBUINT16 startCount[segCount]; /* Start character code for each segment. */ |
594 | | HBINT16 idDelta[segCount]; /* Delta for all character codes in segment. */ |
595 | | HBUINT16 idRangeOffset[segCount];/* Offsets into glyphIdArray or 0 */ |
596 | | UnsizedArrayOf<HBUINT16> |
597 | | glyphIdArray; /* Glyph index array (arbitrary length) */ |
598 | | #endif |
599 | | |
600 | | public: |
601 | | DEFINE_SIZE_ARRAY (14, values); |
602 | | }; |
603 | | |
604 | | struct CmapSubtableLongGroup |
605 | | { |
606 | | friend struct CmapSubtableFormat12; |
607 | | friend struct CmapSubtableFormat13; |
608 | | template<typename U> |
609 | | friend struct CmapSubtableLongSegmented; |
610 | | friend struct cmap; |
611 | | |
612 | | int cmp (hb_codepoint_t codepoint) const |
613 | 15.6M | { |
614 | 15.6M | if (codepoint < startCharCode) return -1; |
615 | 7.60M | if (codepoint > endCharCode) return +1; |
616 | 1.23M | return 0; |
617 | 7.60M | } |
618 | | |
619 | | bool sanitize (hb_sanitize_context_t *c) const |
620 | 0 | { |
621 | 0 | TRACE_SANITIZE (this); |
622 | 0 | return_trace (c->check_struct (this)); |
623 | 0 | } |
624 | | |
625 | | private: |
626 | | HBUINT32 startCharCode; /* First character code in this group. */ |
627 | | HBUINT32 endCharCode; /* Last character code in this group. */ |
628 | | HBUINT32 glyphID; /* Glyph index; interpretation depends on |
629 | | * subtable format. */ |
630 | | public: |
631 | | DEFINE_SIZE_STATIC (12); |
632 | | }; |
633 | | DECLARE_NULL_NAMESPACE_BYTES (OT, CmapSubtableLongGroup); |
634 | | |
635 | | template <typename UINT> |
636 | | struct CmapSubtableTrimmed |
637 | | { |
638 | | bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const |
639 | 142k | { |
640 | | /* Rely on our implicit array bound-checking. */ |
641 | 142k | hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode]; |
642 | 142k | if (unlikely (!gid)) |
643 | 140k | return false; |
644 | 2.60k | *glyph = gid; |
645 | 2.60k | return true; |
646 | 142k | } OT::CmapSubtableTrimmed<OT::IntType<unsigned short, 2u> >::get_glyph(unsigned int, unsigned int*) const Line | Count | Source | 639 | 58.8k | { | 640 | | /* Rely on our implicit array bound-checking. */ | 641 | 58.8k | hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode]; | 642 | 58.8k | if (unlikely (!gid)) | 643 | 57.4k | return false; | 644 | 1.40k | *glyph = gid; | 645 | 1.40k | return true; | 646 | 58.8k | } |
OT::CmapSubtableTrimmed<OT::IntType<unsigned int, 4u> >::get_glyph(unsigned int, unsigned int*) const Line | Count | Source | 639 | 83.7k | { | 640 | | /* Rely on our implicit array bound-checking. */ | 641 | 83.7k | hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode]; | 642 | 83.7k | if (unlikely (!gid)) | 643 | 82.5k | return false; | 644 | 1.20k | *glyph = gid; | 645 | 1.20k | return true; | 646 | 83.7k | } |
|
647 | | |
648 | | unsigned get_language () const |
649 | 0 | { |
650 | 0 | return language; |
651 | 0 | } Unexecuted instantiation: OT::CmapSubtableTrimmed<OT::IntType<unsigned short, 2u> >::get_language() const Unexecuted instantiation: OT::CmapSubtableTrimmed<OT::IntType<unsigned int, 4u> >::get_language() const |
652 | | |
653 | | void collect_unicodes (hb_set_t *out) const |
654 | 1.76k | { |
655 | 1.76k | hb_codepoint_t start = startCharCode; |
656 | 1.76k | unsigned int count = glyphIdArray.len; |
657 | 392k | for (unsigned int i = 0; i < count; i++) |
658 | 390k | if (glyphIdArray[i]) |
659 | 342k | out->add (start + i); |
660 | 1.76k | } OT::CmapSubtableTrimmed<OT::IntType<unsigned short, 2u> >::collect_unicodes(hb_set_t*) const Line | Count | Source | 654 | 720 | { | 655 | 720 | hb_codepoint_t start = startCharCode; | 656 | 720 | unsigned int count = glyphIdArray.len; | 657 | 194k | for (unsigned int i = 0; i < count; i++) | 658 | 193k | if (glyphIdArray[i]) | 659 | 164k | out->add (start + i); | 660 | 720 | } |
OT::CmapSubtableTrimmed<OT::IntType<unsigned int, 4u> >::collect_unicodes(hb_set_t*) const Line | Count | Source | 654 | 1.04k | { | 655 | 1.04k | hb_codepoint_t start = startCharCode; | 656 | 1.04k | unsigned int count = glyphIdArray.len; | 657 | 197k | for (unsigned int i = 0; i < count; i++) | 658 | 196k | if (glyphIdArray[i]) | 659 | 178k | out->add (start + i); | 660 | 1.04k | } |
|
661 | | |
662 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
663 | | hb_map_t *mapping /* OUT */) const |
664 | 0 | { |
665 | 0 | hb_codepoint_t start_cp = startCharCode; |
666 | 0 | unsigned count = glyphIdArray.len; |
667 | 0 | for (unsigned i = 0; i < count; i++) |
668 | 0 | if (glyphIdArray[i]) |
669 | 0 | { |
670 | 0 | hb_codepoint_t unicode = start_cp + i; |
671 | 0 | hb_codepoint_t glyphid = glyphIdArray[i]; |
672 | 0 | unicodes->add (unicode); |
673 | 0 | mapping->set (unicode, glyphid); |
674 | 0 | } |
675 | 0 | } Unexecuted instantiation: OT::CmapSubtableTrimmed<OT::IntType<unsigned short, 2u> >::collect_mapping(hb_set_t*, hb_map_t*) const Unexecuted instantiation: OT::CmapSubtableTrimmed<OT::IntType<unsigned int, 4u> >::collect_mapping(hb_set_t*, hb_map_t*) const |
676 | | |
677 | | bool sanitize (hb_sanitize_context_t *c) const |
678 | 21.6k | { |
679 | 21.6k | TRACE_SANITIZE (this); |
680 | 21.6k | return_trace (c->check_struct (this) && glyphIdArray.sanitize (c)); |
681 | 21.6k | } OT::CmapSubtableTrimmed<OT::IntType<unsigned short, 2u> >::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 678 | 18.1k | { | 679 | 18.1k | TRACE_SANITIZE (this); | 680 | 18.1k | return_trace (c->check_struct (this) && glyphIdArray.sanitize (c)); | 681 | 18.1k | } |
OT::CmapSubtableTrimmed<OT::IntType<unsigned int, 4u> >::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 678 | 3.42k | { | 679 | 3.42k | TRACE_SANITIZE (this); | 680 | 3.42k | return_trace (c->check_struct (this) && glyphIdArray.sanitize (c)); | 681 | 3.42k | } |
|
682 | | |
683 | | protected: |
684 | | UINT formatReserved; /* Subtable format and (maybe) padding. */ |
685 | | UINT length; /* Byte length of this subtable. */ |
686 | | UINT language; /* Ignore. */ |
687 | | UINT startCharCode; /* First character code covered. */ |
688 | | ArrayOf<HBGlyphID16, UINT> |
689 | | glyphIdArray; /* Array of glyph index values for character |
690 | | * codes in the range. */ |
691 | | public: |
692 | | DEFINE_SIZE_ARRAY (5 * sizeof (UINT), glyphIdArray); |
693 | | }; |
694 | | |
695 | | struct CmapSubtableFormat6 : CmapSubtableTrimmed<HBUINT16> {}; |
696 | | struct CmapSubtableFormat10 : CmapSubtableTrimmed<HBUINT32> {}; |
697 | | |
698 | | template <typename T> |
699 | | struct CmapSubtableLongSegmented |
700 | | { |
701 | | friend struct cmap; |
702 | | |
703 | | bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const |
704 | 4.35M | { |
705 | 4.35M | hb_codepoint_t gid = T::group_get_glyph (groups.bsearch (codepoint), codepoint); |
706 | 4.35M | if (unlikely (!gid)) |
707 | 3.12M | return false; |
708 | 1.23M | *glyph = gid; |
709 | 1.23M | return true; |
710 | 4.35M | } OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat12>::get_glyph(unsigned int, unsigned int*) const Line | Count | Source | 704 | 3.44M | { | 705 | 3.44M | hb_codepoint_t gid = T::group_get_glyph (groups.bsearch (codepoint), codepoint); | 706 | 3.44M | if (unlikely (!gid)) | 707 | 2.95M | return false; | 708 | 490k | *glyph = gid; | 709 | 490k | return true; | 710 | 3.44M | } |
OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat13>::get_glyph(unsigned int, unsigned int*) const Line | Count | Source | 704 | 910k | { | 705 | 910k | hb_codepoint_t gid = T::group_get_glyph (groups.bsearch (codepoint), codepoint); | 706 | 910k | if (unlikely (!gid)) | 707 | 170k | return false; | 708 | 739k | *glyph = gid; | 709 | 739k | return true; | 710 | 910k | } |
|
711 | | |
712 | | unsigned get_language () const |
713 | 0 | { |
714 | 0 | return language; |
715 | 0 | } Unexecuted instantiation: OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat12>::get_language() const Unexecuted instantiation: OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat13>::get_language() const |
716 | | |
717 | | void collect_unicodes (hb_set_t *out, unsigned int num_glyphs) const |
718 | 38.7k | { |
719 | 3.23M | for (unsigned int i = 0; i < this->groups.len; i++) |
720 | 3.19M | { |
721 | 3.19M | hb_codepoint_t start = this->groups[i].startCharCode; |
722 | 3.19M | hb_codepoint_t end = hb_min ((hb_codepoint_t) this->groups[i].endCharCode, |
723 | 3.19M | (hb_codepoint_t) HB_UNICODE_MAX); |
724 | 3.19M | hb_codepoint_t gid = this->groups[i].glyphID; |
725 | 3.19M | if (!gid) |
726 | 33.5k | { |
727 | | /* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */ |
728 | 33.5k | if (! T::group_get_glyph (this->groups[i], end)) continue; |
729 | 6.19k | start++; |
730 | 6.19k | gid++; |
731 | 6.19k | } |
732 | 3.17M | if (unlikely ((unsigned int) gid >= num_glyphs)) continue; |
733 | 2.79M | if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs)) |
734 | 37.8k | end = start + (hb_codepoint_t) num_glyphs - gid; |
735 | | |
736 | 2.79M | out->add_range (start, hb_min (end, 0x10FFFFu)); |
737 | 2.79M | } |
738 | 38.7k | } OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat12>::collect_unicodes(hb_set_t*, unsigned int) const Line | Count | Source | 718 | 36.0k | { | 719 | 3.18M | for (unsigned int i = 0; i < this->groups.len; i++) | 720 | 3.14M | { | 721 | 3.14M | hb_codepoint_t start = this->groups[i].startCharCode; | 722 | 3.14M | hb_codepoint_t end = hb_min ((hb_codepoint_t) this->groups[i].endCharCode, | 723 | 3.14M | (hb_codepoint_t) HB_UNICODE_MAX); | 724 | 3.14M | hb_codepoint_t gid = this->groups[i].glyphID; | 725 | 3.14M | if (!gid) | 726 | 26.1k | { | 727 | | /* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */ | 728 | 26.1k | if (! T::group_get_glyph (this->groups[i], end)) continue; | 729 | 6.19k | start++; | 730 | 6.19k | gid++; | 731 | 6.19k | } | 732 | 3.12M | if (unlikely ((unsigned int) gid >= num_glyphs)) continue; | 733 | 2.78M | if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs)) | 734 | 30.7k | end = start + (hb_codepoint_t) num_glyphs - gid; | 735 | | | 736 | 2.78M | out->add_range (start, hb_min (end, 0x10FFFFu)); | 737 | 2.78M | } | 738 | 36.0k | } |
OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat13>::collect_unicodes(hb_set_t*, unsigned int) const Line | Count | Source | 718 | 2.68k | { | 719 | 52.7k | for (unsigned int i = 0; i < this->groups.len; i++) | 720 | 50.0k | { | 721 | 50.0k | hb_codepoint_t start = this->groups[i].startCharCode; | 722 | 50.0k | hb_codepoint_t end = hb_min ((hb_codepoint_t) this->groups[i].endCharCode, | 723 | 50.0k | (hb_codepoint_t) HB_UNICODE_MAX); | 724 | 50.0k | hb_codepoint_t gid = this->groups[i].glyphID; | 725 | 50.0k | if (!gid) | 726 | 7.44k | { | 727 | | /* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */ | 728 | 7.44k | if (! T::group_get_glyph (this->groups[i], end)) continue; | 729 | 0 | start++; | 730 | 0 | gid++; | 731 | 0 | } | 732 | 42.6k | if (unlikely ((unsigned int) gid >= num_glyphs)) continue; | 733 | 8.67k | if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs)) | 734 | 7.08k | end = start + (hb_codepoint_t) num_glyphs - gid; | 735 | | | 736 | 8.67k | out->add_range (start, hb_min (end, 0x10FFFFu)); | 737 | 8.67k | } | 738 | 2.68k | } |
|
739 | | |
740 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
741 | | hb_map_t *mapping, /* OUT */ |
742 | | unsigned num_glyphs) const |
743 | 0 | { |
744 | 0 | hb_codepoint_t last_end = 0; |
745 | 0 | for (unsigned i = 0; i < this->groups.len; i++) |
746 | 0 | { |
747 | 0 | hb_codepoint_t start = this->groups[i].startCharCode; |
748 | 0 | hb_codepoint_t end = hb_min ((hb_codepoint_t) this->groups[i].endCharCode, |
749 | 0 | (hb_codepoint_t) HB_UNICODE_MAX); |
750 | 0 | if (unlikely (start > end || start < last_end)) { |
751 | | // Range is not in order and is invalid, skip it. |
752 | 0 | continue; |
753 | 0 | } |
754 | 0 | last_end = end; |
755 | | |
756 | |
|
757 | 0 | hb_codepoint_t gid = this->groups[i].glyphID; |
758 | 0 | if (!gid) |
759 | 0 | { |
760 | | /* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */ |
761 | 0 | if (! T::group_get_glyph (this->groups[i], end)) continue; |
762 | 0 | start++; |
763 | 0 | gid++; |
764 | 0 | } |
765 | 0 | if (unlikely ((unsigned int) gid >= num_glyphs)) continue; |
766 | 0 | if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs)) |
767 | 0 | end = start + (hb_codepoint_t) num_glyphs - gid; |
768 | |
|
769 | 0 | for (unsigned cp = start; cp <= end; cp++) |
770 | 0 | { |
771 | 0 | unicodes->add (cp); |
772 | 0 | mapping->set (cp, gid); |
773 | 0 | gid++; |
774 | 0 | } |
775 | 0 | } |
776 | 0 | } Unexecuted instantiation: OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat12>::collect_mapping(hb_set_t*, hb_map_t*, unsigned int) const Unexecuted instantiation: OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat13>::collect_mapping(hb_set_t*, hb_map_t*, unsigned int) const |
777 | | |
778 | | bool sanitize (hb_sanitize_context_t *c) const |
779 | 68.3k | { |
780 | 68.3k | TRACE_SANITIZE (this); |
781 | 68.3k | return_trace (c->check_struct (this) && groups.sanitize (c)); |
782 | 68.3k | } OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat12>::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 779 | 60.2k | { | 780 | 60.2k | TRACE_SANITIZE (this); | 781 | 60.2k | return_trace (c->check_struct (this) && groups.sanitize (c)); | 782 | 60.2k | } |
OT::CmapSubtableLongSegmented<OT::CmapSubtableFormat13>::sanitize(hb_sanitize_context_t*) const Line | Count | Source | 779 | 8.07k | { | 780 | 8.07k | TRACE_SANITIZE (this); | 781 | 8.07k | return_trace (c->check_struct (this) && groups.sanitize (c)); | 782 | 8.07k | } |
|
783 | | |
784 | | protected: |
785 | | HBUINT16 format; /* Subtable format; set to 12. */ |
786 | | HBUINT16 reserved; /* Reserved; set to 0. */ |
787 | | HBUINT32 length; /* Byte length of this subtable. */ |
788 | | HBUINT32 language; /* Ignore. */ |
789 | | SortedArray32Of<CmapSubtableLongGroup> |
790 | | groups; /* Groupings. */ |
791 | | public: |
792 | | DEFINE_SIZE_ARRAY (16, groups); |
793 | | }; |
794 | | |
795 | | struct CmapSubtableFormat12 : CmapSubtableLongSegmented<CmapSubtableFormat12> |
796 | | { |
797 | | static hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group, |
798 | | hb_codepoint_t u) |
799 | 3.47M | { return likely (group.startCharCode <= group.endCharCode) ? |
800 | 2.95M | group.glyphID + (u - group.startCharCode) : 0; } |
801 | | |
802 | | |
803 | | template<typename Iterator, |
804 | | hb_requires (hb_is_iterator (Iterator))> |
805 | | void serialize (hb_serialize_context_t *c, |
806 | | Iterator it) |
807 | 0 | { |
808 | 0 | if (!it) return; |
809 | 0 | unsigned table_initpos = c->length (); |
810 | 0 | if (unlikely (!c->extend_min (this))) return; |
811 | 0 |
|
812 | 0 | hb_codepoint_t startCharCode = (hb_codepoint_t) -1, endCharCode = (hb_codepoint_t) -1; |
813 | 0 | hb_codepoint_t glyphID = 0; |
814 | 0 |
|
815 | 0 | for (const auto& _ : +it) |
816 | 0 | { |
817 | 0 | if (startCharCode == (hb_codepoint_t) -1) |
818 | 0 | { |
819 | 0 | startCharCode = _.first; |
820 | 0 | endCharCode = _.first; |
821 | 0 | glyphID = _.second; |
822 | 0 | } |
823 | 0 | else if (!_is_gid_consecutive (endCharCode, startCharCode, glyphID, _.first, _.second)) |
824 | 0 | { |
825 | 0 | CmapSubtableLongGroup grouprecord; |
826 | 0 | grouprecord.startCharCode = startCharCode; |
827 | 0 | grouprecord.endCharCode = endCharCode; |
828 | 0 | grouprecord.glyphID = glyphID; |
829 | 0 | c->copy<CmapSubtableLongGroup> (grouprecord); |
830 | 0 |
|
831 | 0 | startCharCode = _.first; |
832 | 0 | endCharCode = _.first; |
833 | 0 | glyphID = _.second; |
834 | 0 | } |
835 | 0 | else |
836 | 0 | endCharCode = _.first; |
837 | 0 | } |
838 | 0 |
|
839 | 0 | CmapSubtableLongGroup record; |
840 | 0 | record.startCharCode = startCharCode; |
841 | 0 | record.endCharCode = endCharCode; |
842 | 0 | record.glyphID = glyphID; |
843 | 0 | c->copy<CmapSubtableLongGroup> (record); |
844 | 0 |
|
845 | 0 | this->format = 12; |
846 | 0 | this->reserved = 0; |
847 | 0 | this->length = c->length () - table_initpos; |
848 | 0 | this->groups.len = (this->length - min_size) / CmapSubtableLongGroup::static_size; |
849 | 0 | } Unexecuted instantiation: hb-common.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>) Unexecuted instantiation: hb-common.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>) Unexecuted instantiation: hb-face.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>) Unexecuted instantiation: hb-face.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>) Unexecuted instantiation: hb-ot-face.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>) Unexecuted instantiation: hb-ot-face.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>) Unexecuted instantiation: hb-ot-font.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>) Unexecuted instantiation: hb-ot-font.cc:void OT::CmapSubtableFormat12::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>) |
850 | | |
851 | | static size_t get_sub_table_size (const hb_sorted_vector_t<CmapSubtableLongGroup> &groups_data) |
852 | 0 | { return 16 + 12 * groups_data.length; } |
853 | | |
854 | | private: |
855 | | static bool _is_gid_consecutive (hb_codepoint_t endCharCode, |
856 | | hb_codepoint_t startCharCode, |
857 | | hb_codepoint_t glyphID, |
858 | | hb_codepoint_t cp, |
859 | | hb_codepoint_t new_gid) |
860 | 0 | { |
861 | 0 | return (cp - 1 == endCharCode) && |
862 | 0 | new_gid == glyphID + (cp - startCharCode); |
863 | 0 | } |
864 | | |
865 | | }; |
866 | | |
867 | | struct CmapSubtableFormat13 : CmapSubtableLongSegmented<CmapSubtableFormat13> |
868 | | { |
869 | | static hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group, |
870 | | hb_codepoint_t u HB_UNUSED) |
871 | 917k | { return group.glyphID; } |
872 | | }; |
873 | | |
874 | | typedef enum |
875 | | { |
876 | | GLYPH_VARIANT_NOT_FOUND = 0, |
877 | | GLYPH_VARIANT_FOUND = 1, |
878 | | GLYPH_VARIANT_USE_DEFAULT = 2 |
879 | | } glyph_variant_t; |
880 | | |
881 | | struct UnicodeValueRange |
882 | | { |
883 | | int cmp (const hb_codepoint_t &codepoint) const |
884 | 169 | { |
885 | 169 | if (codepoint < startUnicodeValue) return -1; |
886 | 111 | if (codepoint > startUnicodeValue + additionalCount) return +1; |
887 | 26 | return 0; |
888 | 111 | } |
889 | | |
890 | | bool sanitize (hb_sanitize_context_t *c) const |
891 | 0 | { |
892 | 0 | TRACE_SANITIZE (this); |
893 | 0 | return_trace (c->check_struct (this)); |
894 | 0 | } |
895 | | |
896 | | HBUINT24 startUnicodeValue; /* First value in this range. */ |
897 | | HBUINT8 additionalCount; /* Number of additional values in this |
898 | | * range. */ |
899 | | public: |
900 | | DEFINE_SIZE_STATIC (4); |
901 | | }; |
902 | | |
903 | | struct DefaultUVS : SortedArray32Of<UnicodeValueRange> |
904 | | { |
905 | | void collect_unicodes (hb_set_t *out) const |
906 | 312k | { |
907 | 312k | unsigned int count = len; |
908 | 312k | for (unsigned int i = 0; i < count; i++) |
909 | 174 | { |
910 | 174 | hb_codepoint_t first = arrayZ[i].startUnicodeValue; |
911 | 174 | hb_codepoint_t last = hb_min ((hb_codepoint_t) (first + arrayZ[i].additionalCount), |
912 | 174 | (hb_codepoint_t) HB_UNICODE_MAX); |
913 | 174 | out->add_range (first, last); |
914 | 174 | } |
915 | 312k | } |
916 | | |
917 | | DefaultUVS* copy (hb_serialize_context_t *c, |
918 | | const hb_set_t *unicodes) const |
919 | 0 | { |
920 | 0 | DefaultUVS *out = c->start_embed<DefaultUVS> (); |
921 | 0 | if (unlikely (!out)) return nullptr; |
922 | 0 | auto snap = c->snapshot (); |
923 | 0 |
|
924 | 0 | HBUINT32 len; |
925 | 0 | len = 0; |
926 | 0 | if (unlikely (!c->copy<HBUINT32> (len))) return nullptr; |
927 | 0 | unsigned init_len = c->length (); |
928 | 0 |
|
929 | 0 | if (this->len > unicodes->get_population () * hb_bit_storage ((unsigned) this->len)) |
930 | 0 | { |
931 | 0 | hb_codepoint_t start = HB_SET_VALUE_INVALID; |
932 | 0 | hb_codepoint_t end = HB_SET_VALUE_INVALID; |
933 | 0 |
|
934 | 0 | for (hb_codepoint_t u = HB_SET_VALUE_INVALID; |
935 | 0 | unicodes->next (&u);) |
936 | 0 | { |
937 | 0 | if (!as_array ().bsearch (u)) |
938 | 0 | continue; |
939 | 0 | if (start == HB_SET_VALUE_INVALID) |
940 | 0 | { |
941 | 0 | start = u; |
942 | 0 | end = start - 1; |
943 | 0 | } |
944 | 0 | if (end + 1 != u || end - start == 255) |
945 | 0 | { |
946 | 0 | UnicodeValueRange rec; |
947 | 0 | rec.startUnicodeValue = start; |
948 | 0 | rec.additionalCount = end - start; |
949 | 0 | c->copy<UnicodeValueRange> (rec); |
950 | 0 | start = u; |
951 | 0 | } |
952 | 0 | end = u; |
953 | 0 | } |
954 | 0 | if (start != HB_SET_VALUE_INVALID) |
955 | 0 | { |
956 | 0 | UnicodeValueRange rec; |
957 | 0 | rec.startUnicodeValue = start; |
958 | 0 | rec.additionalCount = end - start; |
959 | 0 | c->copy<UnicodeValueRange> (rec); |
960 | 0 | } |
961 | 0 |
|
962 | 0 | } |
963 | 0 | else |
964 | 0 | { |
965 | 0 | hb_codepoint_t lastCode = HB_SET_VALUE_INVALID; |
966 | 0 | int count = -1; |
967 | 0 |
|
968 | 0 | for (const UnicodeValueRange& _ : *this) |
969 | 0 | { |
970 | 0 | hb_codepoint_t curEntry = (hb_codepoint_t) (_.startUnicodeValue - 1); |
971 | 0 | hb_codepoint_t end = curEntry + _.additionalCount + 2; |
972 | 0 |
|
973 | 0 | for (; unicodes->next (&curEntry) && curEntry < end;) |
974 | 0 | { |
975 | 0 | count += 1; |
976 | 0 | if (lastCode == HB_SET_VALUE_INVALID) |
977 | 0 | lastCode = curEntry; |
978 | 0 | else if (lastCode + count != curEntry) |
979 | 0 | { |
980 | 0 | UnicodeValueRange rec; |
981 | 0 | rec.startUnicodeValue = lastCode; |
982 | 0 | rec.additionalCount = count - 1; |
983 | 0 | c->copy<UnicodeValueRange> (rec); |
984 | 0 |
|
985 | 0 | lastCode = curEntry; |
986 | 0 | count = 0; |
987 | 0 | } |
988 | 0 | } |
989 | 0 | } |
990 | 0 |
|
991 | 0 | if (lastCode != HB_MAP_VALUE_INVALID) |
992 | 0 | { |
993 | 0 | UnicodeValueRange rec; |
994 | 0 | rec.startUnicodeValue = lastCode; |
995 | 0 | rec.additionalCount = count; |
996 | 0 | c->copy<UnicodeValueRange> (rec); |
997 | 0 | } |
998 | 0 | } |
999 | 0 |
|
1000 | 0 | if (c->length () - init_len == 0) |
1001 | 0 | { |
1002 | 0 | c->revert (snap); |
1003 | 0 | return nullptr; |
1004 | 0 | } |
1005 | 0 | else |
1006 | 0 | { |
1007 | 0 | if (unlikely (!c->check_assign (out->len, |
1008 | 0 | (c->length () - init_len) / UnicodeValueRange::static_size, |
1009 | 0 | HB_SERIALIZE_ERROR_INT_OVERFLOW))) return nullptr; |
1010 | 0 | return out; |
1011 | 0 | } |
1012 | 0 | } |
1013 | | |
1014 | | public: |
1015 | | DEFINE_SIZE_ARRAY (4, *this); |
1016 | | }; |
1017 | | |
1018 | | struct UVSMapping |
1019 | | { |
1020 | | int cmp (const hb_codepoint_t &codepoint) const |
1021 | 59 | { return unicodeValue.cmp (codepoint); } |
1022 | | |
1023 | | bool sanitize (hb_sanitize_context_t *c) const |
1024 | 0 | { |
1025 | 0 | TRACE_SANITIZE (this); |
1026 | 0 | return_trace (c->check_struct (this)); |
1027 | 0 | } |
1028 | | |
1029 | | HBUINT24 unicodeValue; /* Base Unicode value of the UVS */ |
1030 | | HBGlyphID16 glyphID; /* Glyph ID of the UVS */ |
1031 | | public: |
1032 | | DEFINE_SIZE_STATIC (5); |
1033 | | }; |
1034 | | |
1035 | | struct NonDefaultUVS : SortedArray32Of<UVSMapping> |
1036 | | { |
1037 | | void collect_unicodes (hb_set_t *out) const |
1038 | 312k | { |
1039 | 312k | for (const auto& a : as_array ()) |
1040 | 231 | out->add (a.unicodeValue); |
1041 | 312k | } |
1042 | | |
1043 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
1044 | | hb_map_t *mapping /* OUT */) const |
1045 | 0 | { |
1046 | 0 | for (const auto& a : as_array ()) |
1047 | 0 | { |
1048 | 0 | hb_codepoint_t unicode = a.unicodeValue; |
1049 | 0 | hb_codepoint_t glyphid = a.glyphID; |
1050 | 0 | unicodes->add (unicode); |
1051 | 0 | mapping->set (unicode, glyphid); |
1052 | 0 | } |
1053 | 0 | } |
1054 | | |
1055 | | void closure_glyphs (const hb_set_t *unicodes, |
1056 | | hb_set_t *glyphset) const |
1057 | 0 | { |
1058 | 0 | + as_array () |
1059 | 0 | | hb_filter (unicodes, &UVSMapping::unicodeValue) |
1060 | 0 | | hb_map (&UVSMapping::glyphID) |
1061 | 0 | | hb_sink (glyphset) |
1062 | 0 | ; |
1063 | 0 | } |
1064 | | |
1065 | | NonDefaultUVS* copy (hb_serialize_context_t *c, |
1066 | | const hb_set_t *unicodes, |
1067 | | const hb_set_t *glyphs_requested, |
1068 | | const hb_map_t *glyph_map) const |
1069 | 0 | { |
1070 | 0 | NonDefaultUVS *out = c->start_embed<NonDefaultUVS> (); |
1071 | 0 | if (unlikely (!out)) return nullptr; |
1072 | 0 |
|
1073 | 0 | auto it = |
1074 | 0 | + as_array () |
1075 | 0 | | hb_filter ([&] (const UVSMapping& _) |
1076 | 0 | { |
1077 | 0 | return unicodes->has (_.unicodeValue) || glyphs_requested->has (_.glyphID); |
1078 | 0 | }) |
1079 | 0 | ; |
1080 | 0 |
|
1081 | 0 | if (!it) return nullptr; |
1082 | 0 |
|
1083 | 0 | HBUINT32 len; |
1084 | 0 | len = it.len (); |
1085 | 0 | if (unlikely (!c->copy<HBUINT32> (len))) return nullptr; |
1086 | 0 |
|
1087 | 0 | for (const UVSMapping& _ : it) |
1088 | 0 | { |
1089 | 0 | UVSMapping mapping; |
1090 | 0 | mapping.unicodeValue = _.unicodeValue; |
1091 | 0 | mapping.glyphID = glyph_map->get (_.glyphID); |
1092 | 0 | c->copy<UVSMapping> (mapping); |
1093 | 0 | } |
1094 | 0 |
|
1095 | 0 | return out; |
1096 | 0 | } |
1097 | | |
1098 | | public: |
1099 | | DEFINE_SIZE_ARRAY (4, *this); |
1100 | | }; |
1101 | | |
1102 | | struct VariationSelectorRecord |
1103 | | { |
1104 | | glyph_variant_t get_glyph (hb_codepoint_t codepoint, |
1105 | | hb_codepoint_t *glyph, |
1106 | | const void *base) const |
1107 | 313k | { |
1108 | 313k | if ((base+defaultUVS).bfind (codepoint)) |
1109 | 26 | return GLYPH_VARIANT_USE_DEFAULT; |
1110 | 313k | const UVSMapping &nonDefault = (base+nonDefaultUVS).bsearch (codepoint); |
1111 | 313k | if (nonDefault.glyphID) |
1112 | 3 | { |
1113 | 3 | *glyph = nonDefault.glyphID; |
1114 | 3 | return GLYPH_VARIANT_FOUND; |
1115 | 3 | } |
1116 | 313k | return GLYPH_VARIANT_NOT_FOUND; |
1117 | 313k | } |
1118 | | |
1119 | | VariationSelectorRecord(const VariationSelectorRecord& other) |
1120 | 0 | { |
1121 | 0 | *this = other; |
1122 | 0 | } |
1123 | | |
1124 | | void operator= (const VariationSelectorRecord& other) |
1125 | 0 | { |
1126 | 0 | varSelector = other.varSelector; |
1127 | 0 | HBUINT32 offset = other.defaultUVS; |
1128 | 0 | defaultUVS = offset; |
1129 | 0 | offset = other.nonDefaultUVS; |
1130 | 0 | nonDefaultUVS = offset; |
1131 | 0 | } |
1132 | | |
1133 | | void collect_unicodes (hb_set_t *out, const void *base) const |
1134 | 312k | { |
1135 | 312k | (base+defaultUVS).collect_unicodes (out); |
1136 | 312k | (base+nonDefaultUVS).collect_unicodes (out); |
1137 | 312k | } |
1138 | | |
1139 | | void collect_mapping (const void *base, |
1140 | | hb_set_t *unicodes, /* OUT */ |
1141 | | hb_map_t *mapping /* OUT */) const |
1142 | 0 | { |
1143 | 0 | (base+defaultUVS).collect_unicodes (unicodes); |
1144 | 0 | (base+nonDefaultUVS).collect_mapping (unicodes, mapping); |
1145 | 0 | } |
1146 | | |
1147 | | int cmp (const hb_codepoint_t &variation_selector) const |
1148 | 10.4k | { return varSelector.cmp (variation_selector); } |
1149 | | |
1150 | | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
1151 | 31.2k | { |
1152 | 31.2k | TRACE_SANITIZE (this); |
1153 | 31.2k | return_trace (c->check_struct (this) && |
1154 | 31.2k | defaultUVS.sanitize (c, base) && |
1155 | 31.2k | nonDefaultUVS.sanitize (c, base)); |
1156 | 31.2k | } |
1157 | | |
1158 | | hb_pair_t<unsigned, unsigned> |
1159 | | copy (hb_serialize_context_t *c, |
1160 | | const hb_set_t *unicodes, |
1161 | | const hb_set_t *glyphs_requested, |
1162 | | const hb_map_t *glyph_map, |
1163 | | const void *base) const |
1164 | 0 | { |
1165 | 0 | auto snap = c->snapshot (); |
1166 | 0 | auto *out = c->embed<VariationSelectorRecord> (*this); |
1167 | 0 | if (unlikely (!out)) return hb_pair (0, 0); |
1168 | 0 |
|
1169 | 0 | out->defaultUVS = 0; |
1170 | 0 | out->nonDefaultUVS = 0; |
1171 | 0 |
|
1172 | 0 | unsigned non_default_uvs_objidx = 0; |
1173 | 0 | if (nonDefaultUVS != 0) |
1174 | 0 | { |
1175 | 0 | c->push (); |
1176 | 0 | if (c->copy (base+nonDefaultUVS, unicodes, glyphs_requested, glyph_map)) |
1177 | 0 | non_default_uvs_objidx = c->pop_pack (); |
1178 | 0 | else c->pop_discard (); |
1179 | 0 | } |
1180 | 0 |
|
1181 | 0 | unsigned default_uvs_objidx = 0; |
1182 | 0 | if (defaultUVS != 0) |
1183 | 0 | { |
1184 | 0 | c->push (); |
1185 | 0 | if (c->copy (base+defaultUVS, unicodes)) |
1186 | 0 | default_uvs_objidx = c->pop_pack (); |
1187 | 0 | else c->pop_discard (); |
1188 | 0 | } |
1189 | 0 |
|
1190 | 0 |
|
1191 | 0 | if (!default_uvs_objidx && !non_default_uvs_objidx) |
1192 | 0 | c->revert (snap); |
1193 | 0 |
|
1194 | 0 | return hb_pair (default_uvs_objidx, non_default_uvs_objidx); |
1195 | 0 | } |
1196 | | |
1197 | | HBUINT24 varSelector; /* Variation selector. */ |
1198 | | Offset32To<DefaultUVS> |
1199 | | defaultUVS; /* Offset to Default UVS Table. May be 0. */ |
1200 | | Offset32To<NonDefaultUVS> |
1201 | | nonDefaultUVS; /* Offset to Non-Default UVS Table. May be 0. */ |
1202 | | public: |
1203 | | DEFINE_SIZE_STATIC (11); |
1204 | | }; |
1205 | | |
1206 | | struct CmapSubtableFormat14 |
1207 | | { |
1208 | | glyph_variant_t get_glyph_variant (hb_codepoint_t codepoint, |
1209 | | hb_codepoint_t variation_selector, |
1210 | | hb_codepoint_t *glyph) const |
1211 | 313k | { return record.bsearch (variation_selector).get_glyph (codepoint, glyph, this); } |
1212 | | |
1213 | | void collect_variation_selectors (hb_set_t *out) const |
1214 | 312k | { |
1215 | 312k | for (const auto& a : record.as_array ()) |
1216 | 12.9k | out->add (a.varSelector); |
1217 | 312k | } |
1218 | | void collect_variation_unicodes (hb_codepoint_t variation_selector, |
1219 | | hb_set_t *out) const |
1220 | 312k | { record.bsearch (variation_selector).collect_unicodes (out, this); } |
1221 | | |
1222 | | void serialize (hb_serialize_context_t *c, |
1223 | | const hb_set_t *unicodes, |
1224 | | const hb_set_t *glyphs_requested, |
1225 | | const hb_map_t *glyph_map, |
1226 | | const void *base) |
1227 | 0 | { |
1228 | 0 | auto snap = c->snapshot (); |
1229 | 0 | unsigned table_initpos = c->length (); |
1230 | 0 | const char* init_tail = c->tail; |
1231 | 0 |
|
1232 | 0 | if (unlikely (!c->extend_min (this))) return; |
1233 | 0 | this->format = 14; |
1234 | 0 |
|
1235 | 0 | auto src_tbl = reinterpret_cast<const CmapSubtableFormat14*> (base); |
1236 | 0 |
|
1237 | 0 | /* |
1238 | 0 | * Some versions of OTS require that offsets are in order. Due to the use |
1239 | 0 | * of push()/pop_pack() serializing the variation records in order results |
1240 | 0 | * in the offsets being in reverse order (first record has the largest |
1241 | 0 | * offset). While this is perfectly valid, it will cause some versions of |
1242 | 0 | * OTS to consider this table bad. |
1243 | 0 | * |
1244 | 0 | * So to prevent this issue we serialize the variation records in reverse |
1245 | 0 | * order, so that the offsets are ordered from small to large. Since |
1246 | 0 | * variation records are supposed to be in increasing order of varSelector |
1247 | 0 | * we then have to reverse the order of the written variation selector |
1248 | 0 | * records after everything is finalized. |
1249 | 0 | */ |
1250 | 0 | hb_vector_t<hb_pair_t<unsigned, unsigned>> obj_indices; |
1251 | 0 | for (int i = src_tbl->record.len - 1; i >= 0; i--) |
1252 | 0 | { |
1253 | 0 | hb_pair_t<unsigned, unsigned> result = src_tbl->record[i].copy (c, unicodes, glyphs_requested, glyph_map, base); |
1254 | 0 | if (result.first || result.second) |
1255 | 0 | obj_indices.push (result); |
1256 | 0 | } |
1257 | 0 |
|
1258 | 0 | if (c->length () - table_initpos == CmapSubtableFormat14::min_size) |
1259 | 0 | { |
1260 | 0 | c->revert (snap); |
1261 | 0 | return; |
1262 | 0 | } |
1263 | 0 |
|
1264 | 0 | if (unlikely (!c->check_success (!obj_indices.in_error ()))) |
1265 | 0 | return; |
1266 | 0 |
|
1267 | 0 | int tail_len = init_tail - c->tail; |
1268 | 0 | c->check_assign (this->length, c->length () - table_initpos + tail_len, |
1269 | 0 | HB_SERIALIZE_ERROR_INT_OVERFLOW); |
1270 | 0 | c->check_assign (this->record.len, |
1271 | 0 | (c->length () - table_initpos - CmapSubtableFormat14::min_size) / |
1272 | 0 | VariationSelectorRecord::static_size, |
1273 | 0 | HB_SERIALIZE_ERROR_INT_OVERFLOW); |
1274 | 0 |
|
1275 | 0 | /* Correct the incorrect write order by reversing the order of the variation |
1276 | 0 | records array. */ |
1277 | 0 | _reverse_variation_records (); |
1278 | 0 |
|
1279 | 0 | /* Now that records are in the right order, we can set up the offsets. */ |
1280 | 0 | _add_links_to_variation_records (c, obj_indices); |
1281 | 0 | } |
1282 | | |
1283 | | void _reverse_variation_records () |
1284 | 0 | { |
1285 | 0 | record.as_array ().reverse (); |
1286 | 0 | } |
1287 | | |
1288 | | void _add_links_to_variation_records (hb_serialize_context_t *c, |
1289 | | const hb_vector_t<hb_pair_t<unsigned, unsigned>>& obj_indices) |
1290 | 0 | { |
1291 | 0 | for (unsigned i = 0; i < obj_indices.length; i++) |
1292 | 0 | { |
1293 | 0 | /* |
1294 | 0 | * Since the record array has been reversed (see comments in copy()) |
1295 | 0 | * but obj_indices has not been, the indices at obj_indices[i] |
1296 | 0 | * are for the variation record at record[j]. |
1297 | 0 | */ |
1298 | 0 | int j = obj_indices.length - 1 - i; |
1299 | 0 | c->add_link (record[j].defaultUVS, obj_indices[i].first); |
1300 | 0 | c->add_link (record[j].nonDefaultUVS, obj_indices[i].second); |
1301 | 0 | } |
1302 | 0 | } |
1303 | | |
1304 | | void closure_glyphs (const hb_set_t *unicodes, |
1305 | | hb_set_t *glyphset) const |
1306 | 0 | { |
1307 | 0 | + hb_iter (record) |
1308 | 0 | | hb_filter (hb_bool, &VariationSelectorRecord::nonDefaultUVS) |
1309 | 0 | | hb_map (&VariationSelectorRecord::nonDefaultUVS) |
1310 | 0 | | hb_map (hb_add (this)) |
1311 | 0 | | hb_apply ([=] (const NonDefaultUVS& _) { _.closure_glyphs (unicodes, glyphset); }) |
1312 | 0 | ; |
1313 | 0 | } |
1314 | | |
1315 | | void collect_unicodes (hb_set_t *out) const |
1316 | 0 | { |
1317 | 0 | for (const VariationSelectorRecord& _ : record) |
1318 | 0 | _.collect_unicodes (out, this); |
1319 | 0 | } |
1320 | | |
1321 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
1322 | | hb_map_t *mapping /* OUT */) const |
1323 | 0 | { |
1324 | 0 | for (const VariationSelectorRecord& _ : record) |
1325 | 0 | _.collect_mapping (this, unicodes, mapping); |
1326 | 0 | } |
1327 | | |
1328 | | bool sanitize (hb_sanitize_context_t *c) const |
1329 | 6.30k | { |
1330 | 6.30k | TRACE_SANITIZE (this); |
1331 | 6.30k | return_trace (c->check_struct (this) && |
1332 | 6.30k | record.sanitize (c, this)); |
1333 | 6.30k | } |
1334 | | |
1335 | | protected: |
1336 | | HBUINT16 format; /* Format number is set to 14. */ |
1337 | | HBUINT32 length; /* Byte length of this subtable. */ |
1338 | | SortedArray32Of<VariationSelectorRecord> |
1339 | | record; /* Variation selector records; sorted |
1340 | | * in increasing order of `varSelector'. */ |
1341 | | public: |
1342 | | DEFINE_SIZE_ARRAY (10, record); |
1343 | | }; |
1344 | | |
1345 | | struct CmapSubtable |
1346 | | { |
1347 | | /* Note: We intentionally do NOT implement subtable formats 2 and 8. */ |
1348 | | |
1349 | | bool get_glyph (hb_codepoint_t codepoint, |
1350 | | hb_codepoint_t *glyph) const |
1351 | 17.4M | { |
1352 | 17.4M | switch (u.format) { |
1353 | 15.5M | case 0: return u.format0 .get_glyph (codepoint, glyph); |
1354 | 635k | case 4: return u.format4 .get_glyph (codepoint, glyph); |
1355 | 58.8k | case 6: return u.format6 .get_glyph (codepoint, glyph); |
1356 | 83.7k | case 10: return u.format10.get_glyph (codepoint, glyph); |
1357 | 81.4k | case 12: return u.format12.get_glyph (codepoint, glyph); |
1358 | 910k | case 13: return u.format13.get_glyph (codepoint, glyph); |
1359 | 1.10k | case 14: |
1360 | 145k | default: return false; |
1361 | 17.4M | } |
1362 | 17.4M | } |
1363 | | void collect_unicodes (hb_set_t *out, unsigned int num_glyphs = UINT_MAX) const |
1364 | 312k | { |
1365 | 312k | switch (u.format) { |
1366 | 203k | case 0: u.format0 .collect_unicodes (out); return; |
1367 | 66.3k | case 4: u.format4 .collect_unicodes (out); return; |
1368 | 720 | case 6: u.format6 .collect_unicodes (out); return; |
1369 | 1.04k | case 10: u.format10.collect_unicodes (out); return; |
1370 | 36.0k | case 12: u.format12.collect_unicodes (out, num_glyphs); return; |
1371 | 2.68k | case 13: u.format13.collect_unicodes (out, num_glyphs); return; |
1372 | 13 | case 14: |
1373 | 1.61k | default: return; |
1374 | 312k | } |
1375 | 312k | } |
1376 | | |
1377 | | void collect_mapping (hb_set_t *unicodes, /* OUT */ |
1378 | | hb_map_t *mapping, /* OUT */ |
1379 | | unsigned num_glyphs = UINT_MAX) const |
1380 | 0 | { |
1381 | 0 | switch (u.format) { |
1382 | 0 | case 0: u.format0 .collect_mapping (unicodes, mapping); return; |
1383 | 0 | case 4: u.format4 .collect_mapping (unicodes, mapping); return; |
1384 | 0 | case 6: u.format6 .collect_mapping (unicodes, mapping); return; |
1385 | 0 | case 10: u.format10.collect_mapping (unicodes, mapping); return; |
1386 | 0 | case 12: u.format12.collect_mapping (unicodes, mapping, num_glyphs); return; |
1387 | 0 | case 13: u.format13.collect_mapping (unicodes, mapping, num_glyphs); return; |
1388 | 0 | case 14: |
1389 | 0 | default: return; |
1390 | 0 | } |
1391 | 0 | } |
1392 | | |
1393 | | unsigned get_language () const |
1394 | 0 | { |
1395 | 0 | switch (u.format) { |
1396 | 0 | case 0: return u.format0 .get_language (); |
1397 | 0 | case 4: return u.format4 .get_language (); |
1398 | 0 | case 6: return u.format6 .get_language (); |
1399 | 0 | case 10: return u.format10.get_language (); |
1400 | 0 | case 12: return u.format12.get_language (); |
1401 | 0 | case 13: return u.format13.get_language (); |
1402 | 0 | case 14: |
1403 | 0 | default: return 0; |
1404 | 0 | } |
1405 | 0 | } |
1406 | | |
1407 | | template<typename Iterator, |
1408 | | hb_requires (hb_is_iterator (Iterator))> |
1409 | | void serialize (hb_serialize_context_t *c, |
1410 | | Iterator it, |
1411 | | unsigned format, |
1412 | | const hb_subset_plan_t *plan, |
1413 | | const void *base) |
1414 | 0 | { |
1415 | 0 | switch (format) { |
1416 | 0 | case 4: return u.format4.serialize (c, it); |
1417 | 0 | case 12: return u.format12.serialize (c, it); |
1418 | 0 | case 14: return u.format14.serialize (c, &plan->unicodes, &plan->glyphs_requested, plan->glyph_map, base); |
1419 | 0 | default: return; |
1420 | 0 | } |
1421 | 0 | } Unexecuted instantiation: hb-common.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, unsigned int, hb_subset_plan_t const*, void const*) Unexecuted instantiation: hb-common.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, unsigned int, hb_subset_plan_t const*, void const*) Unexecuted instantiation: hb-face.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, unsigned int, hb_subset_plan_t const*, void const*) Unexecuted instantiation: hb-face.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, unsigned int, hb_subset_plan_t const*, void const*) Unexecuted instantiation: hb-ot-face.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>, unsigned int, hb_subset_plan_t const*, void const*) Unexecuted instantiation: hb-ot-face.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, unsigned int, hb_subset_plan_t const*, void const*) Unexecuted instantiation: hb-ot-font.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, unsigned int, hb_subset_plan_t const*, void const*) Unexecuted instantiation: hb-ot-font.cc:void OT::CmapSubtable::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, unsigned int, hb_subset_plan_t const*, void const*) |
1422 | | |
1423 | | bool sanitize (hb_sanitize_context_t *c) const |
1424 | 536k | { |
1425 | 536k | TRACE_SANITIZE (this); |
1426 | 536k | if (!u.format.sanitize (c)) return_trace (false); |
1427 | 488k | switch (u.format) { |
1428 | 68.2k | case 0: return_trace (u.format0 .sanitize (c)); |
1429 | 216k | case 4: return_trace (u.format4 .sanitize (c)); |
1430 | 18.1k | case 6: return_trace (u.format6 .sanitize (c)); |
1431 | 3.42k | case 10: return_trace (u.format10.sanitize (c)); |
1432 | 60.2k | case 12: return_trace (u.format12.sanitize (c)); |
1433 | 8.07k | case 13: return_trace (u.format13.sanitize (c)); |
1434 | 6.30k | case 14: return_trace (u.format14.sanitize (c)); |
1435 | 107k | default:return_trace (true); |
1436 | 488k | } |
1437 | 488k | } |
1438 | | |
1439 | | public: |
1440 | | union { |
1441 | | HBUINT16 format; /* Format identifier */ |
1442 | | CmapSubtableFormat0 format0; |
1443 | | CmapSubtableFormat4 format4; |
1444 | | CmapSubtableFormat6 format6; |
1445 | | CmapSubtableFormat10 format10; |
1446 | | CmapSubtableFormat12 format12; |
1447 | | CmapSubtableFormat13 format13; |
1448 | | CmapSubtableFormat14 format14; |
1449 | | } u; |
1450 | | public: |
1451 | | DEFINE_SIZE_UNION (2, format); |
1452 | | }; |
1453 | | |
1454 | | |
1455 | | struct EncodingRecord |
1456 | | { |
1457 | | int cmp (const EncodingRecord &other) const |
1458 | 1.08M | { |
1459 | 1.08M | int ret; |
1460 | 1.08M | ret = platformID.cmp (other.platformID); |
1461 | 1.08M | if (ret) return ret; |
1462 | 576k | ret = encodingID.cmp (other.encodingID); |
1463 | 576k | if (ret) return ret; |
1464 | 126k | return 0; |
1465 | 576k | } |
1466 | | |
1467 | | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
1468 | 605k | { |
1469 | 605k | TRACE_SANITIZE (this); |
1470 | 605k | return_trace (c->check_struct (this) && |
1471 | 605k | subtable.sanitize (c, base)); |
1472 | 605k | } |
1473 | | |
1474 | | template<typename Iterator, |
1475 | | hb_requires (hb_is_iterator (Iterator))> |
1476 | | EncodingRecord* copy (hb_serialize_context_t *c, |
1477 | | Iterator it, |
1478 | | unsigned format, |
1479 | | const void *base, |
1480 | | const hb_subset_plan_t *plan, |
1481 | | /* INOUT */ unsigned *objidx) const |
1482 | 0 | { |
1483 | 0 | TRACE_SERIALIZE (this); |
1484 | 0 | auto snap = c->snapshot (); |
1485 | 0 | auto *out = c->embed (this); |
1486 | 0 | if (unlikely (!out)) return_trace (nullptr); |
1487 | 0 | out->subtable = 0; |
1488 | 0 |
|
1489 | 0 | if (*objidx == 0) |
1490 | 0 | { |
1491 | 0 | CmapSubtable *cmapsubtable = c->push<CmapSubtable> (); |
1492 | 0 | unsigned origin_length = c->length (); |
1493 | 0 | cmapsubtable->serialize (c, it, format, plan, &(base+subtable)); |
1494 | 0 | if (c->length () - origin_length > 0) *objidx = c->pop_pack (); |
1495 | 0 | else c->pop_discard (); |
1496 | 0 | } |
1497 | 0 |
|
1498 | 0 | if (*objidx == 0) |
1499 | 0 | { |
1500 | 0 | c->revert (snap); |
1501 | 0 | return_trace (nullptr); |
1502 | 0 | } |
1503 | 0 |
|
1504 | 0 | c->add_link (out->subtable, *objidx); |
1505 | 0 | return_trace (out); |
1506 | 0 | } Unexecuted instantiation: hb-common.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const Unexecuted instantiation: hb-common.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const Unexecuted instantiation: hb-face.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const Unexecuted instantiation: hb-face.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const Unexecuted instantiation: hb-ot-face.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_11 const&)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const Unexecuted instantiation: hb-ot-face.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const Unexecuted instantiation: hb-ot-font.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_set_t const&, $_5 const&, ($_10 const&)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const Unexecuted instantiation: hb-ot-font.cc:OT::EncodingRecord* OT::EncodingRecord::copy<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, unsigned int, void const*, hb_subset_plan_t const*, unsigned int*) const |
1507 | | |
1508 | | HBUINT16 platformID; /* Platform ID. */ |
1509 | | HBUINT16 encodingID; /* Platform-specific encoding ID. */ |
1510 | | Offset32To<CmapSubtable> |
1511 | | subtable; /* Byte offset from beginning of table to the subtable for this encoding. */ |
1512 | | public: |
1513 | | DEFINE_SIZE_STATIC (8); |
1514 | | }; |
1515 | | |
1516 | | struct cmap; |
1517 | | |
1518 | | struct SubtableUnicodesCache { |
1519 | | |
1520 | | private: |
1521 | | hb_blob_ptr_t<cmap> base_blob; |
1522 | | const char* base; |
1523 | | hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> cached_unicodes; |
1524 | | |
1525 | | public: |
1526 | | |
1527 | | static SubtableUnicodesCache* create (hb_blob_ptr_t<cmap> source_table) |
1528 | 0 | { |
1529 | 0 | SubtableUnicodesCache* cache = |
1530 | 0 | (SubtableUnicodesCache*) hb_malloc (sizeof(SubtableUnicodesCache)); |
1531 | 0 | new (cache) SubtableUnicodesCache (source_table); |
1532 | 0 | return cache; |
1533 | 0 | } |
1534 | | |
1535 | 0 | static void destroy (void* value) { |
1536 | 0 | if (!value) return; |
1537 | 0 |
|
1538 | 0 | SubtableUnicodesCache* cache = (SubtableUnicodesCache*) value; |
1539 | 0 | cache->~SubtableUnicodesCache (); |
1540 | 0 | hb_free (cache); |
1541 | 0 | } |
1542 | | |
1543 | | SubtableUnicodesCache(const void* cmap_base) |
1544 | | : base_blob(), |
1545 | | base ((const char*) cmap_base), |
1546 | | cached_unicodes () |
1547 | 0 | {} |
1548 | | |
1549 | | SubtableUnicodesCache(hb_blob_ptr_t<cmap> base_blob_) |
1550 | | : base_blob(base_blob_), |
1551 | | base ((const char *) base_blob.get()), |
1552 | | cached_unicodes () |
1553 | 0 | {} |
1554 | | |
1555 | | ~SubtableUnicodesCache() |
1556 | 0 | { |
1557 | 0 | base_blob.destroy (); |
1558 | 0 | } |
1559 | | |
1560 | | bool same_base(const void* other) const |
1561 | 0 | { |
1562 | 0 | return other == (const void*) base; |
1563 | 0 | } |
1564 | | |
1565 | | const hb_set_t* set_for (const EncodingRecord* record, |
1566 | | SubtableUnicodesCache& mutable_cache) const |
1567 | 0 | { |
1568 | 0 | if (cached_unicodes.has ((unsigned) ((const char *) record - base))) |
1569 | 0 | return cached_unicodes.get ((unsigned) ((const char *) record - base)); |
1570 | 0 |
|
1571 | 0 | return mutable_cache.set_for (record); |
1572 | 0 | } |
1573 | | |
1574 | | const hb_set_t* set_for (const EncodingRecord* record) |
1575 | 0 | { |
1576 | 0 | if (!cached_unicodes.has ((unsigned) ((const char *) record - base))) |
1577 | 0 | { |
1578 | 0 | hb_set_t *s = hb_set_create (); |
1579 | 0 | if (unlikely (s->in_error ())) |
1580 | 0 | return hb_set_get_empty (); |
1581 | 0 |
|
1582 | 0 | (base+record->subtable).collect_unicodes (s); |
1583 | 0 |
|
1584 | 0 | if (unlikely (!cached_unicodes.set ((unsigned) ((const char *) record - base), hb::unique_ptr<hb_set_t> {s}))) |
1585 | 0 | return hb_set_get_empty (); |
1586 | 0 |
|
1587 | 0 | return s; |
1588 | 0 | } |
1589 | 0 | return cached_unicodes.get ((unsigned) ((const char *) record - base)); |
1590 | 0 | } |
1591 | | |
1592 | | }; |
1593 | | |
1594 | | static inline uint_fast16_t |
1595 | | _hb_symbol_pua_map (unsigned codepoint) |
1596 | 107k | { |
1597 | 107k | if (codepoint <= 0x00FFu) |
1598 | 59.8k | { |
1599 | | /* For symbol-encoded OpenType fonts, we duplicate the |
1600 | | * U+F000..F0FF range at U+0000..U+00FF. That's what |
1601 | | * Windows seems to do, and that's hinted about at: |
1602 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/recom |
1603 | | * under "Non-Standard (Symbol) Fonts". */ |
1604 | 59.8k | return 0xF000u + codepoint; |
1605 | 59.8k | } |
1606 | 47.3k | return 0; |
1607 | 107k | } Unexecuted instantiation: hb-common.cc:OT::_hb_symbol_pua_map(unsigned int) hb-face.cc:OT::_hb_symbol_pua_map(unsigned int) Line | Count | Source | 1596 | 107k | { | 1597 | 107k | if (codepoint <= 0x00FFu) | 1598 | 59.8k | { | 1599 | | /* For symbol-encoded OpenType fonts, we duplicate the | 1600 | | * U+F000..F0FF range at U+0000..U+00FF. That's what | 1601 | | * Windows seems to do, and that's hinted about at: | 1602 | | * https://docs.microsoft.com/en-us/typography/opentype/spec/recom | 1603 | | * under "Non-Standard (Symbol) Fonts". */ | 1604 | 59.8k | return 0xF000u + codepoint; | 1605 | 59.8k | } | 1606 | 47.3k | return 0; | 1607 | 107k | } |
Unexecuted instantiation: hb-ot-face.cc:OT::_hb_symbol_pua_map(unsigned int) Unexecuted instantiation: hb-ot-font.cc:OT::_hb_symbol_pua_map(unsigned int) |
1608 | | |
1609 | | struct cmap |
1610 | | { |
1611 | | static constexpr hb_tag_t tableTag = HB_OT_TAG_cmap; |
1612 | | |
1613 | | |
1614 | 0 | static SubtableUnicodesCache* create_filled_cache(hb_blob_ptr_t<cmap> source_table) { |
1615 | 0 | const cmap* cmap = source_table.get(); |
1616 | 0 | auto it = |
1617 | 0 | + hb_iter (cmap->encodingRecord) |
1618 | 0 | | hb_filter ([&](const EncodingRecord& _) { |
1619 | 0 | return cmap::filter_encoding_records_for_subset (cmap, _); |
1620 | 0 | }) |
1621 | 0 | ; |
1622 | 0 |
|
1623 | 0 | SubtableUnicodesCache* cache = SubtableUnicodesCache::create(source_table); |
1624 | 0 | for (const EncodingRecord& _ : it) |
1625 | 0 | cache->set_for(&_); // populate the cache for this encoding record. |
1626 | 0 |
|
1627 | 0 | return cache; |
1628 | 0 | } |
1629 | | |
1630 | | template<typename Iterator, typename EncodingRecIter, |
1631 | | hb_requires (hb_is_iterator (EncodingRecIter))> |
1632 | | bool serialize (hb_serialize_context_t *c, |
1633 | | Iterator it, |
1634 | | EncodingRecIter encodingrec_iter, |
1635 | | const void *base, |
1636 | | hb_subset_plan_t *plan, |
1637 | | bool drop_format_4 = false) |
1638 | 0 | { |
1639 | 0 | if (unlikely (!c->extend_min ((*this)))) return false; |
1640 | 0 | this->version = 0; |
1641 | 0 |
|
1642 | 0 | unsigned format4objidx = 0, format12objidx = 0, format14objidx = 0; |
1643 | 0 | auto snap = c->snapshot (); |
1644 | 0 |
|
1645 | 0 | SubtableUnicodesCache local_unicodes_cache (base); |
1646 | 0 | const SubtableUnicodesCache* unicodes_cache = &local_unicodes_cache; |
1647 | 0 |
|
1648 | 0 | if (plan->accelerator && |
1649 | 0 | plan->accelerator->cmap_cache && |
1650 | 0 | plan->accelerator->cmap_cache->same_base (base)) |
1651 | 0 | unicodes_cache = plan->accelerator->cmap_cache; |
1652 | 0 |
|
1653 | 0 | for (const EncodingRecord& _ : encodingrec_iter) |
1654 | 0 | { |
1655 | 0 | if (c->in_error ()) |
1656 | 0 | return false; |
1657 | 0 |
|
1658 | 0 | unsigned format = (base+_.subtable).u.format; |
1659 | 0 | if (format != 4 && format != 12 && format != 14) continue; |
1660 | 0 |
|
1661 | 0 | const hb_set_t* unicodes_set = unicodes_cache->set_for (&_, local_unicodes_cache); |
1662 | 0 |
|
1663 | 0 | if (!drop_format_4 && format == 4) |
1664 | 0 | { |
1665 | 0 | c->copy (_, + it | hb_filter (*unicodes_set, hb_first), 4u, base, plan, &format4objidx); |
1666 | 0 | if (c->in_error () && c->only_overflow ()) |
1667 | 0 | { |
1668 | 0 | // cmap4 overflowed, reset and retry serialization without format 4 subtables. |
1669 | 0 | c->revert (snap); |
1670 | 0 | return serialize (c, it, |
1671 | 0 | encodingrec_iter, |
1672 | 0 | base, |
1673 | 0 | plan, |
1674 | 0 | true); |
1675 | 0 | } |
1676 | 0 | } |
1677 | 0 |
|
1678 | 0 | else if (format == 12) |
1679 | 0 | { |
1680 | 0 | if (_can_drop (_, |
1681 | 0 | *unicodes_set, |
1682 | 0 | base, |
1683 | 0 | *unicodes_cache, |
1684 | 0 | local_unicodes_cache, |
1685 | 0 | + it | hb_map (hb_first), encodingrec_iter)) |
1686 | 0 | continue; |
1687 | 0 | c->copy (_, + it | hb_filter (*unicodes_set, hb_first), 12u, base, plan, &format12objidx); |
1688 | 0 | } |
1689 | 0 | else if (format == 14) c->copy (_, it, 14u, base, plan, &format14objidx); |
1690 | 0 | } |
1691 | 0 | c->check_assign(this->encodingRecord.len, |
1692 | 0 | (c->length () - cmap::min_size)/EncodingRecord::static_size, |
1693 | 0 | HB_SERIALIZE_ERROR_INT_OVERFLOW); |
1694 | 0 |
|
1695 | 0 | // Fail if format 4 was dropped and there is no cmap12. |
1696 | 0 | return !drop_format_4 || format12objidx; |
1697 | 0 | } Unexecuted instantiation: hb-common.cc:bool OT::cmap::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, void const*, hb_subset_plan_t*, bool) Unexecuted instantiation: hb-face.cc:bool OT::cmap::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, void const*, hb_subset_plan_t*, bool) Unexecuted instantiation: hb-ot-face.cc:bool OT::cmap::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_11 const, ($_11 const&)0>, ($_11 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_11 const, ($_11 const&)0>, void const*, hb_subset_plan_t*, bool) Unexecuted instantiation: hb-ot-font.cc:bool OT::cmap::serialize<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, ($_10 const&)0>(hb_serialize_context_t*, hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, void const*, hb_subset_plan_t*, bool) |
1698 | | |
1699 | | template<typename Iterator, typename EncodingRecordIterator, |
1700 | | hb_requires (hb_is_iterator (Iterator)), |
1701 | | hb_requires (hb_is_iterator (EncodingRecordIterator))> |
1702 | | bool _can_drop (const EncodingRecord& cmap12, |
1703 | | const hb_set_t& cmap12_unicodes, |
1704 | | const void* base, |
1705 | | const SubtableUnicodesCache& unicodes_cache, |
1706 | | SubtableUnicodesCache& local_unicodes_cache, |
1707 | | Iterator subset_unicodes, |
1708 | | EncodingRecordIterator encoding_records) |
1709 | 0 | { |
1710 | 0 | for (auto cp : + subset_unicodes | hb_filter (cmap12_unicodes)) |
1711 | 0 | { |
1712 | 0 | if (cp >= 0x10000) return false; |
1713 | 0 | } |
1714 | 0 |
|
1715 | 0 | unsigned target_platform; |
1716 | 0 | unsigned target_encoding; |
1717 | 0 | unsigned target_language = (base+cmap12.subtable).get_language (); |
1718 | 0 |
|
1719 | 0 | if (cmap12.platformID == 0 && cmap12.encodingID == 4) |
1720 | 0 | { |
1721 | 0 | target_platform = 0; |
1722 | 0 | target_encoding = 3; |
1723 | 0 | } else if (cmap12.platformID == 3 && cmap12.encodingID == 10) { |
1724 | 0 | target_platform = 3; |
1725 | 0 | target_encoding = 1; |
1726 | 0 | } else { |
1727 | 0 | return false; |
1728 | 0 | } |
1729 | 0 |
|
1730 | 0 | for (const auto& _ : encoding_records) |
1731 | 0 | { |
1732 | 0 | if (_.platformID != target_platform |
1733 | 0 | || _.encodingID != target_encoding |
1734 | 0 | || (base+_.subtable).get_language() != target_language) |
1735 | 0 | continue; |
1736 | 0 |
|
1737 | 0 | const hb_set_t* sibling_unicodes = unicodes_cache.set_for (&_, local_unicodes_cache); |
1738 | 0 |
|
1739 | 0 | auto cmap12 = + subset_unicodes | hb_filter (cmap12_unicodes); |
1740 | 0 | auto sibling = + subset_unicodes | hb_filter (*sibling_unicodes); |
1741 | 0 | for (; cmap12 && sibling; cmap12++, sibling++) |
1742 | 0 | { |
1743 | 0 | unsigned a = *cmap12; |
1744 | 0 | unsigned b = *sibling; |
1745 | 0 | if (a != b) return false; |
1746 | 0 | } |
1747 | 0 |
|
1748 | 0 | return !cmap12 && !sibling; |
1749 | 0 | } |
1750 | 0 |
|
1751 | 0 | return false; |
1752 | 0 | } Unexecuted instantiation: hb-common.cc:bool OT::cmap::_can_drop<hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_10 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, ($_10 const&)0, ($_10 const&)0>(hb_sorted_array_t<OT::EncodingRecord const>, hb_set_t const&, void const*, OT::SubtableUnicodesCache const&, void const&, hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_10 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>) Unexecuted instantiation: hb-face.cc:bool OT::cmap::_can_drop<hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_10 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, ($_10 const&)0, ($_10 const&)0>(hb_sorted_array_t<OT::EncodingRecord const>, hb_set_t const&, void const*, OT::SubtableUnicodesCache const&, void const&, hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_10 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>) Unexecuted instantiation: hb-ot-face.cc:bool OT::cmap::_can_drop<hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_11 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_11 const, ($_11 const&)0>, ($_11 const&)0, ($_11 const&)0>(hb_sorted_array_t<OT::EncodingRecord const>, hb_set_t const&, void const*, OT::SubtableUnicodesCache const&, void const&, hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_11 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_11 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_11 const, ($_11 const&)0>) Unexecuted instantiation: hb-ot-font.cc:bool OT::cmap::_can_drop<hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_10 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>, ($_10 const&)0, ($_10 const&)0>(hb_sorted_array_t<OT::EncodingRecord const>, hb_set_t const&, void const*, OT::SubtableUnicodesCache const&, void const&, hb_map_iter_t<hb_filter_iter_t<hb_sorted_array_t<hb_pair_t<unsigned int, unsigned int> const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(hb_pair_t<unsigned int, unsigned int>)#1}, $_10 const&, (void*)0>, $_5 const&, (hb_function_sortedness_t)0, ($_10 const&)0>, hb_filter_iter_t<hb_sorted_array_t<OT::EncodingRecord const>, OT::cmap::subset(hb_subset_context_t*) const::{lambda(OT::EncodingRecord&)#1}, $_10 const, ($_10 const&)0>) |
1753 | | |
1754 | | void closure_glyphs (const hb_set_t *unicodes, |
1755 | | hb_set_t *glyphset) const |
1756 | 0 | { |
1757 | 0 | + hb_iter (encodingRecord) |
1758 | 0 | | hb_map (&EncodingRecord::subtable) |
1759 | 0 | | hb_map (hb_add (this)) |
1760 | 0 | | hb_filter ([&] (const CmapSubtable& _) { return _.u.format == 14; }) |
1761 | 0 | | hb_apply ([=] (const CmapSubtable& _) { _.u.format14.closure_glyphs (unicodes, glyphset); }) |
1762 | 0 | ; |
1763 | 0 | } |
1764 | | |
1765 | | bool subset (hb_subset_context_t *c) const |
1766 | 0 | { |
1767 | 0 | TRACE_SUBSET (this); |
1768 | 0 |
|
1769 | 0 | cmap *cmap_prime = c->serializer->start_embed<cmap> (); |
1770 | 0 | if (unlikely (!c->serializer->check_success (cmap_prime))) return_trace (false); |
1771 | 0 |
|
1772 | 0 | auto encodingrec_iter = |
1773 | 0 | + hb_iter (encodingRecord) |
1774 | 0 | | hb_filter ([&](const EncodingRecord& _) { |
1775 | 0 | return cmap::filter_encoding_records_for_subset (this, _); |
1776 | 0 | }) |
1777 | 0 | ; |
1778 | 0 |
|
1779 | 0 | if (unlikely (!encodingrec_iter.len ())) return_trace (false); |
1780 | 0 |
|
1781 | 0 | const EncodingRecord *unicode_bmp= nullptr, *unicode_ucs4 = nullptr, *ms_bmp = nullptr, *ms_ucs4 = nullptr; |
1782 | 0 | bool has_format12 = false; |
1783 | 0 |
|
1784 | 0 | for (const EncodingRecord& _ : encodingrec_iter) |
1785 | 0 | { |
1786 | 0 | unsigned format = (this + _.subtable).u.format; |
1787 | 0 | if (format == 12) has_format12 = true; |
1788 | 0 |
|
1789 | 0 | const EncodingRecord *table = std::addressof (_); |
1790 | 0 | if (_.platformID == 0 && _.encodingID == 3) unicode_bmp = table; |
1791 | 0 | else if (_.platformID == 0 && _.encodingID == 4) unicode_ucs4 = table; |
1792 | 0 | else if (_.platformID == 3 && _.encodingID == 1) ms_bmp = table; |
1793 | 0 | else if (_.platformID == 3 && _.encodingID == 10) ms_ucs4 = table; |
1794 | 0 | } |
1795 | 0 |
|
1796 | 0 | if (unlikely (!has_format12 && !unicode_bmp && !ms_bmp)) return_trace (false); |
1797 | 0 | if (unlikely (has_format12 && (!unicode_ucs4 && !ms_ucs4))) return_trace (false); |
1798 | 0 |
|
1799 | 0 | auto it = |
1800 | 0 | + c->plan->unicode_to_new_gid_list.iter () |
1801 | 0 | | hb_filter ([&] (const hb_pair_t<hb_codepoint_t, hb_codepoint_t> _) |
1802 | 0 | { return (_.second != HB_MAP_VALUE_INVALID); }) |
1803 | 0 | ; |
1804 | 0 |
|
1805 | 0 | return_trace (cmap_prime->serialize (c->serializer, |
1806 | 0 | it, |
1807 | 0 | encodingrec_iter, |
1808 | 0 | this, |
1809 | 0 | c->plan)); |
1810 | 0 | } |
1811 | | |
1812 | | const CmapSubtable *find_best_subtable (bool *symbol = nullptr) const |
1813 | 307k | { |
1814 | 307k | if (symbol) *symbol = false; |
1815 | | |
1816 | 307k | const CmapSubtable *subtable; |
1817 | | |
1818 | | /* Symbol subtable. |
1819 | | * Prefer symbol if available. |
1820 | | * https://github.com/harfbuzz/harfbuzz/issues/1918 */ |
1821 | 307k | if ((subtable = this->find_subtable (3, 0))) |
1822 | 3.58k | { |
1823 | 3.58k | if (symbol) *symbol = true; |
1824 | 3.58k | return subtable; |
1825 | 3.58k | } |
1826 | | |
1827 | | /* 32-bit subtables. */ |
1828 | 304k | if ((subtable = this->find_subtable (3, 10))) return subtable; |
1829 | 266k | if ((subtable = this->find_subtable (0, 6))) return subtable; |
1830 | 266k | if ((subtable = this->find_subtable (0, 4))) return subtable; |
1831 | | |
1832 | | /* 16-bit subtables. */ |
1833 | 265k | if ((subtable = this->find_subtable (3, 1))) return subtable; |
1834 | 201k | if ((subtable = this->find_subtable (0, 3))) return subtable; |
1835 | 198k | if ((subtable = this->find_subtable (0, 2))) return subtable; |
1836 | 198k | if ((subtable = this->find_subtable (0, 1))) return subtable; |
1837 | 198k | if ((subtable = this->find_subtable (0, 0))) return subtable; |
1838 | | |
1839 | | /* Meh. */ |
1840 | 197k | return &Null (CmapSubtable); |
1841 | 198k | } |
1842 | | |
1843 | | struct accelerator_t |
1844 | | { |
1845 | | using cache_t = hb_cache_t<21, 16, 8, true>; |
1846 | | |
1847 | | accelerator_t (hb_face_t *face) |
1848 | 307k | { |
1849 | 307k | this->table = hb_sanitize_context_t ().reference_table<cmap> (face); |
1850 | 307k | bool symbol; |
1851 | 307k | this->subtable = table->find_best_subtable (&symbol); |
1852 | 307k | this->subtable_uvs = &Null (CmapSubtableFormat14); |
1853 | 307k | { |
1854 | 307k | const CmapSubtable *st = table->find_subtable (0, 5); |
1855 | 307k | if (st && st->u.format == 14) |
1856 | 1.94k | subtable_uvs = &st->u.format14; |
1857 | 307k | } |
1858 | | |
1859 | 307k | this->get_glyph_data = subtable; |
1860 | 307k | if (unlikely (symbol)) |
1861 | 3.58k | { |
1862 | 3.58k | switch ((unsigned) face->table.OS2->get_font_page ()) { |
1863 | 1.79k | case OS2::font_page_t::FONT_PAGE_NONE: |
1864 | 1.79k | this->get_glyph_funcZ = get_glyph_from_symbol<CmapSubtable, _hb_symbol_pua_map>; |
1865 | 1.79k | break; |
1866 | 0 | #ifndef HB_NO_OT_SHAPER_ARABIC_FALLBACK |
1867 | 1.02k | case OS2::font_page_t::FONT_PAGE_SIMP_ARABIC: |
1868 | 1.02k | this->get_glyph_funcZ = get_glyph_from_symbol<CmapSubtable, _hb_arabic_pua_simp_map>; |
1869 | 1.02k | break; |
1870 | 718 | case OS2::font_page_t::FONT_PAGE_TRAD_ARABIC: |
1871 | 718 | this->get_glyph_funcZ = get_glyph_from_symbol<CmapSubtable, _hb_arabic_pua_trad_map>; |
1872 | 718 | break; |
1873 | 0 | #endif |
1874 | 49 | default: |
1875 | 49 | this->get_glyph_funcZ = get_glyph_from<CmapSubtable>; |
1876 | 49 | break; |
1877 | 3.58k | } |
1878 | 3.58k | } |
1879 | 304k | else |
1880 | 304k | { |
1881 | 304k | switch (subtable->u.format) { |
1882 | | /* Accelerate format 4 and format 12. */ |
1883 | 204k | default: |
1884 | 204k | this->get_glyph_funcZ = get_glyph_from<CmapSubtable>; |
1885 | 204k | break; |
1886 | 35.5k | case 12: |
1887 | 35.5k | this->get_glyph_funcZ = get_glyph_from<CmapSubtableFormat12>; |
1888 | 35.5k | break; |
1889 | 64.1k | case 4: |
1890 | 64.1k | { |
1891 | 64.1k | this->format4_accel.init (&subtable->u.format4); |
1892 | 64.1k | this->get_glyph_data = &this->format4_accel; |
1893 | 64.1k | this->get_glyph_funcZ = this->format4_accel.get_glyph_func; |
1894 | 64.1k | break; |
1895 | 0 | } |
1896 | 304k | } |
1897 | 304k | } |
1898 | 307k | } |
1899 | 307k | ~accelerator_t () { this->table.destroy (); } |
1900 | | |
1901 | | inline bool _cached_get (hb_codepoint_t unicode, |
1902 | | hb_codepoint_t *glyph, |
1903 | | cache_t *cache) const |
1904 | 27.3M | { |
1905 | 27.3M | unsigned v; |
1906 | 27.3M | if (cache && cache->get (unicode, &v)) |
1907 | 1.23M | { |
1908 | 1.23M | *glyph = v; |
1909 | 1.23M | return true; |
1910 | 1.23M | } |
1911 | 26.0M | bool ret = this->get_glyph_funcZ (this->get_glyph_data, unicode, glyph); |
1912 | | |
1913 | 26.0M | if (cache && ret) |
1914 | 2.22M | cache->set (unicode, *glyph); |
1915 | 26.0M | return ret; |
1916 | 27.3M | } |
1917 | | |
1918 | | bool get_nominal_glyph (hb_codepoint_t unicode, |
1919 | | hb_codepoint_t *glyph, |
1920 | | cache_t *cache = nullptr) const |
1921 | 21.4M | { |
1922 | 21.4M | if (unlikely (!this->get_glyph_funcZ)) return 0; |
1923 | 21.2M | return _cached_get (unicode, glyph, cache); |
1924 | 21.4M | } |
1925 | | |
1926 | | unsigned int get_nominal_glyphs (unsigned int count, |
1927 | | const hb_codepoint_t *first_unicode, |
1928 | | unsigned int unicode_stride, |
1929 | | hb_codepoint_t *first_glyph, |
1930 | | unsigned int glyph_stride, |
1931 | | cache_t *cache = nullptr) const |
1932 | 5.52M | { |
1933 | 5.52M | if (unlikely (!this->get_glyph_funcZ)) return 0; |
1934 | | |
1935 | 5.49M | unsigned int done; |
1936 | 5.49M | for (done = 0; |
1937 | 6.58M | done < count && _cached_get (*first_unicode, first_glyph, cache); |
1938 | 5.49M | done++) |
1939 | 1.09M | { |
1940 | 1.09M | first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride); |
1941 | 1.09M | first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
1942 | 1.09M | } |
1943 | 5.49M | return done; |
1944 | 5.52M | } |
1945 | | |
1946 | | bool get_variation_glyph (hb_codepoint_t unicode, |
1947 | | hb_codepoint_t variation_selector, |
1948 | | hb_codepoint_t *glyph, |
1949 | | cache_t *cache = nullptr) const |
1950 | 313k | { |
1951 | 313k | switch (this->subtable_uvs->get_glyph_variant (unicode, |
1952 | 313k | variation_selector, |
1953 | 313k | glyph)) |
1954 | 313k | { |
1955 | 313k | case GLYPH_VARIANT_NOT_FOUND: return false; |
1956 | 3 | case GLYPH_VARIANT_FOUND: return true; |
1957 | 26 | case GLYPH_VARIANT_USE_DEFAULT: break; |
1958 | 313k | } |
1959 | | |
1960 | 26 | return get_nominal_glyph (unicode, glyph, cache); |
1961 | 313k | } |
1962 | | |
1963 | | void collect_unicodes (hb_set_t *out, unsigned int num_glyphs) const |
1964 | 312k | { subtable->collect_unicodes (out, num_glyphs); } |
1965 | | void collect_mapping (hb_set_t *unicodes, hb_map_t *mapping, |
1966 | | unsigned num_glyphs = UINT_MAX) const |
1967 | 0 | { subtable->collect_mapping (unicodes, mapping, num_glyphs); } |
1968 | | void collect_variation_selectors (hb_set_t *out) const |
1969 | 312k | { subtable_uvs->collect_variation_selectors (out); } |
1970 | | void collect_variation_unicodes (hb_codepoint_t variation_selector, |
1971 | | hb_set_t *out) const |
1972 | 312k | { subtable_uvs->collect_variation_unicodes (variation_selector, out); } |
1973 | | |
1974 | | protected: |
1975 | | typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj, |
1976 | | hb_codepoint_t codepoint, |
1977 | | hb_codepoint_t *glyph); |
1978 | | typedef uint_fast16_t (*hb_pua_remap_func_t) (unsigned); |
1979 | | |
1980 | | template <typename Type> |
1981 | | HB_INTERNAL static bool get_glyph_from (const void *obj, |
1982 | | hb_codepoint_t codepoint, |
1983 | | hb_codepoint_t *glyph) |
1984 | 19.9M | { |
1985 | 19.9M | const Type *typed_obj = (const Type *) obj; |
1986 | 19.9M | return typed_obj->get_glyph (codepoint, glyph); |
1987 | 19.9M | } bool OT::cmap::accelerator_t::get_glyph_from<OT::CmapSubtable>(void const*, unsigned int, unsigned int*) Line | Count | Source | 1984 | 16.5M | { | 1985 | 16.5M | const Type *typed_obj = (const Type *) obj; | 1986 | 16.5M | return typed_obj->get_glyph (codepoint, glyph); | 1987 | 16.5M | } |
bool OT::cmap::accelerator_t::get_glyph_from<OT::CmapSubtableFormat12>(void const*, unsigned int, unsigned int*) Line | Count | Source | 1984 | 3.36M | { | 1985 | 3.36M | const Type *typed_obj = (const Type *) obj; | 1986 | 3.36M | return typed_obj->get_glyph (codepoint, glyph); | 1987 | 3.36M | } |
|
1988 | | |
1989 | | template <typename Type, hb_pua_remap_func_t remap> |
1990 | | HB_INTERNAL static bool get_glyph_from_symbol (const void *obj, |
1991 | | hb_codepoint_t codepoint, |
1992 | | hb_codepoint_t *glyph) |
1993 | 667k | { |
1994 | 667k | const Type *typed_obj = (const Type *) obj; |
1995 | 667k | if (likely (typed_obj->get_glyph (codepoint, glyph))) |
1996 | 164k | return true; |
1997 | | |
1998 | 502k | if (hb_codepoint_t c = remap (codepoint)) |
1999 | 187k | return typed_obj->get_glyph (c, glyph); |
2000 | | |
2001 | 315k | return false; |
2002 | 502k | } Unexecuted instantiation: hb-common.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &OT::_hb_symbol_pua_map>(void const*, unsigned int, unsigned int*) Unexecuted instantiation: hb-common.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_simp_map(unsigned int))>(void const*, unsigned int, unsigned int*) Unexecuted instantiation: hb-common.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_trad_map(unsigned int))>(void const*, unsigned int, unsigned int*) hb-face.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &OT::_hb_symbol_pua_map>(void const*, unsigned int, unsigned int*) Line | Count | Source | 1993 | 231k | { | 1994 | 231k | const Type *typed_obj = (const Type *) obj; | 1995 | 231k | if (likely (typed_obj->get_glyph (codepoint, glyph))) | 1996 | 124k | return true; | 1997 | | | 1998 | 107k | if (hb_codepoint_t c = remap (codepoint)) | 1999 | 59.8k | return typed_obj->get_glyph (c, glyph); | 2000 | | | 2001 | 47.3k | return false; | 2002 | 107k | } |
hb-face.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_simp_map(unsigned int))>(void const*, unsigned int, unsigned int*) Line | Count | Source | 1993 | 282k | { | 1994 | 282k | const Type *typed_obj = (const Type *) obj; | 1995 | 282k | if (likely (typed_obj->get_glyph (codepoint, glyph))) | 1996 | 24.8k | return true; | 1997 | | | 1998 | 257k | if (hb_codepoint_t c = remap (codepoint)) | 1999 | 81.0k | return typed_obj->get_glyph (c, glyph); | 2000 | | | 2001 | 176k | return false; | 2002 | 257k | } |
hb-face.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_trad_map(unsigned int))>(void const*, unsigned int, unsigned int*) Line | Count | Source | 1993 | 153k | { | 1994 | 153k | const Type *typed_obj = (const Type *) obj; | 1995 | 153k | if (likely (typed_obj->get_glyph (codepoint, glyph))) | 1996 | 15.1k | return true; | 1997 | | | 1998 | 138k | if (hb_codepoint_t c = remap (codepoint)) | 1999 | 46.7k | return typed_obj->get_glyph (c, glyph); | 2000 | | | 2001 | 91.3k | return false; | 2002 | 138k | } |
Unexecuted instantiation: hb-ot-face.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &OT::_hb_symbol_pua_map>(void const*, unsigned int, unsigned int*) Unexecuted instantiation: hb-ot-face.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_simp_map(unsigned int))>(void const*, unsigned int, unsigned int*) Unexecuted instantiation: hb-ot-face.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_trad_map(unsigned int))>(void const*, unsigned int, unsigned int*) Unexecuted instantiation: hb-ot-font.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &OT::_hb_symbol_pua_map>(void const*, unsigned int, unsigned int*) Unexecuted instantiation: hb-ot-font.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_simp_map(unsigned int))>(void const*, unsigned int, unsigned int*) Unexecuted instantiation: hb-ot-font.cc:bool OT::cmap::accelerator_t::get_glyph_from_symbol<OT::CmapSubtable, &(_hb_arabic_pua_trad_map(unsigned int))>(void const*, unsigned int, unsigned int*) |
2003 | | |
2004 | | private: |
2005 | | hb_nonnull_ptr_t<const CmapSubtable> subtable; |
2006 | | hb_nonnull_ptr_t<const CmapSubtableFormat14> subtable_uvs; |
2007 | | |
2008 | | hb_cmap_get_glyph_func_t get_glyph_funcZ; |
2009 | | const void *get_glyph_data; |
2010 | | |
2011 | | CmapSubtableFormat4::accelerator_t format4_accel; |
2012 | | |
2013 | | public: |
2014 | | hb_blob_ptr_t<cmap> table; |
2015 | | }; |
2016 | | |
2017 | | protected: |
2018 | | |
2019 | | const CmapSubtable *find_subtable (unsigned int platform_id, |
2020 | | unsigned int encoding_id) const |
2021 | 2.51M | { |
2022 | 2.51M | EncodingRecord key; |
2023 | 2.51M | key.platformID = platform_id; |
2024 | 2.51M | key.encodingID = encoding_id; |
2025 | | |
2026 | 2.51M | const EncodingRecord &result = encodingRecord.bsearch (key); |
2027 | 2.51M | if (!result.subtable) |
2028 | 2.40M | return nullptr; |
2029 | | |
2030 | 112k | return &(this+result.subtable); |
2031 | 2.51M | } |
2032 | | |
2033 | | const EncodingRecord *find_encodingrec (unsigned int platform_id, |
2034 | | unsigned int encoding_id) const |
2035 | 0 | { |
2036 | 0 | EncodingRecord key; |
2037 | 0 | key.platformID = platform_id; |
2038 | 0 | key.encodingID = encoding_id; |
2039 | 0 |
|
2040 | 0 | return encodingRecord.as_array ().bsearch (key); |
2041 | 0 | } |
2042 | | |
2043 | | bool find_subtable (unsigned format) const |
2044 | 0 | { |
2045 | 0 | auto it = |
2046 | 0 | + hb_iter (encodingRecord) |
2047 | 0 | | hb_map (&EncodingRecord::subtable) |
2048 | 0 | | hb_map (hb_add (this)) |
2049 | 0 | | hb_filter ([&] (const CmapSubtable& _) { return _.u.format == format; }) |
2050 | 0 | ; |
2051 | 0 |
|
2052 | 0 | return it.len (); |
2053 | 0 | } |
2054 | | |
2055 | | public: |
2056 | | |
2057 | | bool sanitize (hb_sanitize_context_t *c) const |
2058 | 193k | { |
2059 | 193k | TRACE_SANITIZE (this); |
2060 | 193k | return_trace (c->check_struct (this) && |
2061 | 193k | likely (version == 0) && |
2062 | 193k | encodingRecord.sanitize (c, this)); |
2063 | 193k | } |
2064 | | |
2065 | | private: |
2066 | | |
2067 | | static bool filter_encoding_records_for_subset(const cmap* cmap, |
2068 | | const EncodingRecord& _) |
2069 | 0 | { |
2070 | 0 | return |
2071 | 0 | (_.platformID == 0 && _.encodingID == 3) || |
2072 | 0 | (_.platformID == 0 && _.encodingID == 4) || |
2073 | 0 | (_.platformID == 3 && _.encodingID == 1) || |
2074 | 0 | (_.platformID == 3 && _.encodingID == 10) || |
2075 | 0 | (cmap + _.subtable).u.format == 14; |
2076 | 0 | } |
2077 | | |
2078 | | protected: |
2079 | | HBUINT16 version; /* Table version number (0). */ |
2080 | | SortedArray16Of<EncodingRecord> |
2081 | | encodingRecord; /* Encoding tables. */ |
2082 | | public: |
2083 | | DEFINE_SIZE_ARRAY (4, encodingRecord); |
2084 | | }; |
2085 | | |
2086 | | struct cmap_accelerator_t : cmap::accelerator_t { |
2087 | 307k | cmap_accelerator_t (hb_face_t *face) : cmap::accelerator_t (face) {} |
2088 | | }; |
2089 | | |
2090 | | } /* namespace OT */ |
2091 | | |
2092 | | |
2093 | | #endif /* HB_OT_CMAP_TABLE_HH */ |