2 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009 Red Hat, Inc.
4 * Copyright © 2011,2012 Google, Inc.
6 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
26 * Red Hat Author(s): Owen Taylor, Behdad Esfahbod
27 * Google Author(s): Behdad Esfahbod
31 #error "Include <hb.h> instead."
37 #include "hb-common.h"
38 #include "hb-unicode.h"
44 typedef struct hb_glyph_info_t
{
45 hb_codepoint_t codepoint
;
54 typedef struct hb_glyph_position_t
{
55 hb_position_t x_advance
;
56 hb_position_t y_advance
;
57 hb_position_t x_offset
;
58 hb_position_t y_offset
;
62 } hb_glyph_position_t
;
65 typedef struct hb_segment_properties_t
{
66 hb_direction_t direction
;
68 hb_language_t language
;
72 } hb_segment_properties_t
;
74 #define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \
76 HB_LANGUAGE_INVALID, \
81 hb_segment_properties_equal (const hb_segment_properties_t
*a
,
82 const hb_segment_properties_t
*b
);
85 hb_segment_properties_hash (const hb_segment_properties_t
*p
);
93 typedef struct hb_buffer_t hb_buffer_t
;
96 hb_buffer_create (void);
99 hb_buffer_get_empty (void);
102 hb_buffer_reference (hb_buffer_t
*buffer
);
105 hb_buffer_destroy (hb_buffer_t
*buffer
);
108 hb_buffer_set_user_data (hb_buffer_t
*buffer
,
109 hb_user_data_key_t
*key
,
111 hb_destroy_func_t destroy
,
115 hb_buffer_get_user_data (hb_buffer_t
*buffer
,
116 hb_user_data_key_t
*key
);
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
;
126 hb_buffer_set_content_type (hb_buffer_t
*buffer
,
127 hb_buffer_content_type_t content_type
);
129 hb_buffer_content_type_t
130 hb_buffer_get_content_type (hb_buffer_t
*buffer
);
134 hb_buffer_set_unicode_funcs (hb_buffer_t
*buffer
,
135 hb_unicode_funcs_t
*unicode_funcs
);
138 hb_buffer_get_unicode_funcs (hb_buffer_t
*buffer
);
141 hb_buffer_set_direction (hb_buffer_t
*buffer
,
142 hb_direction_t direction
);
145 hb_buffer_get_direction (hb_buffer_t
*buffer
);
148 hb_buffer_set_script (hb_buffer_t
*buffer
,
152 hb_buffer_get_script (hb_buffer_t
*buffer
);
155 hb_buffer_set_language (hb_buffer_t
*buffer
,
156 hb_language_t language
);
160 hb_buffer_get_language (hb_buffer_t
*buffer
);
163 hb_buffer_set_segment_properties (hb_buffer_t
*buffer
,
164 const hb_segment_properties_t
*props
);
167 hb_buffer_get_segment_properties (hb_buffer_t
*buffer
,
168 hb_segment_properties_t
*props
);
171 hb_buffer_guess_segment_properties (hb_buffer_t
*buffer
);
174 typedef enum { /*< flags >*/
175 HB_BUFFER_FLAG_DEFAULT
= 0x00000000u
,
176 HB_BUFFER_FLAG_BOT
= 0x00000001u
, /* Beginning-of-text */
177 HB_BUFFER_FLAG_EOT
= 0x00000002u
, /* End-of-text */
178 HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES
= 0x00000004u
182 hb_buffer_set_flags (hb_buffer_t
*buffer
,
183 hb_buffer_flags_t flags
);
186 hb_buffer_get_flags (hb_buffer_t
*buffer
);
189 HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES
= 0,
190 HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS
= 1,
191 HB_BUFFER_CLUSTER_LEVEL_CHARACTERS
= 2,
192 HB_BUFFER_CLUSTER_LEVEL_DEFAULT
= HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES
193 } hb_buffer_cluster_level_t
;
196 hb_buffer_set_cluster_level (hb_buffer_t
*buffer
,
197 hb_buffer_cluster_level_t cluster_level
);
199 hb_buffer_cluster_level_t
200 hb_buffer_get_cluster_level (hb_buffer_t
*buffer
);
202 #define HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT 0xFFFDu
204 /* Sets codepoint used to replace invalid UTF-8/16/32 entries.
205 * Default is 0xFFFDu. */
207 hb_buffer_set_replacement_codepoint (hb_buffer_t
*buffer
,
208 hb_codepoint_t replacement
);
211 hb_buffer_get_replacement_codepoint (hb_buffer_t
*buffer
);
214 /* Resets the buffer. Afterwards it's as if it was just created,
215 * except that it has a larger buffer allocated perhaps... */
217 hb_buffer_reset (hb_buffer_t
*buffer
);
219 /* Like reset, but does NOT clear unicode_funcs and replacement_codepoint. */
221 hb_buffer_clear_contents (hb_buffer_t
*buffer
);
223 /* Returns false if allocation failed */
225 hb_buffer_pre_allocate (hb_buffer_t
*buffer
,
229 /* Returns false if allocation has failed before */
231 hb_buffer_allocation_successful (hb_buffer_t
*buffer
);
234 hb_buffer_reverse (hb_buffer_t
*buffer
);
237 hb_buffer_reverse_range (hb_buffer_t
*buffer
,
238 unsigned int start
, unsigned int end
);
241 hb_buffer_reverse_clusters (hb_buffer_t
*buffer
);
244 /* Filling the buffer in */
247 hb_buffer_add (hb_buffer_t
*buffer
,
248 hb_codepoint_t codepoint
,
249 unsigned int cluster
);
252 hb_buffer_add_utf8 (hb_buffer_t
*buffer
,
255 unsigned int item_offset
,
259 hb_buffer_add_utf16 (hb_buffer_t
*buffer
,
260 const uint16_t *text
,
262 unsigned int item_offset
,
266 hb_buffer_add_utf32 (hb_buffer_t
*buffer
,
267 const uint32_t *text
,
269 unsigned int item_offset
,
272 /* Allows only access to first 256 Unicode codepoints. */
274 hb_buffer_add_latin1 (hb_buffer_t
*buffer
,
277 unsigned int item_offset
,
280 /* Like add_utf32 but does NOT check for invalid Unicode codepoints. */
282 hb_buffer_add_codepoints (hb_buffer_t
*buffer
,
283 const hb_codepoint_t
*text
,
285 unsigned int item_offset
,
289 /* Clears any new items added at the end */
291 hb_buffer_set_length (hb_buffer_t
*buffer
,
292 unsigned int length
);
294 /* Return value valid as long as buffer not modified */
296 hb_buffer_get_length (hb_buffer_t
*buffer
);
298 /* Getting glyphs out of the buffer */
300 /* Return value valid as long as buffer not modified */
302 hb_buffer_get_glyph_infos (hb_buffer_t
*buffer
,
303 unsigned int *length
);
305 /* Return value valid as long as buffer not modified */
306 hb_glyph_position_t
*
307 hb_buffer_get_glyph_positions (hb_buffer_t
*buffer
,
308 unsigned int *length
);
311 /* Reorders a glyph buffer to have canonical in-cluster glyph order / position.
312 * The resulting clusters should behave identical to pre-reordering clusters.
313 * NOTE: This has nothing to do with Unicode normalization. */
315 hb_buffer_normalize_glyphs (hb_buffer_t
*buffer
);
322 typedef enum { /*< flags >*/
323 HB_BUFFER_SERIALIZE_FLAG_DEFAULT
= 0x00000000u
,
324 HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS
= 0x00000001u
,
325 HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS
= 0x00000002u
,
326 HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES
= 0x00000004u
327 } hb_buffer_serialize_flags_t
;
330 HB_BUFFER_SERIALIZE_FORMAT_TEXT
= HB_TAG('T','E','X','T'),
331 HB_BUFFER_SERIALIZE_FORMAT_JSON
= HB_TAG('J','S','O','N'),
332 HB_BUFFER_SERIALIZE_FORMAT_INVALID
= HB_TAG_NONE
333 } hb_buffer_serialize_format_t
;
335 /* len=-1 means str is NUL-terminated. */
336 hb_buffer_serialize_format_t
337 hb_buffer_serialize_format_from_string (const char *str
, int len
);
340 hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format
);
343 hb_buffer_serialize_list_formats (void);
345 /* Returns number of items, starting at start, that were serialized. */
347 hb_buffer_serialize_glyphs (hb_buffer_t
*buffer
,
351 unsigned int buf_size
,
352 unsigned int *buf_consumed
, /* May be NULL */
353 hb_font_t
*font
, /* May be NULL */
354 hb_buffer_serialize_format_t format
,
355 hb_buffer_serialize_flags_t flags
);
358 hb_buffer_deserialize_glyphs (hb_buffer_t
*buffer
,
360 int buf_len
, /* -1 means nul-terminated */
361 const char **end_ptr
, /* May be NULL */
362 hb_font_t
*font
, /* May be NULL */
363 hb_buffer_serialize_format_t format
);
368 #endif /* HB_BUFFER_H */