blob: 55a4045719334eb1f0a8c39d2ae79e497fe9cef3 [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 Red Hat, Inc.
Behdad Esfahbod05207a72012-09-25 17:44:53 -04004 * Copyright © 2011,2012 Google, Inc.
Behdad Esfahbod9f8da382006-03-31 12:28:09 +00005 *
Behdad Esfahbod8f0d7e02011-04-15 18:59:56 -04006 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod9f8da382006-03-31 12:28:09 +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 Esfahbod9f8da382006-03-31 12:28:09 +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 Esfahbodc910bec2011-04-13 15:49:06 -040027 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000028 */
Behdad Esfahboda2a9a022008-01-15 22:46:32 +000029
Behdad Esfahbodd1c9eb42012-04-12 13:17:44 -040030#ifndef HB_H_IN
31#error "Include <hb.h> instead."
32#endif
33
Behdad Esfahbod5c0adce2009-05-20 05:42:12 -040034#ifndef HB_BUFFER_H
35#define HB_BUFFER_H
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000036
Behdad Esfahbodb857b492009-05-20 05:35:14 -040037#include "hb-common.h"
Behdad Esfahbod5ebabec2009-11-03 15:15:07 -050038#include "hb-unicode.h"
Behdad Esfahbodf9edf162012-11-15 12:14:09 -080039#include "hb-font.h"
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000040
Behdad Esfahbodf96ffd42009-05-24 15:01:16 -040041HB_BEGIN_DECLS
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000042
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040043
Behdad Esfahbod1bc1cb32012-06-16 15:21:55 -040044typedef struct hb_glyph_info_t {
Behdad Esfahbodf1322e52009-08-01 22:53:04 -040045 hb_codepoint_t codepoint;
Behdad Esfahbod468769b2009-08-08 16:53:23 -040046 hb_mask_t mask;
Behdad Esfahbodf1322e52009-08-01 22:53:04 -040047 uint32_t cluster;
Behdad Esfahbodb54cd072011-04-15 19:12:01 -040048
49 /*< private >*/
Behdad Esfahbod6cb8c342010-10-27 14:27:03 -040050 hb_var_int_t var1;
51 hb_var_int_t var2;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -040052} hb_glyph_info_t;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000053
Behdad Esfahbod1bc1cb32012-06-16 15:21:55 -040054typedef struct hb_glyph_position_t {
Behdad Esfahbodb857b492009-05-20 05:35:14 -040055 hb_position_t x_advance;
56 hb_position_t y_advance;
Behdad Esfahbod9bef3612009-11-05 12:20:11 -050057 hb_position_t x_offset;
58 hb_position_t y_offset;
Behdad Esfahbodb54cd072011-04-15 19:12:01 -040059
60 /*< private >*/
Behdad Esfahbod88474c62010-10-27 14:42:15 -040061 hb_var_int_t var;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -040062} hb_glyph_position_t;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000063
64
Behdad Esfahbodf3064102012-11-15 18:39:46 -080065typedef struct hb_segment_properties_t {
66 hb_direction_t direction;
67 hb_script_t script;
68 hb_language_t language;
69 /*< private >*/
70 void *reserved1;
71 void *reserved2;
72} hb_segment_properties_t;
73
74#define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \
75 HB_SCRIPT_INVALID, \
76 HB_LANGUAGE_INVALID, \
77 NULL, \
78 NULL}
79
80hb_bool_t
81hb_segment_properties_equal (const hb_segment_properties_t *a,
82 const hb_segment_properties_t *b);
83
84unsigned int
85hb_segment_properties_hash (const hb_segment_properties_t *p);
86
87
88
89/*
90 * hb_buffer_t
91 */
92
93typedef struct hb_buffer_t hb_buffer_t;
94
Behdad Esfahbod11fbb542009-08-01 22:19:06 -040095hb_buffer_t *
Behdad Esfahbode6c09cd2011-08-17 19:07:59 +020096hb_buffer_create (void);
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000097
Behdad Esfahbodb857b492009-05-20 05:35:14 -040098hb_buffer_t *
Behdad Esfahbod80a68332011-05-11 18:14:44 -040099hb_buffer_get_empty (void);
100
101hb_buffer_t *
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400102hb_buffer_reference (hb_buffer_t *buffer);
103
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +0000104void
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400105hb_buffer_destroy (hb_buffer_t *buffer);
106
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400107hb_bool_t
108hb_buffer_set_user_data (hb_buffer_t *buffer,
109 hb_user_data_key_t *key,
110 void * data,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200111 hb_destroy_func_t destroy,
112 hb_bool_t replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400113
114void *
115hb_buffer_get_user_data (hb_buffer_t *buffer,
116 hb_user_data_key_t *key);
117
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400118
Behdad Esfahbod92f9bfe2012-11-13 16:50:45 -0800119typedef enum {
120 HB_BUFFER_CONTENT_TYPE_INVALID = 0,
121 HB_BUFFER_CONTENT_TYPE_UNICODE,
122 HB_BUFFER_CONTENT_TYPE_GLYPHS
123} hb_buffer_content_type_t;
124
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400125void
Behdad Esfahbod96fdc042012-09-06 22:26:16 -0400126hb_buffer_set_content_type (hb_buffer_t *buffer,
127 hb_buffer_content_type_t content_type);
128
129hb_buffer_content_type_t
130hb_buffer_get_content_type (hb_buffer_t *buffer);
131
132
133void
Behdad Esfahbod5ebabec2009-11-03 15:15:07 -0500134hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
135 hb_unicode_funcs_t *unicode_funcs);
136
137hb_unicode_funcs_t *
138hb_buffer_get_unicode_funcs (hb_buffer_t *buffer);
139
Behdad Esfahbod5ebabec2009-11-03 15:15:07 -0500140void
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400141hb_buffer_set_direction (hb_buffer_t *buffer,
142 hb_direction_t direction);
143
144hb_direction_t
145hb_buffer_get_direction (hb_buffer_t *buffer);
146
Behdad Esfahbodae070b72009-11-04 20:29:54 -0500147void
148hb_buffer_set_script (hb_buffer_t *buffer,
149 hb_script_t script);
150
151hb_script_t
152hb_buffer_get_script (hb_buffer_t *buffer);
153
154void
155hb_buffer_set_language (hb_buffer_t *buffer,
156 hb_language_t language);
157
Behdad Esfahbodf3064102012-11-15 18:39:46 -0800158
Behdad Esfahbodae070b72009-11-04 20:29:54 -0500159hb_language_t
160hb_buffer_get_language (hb_buffer_t *buffer);
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000161
Behdad Esfahbodf3064102012-11-15 18:39:46 -0800162void
163hb_buffer_set_segment_properties (hb_buffer_t *buffer,
164 const hb_segment_properties_t *props);
165
166void
167hb_buffer_get_segment_properties (hb_buffer_t *buffer,
168 hb_segment_properties_t *props);
169
170void
Behdad Esfahbod3f82f8f2012-11-15 18:45:31 -0800171hb_buffer_guess_segment_properties (hb_buffer_t *buffer);
Behdad Esfahbodf3064102012-11-15 18:39:46 -0800172
Behdad Esfahbod92f9bfe2012-11-13 16:50:45 -0800173
174typedef enum {
175 HB_BUFFER_FLAGS_DEFAULT = 0x00000000,
176 HB_BUFFER_FLAG_BOT = 0x00000001, /* Beginning-of-text */
177 HB_BUFFER_FLAG_EOT = 0x00000002, /* End-of-text */
178 HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES = 0x00000004
179} hb_buffer_flags_t;
180
Behdad Esfahbod0c7df222012-11-13 14:42:35 -0800181void
182hb_buffer_set_flags (hb_buffer_t *buffer,
183 hb_buffer_flags_t flags);
184
185hb_buffer_flags_t
186hb_buffer_get_flags (hb_buffer_t *buffer);
187
Behdad Esfahbod5ebabec2009-11-03 15:15:07 -0500188
Behdad Esfahbodc910bec2011-04-13 15:49:06 -0400189/* Resets the buffer. Afterwards it's as if it was just created,
190 * except that it has a larger buffer allocated perhaps... */
191void
192hb_buffer_reset (hb_buffer_t *buffer);
193
Behdad Esfahbod82ecaff2012-11-13 13:57:52 -0800194/* Like reset, but does NOT clear unicode_funcs. */
195void
Behdad Esfahbod1172dc72013-01-07 16:46:37 -0600196hb_buffer_clear_contents (hb_buffer_t *buffer);
Behdad Esfahbod82ecaff2012-11-13 13:57:52 -0800197
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400198/* Returns false if allocation failed */
Behdad Esfahboda6a79df2010-05-14 23:20:16 -0400199hb_bool_t
Ryan Lortie02a534b2011-04-15 18:34:45 -0400200hb_buffer_pre_allocate (hb_buffer_t *buffer,
201 unsigned int size);
Behdad Esfahbodf9cd1012009-07-28 15:43:34 -0400202
Behdad Esfahbodaab0de52011-04-19 00:32:19 -0400203
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400204/* Returns false if allocation has failed before */
Behdad Esfahbodaab0de52011-04-19 00:32:19 -0400205hb_bool_t
206hb_buffer_allocation_successful (hb_buffer_t *buffer);
207
Behdad Esfahbodfbaf8ff2009-08-10 20:59:25 -0400208void
209hb_buffer_reverse (hb_buffer_t *buffer);
210
Behdad Esfahbodff44f882009-11-06 19:48:16 -0500211void
212hb_buffer_reverse_clusters (hb_buffer_t *buffer);
213
Behdad Esfahbodfbaf8ff2009-08-10 20:59:25 -0400214
215/* Filling the buffer in */
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400216
Behdad Esfahbodf9cd1012009-07-28 15:43:34 -0400217void
Behdad Esfahbodf85faee2011-04-19 00:38:01 -0400218hb_buffer_add (hb_buffer_t *buffer,
219 hb_codepoint_t codepoint,
Behdad Esfahbodf85faee2011-04-19 00:38:01 -0400220 unsigned int cluster);
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000221
Behdad Esfahbod1b7b97f2009-08-10 21:10:37 -0400222void
223hb_buffer_add_utf8 (hb_buffer_t *buffer,
224 const char *text,
Behdad Esfahbod944b2ba2011-08-09 00:23:58 +0200225 int text_length,
Behdad Esfahbod1b7b97f2009-08-10 21:10:37 -0400226 unsigned int item_offset,
Behdad Esfahbod944b2ba2011-08-09 00:23:58 +0200227 int item_length);
Behdad Esfahbod1b7b97f2009-08-10 21:10:37 -0400228
229void
230hb_buffer_add_utf16 (hb_buffer_t *buffer,
231 const uint16_t *text,
Behdad Esfahbod944b2ba2011-08-09 00:23:58 +0200232 int text_length,
Behdad Esfahbod1b7b97f2009-08-10 21:10:37 -0400233 unsigned int item_offset,
Behdad Esfahbod944b2ba2011-08-09 00:23:58 +0200234 int item_length);
Behdad Esfahbod1b7b97f2009-08-10 21:10:37 -0400235
236void
237hb_buffer_add_utf32 (hb_buffer_t *buffer,
238 const uint32_t *text,
Behdad Esfahbod944b2ba2011-08-09 00:23:58 +0200239 int text_length,
Behdad Esfahbod1b7b97f2009-08-10 21:10:37 -0400240 unsigned int item_offset,
Behdad Esfahbod944b2ba2011-08-09 00:23:58 +0200241 int item_length);
Behdad Esfahbod1b7b97f2009-08-10 21:10:37 -0400242
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400243
Behdad Esfahbodc910bec2011-04-13 15:49:06 -0400244/* Clears any new items added at the end */
245hb_bool_t
246hb_buffer_set_length (hb_buffer_t *buffer,
247 unsigned int length);
Behdad Esfahbodfbaf8ff2009-08-10 20:59:25 -0400248
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400249/* Return value valid as long as buffer not modified */
250unsigned int
Behdad Esfahbod3d145282009-11-06 15:13:17 -0500251hb_buffer_get_length (hb_buffer_t *buffer);
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400252
Behdad Esfahbodc910bec2011-04-13 15:49:06 -0400253/* Getting glyphs out of the buffer */
254
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400255/* Return value valid as long as buffer not modified */
256hb_glyph_info_t *
Ryan Lortie70566be2011-04-15 18:32:36 -0400257hb_buffer_get_glyph_infos (hb_buffer_t *buffer,
258 unsigned int *length);
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400259
260/* Return value valid as long as buffer not modified */
261hb_glyph_position_t *
Ryan Lortie70566be2011-04-15 18:32:36 -0400262hb_buffer_get_glyph_positions (hb_buffer_t *buffer,
263 unsigned int *length);
Behdad Esfahbod02a37062009-07-29 18:41:25 -0400264
265
Behdad Esfahbod39b17832012-07-17 17:09:29 -0400266/* Reorders a glyph buffer to have canonical in-cluster glyph order / position.
267 * The resulting clusters should behave identical to pre-reordering clusters.
268 * NOTE: This has nothing to do with Unicode normalization. */
269void
270hb_buffer_normalize_glyphs (hb_buffer_t *buffer);
271
Behdad Esfahbod39b17832012-07-17 17:09:29 -0400272
Behdad Esfahbodc54599a2012-11-15 16:14:23 -0800273/*
274 * Serialize
275 */
Behdad Esfahbod39b17832012-07-17 17:09:29 -0400276
Behdad Esfahbodf9edf162012-11-15 12:14:09 -0800277typedef enum {
278 HB_BUFFER_SERIALIZE_FLAGS_DEFAULT = 0x00000000,
279 HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001,
280 HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002,
281 HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004
282} hb_buffer_serialize_flags_t;
283
284typedef enum {
285 HB_BUFFER_SERIALIZE_FORMAT_TEXT = HB_TAG('T','E','X','T'),
286 HB_BUFFER_SERIALIZE_FORMAT_JSON = HB_TAG('J','S','O','N'),
287 HB_BUFFER_SERIALIZE_FORMAT_INVALID = HB_TAG_NONE
288} hb_buffer_serialize_format_t;
289
290/* len=-1 means str is NUL-terminated. */
291hb_buffer_serialize_format_t
292hb_buffer_serialize_format_from_string (const char *str, int len);
293
294const char *
295hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format);
296
Behdad Esfahbod072ae7a2012-11-15 13:14:12 -0800297const char **
298hb_buffer_serialize_list_formats (void);
299
Behdad Esfahbodf9edf162012-11-15 12:14:09 -0800300/* Returns number of items, starting at start, that were serialized. */
301unsigned int
302hb_buffer_serialize_glyphs (hb_buffer_t *buffer,
303 unsigned int start,
304 unsigned int end,
305 char *buf,
306 unsigned int buf_size,
Behdad Esfahbodbcc8f322013-02-27 12:02:42 -0500307 unsigned int *buf_consumed, /* May be NULL */
Behdad Esfahbodf9edf162012-11-15 12:14:09 -0800308 hb_font_t *font, /* May be NULL */
309 hb_buffer_serialize_format_t format,
310 hb_buffer_serialize_flags_t flags);
311
312hb_bool_t
313hb_buffer_deserialize_glyphs (hb_buffer_t *buffer,
314 const char *buf,
Behdad Esfahbode54dd262013-02-27 13:01:02 -0500315 int buf_len, /* -1 means nul-terminated */
Behdad Esfahbod847794e2013-02-27 17:59:28 -0500316 const char **end_ptr, /* May be NULL */
Behdad Esfahbodf9edf162012-11-15 12:14:09 -0800317 hb_font_t *font, /* May be NULL */
318 hb_buffer_serialize_format_t format);
319
320
Behdad Esfahbodf96ffd42009-05-24 15:01:16 -0400321HB_END_DECLS
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000322
Behdad Esfahbod5c0adce2009-05-20 05:42:12 -0400323#endif /* HB_BUFFER_H */