Imported Upstream version 0.9.3
[platform/upstream/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_H_IN
31 #error "Include <hb.h> instead."
32 #endif
33
34 #ifndef HB_BUFFER_H
35 #define HB_BUFFER_H
36
37 #include "hb-common.h"
38 #include "hb-unicode.h"
39
40 HB_BEGIN_DECLS
41
42
43 typedef struct hb_buffer_t hb_buffer_t;
44
45 typedef struct hb_glyph_info_t {
46   hb_codepoint_t codepoint;
47   hb_mask_t      mask;
48   uint32_t       cluster;
49
50   /*< private >*/
51   hb_var_int_t   var1;
52   hb_var_int_t   var2;
53 } hb_glyph_info_t;
54
55 typedef struct hb_glyph_position_t {
56   hb_position_t  x_advance;
57   hb_position_t  y_advance;
58   hb_position_t  x_offset;
59   hb_position_t  y_offset;
60
61   /*< private >*/
62   hb_var_int_t   var;
63 } hb_glyph_position_t;
64
65
66 hb_buffer_t *
67 hb_buffer_create (void);
68
69 hb_buffer_t *
70 hb_buffer_get_empty (void);
71
72 hb_buffer_t *
73 hb_buffer_reference (hb_buffer_t *buffer);
74
75 void
76 hb_buffer_destroy (hb_buffer_t *buffer);
77
78 hb_bool_t
79 hb_buffer_set_user_data (hb_buffer_t        *buffer,
80                          hb_user_data_key_t *key,
81                          void *              data,
82                          hb_destroy_func_t   destroy,
83                          hb_bool_t           replace);
84
85 void *
86 hb_buffer_get_user_data (hb_buffer_t        *buffer,
87                          hb_user_data_key_t *key);
88
89
90 void
91 hb_buffer_set_unicode_funcs (hb_buffer_t        *buffer,
92                              hb_unicode_funcs_t *unicode_funcs);
93
94 hb_unicode_funcs_t *
95 hb_buffer_get_unicode_funcs (hb_buffer_t        *buffer);
96
97 void
98 hb_buffer_set_direction (hb_buffer_t    *buffer,
99                          hb_direction_t  direction);
100
101 hb_direction_t
102 hb_buffer_get_direction (hb_buffer_t *buffer);
103
104 void
105 hb_buffer_set_script (hb_buffer_t *buffer,
106                       hb_script_t  script);
107
108 hb_script_t
109 hb_buffer_get_script (hb_buffer_t *buffer);
110
111 void
112 hb_buffer_set_language (hb_buffer_t   *buffer,
113                         hb_language_t  language);
114
115 hb_language_t
116 hb_buffer_get_language (hb_buffer_t *buffer);
117
118
119 /* Resets the buffer.  Afterwards it's as if it was just created,
120  * except that it has a larger buffer allocated perhaps... */
121 void
122 hb_buffer_reset (hb_buffer_t *buffer);
123
124 /* Returns false if allocation failed */
125 hb_bool_t
126 hb_buffer_pre_allocate (hb_buffer_t  *buffer,
127                         unsigned int  size);
128
129
130 /* Returns false if allocation has failed before */
131 hb_bool_t
132 hb_buffer_allocation_successful (hb_buffer_t  *buffer);
133
134 void
135 hb_buffer_reverse (hb_buffer_t *buffer);
136
137 void
138 hb_buffer_reverse_clusters (hb_buffer_t *buffer);
139
140 void
141 hb_buffer_guess_properties (hb_buffer_t *buffer);
142
143
144 /* Filling the buffer in */
145
146 void
147 hb_buffer_add (hb_buffer_t    *buffer,
148                hb_codepoint_t  codepoint,
149                hb_mask_t       mask,
150                unsigned int    cluster);
151
152 void
153 hb_buffer_add_utf8 (hb_buffer_t  *buffer,
154                     const char   *text,
155                     int           text_length,
156                     unsigned int  item_offset,
157                     int           item_length);
158
159 void
160 hb_buffer_add_utf16 (hb_buffer_t    *buffer,
161                      const uint16_t *text,
162                      int             text_length,
163                      unsigned int    item_offset,
164                      int             item_length);
165
166 void
167 hb_buffer_add_utf32 (hb_buffer_t    *buffer,
168                      const uint32_t *text,
169                      int             text_length,
170                      unsigned int    item_offset,
171                      int             item_length);
172
173
174 /* Clears any new items added at the end */
175 hb_bool_t
176 hb_buffer_set_length (hb_buffer_t  *buffer,
177                       unsigned int  length);
178
179 /* Return value valid as long as buffer not modified */
180 unsigned int
181 hb_buffer_get_length (hb_buffer_t *buffer);
182
183 /* Getting glyphs out of the buffer */
184
185 /* Return value valid as long as buffer not modified */
186 hb_glyph_info_t *
187 hb_buffer_get_glyph_infos (hb_buffer_t  *buffer,
188                            unsigned int *length);
189
190 /* Return value valid as long as buffer not modified */
191 hb_glyph_position_t *
192 hb_buffer_get_glyph_positions (hb_buffer_t  *buffer,
193                                unsigned int *length);
194
195
196 /* Reorders a glyph buffer to have canonical in-cluster glyph order / position.
197  * The resulting clusters should behave identical to pre-reordering clusters.
198  * NOTE: This has nothing to do with Unicode normalization. */
199 void
200 hb_buffer_normalize_glyphs (hb_buffer_t *buffer);
201
202 /*
203  * NOT IMPLEMENTED
204  void
205  hb_buffer_normalize_characters (hb_buffer_t *buffer);
206 */
207
208
209 HB_END_DECLS
210
211 #endif /* HB_BUFFER_H */