/src/harfbuzz/src/hb-buffer.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 1998-2004 David Turner and Werner Lemberg |
3 | | * Copyright © 2004,2007,2009,2010 Red Hat, Inc. |
4 | | * Copyright © 2011,2012 Google, Inc. |
5 | | * |
6 | | * This is part of HarfBuzz, a text shaping library. |
7 | | * |
8 | | * Permission is hereby granted, without written agreement and without |
9 | | * license or royalty fees, to use, copy, modify, and distribute this |
10 | | * software and its documentation for any purpose, provided that the |
11 | | * above copyright notice and the following two paragraphs appear in |
12 | | * all copies of this software. |
13 | | * |
14 | | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
15 | | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
16 | | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
17 | | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
18 | | * DAMAGE. |
19 | | * |
20 | | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
21 | | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
22 | | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
23 | | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
24 | | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
25 | | * |
26 | | * Red Hat Author(s): Owen Taylor, Behdad Esfahbod |
27 | | * Google Author(s): Behdad Esfahbod |
28 | | */ |
29 | | |
30 | | #ifndef HB_BUFFER_HH |
31 | | #define HB_BUFFER_HH |
32 | | |
33 | | #include "hb.hh" |
34 | | #include "hb-unicode.hh" |
35 | | #include "hb-set-digest.hh" |
36 | | |
37 | | |
38 | | static_assert ((sizeof (hb_glyph_info_t) == 20), ""); |
39 | | static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), ""); |
40 | | |
41 | | HB_MARK_AS_FLAG_T (hb_glyph_flags_t); |
42 | | HB_MARK_AS_FLAG_T (hb_buffer_flags_t); |
43 | | HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t); |
44 | | HB_MARK_AS_FLAG_T (hb_buffer_diff_flags_t); |
45 | | |
46 | | enum hb_buffer_scratch_flags_t { |
47 | | HB_BUFFER_SCRATCH_FLAG_DEFAULT = 0x00000000u, |
48 | | HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII = 0x00000001u, |
49 | | HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES = 0x00000002u, |
50 | | HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK = 0x00000004u, |
51 | | HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT = 0x00000008u, |
52 | | HB_BUFFER_SCRATCH_FLAG_HAS_CGJ = 0x00000010u, |
53 | | HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS = 0x00000020u, |
54 | | HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE = 0x00000040u, |
55 | | |
56 | | /* Reserved for shapers' internal use. */ |
57 | | HB_BUFFER_SCRATCH_FLAG_SHAPER0 = 0x01000000u, |
58 | | HB_BUFFER_SCRATCH_FLAG_SHAPER1 = 0x02000000u, |
59 | | HB_BUFFER_SCRATCH_FLAG_SHAPER2 = 0x04000000u, |
60 | | HB_BUFFER_SCRATCH_FLAG_SHAPER3 = 0x08000000u, |
61 | | }; |
62 | | HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t); |
63 | | |
64 | | |
65 | | /* |
66 | | * hb_buffer_t |
67 | | */ |
68 | | |
69 | | struct hb_buffer_t |
70 | | { |
71 | | hb_object_header_t header; |
72 | | |
73 | | /* |
74 | | * Information about how the text in the buffer should be treated. |
75 | | */ |
76 | | |
77 | | hb_unicode_funcs_t *unicode; /* Unicode functions */ |
78 | | hb_buffer_flags_t flags; /* BOT / EOT / etc. */ |
79 | | hb_buffer_cluster_level_t cluster_level; |
80 | | hb_codepoint_t replacement; /* U+FFFD or something else. */ |
81 | | hb_codepoint_t invisible; /* 0 or something else. */ |
82 | | hb_codepoint_t not_found; /* 0 or something else. */ |
83 | | |
84 | | /* |
85 | | * Buffer contents |
86 | | */ |
87 | | |
88 | | hb_buffer_content_type_t content_type; |
89 | | hb_segment_properties_t props; /* Script, language, direction */ |
90 | | |
91 | | bool successful; /* Allocations successful */ |
92 | | bool shaping_failed; /* Shaping failure */ |
93 | | bool have_output; /* Whether we have an output buffer going on */ |
94 | | bool have_positions; /* Whether we have positions */ |
95 | | |
96 | | unsigned int idx; /* Cursor into ->info and ->pos arrays */ |
97 | | unsigned int len; /* Length of ->info and ->pos arrays */ |
98 | | unsigned int out_len; /* Length of ->out_info array if have_output */ |
99 | | |
100 | | unsigned int allocated; /* Length of allocated arrays */ |
101 | | hb_glyph_info_t *info; |
102 | | hb_glyph_info_t *out_info; |
103 | | hb_glyph_position_t *pos; |
104 | | |
105 | | /* Text before / after the main buffer contents. |
106 | | * Always in Unicode, and ordered outward. |
107 | | * Index 0 is for "pre-context", 1 for "post-context". */ |
108 | | static constexpr unsigned CONTEXT_LENGTH = 5u; |
109 | | hb_codepoint_t context[2][CONTEXT_LENGTH]; |
110 | | unsigned int context_len[2]; |
111 | | |
112 | | |
113 | | /* |
114 | | * Managed by enter / leave |
115 | | */ |
116 | | |
117 | | uint8_t allocated_var_bits; |
118 | | uint8_t serial; |
119 | | hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */ |
120 | | unsigned int max_len; /* Maximum allowed len. */ |
121 | | int max_ops; /* Maximum allowed operations. */ |
122 | | /* The bits here reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ |
123 | | |
124 | | |
125 | | /* |
126 | | * Messaging callback |
127 | | */ |
128 | | |
129 | | #ifndef HB_NO_BUFFER_MESSAGE |
130 | | hb_buffer_message_func_t message_func; |
131 | | void *message_data; |
132 | | hb_destroy_func_t message_destroy; |
133 | | unsigned message_depth; /* How deeply are we inside a message callback? */ |
134 | | #else |
135 | | static constexpr unsigned message_depth = 0u; |
136 | | #endif |
137 | | |
138 | | |
139 | | |
140 | | /* Methods */ |
141 | | |
142 | 0 | HB_NODISCARD bool in_error () const { return !successful; } |
143 | | |
144 | | void allocate_var (unsigned int start, unsigned int count) |
145 | 418M | { |
146 | 418M | unsigned int end = start + count; |
147 | 418M | assert (end <= 8); |
148 | 0 | unsigned int bits = (1u<<end) - (1u<<start); |
149 | 418M | assert (0 == (allocated_var_bits & bits)); |
150 | 0 | allocated_var_bits |= bits; |
151 | 418M | } |
152 | | bool try_allocate_var (unsigned int start, unsigned int count) |
153 | 144k | { |
154 | 144k | unsigned int end = start + count; |
155 | 144k | assert (end <= 8); |
156 | 0 | unsigned int bits = (1u<<end) - (1u<<start); |
157 | 144k | if (allocated_var_bits & bits) |
158 | 2.11k | return false; |
159 | 142k | allocated_var_bits |= bits; |
160 | 142k | return true; |
161 | 144k | } |
162 | | void deallocate_var (unsigned int start, unsigned int count) |
163 | 418M | { |
164 | 418M | unsigned int end = start + count; |
165 | 418M | assert (end <= 8); |
166 | 0 | unsigned int bits = (1u<<end) - (1u<<start); |
167 | 418M | assert (bits == (allocated_var_bits & bits)); |
168 | 0 | allocated_var_bits &= ~bits; |
169 | 418M | } |
170 | | void assert_var (unsigned int start, unsigned int count) |
171 | 725M | { |
172 | 725M | unsigned int end = start + count; |
173 | 725M | assert (end <= 8); |
174 | 725M | HB_UNUSED unsigned int bits = (1u<<end) - (1u<<start); |
175 | 725M | assert (bits == (allocated_var_bits & bits)); |
176 | 725M | } |
177 | | void deallocate_var_all () |
178 | 433M | { |
179 | 433M | allocated_var_bits = 0; |
180 | 433M | } |
181 | | |
182 | 4.43G | hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; } |
183 | 0 | hb_glyph_info_t cur (unsigned int i = 0) const { return info[idx + i]; } |
184 | | |
185 | 32.2M | hb_glyph_position_t &cur_pos (unsigned int i = 0) { return pos[idx + i]; } |
186 | 0 | hb_glyph_position_t cur_pos (unsigned int i = 0) const { return pos[idx + i]; } |
187 | | |
188 | 4.44M | hb_glyph_info_t &prev () { return out_info[out_len ? out_len - 1 : 0]; } |
189 | 0 | hb_glyph_info_t prev () const { return out_info[out_len ? out_len - 1 : 0]; } |
190 | | |
191 | | hb_set_digest_t digest () const |
192 | 106M | { |
193 | 106M | hb_set_digest_t d; |
194 | 106M | d.init (); |
195 | 106M | d.add_array (&info[0].codepoint, len, sizeof (info[0])); |
196 | 106M | return d; |
197 | 106M | } |
198 | | |
199 | | HB_INTERNAL void similar (const hb_buffer_t &src); |
200 | | HB_INTERNAL void reset (); |
201 | | HB_INTERNAL void clear (); |
202 | | |
203 | | /* Called around shape() */ |
204 | | HB_INTERNAL void enter (); |
205 | | HB_INTERNAL void leave (); |
206 | | |
207 | | #ifndef HB_NO_BUFFER_VERIFY |
208 | | HB_INTERNAL |
209 | | #endif |
210 | | bool verify (hb_buffer_t *text_buffer, |
211 | | hb_font_t *font, |
212 | | const hb_feature_t *features, |
213 | | unsigned int num_features, |
214 | | const char * const *shapers) |
215 | | #ifndef HB_NO_BUFFER_VERIFY |
216 | | ; |
217 | | #else |
218 | | { return true; } |
219 | | #endif |
220 | | |
221 | 7.56G | unsigned int backtrack_len () const { return have_output ? out_len : idx; } |
222 | 6.85G | unsigned int lookahead_len () const { return len - idx; } |
223 | 5.67M | uint8_t next_serial () { return ++serial ? serial : ++serial; } |
224 | | |
225 | | HB_INTERNAL void add (hb_codepoint_t codepoint, |
226 | | unsigned int cluster); |
227 | | HB_INTERNAL void add_info (const hb_glyph_info_t &glyph_info); |
228 | | |
229 | | void reverse_range (unsigned start, unsigned end) |
230 | 1.60M | { |
231 | 1.60M | hb_array_t<hb_glyph_info_t> (info, len).reverse (start, end); |
232 | 1.60M | if (have_positions) |
233 | 132k | hb_array_t<hb_glyph_position_t> (pos, len).reverse (start, end); |
234 | 1.60M | } |
235 | 492k | void reverse () { reverse_range (0, len); } |
236 | | |
237 | | template <typename FuncType> |
238 | | void reverse_groups (const FuncType& group, |
239 | | bool merge_clusters = false) |
240 | 0 | { |
241 | 0 | if (unlikely (!len)) |
242 | 0 | return; |
243 | | |
244 | 0 | unsigned start = 0; |
245 | 0 | unsigned i; |
246 | 0 | for (i = 1; i < len; i++) |
247 | 0 | { |
248 | 0 | if (!group (info[i - 1], info[i])) |
249 | 0 | { |
250 | 0 | if (merge_clusters) |
251 | 0 | this->merge_clusters (start, i); |
252 | 0 | reverse_range (start, i); |
253 | 0 | start = i; |
254 | 0 | } |
255 | 0 | } |
256 | 0 | if (merge_clusters) |
257 | 0 | this->merge_clusters (start, i); |
258 | 0 | reverse_range (start, i); |
259 | |
|
260 | 0 | reverse (); |
261 | 0 | } |
262 | | |
263 | | template <typename FuncType> |
264 | | unsigned group_end (unsigned start, const FuncType& group) const |
265 | 109M | { |
266 | 310M | while (++start < len && group (info[start - 1], info[start])) |
267 | 200M | ; |
268 | | |
269 | 109M | return start; |
270 | 109M | } |
271 | | |
272 | | static bool _cluster_group_func (const hb_glyph_info_t& a, |
273 | | const hb_glyph_info_t& b) |
274 | 204M | { return a.cluster == b.cluster; } |
275 | | |
276 | 0 | void reverse_clusters () { reverse_groups (_cluster_group_func); } |
277 | | |
278 | | HB_INTERNAL void guess_segment_properties (); |
279 | | |
280 | | HB_INTERNAL bool sync (); |
281 | | HB_INTERNAL int sync_so_far (); |
282 | | HB_INTERNAL void clear_output (); |
283 | | HB_INTERNAL void clear_positions (); |
284 | | |
285 | | template <typename T> |
286 | | HB_NODISCARD bool replace_glyphs (unsigned int num_in, |
287 | | unsigned int num_out, |
288 | | const T *glyph_data) |
289 | 351M | { |
290 | 351M | if (unlikely (!make_room_for (num_in, num_out))) return false; |
291 | | |
292 | 349M | assert (idx + num_in <= len); |
293 | | |
294 | 0 | merge_clusters (idx, idx + num_in); |
295 | | |
296 | 349M | hb_glyph_info_t &orig_info = idx < len ? cur() : prev(); |
297 | | |
298 | 349M | hb_glyph_info_t *pinfo = &out_info[out_len]; |
299 | 781M | for (unsigned int i = 0; i < num_out; i++) |
300 | 431M | { |
301 | 431M | *pinfo = orig_info; |
302 | 431M | pinfo->codepoint = glyph_data[i]; |
303 | 431M | pinfo++; |
304 | 431M | } |
305 | | |
306 | 349M | idx += num_in; |
307 | 349M | out_len += num_out; |
308 | 349M | return true; |
309 | 351M | } bool hb_buffer_t::replace_glyphs<unsigned int>(unsigned int, unsigned int, unsigned int const*) Line | Count | Source | 289 | 266M | { | 290 | 266M | if (unlikely (!make_room_for (num_in, num_out))) return false; | 291 | | | 292 | 264M | assert (idx + num_in <= len); | 293 | | | 294 | 0 | merge_clusters (idx, idx + num_in); | 295 | | | 296 | 264M | hb_glyph_info_t &orig_info = idx < len ? cur() : prev(); | 297 | | | 298 | 264M | hb_glyph_info_t *pinfo = &out_info[out_len]; | 299 | 529M | for (unsigned int i = 0; i < num_out; i++) | 300 | 264M | { | 301 | 264M | *pinfo = orig_info; | 302 | 264M | pinfo->codepoint = glyph_data[i]; | 303 | 264M | pinfo++; | 304 | 264M | } | 305 | | | 306 | 264M | idx += num_in; | 307 | 264M | out_len += num_out; | 308 | 264M | return true; | 309 | 266M | } |
bool hb_buffer_t::replace_glyphs<OT::HBGlyphID16>(unsigned int, unsigned int, OT::HBGlyphID16 const*) Line | Count | Source | 289 | 84.8M | { | 290 | 84.8M | if (unlikely (!make_room_for (num_in, num_out))) return false; | 291 | | | 292 | 84.8M | assert (idx + num_in <= len); | 293 | | | 294 | 0 | merge_clusters (idx, idx + num_in); | 295 | | | 296 | 84.8M | hb_glyph_info_t &orig_info = idx < len ? cur() : prev(); | 297 | | | 298 | 84.8M | hb_glyph_info_t *pinfo = &out_info[out_len]; | 299 | 251M | for (unsigned int i = 0; i < num_out; i++) | 300 | 166M | { | 301 | 166M | *pinfo = orig_info; | 302 | 166M | pinfo->codepoint = glyph_data[i]; | 303 | 166M | pinfo++; | 304 | 166M | } | 305 | | | 306 | 84.8M | idx += num_in; | 307 | 84.8M | out_len += num_out; | 308 | 84.8M | return true; | 309 | 84.8M | } |
|
310 | | |
311 | | HB_NODISCARD bool replace_glyph (hb_codepoint_t glyph_index) |
312 | 6.95M | { return replace_glyphs (1, 1, &glyph_index); } |
313 | | |
314 | | /* Makes a copy of the glyph at idx to output and replace glyph_index */ |
315 | | HB_NODISCARD bool output_glyph (hb_codepoint_t glyph_index) |
316 | 259M | { return replace_glyphs (0, 1, &glyph_index); } |
317 | | |
318 | | HB_NODISCARD bool output_info (const hb_glyph_info_t &glyph_info) |
319 | 51.2M | { |
320 | 51.2M | if (unlikely (!make_room_for (0, 1))) return false; |
321 | | |
322 | 51.2M | out_info[out_len] = glyph_info; |
323 | | |
324 | 51.2M | out_len++; |
325 | 51.2M | return true; |
326 | 51.2M | } |
327 | | /* Copies glyph at idx to output but doesn't advance idx */ |
328 | | HB_NODISCARD bool copy_glyph () |
329 | 51.1M | { |
330 | | /* Extra copy because cur()'s return can be freed within |
331 | | * output_info() call if buffer reallocates. */ |
332 | 51.1M | return output_info (hb_glyph_info_t (cur())); |
333 | 51.1M | } |
334 | | |
335 | | /* Copies glyph at idx to output and advance idx. |
336 | | * If there's no output, just advance idx. */ |
337 | | HB_NODISCARD bool next_glyph () |
338 | 687M | { |
339 | 687M | if (have_output) |
340 | 510M | { |
341 | 510M | if (out_info != info || out_len != idx) |
342 | 66.8M | { |
343 | 66.8M | if (unlikely (!make_room_for (1, 1))) return false; |
344 | 66.8M | out_info[out_len] = info[idx]; |
345 | 66.8M | } |
346 | 510M | out_len++; |
347 | 510M | } |
348 | | |
349 | 687M | idx++; |
350 | 687M | return true; |
351 | 687M | } |
352 | | /* Copies n glyphs at idx to output and advance idx. |
353 | | * If there's no output, just advance idx. */ |
354 | | HB_NODISCARD bool next_glyphs (unsigned int n) |
355 | 211M | { |
356 | 211M | if (have_output) |
357 | 211M | { |
358 | 211M | if (out_info != info || out_len != idx) |
359 | 818k | { |
360 | 818k | if (unlikely (!make_room_for (n, n))) return false; |
361 | 818k | memmove (out_info + out_len, info + idx, n * sizeof (out_info[0])); |
362 | 818k | } |
363 | 211M | out_len += n; |
364 | 211M | } |
365 | | |
366 | 211M | idx += n; |
367 | 211M | return true; |
368 | 211M | } |
369 | | /* Advance idx without copying to output. */ |
370 | 77.4M | void skip_glyph () { idx++; } |
371 | | void reset_masks (hb_mask_t mask) |
372 | 104M | { |
373 | 392M | for (unsigned int j = 0; j < len; j++) |
374 | 287M | info[j].mask = mask; |
375 | 104M | } |
376 | | void add_masks (hb_mask_t mask) |
377 | 0 | { |
378 | 0 | for (unsigned int j = 0; j < len; j++) |
379 | 0 | info[j].mask |= mask; |
380 | 0 | } |
381 | | HB_INTERNAL void set_masks (hb_mask_t value, hb_mask_t mask, |
382 | | unsigned int cluster_start, unsigned int cluster_end); |
383 | | |
384 | | void merge_clusters (unsigned int start, unsigned int end) |
385 | 501M | { |
386 | 501M | if (end - start < 2) |
387 | 467M | return; |
388 | 33.6M | merge_clusters_impl (start, end); |
389 | 33.6M | } |
390 | | HB_INTERNAL void merge_clusters_impl (unsigned int start, unsigned int end); |
391 | | HB_INTERNAL void merge_out_clusters (unsigned int start, unsigned int end); |
392 | | /* Merge clusters for deleting current glyph, and skip it. */ |
393 | | HB_INTERNAL void delete_glyph (); |
394 | | HB_INTERNAL void delete_glyphs_inplace (bool (*filter) (const hb_glyph_info_t *info)); |
395 | | |
396 | | |
397 | | |
398 | | /* Adds glyph flags in mask to infos with clusters between start and end. |
399 | | * The start index will be from out-buffer if from_out_buffer is true. |
400 | | * If interior is true, then the cluster having the minimum value is skipped. */ |
401 | | void _set_glyph_flags (hb_mask_t mask, |
402 | | unsigned start = 0, |
403 | | unsigned end = (unsigned) -1, |
404 | | bool interior = false, |
405 | | bool from_out_buffer = false) |
406 | 351M | { |
407 | 351M | end = hb_min (end, len); |
408 | | |
409 | 351M | if (interior && !from_out_buffer && end - start < 2) |
410 | 57.4M | return; |
411 | | |
412 | 293M | scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS; |
413 | | |
414 | 293M | if (!from_out_buffer || !have_output) |
415 | 146M | { |
416 | 146M | if (!interior) |
417 | 0 | { |
418 | 0 | for (unsigned i = start; i < end; i++) |
419 | 0 | info[i].mask |= mask; |
420 | 0 | } |
421 | 146M | else |
422 | 146M | { |
423 | 146M | unsigned cluster = _infos_find_min_cluster (info, start, end); |
424 | 146M | _infos_set_glyph_flags (info, start, end, cluster, mask); |
425 | 146M | } |
426 | 146M | } |
427 | 147M | else |
428 | 147M | { |
429 | 147M | assert (start <= out_len); |
430 | 0 | assert (idx <= end); |
431 | | |
432 | 147M | if (!interior) |
433 | 0 | { |
434 | 0 | for (unsigned i = start; i < out_len; i++) |
435 | 0 | out_info[i].mask |= mask; |
436 | 0 | for (unsigned i = idx; i < end; i++) |
437 | 0 | info[i].mask |= mask; |
438 | 0 | } |
439 | 147M | else |
440 | 147M | { |
441 | 147M | unsigned cluster = _infos_find_min_cluster (info, idx, end); |
442 | 147M | cluster = _infos_find_min_cluster (out_info, start, out_len, cluster); |
443 | | |
444 | 147M | _infos_set_glyph_flags (out_info, start, out_len, cluster, mask); |
445 | 147M | _infos_set_glyph_flags (info, idx, end, cluster, mask); |
446 | 147M | } |
447 | 147M | } |
448 | 293M | } |
449 | | |
450 | | void unsafe_to_break (unsigned int start = 0, unsigned int end = -1) |
451 | 77.5M | { |
452 | 77.5M | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_BREAK | HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
453 | 77.5M | start, end, |
454 | 77.5M | true); |
455 | 77.5M | } |
456 | | void safe_to_insert_tatweel (unsigned int start = 0, unsigned int end = -1) |
457 | 839 | { |
458 | 839 | if ((flags & HB_BUFFER_FLAG_PRODUCE_SAFE_TO_INSERT_TATWEEL) == 0) |
459 | 839 | { |
460 | 839 | unsafe_to_break (start, end); |
461 | 839 | return; |
462 | 839 | } |
463 | 0 | _set_glyph_flags (HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL, |
464 | 0 | start, end, |
465 | 0 | true); |
466 | 0 | } |
467 | | void unsafe_to_concat (unsigned int start = 0, unsigned int end = -1) |
468 | 59.3M | { |
469 | 59.3M | if (likely ((flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) == 0)) |
470 | 59.3M | return; |
471 | 0 | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
472 | 0 | start, end, |
473 | 0 | true); |
474 | 0 | } |
475 | | void unsafe_to_break_from_outbuffer (unsigned int start = 0, unsigned int end = -1) |
476 | 273M | { |
477 | 273M | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_BREAK | HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
478 | 273M | start, end, |
479 | 273M | true, true); |
480 | 273M | } |
481 | | void unsafe_to_concat_from_outbuffer (unsigned int start = 0, unsigned int end = -1) |
482 | 8.74M | { |
483 | 8.74M | if (likely ((flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) == 0)) |
484 | 8.74M | return; |
485 | 0 | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
486 | 0 | start, end, |
487 | 0 | false, true); |
488 | 0 | } |
489 | | |
490 | | |
491 | | /* Internal methods */ |
492 | | HB_NODISCARD HB_INTERNAL bool move_to (unsigned int i); /* i is output-buffer index. */ |
493 | | |
494 | | HB_NODISCARD HB_INTERNAL bool enlarge (unsigned int size); |
495 | | |
496 | | HB_NODISCARD bool ensure (unsigned int size) |
497 | 1.64G | { return likely (!size || size < allocated) ? true : enlarge (size); } |
498 | | |
499 | | HB_NODISCARD bool ensure_inplace (unsigned int size) |
500 | 0 | { return likely (!size || size < allocated); } |
501 | | |
502 | | void assert_glyphs () |
503 | 0 | { |
504 | 0 | assert ((content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS) || |
505 | 0 | (!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); |
506 | 0 | } |
507 | | void assert_unicode () |
508 | 130M | { |
509 | 130M | assert ((content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) || |
510 | 130M | (!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); |
511 | 130M | } |
512 | | HB_NODISCARD bool ensure_glyphs () |
513 | 0 | { |
514 | 0 | if (unlikely (content_type != HB_BUFFER_CONTENT_TYPE_GLYPHS)) |
515 | 0 | { |
516 | 0 | if (content_type != HB_BUFFER_CONTENT_TYPE_INVALID) |
517 | 0 | return false; |
518 | 0 | assert (len == 0); |
519 | 0 | content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; |
520 | 0 | } |
521 | 0 | return true; |
522 | 0 | } |
523 | | HB_NODISCARD bool ensure_unicode () |
524 | 0 | { |
525 | 0 | if (unlikely (content_type != HB_BUFFER_CONTENT_TYPE_UNICODE)) |
526 | 0 | { |
527 | 0 | if (content_type != HB_BUFFER_CONTENT_TYPE_INVALID) |
528 | 0 | return false; |
529 | 0 | assert (len == 0); |
530 | 0 | content_type = HB_BUFFER_CONTENT_TYPE_UNICODE; |
531 | 0 | } |
532 | 0 | return true; |
533 | 0 | } |
534 | | |
535 | | HB_NODISCARD HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); |
536 | | HB_NODISCARD HB_INTERNAL bool shift_forward (unsigned int count); |
537 | | |
538 | | typedef long scratch_buffer_t; |
539 | | HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size); |
540 | | |
541 | 389M | void clear_context (unsigned int side) { context_len[side] = 0; } |
542 | | |
543 | | HB_INTERNAL void sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *)); |
544 | | |
545 | | bool messaging () |
546 | 7.39G | { |
547 | | #ifdef HB_NO_BUFFER_MESSAGE |
548 | | return false; |
549 | | #else |
550 | 7.39G | return unlikely (message_func); |
551 | 7.39G | #endif |
552 | 7.39G | } |
553 | | bool message (hb_font_t *font, const char *fmt, ...) HB_PRINTF_FUNC(3, 4) |
554 | 209M | { |
555 | | #ifdef HB_NO_BUFFER_MESSAGE |
556 | | return true; |
557 | | #else |
558 | 209M | if (likely (!messaging ())) |
559 | 209M | return true; |
560 | | |
561 | 0 | va_list ap; |
562 | 0 | va_start (ap, fmt); |
563 | 0 | bool ret = message_impl (font, fmt, ap); |
564 | 0 | va_end (ap); |
565 | |
|
566 | 0 | return ret; |
567 | 209M | #endif |
568 | 209M | } |
569 | | HB_INTERNAL bool message_impl (hb_font_t *font, const char *fmt, va_list ap) HB_PRINTF_FUNC(3, 0); |
570 | | |
571 | | static void |
572 | | set_cluster (hb_glyph_info_t &inf, unsigned int cluster, unsigned int mask = 0) |
573 | 190G | { |
574 | 190G | if (inf.cluster != cluster) |
575 | 26.0M | inf.mask = (inf.mask & ~HB_GLYPH_FLAG_DEFINED) | (mask & HB_GLYPH_FLAG_DEFINED); |
576 | 190G | inf.cluster = cluster; |
577 | 190G | } |
578 | | void |
579 | | _infos_set_glyph_flags (hb_glyph_info_t *infos, |
580 | | unsigned int start, unsigned int end, |
581 | | unsigned int cluster, |
582 | | hb_mask_t mask) |
583 | 440M | { |
584 | 57.4G | for (unsigned int i = start; i < end; i++) |
585 | 57.0G | if (cluster != infos[i].cluster) |
586 | 25.3G | { |
587 | 25.3G | scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS; |
588 | 25.3G | infos[i].mask |= mask; |
589 | 25.3G | } |
590 | 440M | } |
591 | | static unsigned |
592 | | _infos_find_min_cluster (const hb_glyph_info_t *infos, |
593 | | unsigned start, unsigned end, |
594 | | unsigned cluster = UINT_MAX) |
595 | 440M | { |
596 | 57.4G | for (unsigned int i = start; i < end; i++) |
597 | 57.0G | cluster = hb_min (cluster, infos[i].cluster); |
598 | 440M | return cluster; |
599 | 440M | } |
600 | | |
601 | | void clear_glyph_flags (hb_mask_t mask = 0) |
602 | 0 | { |
603 | 0 | for (unsigned int i = 0; i < len; i++) |
604 | 0 | info[i].mask = (info[i].mask & ~HB_GLYPH_FLAG_DEFINED) | (mask & HB_GLYPH_FLAG_DEFINED); |
605 | 0 | } |
606 | | }; |
607 | | DECLARE_NULL_INSTANCE (hb_buffer_t); |
608 | | |
609 | | |
610 | | #define foreach_group(buffer, start, end, group_func) \ |
611 | 6.60M | for (unsigned int \ |
612 | 6.60M | _count = buffer->len, \ |
613 | 6.60M | start = 0, end = _count ? buffer->group_end (0, group_func) : 0; \ |
614 | 109M | start < _count; \ |
615 | 103M | start = end, end = buffer->group_end (start, group_func)) |
616 | | |
617 | | #define foreach_cluster(buffer, start, end) \ |
618 | 378k | foreach_group (buffer, start, end, hb_buffer_t::_cluster_group_func) |
619 | | |
620 | | |
621 | | #define HB_BUFFER_XALLOCATE_VAR(b, func, var) \ |
622 | 1.56G | b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ |
623 | 1.56G | sizeof (b->info[0].var)) |
624 | 418M | #define HB_BUFFER_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var ()) |
625 | 144k | #define HB_BUFFER_TRY_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, try_allocate_var, var ()) |
626 | 418M | #define HB_BUFFER_DEALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var ()) |
627 | 725M | #define HB_BUFFER_ASSERT_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, assert_var, var ()) |
628 | | |
629 | | |
630 | | #endif /* HB_BUFFER_HH */ |