blob: 33ddcbc870f27d5830e17f8e637ed41a10a17366 [file] [log] [blame]
Behdad Esfahboda2a9a022008-01-15 22:46:32 +00001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009,2010 Red Hat, Inc.
Behdad Esfahbod05207a72012-09-25 17:44:53 -04004 * Copyright © 2011,2012 Google, Inc.
Behdad Esfahbod6b347132007-10-11 08:30:50 +00005 *
Behdad Esfahbod8f0d7e02011-04-15 18:59:56 -04006 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod6b347132007-10-11 08:30:50 +00007 *
Behdad Esfahboda2a9a022008-01-15 22:46:32 +00008 * 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.
Behdad Esfahbod6b347132007-10-11 08:30:50 +000013 *
Behdad Esfahboda2a9a022008-01-15 22:46:32 +000014 * 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
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040027 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod6b347132007-10-11 08:30:50 +000028 */
Behdad Esfahboda2a9a022008-01-15 22:46:32 +000029
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070030#ifndef HB_BUFFER_HH
31#define HB_BUFFER_HH
Behdad Esfahbod6b347132007-10-11 08:30:50 +000032
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070033#include "hb.hh"
34#include "hb-unicode.hh"
Behdad Esfahbod6b347132007-10-11 08:30:50 +000035
Behdad Esfahbod6b347132007-10-11 08:30:50 +000036
Behdad Esfahbodbaf77792017-11-14 21:53:48 -080037#ifndef HB_BUFFER_MAX_LEN_FACTOR
38#define HB_BUFFER_MAX_LEN_FACTOR 32
Behdad Esfahbod43017032015-11-05 23:44:59 -080039#endif
40#ifndef HB_BUFFER_MAX_LEN_MIN
41#define HB_BUFFER_MAX_LEN_MIN 8192
42#endif
Behdad Esfahbodf1c4adb2015-11-06 09:46:05 -080043#ifndef HB_BUFFER_MAX_LEN_DEFAULT
Behdad Esfahbod43017032015-11-05 23:44:59 -080044#define HB_BUFFER_MAX_LEN_DEFAULT 0x3FFFFFFF /* Shaping more than a billion chars? Let us know! */
45#endif
46
Behdad Esfahbodbaf77792017-11-14 21:53:48 -080047#ifndef HB_BUFFER_MAX_OPS_FACTOR
48#define HB_BUFFER_MAX_OPS_FACTOR 64
49#endif
50#ifndef HB_BUFFER_MAX_OPS_MIN
51#define HB_BUFFER_MAX_OPS_MIN 1024
52#endif
53#ifndef HB_BUFFER_MAX_OPS_DEFAULT
54#define HB_BUFFER_MAX_OPS_DEFAULT 0x1FFFFFFF /* Shaping more than a billion operations? Let us know! */
55#endif
56
Behdad Esfahbod606bf572018-09-16 19:33:48 +020057static_assert ((sizeof (hb_glyph_info_t) == 20), "");
58static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), "");
Behdad Esfahbodf1322e52009-08-01 22:53:04 -040059
Chun-wei Fan167c3272015-11-09 17:17:56 +080060HB_MARK_AS_FLAG_T (hb_buffer_flags_t);
61HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t);
Jonathan Kew331d66c2014-07-19 23:09:09 +010062HB_MARK_AS_FLAG_T (hb_buffer_diff_flags_t);
Behdad Esfahbodaa7044d2015-11-04 16:25:57 -080063
Behdad Esfahbod49ef6302015-11-04 17:27:07 -080064enum hb_buffer_scratch_flags_t {
65 HB_BUFFER_SCRATCH_FLAG_DEFAULT = 0x00000000u,
Behdad Esfahbode3e4bb02015-11-04 18:58:02 -080066 HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII = 0x00000001u,
67 HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES = 0x00000002u,
68 HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK = 0x00000004u,
Behdad Esfahbodcbc3a762016-02-11 16:48:13 +070069 HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT = 0x00000008u,
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -070070 HB_BUFFER_SCRATCH_FLAG_HAS_UNSAFE_TO_BREAK = 0x00000010u,
Behdad Esfahbodc36f3f52018-10-02 14:34:29 +020071 HB_BUFFER_SCRATCH_FLAG_HAS_CGJ = 0x00000020u,
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -070072
Behdad Esfahbod73fec392015-11-05 15:22:18 -080073 /* Reserved for complex shapers' internal use. */
74 HB_BUFFER_SCRATCH_FLAG_COMPLEX0 = 0x01000000u,
75 HB_BUFFER_SCRATCH_FLAG_COMPLEX1 = 0x02000000u,
76 HB_BUFFER_SCRATCH_FLAG_COMPLEX2 = 0x04000000u,
77 HB_BUFFER_SCRATCH_FLAG_COMPLEX3 = 0x08000000u,
Behdad Esfahbod49ef6302015-11-04 17:27:07 -080078};
Chun-wei Fan167c3272015-11-09 17:17:56 +080079HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t);
Behdad Esfahbod49ef6302015-11-04 17:27:07 -080080
Behdad Esfahbod2f87ceb2012-07-27 04:02:38 -040081
82/*
Behdad Esfahbod2f87ceb2012-07-27 04:02:38 -040083 * hb_buffer_t
84 */
Behdad Esfahbodf1322e52009-08-01 22:53:04 -040085
Behdad Esfahbod35066722018-08-06 06:17:48 -070086struct hb_buffer_t
87{
Behdad Esfahbodfca368c2011-04-21 18:24:02 -040088 hb_object_header_t header;
Behdad Esfahbod6220e5f2012-06-06 03:30:09 -040089 ASSERT_POD ();
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040090
91 /* Information about how the text in the buffer should be treated */
Behdad Esfahboda7c50462010-10-08 18:47:47 -040092 hb_unicode_funcs_t *unicode; /* Unicode functions */
Behdad Esfahbod0c7df222012-11-13 14:42:35 -080093 hb_buffer_flags_t flags; /* BOT / EOT / etc. */
Behdad Esfahbod376d5872015-07-22 16:51:12 +010094 hb_buffer_cluster_level_t cluster_level;
Behdad Esfahbod976c8f42014-07-16 15:34:20 -040095 hb_codepoint_t replacement; /* U+FFFD or something else. */
Bruce Mitchener90218fa2018-01-31 20:44:45 +070096 hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */
Behdad Esfahbod43017032015-11-05 23:44:59 -080097 unsigned int max_len; /* Maximum allowed len. */
Behdad Esfahbodbaf77792017-11-14 21:53:48 -080098 int max_ops; /* Maximum allowed operations. */
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040099
100 /* Buffer contents */
Behdad Esfahbod96fdc042012-09-06 22:26:16 -0400101 hb_buffer_content_type_t content_type;
Behdad Esfahbodb5fbc3b2014-08-11 18:40:01 -0400102 hb_segment_properties_t props; /* Script, language, direction */
Behdad Esfahbod96fdc042012-09-06 22:26:16 -0400103
Behdad Esfahbod7185b272018-05-31 20:03:00 -0700104 bool successful; /* Allocations successful */
Behdad Esfahbodfca368c2011-04-21 18:24:02 -0400105 bool have_output; /* Whether we have an output buffer going on */
106 bool have_positions; /* Whether we have positions */
Behdad Esfahbod910a33f2010-05-14 22:13:38 -0400107
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400108 unsigned int idx; /* Cursor into ->info and ->pos arrays */
Behdad Esfahbod910a33f2010-05-14 22:13:38 -0400109 unsigned int len; /* Length of ->info and ->pos arrays */
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -0500110 unsigned int out_len; /* Length of ->out array if have_output */
Behdad Esfahbodd0316a82010-05-12 23:34:52 -0400111
Behdad Esfahbodc0af1932011-04-15 19:26:24 -0400112 unsigned int allocated; /* Length of allocated arrays */
Behdad Esfahbod88474c62010-10-27 14:42:15 -0400113 hb_glyph_info_t *info;
114 hb_glyph_info_t *out_info;
115 hb_glyph_position_t *pos;
Behdad Esfahbodd0316a82010-05-12 23:34:52 -0400116
Behdad Esfahbodf4a579b2011-07-25 16:20:16 -0400117 unsigned int serial;
Behdad Esfahbod05207a72012-09-25 17:44:53 -0400118
Behdad Esfahbod05207a72012-09-25 17:44:53 -0400119 /* Text before / after the main buffer contents.
120 * Always in Unicode, and ordered outward.
121 * Index 0 is for "pre-context", 1 for "post-context". */
Behdad Esfahbodfda994e2018-09-07 15:02:57 -0400122 enum { CONTEXT_LENGTH = 5 };
Behdad Esfahbod05207a72012-09-25 17:44:53 -0400123 hb_codepoint_t context[2][CONTEXT_LENGTH];
124 unsigned int context_len[2];
125
Behdad Esfahbod98816502016-02-25 12:23:02 +0900126 /* Debugging API */
Behdad Esfahbod0475ef22015-12-18 18:17:07 +0000127 hb_buffer_message_func_t message_func;
128 void *message_data;
129 hb_destroy_func_t message_destroy;
130
Behdad Esfahbod98816502016-02-25 12:23:02 +0900131 /* Internal debugging. */
Behdad Esfahbod0c7fb742016-02-25 14:40:09 +0900132 /* The bits here reflect current allocations of the bytes in glyph_info_t's var1 and var2. */
133#ifndef HB_NDEBUG
134 uint8_t allocated_var_bits;
Behdad Esfahbod98816502016-02-25 12:23:02 +0900135#endif
Behdad Esfahbod173dab62017-11-14 21:27:24 -0800136
137
138 /* Methods */
139
Behdad Esfahbod0c7fb742016-02-25 14:40:09 +0900140 inline void allocate_var (unsigned int start, unsigned int count)
141 {
142#ifndef HB_NDEBUG
143 unsigned int end = start + count;
144 assert (end <= 8);
Behdad Esfahbod33317312016-08-08 17:24:04 -0700145 unsigned int bits = (1u<<end) - (1u<<start);
Behdad Esfahbod0c7fb742016-02-25 14:40:09 +0900146 assert (0 == (allocated_var_bits & bits));
147 allocated_var_bits |= bits;
148#endif
149 }
150 inline void deallocate_var (unsigned int start, unsigned int count)
151 {
152#ifndef HB_NDEBUG
153 unsigned int end = start + count;
154 assert (end <= 8);
Behdad Esfahbod33317312016-08-08 17:24:04 -0700155 unsigned int bits = (1u<<end) - (1u<<start);
Behdad Esfahbod0c7fb742016-02-25 14:40:09 +0900156 assert (bits == (allocated_var_bits & bits));
157 allocated_var_bits &= ~bits;
158#endif
159 }
160 inline void assert_var (unsigned int start, unsigned int count)
161 {
162#ifndef HB_NDEBUG
163 unsigned int end = start + count;
164 assert (end <= 8);
Behdad Esfahbod33317312016-08-08 17:24:04 -0700165 unsigned int bits = (1u<<end) - (1u<<start);
Behdad Esfahbod0c7fb742016-02-25 14:40:09 +0900166 assert (bits == (allocated_var_bits & bits));
167#endif
168 }
169 inline void deallocate_var_all (void)
170 {
171#ifndef HB_NDEBUG
172 allocated_var_bits = 0;
173#endif
174 }
Behdad Esfahbod98816502016-02-25 12:23:02 +0900175
Behdad Esfahbod173dab62017-11-14 21:27:24 -0800176 inline hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; }
177 inline hb_glyph_info_t cur (unsigned int i = 0) const { return info[idx + i]; }
Behdad Esfahbodd0316a82010-05-12 23:34:52 -0400178
Behdad Esfahbod173dab62017-11-14 21:27:24 -0800179 inline hb_glyph_position_t &cur_pos (unsigned int i = 0) { return pos[idx + i]; }
180 inline hb_glyph_position_t cur_pos (unsigned int i = 0) const { return pos[idx + i]; }
181
182 inline hb_glyph_info_t &prev (void) { return out_info[out_len ? out_len - 1 : 0]; }
183 inline hb_glyph_info_t prev (void) const { return out_info[out_len ? out_len - 1 : 0]; }
184
185 inline bool has_separate_output (void) const { return info != out_info; }
186
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400187
188 HB_INTERNAL void reset (void);
Behdad Esfahbod82ecaff2012-11-13 13:57:52 -0800189 HB_INTERNAL void clear (void);
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400190
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -0500191 inline unsigned int backtrack_len (void) const
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400192 { return have_output? out_len : idx; }
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200193 inline unsigned int lookahead_len (void) const
194 { return len - idx; }
Behdad Esfahboddbf56b12010-10-27 17:06:12 -0400195 inline unsigned int next_serial (void) { return serial++; }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400196
197 HB_INTERNAL void add (hb_codepoint_t codepoint,
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400198 unsigned int cluster);
Behdad Esfahbod847794e2013-02-27 17:59:28 -0500199 HB_INTERNAL void add_info (const hb_glyph_info_t &glyph_info);
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400200
201 HB_INTERNAL void reverse_range (unsigned int start, unsigned int end);
202 HB_INTERNAL void reverse (void);
203 HB_INTERNAL void reverse_clusters (void);
Behdad Esfahbod3f82f8f2012-11-15 18:45:31 -0800204 HB_INTERNAL void guess_segment_properties (void);
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400205
206 HB_INTERNAL void swap_buffers (void);
Behdad Esfahbod0bc7a382012-10-29 22:02:45 -0700207 HB_INTERNAL void remove_output (void);
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400208 HB_INTERNAL void clear_output (void);
209 HB_INTERNAL void clear_positions (void);
Behdad Esfahbod69cc4922012-07-31 14:51:36 -0400210
Behdad Esfahbod9ebe8c02011-08-26 09:29:42 +0200211 HB_INTERNAL void replace_glyphs (unsigned int num_in,
212 unsigned int num_out,
Behdad Esfahbod8e3715f2012-04-23 22:18:54 -0400213 const hb_codepoint_t *glyph_data);
Behdad Esfahbod69cc4922012-07-31 14:51:36 -0400214
Behdad Esfahbod2a6f1522018-10-03 20:09:14 +0200215 inline void replace_glyph (hb_codepoint_t glyph_index)
216 {
217 if (unlikely (out_info != info || out_len != idx)) {
218 if (unlikely (!make_room_for (1, 1))) return;
219 out_info[out_len] = info[idx];
220 }
221 out_info[out_len].codepoint = glyph_index;
222
223 idx++;
224 out_len++;
225 }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400226 /* Makes a copy of the glyph at idx to output and replace glyph_index */
Behdad Esfahbod2a6f1522018-10-03 20:09:14 +0200227 inline hb_glyph_info_t & output_glyph (hb_codepoint_t glyph_index)
228 {
229 if (unlikely (!make_room_for (0, 1))) return Crap(hb_glyph_info_t);
230
231 out_info[out_len] = info[idx];
232 out_info[out_len].codepoint = glyph_index;
233
234 out_len++;
235
236 return out_info[out_len - 1];
237 }
238 inline void output_info (const hb_glyph_info_t &glyph_info)
239 {
240 if (unlikely (!make_room_for (0, 1))) return;
241
242 out_info[out_len] = glyph_info;
243
244 out_len++;
245 }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400246 /* Copies glyph at idx to output but doesn't advance idx */
Behdad Esfahbod2a6f1522018-10-03 20:09:14 +0200247 inline void copy_glyph (void)
248 {
249 if (unlikely (!make_room_for (0, 1))) return;
250
251 out_info[out_len] = info[idx];
252
253 out_len++;
254 }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400255 /* Copies glyph at idx to output and advance idx.
256 * If there's no output, just advance idx. */
Behdad Esfahbod1be368e2012-08-31 16:29:17 -0400257 inline void
258 next_glyph (void)
259 {
260 if (have_output)
261 {
262 if (unlikely (out_info != info || out_len != idx)) {
Behdad Esfahbod13188cb2015-11-19 11:59:03 -0800263 if (unlikely (!make_room_for (1, 1))) return;
Behdad Esfahbod1be368e2012-08-31 16:29:17 -0400264 out_info[out_len] = info[idx];
265 }
266 out_len++;
267 }
Behdad Esfahbod18e1c6b2015-11-19 11:50:58 -0800268
Behdad Esfahbod1be368e2012-08-31 16:29:17 -0400269 idx++;
270 }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400271 /* Advance idx without copying to output. */
Behdad Esfahbod2a6f1522018-10-03 20:09:14 +0200272 inline void skip_glyph (void)
273 {
274 idx++;
275 }
Behdad Esfahbodbd7378b2010-10-13 18:33:16 -0400276 inline void reset_masks (hb_mask_t mask)
277 {
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400278 for (unsigned int j = 0; j < len; j++)
279 info[j].mask = mask;
Behdad Esfahbodbd7378b2010-10-13 18:33:16 -0400280 }
281 inline void add_masks (hb_mask_t mask)
282 {
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400283 for (unsigned int j = 0; j < len; j++)
284 info[j].mask |= mask;
Behdad Esfahbodbd7378b2010-10-13 18:33:16 -0400285 }
Behdad Esfahbod40bd7e92016-05-02 14:47:45 +0200286 HB_INTERNAL void set_masks (hb_mask_t value, hb_mask_t mask,
287 unsigned int cluster_start, unsigned int cluster_end);
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400288
Behdad Esfahbod40bd7e92016-05-02 14:47:45 +0200289 inline void merge_clusters (unsigned int start, unsigned int end)
Behdad Esfahbod701112d2015-07-22 15:42:20 +0100290 {
291 if (end - start < 2)
292 return;
293 merge_clusters_impl (start, end);
294 }
Behdad Esfahbod40bd7e92016-05-02 14:47:45 +0200295 HB_INTERNAL void merge_clusters_impl (unsigned int start, unsigned int end);
296 HB_INTERNAL void merge_out_clusters (unsigned int start, unsigned int end);
Behdad Esfahbod5f13bbd2015-06-19 13:31:49 -0700297 /* Merge clusters for deleting current glyph, and skip it. */
298 HB_INTERNAL void delete_glyph (void);
Behdad Esfahbodd4cc4472012-04-07 21:52:28 -0400299
Behdad Esfahbod40bd7e92016-05-02 14:47:45 +0200300 inline void unsafe_to_break (unsigned int start,
301 unsigned int end)
302 {
303 if (end - start < 2)
304 return;
305 unsafe_to_break_impl (start, end);
306 }
307 HB_INTERNAL void unsafe_to_break_impl (unsigned int start, unsigned int end);
308 HB_INTERNAL void unsafe_to_break_from_outbuffer (unsigned int start, unsigned int end);
309
310
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400311 /* Internal methods */
Behdad Esfahbod2a6f1522018-10-03 20:09:14 +0200312 HB_INTERNAL bool move_to (unsigned int i); /* i is output-buffer index. */
313
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400314 HB_INTERNAL bool enlarge (unsigned int size);
315
316 inline bool ensure (unsigned int size)
Behdad Esfahbod02c6c8c2013-11-15 13:05:38 -0500317 { return likely (!size || size < allocated) ? true : enlarge (size); }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400318
Behdad Esfahboda6b8dc82014-08-11 15:08:19 -0400319 inline bool ensure_inplace (unsigned int size)
320 { return likely (!size || size < allocated); }
321
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400322 HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out);
Behdad Esfahbod6b65a762013-10-14 18:51:39 +0200323 HB_INTERNAL bool shift_forward (unsigned int count);
Behdad Esfahbode62df432011-08-03 17:38:54 -0400324
Behdad Esfahbod061cb462013-11-13 14:50:25 -0500325 typedef long scratch_buffer_t;
Behdad Esfahbod68c372e2013-11-13 14:44:01 -0500326 HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size);
Behdad Esfahbod05207a72012-09-25 17:44:53 -0400327
328 inline void clear_context (unsigned int side) { context_len[side] = 0; }
Behdad Esfahbode995d332015-09-01 16:13:32 +0100329
330 HB_INTERNAL void sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *));
Behdad Esfahbod0475ef22015-12-18 18:17:07 +0000331
332 inline bool messaging (void) { return unlikely (message_func); }
333 inline bool message (hb_font_t *font, const char *fmt, ...) HB_PRINTF_FUNC(3, 4)
334 {
335 if (!messaging ())
336 return true;
337 va_list ap;
338 va_start (ap, fmt);
339 bool ret = message_impl (font, fmt, ap);
340 va_end (ap);
341 return ret;
342 }
343 HB_INTERNAL bool message_impl (hb_font_t *font, const char *fmt, va_list ap) HB_PRINTF_FUNC(3, 0);
Behdad Esfahbode2a2b5b2017-08-10 20:10:12 -0700344
345 static inline void
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100346 set_cluster (hb_glyph_info_t &inf, unsigned int cluster, unsigned int mask = 0)
Behdad Esfahbode2a2b5b2017-08-10 20:10:12 -0700347 {
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100348 if (inf.cluster != cluster)
Behdad Esfahbode2a2b5b2017-08-10 20:10:12 -0700349 {
350 if (mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK)
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100351 inf.mask |= HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
Behdad Esfahbode2a2b5b2017-08-10 20:10:12 -0700352 else
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100353 inf.mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
Behdad Esfahbode2a2b5b2017-08-10 20:10:12 -0700354 }
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100355 inf.cluster = cluster;
Behdad Esfahbode2a2b5b2017-08-10 20:10:12 -0700356 }
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700357
Behdad Esfahbode4da3802017-11-10 17:14:27 -0800358 inline int
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100359 _unsafe_to_break_find_min_cluster (const hb_glyph_info_t *infos,
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700360 unsigned int start, unsigned int end,
361 unsigned int cluster) const
362 {
363 for (unsigned int i = start; i < end; i++)
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100364 cluster = MIN<unsigned int> (cluster, infos[i].cluster);
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700365 return cluster;
366 }
Behdad Esfahbode4da3802017-11-10 17:14:27 -0800367 inline void
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100368 _unsafe_to_break_set_mask (hb_glyph_info_t *infos,
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700369 unsigned int start, unsigned int end,
370 unsigned int cluster)
371 {
372 for (unsigned int i = start; i < end; i++)
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100373 if (cluster != infos[i].cluster)
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700374 {
375 scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_UNSAFE_TO_BREAK;
Behdad Esfahbod3f291ff2018-01-11 17:57:46 +0100376 infos[i].mask |= HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700377 }
378 }
Behdad Esfahbode4da3802017-11-10 17:14:27 -0800379
380 inline void
381 unsafe_to_break_all (void)
382 {
David Corbett21646cc2018-02-16 12:08:55 -0500383 unsafe_to_break_impl (0, len);
Behdad Esfahbode4da3802017-11-10 17:14:27 -0800384 }
385 inline void
386 safe_to_break_all (void)
387 {
388 for (unsigned int i = 0; i < len; i++)
389 info[i].mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
390 }
Behdad Esfahbodd0316a82010-05-12 23:34:52 -0400391};
Behdad Esfahbod35066722018-08-06 06:17:48 -0700392DECLARE_NULL_INSTANCE (hb_buffer_t);
Behdad Esfahbodd0316a82010-05-12 23:34:52 -0400393
394
Behdad Esfahbod1c17c2b2017-08-11 19:06:07 -0700395/* Loop over clusters. Duplicated in foreach_syllable(). */
396#define foreach_cluster(buffer, start, end) \
397 for (unsigned int \
398 _count = buffer->len, \
399 start = 0, end = _count ? _next_cluster (buffer, 0) : 0; \
400 start < _count; \
401 start = end, end = _next_cluster (buffer, start))
402
403static inline unsigned int
404_next_cluster (hb_buffer_t *buffer, unsigned int start)
405{
406 hb_glyph_info_t *info = buffer->info;
407 unsigned int count = buffer->len;
408
409 unsigned int cluster = info[start].cluster;
410 while (++start < count && cluster == info[start].cluster)
411 ;
412
413 return start;
414}
415
416
Behdad Esfahbod0c7fb742016-02-25 14:40:09 +0900417#define HB_BUFFER_XALLOCATE_VAR(b, func, var) \
Behdad Esfahbodb65c0602011-07-28 16:48:43 -0400418 b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
Behdad Esfahbod0c7fb742016-02-25 14:40:09 +0900419 sizeof (b->info[0].var))
420#define HB_BUFFER_ALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var ())
421#define HB_BUFFER_DEALLOCATE_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var ())
422#define HB_BUFFER_ASSERT_VAR(b, var) HB_BUFFER_XALLOCATE_VAR (b, assert_var, var ())
Behdad Esfahbodb65c0602011-07-28 16:48:43 -0400423
424
Behdad Esfahbodc77ae402018-08-25 22:36:36 -0700425#endif /* HB_BUFFER_HH */