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