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