020a12079aade9a36e159599faab7ba8d389fb44
[framework/uifw/harfbuzz.git] / src / hb-buffer.h
1 /*
2  * Copyright © 1998-2004  David Turner and Werner Lemberg
3  * Copyright © 2004,2007,2009  Red Hat, Inc.
4  * Copyright © 2011  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_H
31 #define HB_BUFFER_H
32
33 #include "hb-common.h"
34 #include "hb-unicode.h"
35
36 HB_BEGIN_DECLS
37
38
39 typedef struct _hb_buffer_t hb_buffer_t;
40
41 typedef struct _hb_glyph_info_t {
42   hb_codepoint_t codepoint;
43   hb_mask_t      mask;
44   uint32_t       cluster;
45
46   /*< private >*/
47   hb_var_int_t   var1;
48   hb_var_int_t   var2;
49 } hb_glyph_info_t;
50
51 typedef struct _hb_glyph_position_t {
52   hb_position_t  x_advance;
53   hb_position_t  y_advance;
54   hb_position_t  x_offset;
55   hb_position_t  y_offset;
56
57   /*< private >*/
58   hb_var_int_t   var;
59 } hb_glyph_position_t;
60
61
62 hb_buffer_t *
63 hb_buffer_create (unsigned int pre_alloc_size);
64
65 hb_buffer_t *
66 hb_buffer_get_empty (void);
67
68 hb_buffer_t *
69 hb_buffer_reference (hb_buffer_t *buffer);
70
71 void
72 hb_buffer_destroy (hb_buffer_t *buffer);
73
74 hb_bool_t
75 hb_buffer_set_user_data (hb_buffer_t        *buffer,
76                          hb_user_data_key_t *key,
77                          void *              data,
78                          hb_destroy_func_t   destroy);
79
80 void *
81 hb_buffer_get_user_data (hb_buffer_t        *buffer,
82                          hb_user_data_key_t *key);
83
84
85 void
86 hb_buffer_set_unicode_funcs (hb_buffer_t        *buffer,
87                              hb_unicode_funcs_t *unicode_funcs);
88
89 hb_unicode_funcs_t *
90 hb_buffer_get_unicode_funcs (hb_buffer_t        *buffer);
91
92 void
93 hb_buffer_set_direction (hb_buffer_t    *buffer,
94                          hb_direction_t  direction);
95
96 hb_direction_t
97 hb_buffer_get_direction (hb_buffer_t *buffer);
98
99 void
100 hb_buffer_set_script (hb_buffer_t *buffer,
101                       hb_script_t  script);
102
103 hb_script_t
104 hb_buffer_get_script (hb_buffer_t *buffer);
105
106 void
107 hb_buffer_set_language (hb_buffer_t   *buffer,
108                         hb_language_t  language);
109
110 hb_language_t
111 hb_buffer_get_language (hb_buffer_t *buffer);
112
113
114 /* Resets the buffer.  Afterwards it's as if it was just created,
115  * except that it has a larger buffer allocated perhaps... */
116 void
117 hb_buffer_reset (hb_buffer_t *buffer);
118
119 /* Returns FALSE if allocation failed */
120 hb_bool_t
121 hb_buffer_pre_allocate (hb_buffer_t  *buffer,
122                         unsigned int  size);
123
124
125 /* Returns FALSE if allocation has failed before */
126 hb_bool_t
127 hb_buffer_allocation_successful (hb_buffer_t  *buffer);
128
129 void
130 hb_buffer_reverse (hb_buffer_t *buffer);
131
132 void
133 hb_buffer_reverse_clusters (hb_buffer_t *buffer);
134
135
136 /* Filling the buffer in */
137
138 void
139 hb_buffer_add (hb_buffer_t    *buffer,
140                hb_codepoint_t  codepoint,
141                hb_mask_t       mask,
142                unsigned int    cluster);
143
144 void
145 hb_buffer_add_utf8 (hb_buffer_t  *buffer,
146                     const char   *text,
147                     unsigned int  text_length,
148                     unsigned int  item_offset,
149                     unsigned int  item_length);
150
151 void
152 hb_buffer_add_utf16 (hb_buffer_t    *buffer,
153                      const uint16_t *text,
154                      unsigned int    text_length,
155                      unsigned int    item_offset,
156                      unsigned int    item_length);
157
158 void
159 hb_buffer_add_utf32 (hb_buffer_t    *buffer,
160                      const uint32_t *text,
161                      unsigned int    text_length,
162                      unsigned int    item_offset,
163                      unsigned int    item_length);
164
165
166 /* Clears any new items added at the end */
167 hb_bool_t
168 hb_buffer_set_length (hb_buffer_t  *buffer,
169                       unsigned int  length);
170
171 /* Return value valid as long as buffer not modified */
172 unsigned int
173 hb_buffer_get_length (hb_buffer_t *buffer);
174
175 /* Getting glyphs out of the buffer */
176
177 /* Return value valid as long as buffer not modified */
178 hb_glyph_info_t *
179 hb_buffer_get_glyph_infos (hb_buffer_t  *buffer,
180                            unsigned int *length);
181
182 /* Return value valid as long as buffer not modified */
183 hb_glyph_position_t *
184 hb_buffer_get_glyph_positions (hb_buffer_t  *buffer,
185                                unsigned int *length);
186
187
188 HB_END_DECLS
189
190 #endif /* HB_BUFFER_H */