/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 | | |
36 | | |
37 | | static_assert ((sizeof (hb_glyph_info_t) == 20), ""); |
38 | | static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), ""); |
39 | | |
40 | | HB_MARK_AS_FLAG_T (hb_glyph_flags_t); |
41 | | HB_MARK_AS_FLAG_T (hb_buffer_flags_t); |
42 | | HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t); |
43 | | HB_MARK_AS_FLAG_T (hb_buffer_diff_flags_t); |
44 | | |
45 | | enum hb_buffer_scratch_flags_t { |
46 | | HB_BUFFER_SCRATCH_FLAG_DEFAULT = 0x00000000u, |
47 | | HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII = 0x00000001u, |
48 | | HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES = 0x00000002u, |
49 | | HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK = 0x00000004u, |
50 | | HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT = 0x00000008u, |
51 | | HB_BUFFER_SCRATCH_FLAG_HAS_CGJ = 0x00000010u, |
52 | | HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS = 0x00000020u, |
53 | | HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE = 0x00000040u, |
54 | | HB_BUFFER_SCRATCH_FLAG_HAS_VARIATION_SELECTOR_FALLBACK= 0x00000080u, |
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 | | hb_codepoint_t not_found_variation_selector; /* HB_CODEPOINT_INVALID or something else. */ |
84 | | |
85 | | /* |
86 | | * Buffer contents |
87 | | */ |
88 | | |
89 | | hb_buffer_content_type_t content_type; |
90 | | hb_segment_properties_t props; /* Script, language, direction */ |
91 | | |
92 | | bool successful; /* Allocations successful */ |
93 | | bool shaping_failed; /* Shaping failure */ |
94 | | bool have_output; /* Whether we have an output buffer going on */ |
95 | | bool have_positions; /* Whether we have positions */ |
96 | | |
97 | | unsigned int idx; /* Cursor into ->info and ->pos arrays */ |
98 | | unsigned int len; /* Length of ->info and ->pos arrays */ |
99 | | unsigned int out_len; /* Length of ->out_info array if have_output */ |
100 | | |
101 | | unsigned int allocated; /* Length of allocated arrays */ |
102 | | hb_glyph_info_t *info; |
103 | | hb_glyph_info_t *out_info; |
104 | | hb_glyph_position_t *pos; |
105 | | |
106 | | /* Text before / after the main buffer contents. |
107 | | * Always in Unicode, and ordered outward. |
108 | | * Index 0 is for "pre-context", 1 for "post-context". */ |
109 | | static constexpr unsigned CONTEXT_LENGTH = 5u; |
110 | | hb_codepoint_t context[2][CONTEXT_LENGTH]; |
111 | | unsigned int context_len[2]; |
112 | | |
113 | | |
114 | | /* |
115 | | * Managed by enter / leave |
116 | | */ |
117 | | |
118 | | uint8_t allocated_var_bits; |
119 | | uint8_t serial; |
120 | | uint32_t random_state; |
121 | | hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */ |
122 | | unsigned int max_len; /* Maximum allowed len. */ |
123 | | int max_ops; /* Maximum allowed operations. */ |
124 | | /* The bits here reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ |
125 | | |
126 | | |
127 | | /* |
128 | | * Messaging callback |
129 | | */ |
130 | | |
131 | | #ifndef HB_NO_BUFFER_MESSAGE |
132 | | hb_buffer_message_func_t message_func; |
133 | | void *message_data; |
134 | | hb_destroy_func_t message_destroy; |
135 | | unsigned message_depth; /* How deeply are we inside a message callback? */ |
136 | | #else |
137 | | static constexpr unsigned message_depth = 0u; |
138 | | #endif |
139 | | |
140 | | |
141 | | |
142 | | /* Methods */ |
143 | | |
144 | 0 | HB_NODISCARD bool in_error () const { return !successful; } |
145 | | |
146 | | void allocate_var (unsigned int start, unsigned int count) |
147 | 805k | { |
148 | 805k | unsigned int end = start + count; |
149 | 805k | assert (end <= 8); |
150 | 805k | unsigned int bits = (1u<<end) - (1u<<start); |
151 | 805k | assert (0 == (allocated_var_bits & bits)); |
152 | 805k | allocated_var_bits |= bits; |
153 | 805k | } |
154 | | bool try_allocate_var (unsigned int start, unsigned int count) |
155 | 0 | { |
156 | 0 | unsigned int end = start + count; |
157 | 0 | assert (end <= 8); |
158 | 0 | unsigned int bits = (1u<<end) - (1u<<start); |
159 | 0 | if (allocated_var_bits & bits) |
160 | 0 | return false; |
161 | 0 | allocated_var_bits |= bits; |
162 | 0 | return true; |
163 | 0 | } |
164 | | void deallocate_var (unsigned int start, unsigned int count) |
165 | 805k | { |
166 | 805k | unsigned int end = start + count; |
167 | 805k | assert (end <= 8); |
168 | 805k | unsigned int bits = (1u<<end) - (1u<<start); |
169 | 805k | assert (bits == (allocated_var_bits & bits)); |
170 | 805k | allocated_var_bits &= ~bits; |
171 | 805k | } |
172 | | void assert_var (unsigned int start, unsigned int count) |
173 | 1.00M | { |
174 | 1.00M | unsigned int end = start + count; |
175 | 1.00M | assert (end <= 8); |
176 | 1.00M | HB_UNUSED unsigned int bits = (1u<<end) - (1u<<start); |
177 | 1.00M | assert (bits == (allocated_var_bits & bits)); |
178 | 1.00M | } |
179 | | void deallocate_var_all () |
180 | 815k | { |
181 | 815k | allocated_var_bits = 0; |
182 | 815k | } |
183 | | |
184 | | HB_ALWAYS_INLINE |
185 | 1.21M | hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; } |
186 | | HB_ALWAYS_INLINE |
187 | 0 | hb_glyph_info_t cur (unsigned int i = 0) const { return info[idx + i]; } |
188 | | |
189 | | HB_ALWAYS_INLINE |
190 | 0 | hb_glyph_position_t &cur_pos (unsigned int i = 0) { return pos[idx + i]; } |
191 | | HB_ALWAYS_INLINE |
192 | 0 | hb_glyph_position_t cur_pos (unsigned int i = 0) const { return pos[idx + i]; } |
193 | | |
194 | | HB_ALWAYS_INLINE |
195 | 12 | hb_glyph_info_t &prev () { return out_info[out_len ? out_len - 1 : 0]; } |
196 | | HB_ALWAYS_INLINE |
197 | 0 | hb_glyph_info_t prev () const { return out_info[out_len ? out_len - 1 : 0]; } |
198 | | |
199 | | template <typename set_t> |
200 | | void collect_codepoints (set_t &d) const |
201 | 402k | { d.clear (); d.add_array (&info[0].codepoint, len, sizeof (info[0])); } Unexecuted instantiation: void hb_buffer_t::collect_codepoints<hb_bit_set_t>(hb_bit_set_t&) const void hb_buffer_t::collect_codepoints<hb_set_digest_t>(hb_set_digest_t&) const Line | Count | Source | 201 | 402k | { d.clear (); d.add_array (&info[0].codepoint, len, sizeof (info[0])); } |
|
202 | | |
203 | | HB_INTERNAL void similar (const hb_buffer_t &src); |
204 | | HB_INTERNAL void reset (); |
205 | | HB_INTERNAL void clear (); |
206 | | |
207 | | /* Called around shape() */ |
208 | | HB_INTERNAL void enter (); |
209 | | HB_INTERNAL void leave (); |
210 | | |
211 | | #ifndef HB_NO_BUFFER_VERIFY |
212 | | HB_INTERNAL |
213 | | #endif |
214 | | bool verify (hb_buffer_t *text_buffer, |
215 | | hb_font_t *font, |
216 | | const hb_feature_t *features, |
217 | | unsigned int num_features, |
218 | | const char * const *shapers) |
219 | | #ifndef HB_NO_BUFFER_VERIFY |
220 | | ; |
221 | | #else |
222 | | { return true; } |
223 | | #endif |
224 | | |
225 | 0 | unsigned int backtrack_len () const { return have_output ? out_len : idx; } |
226 | 0 | unsigned int lookahead_len () const { return len - idx; } |
227 | 0 | uint8_t next_serial () { return ++serial ? serial : ++serial; } |
228 | | |
229 | | HB_INTERNAL void add (hb_codepoint_t codepoint, |
230 | | unsigned int cluster); |
231 | | HB_INTERNAL void add_info (const hb_glyph_info_t &glyph_info); |
232 | | HB_INTERNAL void add_info_and_pos (const hb_glyph_info_t &glyph_info, |
233 | | const hb_glyph_position_t &glyph_pos); |
234 | | |
235 | | void reverse_range (unsigned start, unsigned end) |
236 | 351 | { |
237 | 351 | hb_array_t<hb_glyph_info_t> (info, len).reverse (start, end); |
238 | 351 | if (have_positions) |
239 | 95 | hb_array_t<hb_glyph_position_t> (pos, len).reverse (start, end); |
240 | 351 | } |
241 | 217 | void reverse () { reverse_range (0, len); } |
242 | | |
243 | | template <typename FuncType> |
244 | | void reverse_groups (const FuncType& group, |
245 | | bool merge_clusters = false) |
246 | 122 | { |
247 | 122 | if (unlikely (!len)) |
248 | 0 | return; |
249 | | |
250 | 122 | unsigned start = 0; |
251 | 122 | unsigned i; |
252 | 134 | for (i = 1; i < len; i++) |
253 | 12 | { |
254 | 12 | if (!group (info[i - 1], info[i])) |
255 | 12 | { |
256 | 12 | if (merge_clusters) |
257 | 0 | this->merge_clusters (start, i); |
258 | 12 | reverse_range (start, i); |
259 | 12 | start = i; |
260 | 12 | } |
261 | 12 | } |
262 | 122 | if (merge_clusters) |
263 | 0 | this->merge_clusters (start, i); |
264 | 122 | reverse_range (start, i); |
265 | | |
266 | 122 | reverse (); |
267 | 122 | } |
268 | | |
269 | | template <typename FuncType> |
270 | | unsigned group_end (unsigned start, const FuncType& group) const |
271 | 1.21M | { |
272 | 1.21M | while (++start < len && group (info[start - 1], info[start])) |
273 | 1.70k | ; |
274 | | |
275 | 1.21M | return start; |
276 | 1.21M | } |
277 | | |
278 | | static bool _cluster_group_func (const hb_glyph_info_t& a, |
279 | | const hb_glyph_info_t& b) |
280 | 0 | { return a.cluster == b.cluster; } |
281 | | |
282 | 0 | void reverse_clusters () { reverse_groups (_cluster_group_func); } |
283 | | |
284 | | HB_INTERNAL void guess_segment_properties (); |
285 | | |
286 | | HB_INTERNAL bool sync (); |
287 | | HB_INTERNAL int sync_so_far (); |
288 | | HB_INTERNAL void clear_output (); |
289 | | HB_INTERNAL void clear_positions (); |
290 | | |
291 | | template <typename T> |
292 | | HB_NODISCARD bool replace_glyphs (unsigned int num_in, |
293 | | unsigned int num_out, |
294 | | const T *glyph_data) |
295 | 0 | { |
296 | 0 | if (unlikely (!make_room_for (num_in, num_out))) return false; |
297 | | |
298 | 0 | assert (idx + num_in <= len); |
299 | | |
300 | 0 | merge_clusters (idx, idx + num_in); |
301 | |
|
302 | 0 | hb_glyph_info_t &orig_info = idx < len ? cur() : prev(); |
303 | |
|
304 | 0 | hb_glyph_info_t *pinfo = &out_info[out_len]; |
305 | 0 | for (unsigned int i = 0; i < num_out; i++) |
306 | 0 | { |
307 | 0 | *pinfo = orig_info; |
308 | 0 | pinfo->codepoint = glyph_data[i]; |
309 | 0 | pinfo++; |
310 | 0 | } |
311 | |
|
312 | 0 | idx += num_in; |
313 | 0 | out_len += num_out; |
314 | 0 | return true; |
315 | 0 | } |
316 | | |
317 | | HB_NODISCARD bool replace_glyph (hb_codepoint_t glyph_index) |
318 | 0 | { return replace_glyphs (1, 1, &glyph_index); } |
319 | | |
320 | | /* Makes a copy of the glyph at idx to output and replace glyph_index */ |
321 | | HB_NODISCARD bool output_glyph (hb_codepoint_t glyph_index) |
322 | 0 | { return replace_glyphs (0, 1, &glyph_index); } |
323 | | |
324 | | HB_NODISCARD bool output_info (const hb_glyph_info_t &glyph_info) |
325 | 0 | { |
326 | 0 | if (unlikely (!make_room_for (0, 1))) return false; |
327 | | |
328 | 0 | out_info[out_len] = glyph_info; |
329 | |
|
330 | 0 | out_len++; |
331 | 0 | return true; |
332 | 0 | } |
333 | | /* Copies glyph at idx to output but doesn't advance idx */ |
334 | | HB_NODISCARD bool copy_glyph () |
335 | 0 | { |
336 | | /* Extra copy because cur()'s return can be freed within |
337 | | * output_info() call if buffer reallocates. */ |
338 | 0 | return output_info (hb_glyph_info_t (cur())); |
339 | 0 | } |
340 | | |
341 | | /* Copies glyph at idx to output and advance idx. |
342 | | * If there's no output, just advance idx. */ |
343 | | HB_NODISCARD bool next_glyph () |
344 | 378k | { |
345 | 378k | if (have_output) |
346 | 378k | { |
347 | 378k | if (out_info != info || out_len != idx) |
348 | 0 | { |
349 | 0 | if (unlikely (!make_room_for (1, 1))) return false; |
350 | 0 | out_info[out_len] = info[idx]; |
351 | 0 | } |
352 | 378k | out_len++; |
353 | 378k | } |
354 | | |
355 | 378k | idx++; |
356 | 378k | return true; |
357 | 378k | } |
358 | | /* Copies n glyphs at idx to output and advance idx. |
359 | | * If there's no output, just advance idx. */ |
360 | | HB_NODISCARD bool next_glyphs (unsigned int n) |
361 | 403k | { |
362 | 403k | if (have_output) |
363 | 403k | { |
364 | 403k | if (out_info != info || out_len != idx) |
365 | 0 | { |
366 | 0 | if (unlikely (!make_room_for (n, n))) return false; |
367 | 0 | memmove (out_info + out_len, info + idx, n * sizeof (out_info[0])); |
368 | 0 | } |
369 | 403k | out_len += n; |
370 | 403k | } |
371 | | |
372 | 403k | idx += n; |
373 | 403k | return true; |
374 | 403k | } |
375 | | /* Advance idx without copying to output. */ |
376 | 0 | void skip_glyph () { idx++; } |
377 | | void reset_masks (hb_mask_t mask) |
378 | 201k | { |
379 | 2.20M | for (unsigned int j = 0; j < len; j++) |
380 | 2.00M | info[j].mask = mask; |
381 | 201k | } |
382 | | void add_masks (hb_mask_t mask) |
383 | 0 | { |
384 | 0 | for (unsigned int j = 0; j < len; j++) |
385 | 0 | info[j].mask |= mask; |
386 | 0 | } |
387 | | HB_INTERNAL void set_masks (hb_mask_t value, hb_mask_t mask, |
388 | | unsigned int cluster_start, unsigned int cluster_end); |
389 | | |
390 | | void merge_clusters (unsigned int start, unsigned int end) |
391 | 1.13M | { |
392 | 1.13M | if (end - start < 2) |
393 | 1.13M | return; |
394 | 1.70k | merge_clusters_impl (start, end); |
395 | 1.70k | } |
396 | | HB_INTERNAL void merge_clusters_impl (unsigned int start, unsigned int end); |
397 | | HB_INTERNAL void merge_out_clusters (unsigned int start, unsigned int end); |
398 | | /* Merge clusters for deleting current glyph, and skip it. */ |
399 | | HB_INTERNAL void delete_glyph (); |
400 | | HB_INTERNAL void delete_glyphs_inplace (bool (*filter) (const hb_glyph_info_t *info)); |
401 | | |
402 | | |
403 | | |
404 | | /* Adds glyph flags in mask to infos with clusters between start and end. |
405 | | * The start index will be from out-buffer if from_out_buffer is true. |
406 | | * If interior is true, then the cluster having the minimum value is skipped. */ |
407 | | void _set_glyph_flags (hb_mask_t mask, |
408 | | unsigned start = 0, |
409 | | unsigned end = (unsigned) -1, |
410 | | bool interior = false, |
411 | | bool from_out_buffer = false) |
412 | 3 | { |
413 | 3 | if (unlikely (end != (unsigned) -1 && end - start > 255)) |
414 | 0 | return; |
415 | | |
416 | 3 | end = hb_min (end, len); |
417 | | |
418 | 3 | if (interior && !from_out_buffer && end - start < 2) |
419 | 3 | return; |
420 | | |
421 | 0 | scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS; |
422 | |
|
423 | 0 | if (!from_out_buffer || !have_output) |
424 | 0 | { |
425 | 0 | if (!interior) |
426 | 0 | { |
427 | 0 | for (unsigned i = start; i < end; i++) |
428 | 0 | info[i].mask |= mask; |
429 | 0 | } |
430 | 0 | else |
431 | 0 | { |
432 | 0 | unsigned cluster = _infos_find_min_cluster (info, start, end); |
433 | 0 | _infos_set_glyph_flags (info, start, end, cluster, mask); |
434 | 0 | } |
435 | 0 | } |
436 | 0 | else |
437 | 0 | { |
438 | 0 | assert (start <= out_len); |
439 | 0 | assert (idx <= end); |
440 | | |
441 | 0 | if (!interior) |
442 | 0 | { |
443 | 0 | for (unsigned i = start; i < out_len; i++) |
444 | 0 | out_info[i].mask |= mask; |
445 | 0 | for (unsigned i = idx; i < end; i++) |
446 | 0 | info[i].mask |= mask; |
447 | 0 | } |
448 | 0 | else |
449 | 0 | { |
450 | 0 | unsigned cluster = _infos_find_min_cluster (info, idx, end); |
451 | 0 | cluster = _infos_find_min_cluster (out_info, start, out_len, cluster); |
452 | |
|
453 | 0 | _infos_set_glyph_flags (out_info, start, out_len, cluster, mask); |
454 | 0 | _infos_set_glyph_flags (info, idx, end, cluster, mask); |
455 | 0 | } |
456 | 0 | } |
457 | 0 | } |
458 | | |
459 | | void unsafe_to_break (unsigned int start = 0, unsigned int end = -1) |
460 | 3 | { |
461 | 3 | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_BREAK | HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
462 | 3 | start, end, |
463 | 3 | true); |
464 | 3 | } |
465 | | void safe_to_insert_tatweel (unsigned int start = 0, unsigned int end = -1) |
466 | 0 | { |
467 | 0 | if ((flags & HB_BUFFER_FLAG_PRODUCE_SAFE_TO_INSERT_TATWEEL) == 0) |
468 | 0 | { |
469 | 0 | unsafe_to_break (start, end); |
470 | 0 | return; |
471 | 0 | } |
472 | 0 | _set_glyph_flags (HB_GLYPH_FLAG_SAFE_TO_INSERT_TATWEEL, |
473 | 0 | start, end, |
474 | 0 | true); |
475 | 0 | } |
476 | | #ifndef HB_OPTIMIZE_SIZE |
477 | | HB_ALWAYS_INLINE |
478 | | #endif |
479 | | void unsafe_to_concat (unsigned int start = 0, unsigned int end = -1) |
480 | 2.26k | { |
481 | 2.26k | if (likely ((flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) == 0)) |
482 | 2.26k | return; |
483 | 0 | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
484 | 0 | start, end, |
485 | 0 | false); |
486 | 0 | } |
487 | | void unsafe_to_break_from_outbuffer (unsigned int start = 0, unsigned int end = -1) |
488 | 0 | { |
489 | 0 | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_BREAK | HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
490 | 0 | start, end, |
491 | 0 | true, true); |
492 | 0 | } |
493 | | #ifndef HB_OPTIMIZE_SIZE |
494 | | HB_ALWAYS_INLINE |
495 | | #endif |
496 | | void unsafe_to_concat_from_outbuffer (unsigned int start = 0, unsigned int end = -1) |
497 | 86 | { |
498 | 86 | if (likely ((flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) == 0)) |
499 | 86 | return; |
500 | 0 | _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_CONCAT, |
501 | 0 | start, end, |
502 | 0 | false, true); |
503 | 0 | } |
504 | | |
505 | | |
506 | | /* Internal methods */ |
507 | | HB_NODISCARD HB_INTERNAL bool move_to (unsigned int i); /* i is output-buffer index. */ |
508 | | |
509 | | HB_NODISCARD HB_INTERNAL bool enlarge (unsigned int size); |
510 | | |
511 | | HB_NODISCARD bool resize (unsigned length) |
512 | 0 | { |
513 | 0 | assert (!have_output); |
514 | 0 | if (unlikely (!ensure (length))) return false; |
515 | 0 | len = length; |
516 | 0 | return true; |
517 | 0 | } |
518 | | HB_NODISCARD bool ensure (unsigned int size) |
519 | 2.40M | { return likely (!size || size < allocated) ? true : enlarge (size); } |
520 | | |
521 | | HB_NODISCARD bool ensure_inplace (unsigned int size) |
522 | 0 | { return likely (!size || size < allocated); } |
523 | | |
524 | | void assert_glyphs () |
525 | 0 | { |
526 | 0 | assert ((content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS) || |
527 | 0 | (!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); |
528 | 0 | } |
529 | | void assert_unicode () |
530 | 402k | { |
531 | 402k | assert ((content_type == HB_BUFFER_CONTENT_TYPE_UNICODE) || |
532 | 402k | (!len && (content_type == HB_BUFFER_CONTENT_TYPE_INVALID))); |
533 | 402k | } |
534 | | HB_NODISCARD bool ensure_glyphs () |
535 | 0 | { |
536 | 0 | if (unlikely (content_type != HB_BUFFER_CONTENT_TYPE_GLYPHS)) |
537 | 0 | { |
538 | 0 | if (content_type != HB_BUFFER_CONTENT_TYPE_INVALID) |
539 | 0 | return false; |
540 | 0 | assert (len == 0); |
541 | 0 | content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; |
542 | 0 | } |
543 | 0 | return true; |
544 | 0 | } |
545 | | HB_NODISCARD bool ensure_unicode () |
546 | 0 | { |
547 | 0 | if (unlikely (content_type != HB_BUFFER_CONTENT_TYPE_UNICODE)) |
548 | 0 | { |
549 | 0 | if (content_type != HB_BUFFER_CONTENT_TYPE_INVALID) |
550 | 0 | return false; |
551 | 0 | assert (len == 0); |
552 | 0 | content_type = HB_BUFFER_CONTENT_TYPE_UNICODE; |
553 | 0 | } |
554 | 0 | return true; |
555 | 0 | } |
556 | | |
557 | | HB_NODISCARD HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); |
558 | | HB_NODISCARD HB_INTERNAL bool shift_forward (unsigned int count); |
559 | | |
560 | | typedef long scratch_buffer_t; |
561 | | HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size); |
562 | | |
563 | 201k | void clear_context (unsigned int side) { context_len[side] = 0; } |
564 | | |
565 | | HB_INTERNAL void sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *)); |
566 | | |
567 | | bool messaging () |
568 | 855k | { |
569 | | #ifdef HB_NO_BUFFER_MESSAGE |
570 | | return false; |
571 | | #else |
572 | 855k | return unlikely (message_func); |
573 | 855k | #endif |
574 | 855k | } |
575 | | bool message (hb_font_t *font, const char *fmt, ...) HB_PRINTF_FUNC(3, 4) |
576 | 15.3k | { |
577 | | #ifdef HB_NO_BUFFER_MESSAGE |
578 | | return true; |
579 | | #else |
580 | 15.3k | if (likely (!messaging ())) |
581 | 15.3k | return true; |
582 | | |
583 | 0 | va_list ap; |
584 | 0 | va_start (ap, fmt); |
585 | 0 | bool ret = message_impl (font, fmt, ap); |
586 | 0 | va_end (ap); |
587 | |
|
588 | 0 | return ret; |
589 | 15.3k | #endif |
590 | 15.3k | } |
591 | | HB_INTERNAL bool message_impl (hb_font_t *font, const char *fmt, va_list ap) HB_PRINTF_FUNC(3, 0); |
592 | | |
593 | | static void |
594 | | set_cluster (hb_glyph_info_t &inf, unsigned int cluster, unsigned int mask = 0) |
595 | 3.41k | { |
596 | 3.41k | if (inf.cluster != cluster) |
597 | 1.70k | inf.mask = (inf.mask & ~HB_GLYPH_FLAG_DEFINED) | (mask & HB_GLYPH_FLAG_DEFINED); |
598 | 3.41k | inf.cluster = cluster; |
599 | 3.41k | } |
600 | | void |
601 | | _infos_set_glyph_flags (hb_glyph_info_t *infos, |
602 | | unsigned int start, unsigned int end, |
603 | | unsigned int cluster, |
604 | | hb_mask_t mask) |
605 | 0 | { |
606 | 0 | if (unlikely (start == end)) |
607 | 0 | return; |
608 | | |
609 | 0 | unsigned cluster_first = infos[start].cluster; |
610 | 0 | unsigned cluster_last = infos[end - 1].cluster; |
611 | |
|
612 | 0 | if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS || |
613 | 0 | (cluster != cluster_first && cluster != cluster_last)) |
614 | 0 | { |
615 | 0 | for (unsigned int i = start; i < end; i++) |
616 | 0 | if (cluster != infos[i].cluster) |
617 | 0 | { |
618 | 0 | scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS; |
619 | 0 | infos[i].mask |= mask; |
620 | 0 | } |
621 | 0 | return; |
622 | 0 | } |
623 | | |
624 | | /* Monotone clusters */ |
625 | | |
626 | 0 | if (cluster == cluster_first) |
627 | 0 | { |
628 | 0 | for (unsigned int i = end; start < i && infos[i - 1].cluster != cluster_first; i--) |
629 | 0 | { |
630 | 0 | scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS; |
631 | 0 | infos[i - 1].mask |= mask; |
632 | 0 | } |
633 | 0 | } |
634 | 0 | else /* cluster == cluster_last */ |
635 | 0 | { |
636 | 0 | for (unsigned int i = start; i < end && infos[i].cluster != cluster_last; i++) |
637 | 0 | { |
638 | 0 | scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GLYPH_FLAGS; |
639 | 0 | infos[i].mask |= mask; |
640 | 0 | } |
641 | 0 | } |
642 | 0 | } |
643 | | unsigned |
644 | | _infos_find_min_cluster (const hb_glyph_info_t *infos, |
645 | | unsigned start, unsigned end, |
646 | | unsigned cluster = UINT_MAX) |
647 | 0 | { |
648 | 0 | if (unlikely (start == end)) |
649 | 0 | return cluster; |
650 | | |
651 | 0 | if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) |
652 | 0 | { |
653 | 0 | for (unsigned int i = start; i < end; i++) |
654 | 0 | cluster = hb_min (cluster, infos[i].cluster); |
655 | 0 | return cluster; |
656 | 0 | } |
657 | | |
658 | 0 | return hb_min (cluster, hb_min (infos[start].cluster, infos[end - 1].cluster)); |
659 | 0 | } |
660 | | |
661 | | void clear_glyph_flags (hb_mask_t mask = 0) |
662 | 0 | { |
663 | 0 | for (unsigned int i = 0; i < len; i++) |
664 | 0 | info[i].mask = (info[i].mask & ~HB_GLYPH_FLAG_DEFINED) | (mask & HB_GLYPH_FLAG_DEFINED); |
665 | 0 | } |
666 | | }; |
667 | | DECLARE_NULL_INSTANCE (hb_buffer_t); |
668 | | |
669 | | |
670 | | #define foreach_group(buffer, start, end, group_func) \ |
671 | 79.8k | for (unsigned int \ |
672 | 79.8k | _count = buffer->len, \ |
673 | 79.8k | start = 0, end = _count ? buffer->group_end (0, group_func) : 0; \ |
674 | 1.21M | start < _count; \ |
675 | 1.13M | start = end, end = buffer->group_end (start, group_func)) |
676 | | |
677 | | #define foreach_cluster(buffer, start, end) \ |
678 | 0 | foreach_group (buffer, start, end, hb_buffer_t::_cluster_group_func) |
679 | | |
680 | | |
681 | | #define HB_BUFFER_XALLOCATE_VAR(b, func, var) \ |
682 | 2.61M | b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ |
683 | 2.61M | sizeof (b->info[0].var)) |
684 | 805k | #define HB_BUFFER_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var ()) |
685 | 0 | #define HB_BUFFER_TRY_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, try_allocate_var, var ()) |
686 | 805k | #define HB_BUFFER_DEALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var ()) |
687 | 1.00M | #define HB_BUFFER_ASSERT_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, assert_var, var ()) |
688 | | |
689 | | |
690 | | #endif /* HB_BUFFER_HH */ |