blob: 890a21bc92cc149e99fd923f591e2f044192eb41 [file] [log] [blame]
Behdad Esfahboda2a9a022008-01-15 22:46:32 +00001/*
2 * Copyright (C) 1998-2004 David Turner and Werner Lemberg
3 * Copyright (C) 2004,2007 Red Hat, Inc.
Behdad Esfahbod9f8da382006-03-31 12:28:09 +00004 *
Behdad Esfahboda2a9a022008-01-15 22:46:32 +00005 * This is part of HarfBuzz, an OpenType Layout engine library.
Behdad Esfahbod9f8da382006-03-31 12:28:09 +00006 *
Behdad Esfahboda2a9a022008-01-15 22:46:32 +00007 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 *
25 * Red Hat Author(s): Owen Taylor, Behdad Esfahbod
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000026 */
27
Behdad Esfahbod5c0adce2009-05-20 05:42:12 -040028#include "hb-buffer-private.h"
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000029
Behdad Esfahbod88a5f5a2009-05-25 03:39:11 -040030#include <string.h>
31
Behdad Esfahbodf1322e52009-08-01 22:53:04 -040032
Behdad Esfahbod11fbb542009-08-01 22:19:06 -040033static hb_buffer_t _hb_buffer_nil = {
34 HB_REFERENCE_COUNT_INVALID /* ref_count */
35};
36
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +000037/* Here is how the buffer works internally:
38 *
39 * There are two string pointers: in_string and out_string. They
40 * always have same allocated size, but different length and positions.
41 *
42 * As an optimization, both in_string and out_string may point to the
43 * same piece of memory, which is owned by in_string. This remains the
Behdad Esfahbode35bbd52009-05-30 12:02:46 -040044 * case as long as out_length doesn't exceed in_length at any time.
45 * In that case, swap() is no-op and the glyph operations operate mostly
46 * in-place.
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +000047 *
Behdad Esfahbode35bbd52009-05-30 12:02:46 -040048 * As soon as out_string gets longer than in_string, out_string is moved over
Behdad Esfahbodcbe5a4e2009-08-10 20:24:49 -040049 * to an alternate buffer (which we reuse the positions buffer for!), and its
50 * current contents (out_length entries) are copied to the alt buffer.
51 * This should all remain transparent to the user. swap() then switches
52 * in_string and out_string.
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +000053 */
54
Behdad Esfahbodc968fc22009-05-25 04:04:24 -040055/* XXX err handling */
56
Behdad Esfahbod6b347132007-10-11 08:30:50 +000057/* Internal API */
58
Behdad Esfahbod88a5f5a2009-05-25 03:39:11 -040059static void
Behdad Esfahbodc968fc22009-05-25 04:04:24 -040060hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size)
61{
62 hb_buffer_ensure (buffer, size);
Behdad Esfahbode35bbd52009-05-30 12:02:46 -040063 if (buffer->out_string == buffer->in_string)
64 {
Behdad Esfahbodcbe5a4e2009-08-10 20:24:49 -040065 if (!buffer->positions)
66 buffer->positions = calloc (buffer->allocated, sizeof (buffer->positions[0]));
Behdad Esfahbode35bbd52009-05-30 12:02:46 -040067
Behdad Esfahbodfbaf8ff2009-08-10 20:59:25 -040068 buffer->out_string = (hb_internal_glyph_info_t *) buffer->positions;
Behdad Esfahbode35bbd52009-05-30 12:02:46 -040069 memcpy (buffer->out_string, buffer->in_string, buffer->out_length * sizeof (buffer->out_string[0]));
70 }
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +000071}
72
Behdad Esfahbod6b347132007-10-11 08:30:50 +000073/* Public API */
74
Behdad Esfahbodb857b492009-05-20 05:35:14 -040075hb_buffer_t *
Behdad Esfahbod11fbb542009-08-01 22:19:06 -040076hb_buffer_create (unsigned int pre_alloc_size)
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000077{
Behdad Esfahbodb857b492009-05-20 05:35:14 -040078 hb_buffer_t *buffer;
79
Behdad Esfahbod5fc22e62009-08-03 22:43:02 -040080 if (!HB_OBJECT_DO_CREATE (hb_buffer_t, buffer))
Behdad Esfahbod11fbb542009-08-01 22:19:06 -040081 return &_hb_buffer_nil;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000082
Behdad Esfahbod11fbb542009-08-01 22:19:06 -040083 if (pre_alloc_size)
84 hb_buffer_ensure(buffer, pre_alloc_size);
Behdad Esfahbodf9cd1012009-07-28 15:43:34 -040085
Behdad Esfahbodb857b492009-05-20 05:35:14 -040086 return buffer;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +000087}
88
Behdad Esfahbod11fbb542009-08-01 22:19:06 -040089hb_buffer_t *
90hb_buffer_reference (hb_buffer_t *buffer)
Behdad Esfahbod7a268642007-10-11 07:21:31 +000091{
Behdad Esfahbod11fbb542009-08-01 22:19:06 -040092 HB_OBJECT_DO_REFERENCE (buffer);
93}
94
95unsigned int
96hb_buffer_get_reference_count (hb_buffer_t *buffer)
97{
98 HB_OBJECT_DO_GET_REFERENCE_COUNT (buffer);
99}
100
101void
102hb_buffer_destroy (hb_buffer_t *buffer)
103{
104 HB_OBJECT_DO_DESTROY (buffer);
105
Behdad Esfahbodb857b492009-05-20 05:35:14 -0400106 free (buffer->in_string);
Behdad Esfahbodb857b492009-05-20 05:35:14 -0400107 free (buffer->positions);
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400108
Behdad Esfahbodb857b492009-05-20 05:35:14 -0400109 free (buffer);
Behdad Esfahbod7a268642007-10-11 07:21:31 +0000110}
111
112void
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400113hb_buffer_clear (hb_buffer_t *buffer)
Behdad Esfahbod7a268642007-10-11 07:21:31 +0000114{
115 buffer->in_length = 0;
116 buffer->out_length = 0;
117 buffer->in_pos = 0;
118 buffer->out_pos = 0;
119 buffer->out_string = buffer->in_string;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400120 buffer->max_lig_id = 0;
Behdad Esfahbod7a268642007-10-11 07:21:31 +0000121}
122
Behdad Esfahbodb857b492009-05-20 05:35:14 -0400123void
Behdad Esfahbodf9cd1012009-07-28 15:43:34 -0400124hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size)
125{
126 unsigned int new_allocated = buffer->allocated;
127
128 if (size > new_allocated)
129 {
130 while (size > new_allocated)
131 new_allocated += (new_allocated >> 1) + 8;
132
133 if (buffer->positions)
134 buffer->positions = realloc (buffer->positions, new_allocated * sizeof (buffer->positions[0]));
135
136 if (buffer->out_string != buffer->in_string)
137 {
138 buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0]));
Behdad Esfahbodfbaf8ff2009-08-10 20:59:25 -0400139 buffer->out_string = (hb_internal_glyph_info_t *) buffer->positions;
Behdad Esfahbodf9cd1012009-07-28 15:43:34 -0400140 }
141 else
142 {
143 buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0]));
144 buffer->out_string = buffer->in_string;
Behdad Esfahbodf9cd1012009-07-28 15:43:34 -0400145 }
146
147 buffer->allocated = new_allocated;
148 }
149}
150
151void
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400152hb_buffer_add_glyph (hb_buffer_t *buffer,
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400153 hb_codepoint_t codepoint,
Behdad Esfahbod468769b2009-08-08 16:53:23 -0400154 hb_mask_t mask,
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400155 unsigned int cluster)
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000156{
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400157 hb_internal_glyph_info_t *glyph;
Behdad Esfahbod5c0adce2009-05-20 05:42:12 -0400158
Behdad Esfahbodb857b492009-05-20 05:35:14 -0400159 hb_buffer_ensure (buffer, buffer->in_length + 1);
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000160
161 glyph = &buffer->in_string[buffer->in_length];
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400162 glyph->codepoint = codepoint;
Behdad Esfahbod468769b2009-08-08 16:53:23 -0400163 glyph->mask = mask;
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000164 glyph->cluster = cluster;
165 glyph->component = 0;
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400166 glyph->lig_id = 0;
167 glyph->gproperty = HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN;
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000168
Behdad Esfahbodb857b492009-05-20 05:35:14 -0400169 buffer->in_length++;
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000170}
171
Behdad Esfahbod02a37062009-07-29 18:41:25 -0400172void
173hb_buffer_set_direction (hb_buffer_t *buffer,
174 hb_direction_t direction)
175
176{
177 buffer->direction = direction;
178}
179
180
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000181/* HarfBuzz-Internal API */
182
183HB_INTERNAL void
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400184_hb_buffer_clear_output (hb_buffer_t *buffer)
Behdad Esfahbod7a268642007-10-11 07:21:31 +0000185{
186 buffer->out_length = 0;
187 buffer->out_pos = 0;
188 buffer->out_string = buffer->in_string;
Behdad Esfahbod7a268642007-10-11 07:21:31 +0000189}
190
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400191void
192hb_buffer_clear_positions (hb_buffer_t *buffer)
Behdad Esfahbod06003902007-10-11 07:05:09 +0000193{
Behdad Esfahbod15c3e752009-05-17 06:03:42 -0400194 _hb_buffer_clear_output (buffer);
195
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400196 if (HB_UNLIKELY (!buffer->positions))
197 {
198 buffer->positions = calloc (buffer->allocated, sizeof (buffer->positions[0]));
199 return;
200 }
Behdad Esfahbod06003902007-10-11 07:05:09 +0000201
202 memset (buffer->positions, 0, sizeof (buffer->positions[0]) * buffer->in_length);
Behdad Esfahbod06003902007-10-11 07:05:09 +0000203}
204
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000205HB_INTERNAL void
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400206_hb_buffer_swap (hb_buffer_t *buffer)
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000207{
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400208 unsigned int tmp;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000209
Behdad Esfahbode35bbd52009-05-30 12:02:46 -0400210 if (buffer->out_string != buffer->in_string)
211 {
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400212 hb_internal_glyph_info_t *tmp_string;
Behdad Esfahbode35bbd52009-05-30 12:02:46 -0400213 tmp_string = buffer->in_string;
214 buffer->in_string = buffer->out_string;
Behdad Esfahbodfbaf8ff2009-08-10 20:59:25 -0400215 buffer->out_string = tmp_string;
216 buffer->positions = (hb_internal_glyph_position_t *) buffer->out_string;
Behdad Esfahbode35bbd52009-05-30 12:02:46 -0400217 }
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000218
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400219 tmp = buffer->in_length;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000220 buffer->in_length = buffer->out_length;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400221 buffer->out_length = tmp;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000222
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400223 tmp = buffer->in_pos;
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +0000224 buffer->in_pos = buffer->out_pos;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400225 buffer->out_pos = tmp;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000226}
227
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000228/* The following function copies `num_out' elements from `glyph_data'
229 to `buffer->out_string', advancing the in array pointer in the structure
230 by `num_in' elements, and the out array pointer by `num_out' elements.
231 Finally, it sets the `length' field of `out' equal to
232 `pos' of the `out' structure.
233
234 If `component' is 0xFFFF, the component value from buffer->in_pos
235 will copied `num_out' times, otherwise `component' itself will
236 be used to fill the `component' fields.
237
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400238 If `lig_id' is 0xFFFF, the lig_id value from buffer->in_pos
239 will copied `num_out' times, otherwise `lig_id' itself will
240 be used to fill the `lig_id' fields.
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000241
Behdad Esfahbod468769b2009-08-08 16:53:23 -0400242 The mask for all replacement glyphs are taken
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000243 from the glyph at position `buffer->in_pos'.
244
245 The cluster value for the glyph at position buffer->in_pos is used
246 for all replacement glyphs */
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400247HB_INTERNAL void
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400248_hb_buffer_add_output_glyphs (hb_buffer_t *buffer,
249 unsigned int num_in,
250 unsigned int num_out,
Behdad Esfahbod88a5f5a2009-05-25 03:39:11 -0400251 const uint16_t *glyph_data_be,
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400252 unsigned short component,
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400253 unsigned short lig_id)
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000254{
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400255 unsigned int i;
Behdad Esfahbod468769b2009-08-08 16:53:23 -0400256 unsigned int mask;
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400257 unsigned int cluster;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000258
Behdad Esfahbodb196e6f2009-07-28 15:50:42 -0400259 if (buffer->out_string != buffer->in_string ||
Behdad Esfahbode35bbd52009-05-30 12:02:46 -0400260 buffer->out_pos + num_out > buffer->in_pos + num_in)
261 {
262 hb_buffer_ensure_separate (buffer, buffer->out_pos + num_out);
263 }
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +0000264
Behdad Esfahbod468769b2009-08-08 16:53:23 -0400265 mask = buffer->in_string[buffer->in_pos].mask;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000266 cluster = buffer->in_string[buffer->in_pos].cluster;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400267 if (component == 0xFFFF)
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000268 component = buffer->in_string[buffer->in_pos].component;
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400269 if (lig_id == 0xFFFF)
270 lig_id = buffer->in_string[buffer->in_pos].lig_id;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000271
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400272 for (i = 0; i < num_out; i++)
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000273 {
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400274 hb_internal_glyph_info_t *info = &buffer->out_string[buffer->out_pos + i];
275 info->codepoint = hb_be_uint16 (glyph_data_be[i]);
Behdad Esfahbod468769b2009-08-08 16:53:23 -0400276 info->mask = mask;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400277 info->cluster = cluster;
278 info->component = component;
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400279 info->lig_id = lig_id;
280 info->gproperty = HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000281 }
282
283 buffer->in_pos += num_in;
284 buffer->out_pos += num_out;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000285 buffer->out_length = buffer->out_pos;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000286}
287
Behdad Esfahbod88a5f5a2009-05-25 03:39:11 -0400288
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400289HB_INTERNAL void
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400290_hb_buffer_add_output_glyph (hb_buffer_t *buffer,
291 hb_codepoint_t glyph_index,
292 unsigned short component,
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400293 unsigned short lig_id)
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000294{
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400295 hb_internal_glyph_info_t *info;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000296
Behdad Esfahbode35bbd52009-05-30 12:02:46 -0400297 if (buffer->out_string != buffer->in_string)
298 {
299 hb_buffer_ensure (buffer, buffer->out_pos + 1);
300 buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos];
301 }
302 else if (buffer->out_pos != buffer->in_pos)
303 buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos];
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400304
305 info = &buffer->out_string[buffer->out_pos];
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400306 info->codepoint = glyph_index;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400307 if (component != 0xFFFF)
308 info->component = component;
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400309 if (lig_id != 0xFFFF)
310 info->lig_id = lig_id;
311 info->gproperty = HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400312
313 buffer->in_pos++;
314 buffer->out_pos++;
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400315 buffer->out_length = buffer->out_pos;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000316}
317
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400318HB_INTERNAL void
319_hb_buffer_next_glyph (hb_buffer_t *buffer)
Behdad Esfahbod15c3e752009-05-17 06:03:42 -0400320{
Behdad Esfahbode35bbd52009-05-30 12:02:46 -0400321 if (buffer->out_string != buffer->in_string)
322 {
323 hb_buffer_ensure (buffer, buffer->out_pos + 1);
324 buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos];
325 }
326 else if (buffer->out_pos != buffer->in_pos)
327 buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos];
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +0000328
329 buffer->in_pos++;
330 buffer->out_pos++;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000331 buffer->out_length = buffer->out_pos;
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +0000332}
333
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400334HB_INTERNAL void
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400335_hb_buffer_replace_glyph (hb_buffer_t *buffer,
336 hb_codepoint_t glyph_index)
Behdad Esfahboda8abb8b2007-10-11 00:07:58 +0000337{
Behdad Esfahbode35bbd52009-05-30 12:02:46 -0400338 _hb_buffer_add_output_glyph (buffer, glyph_index, 0xFFFF, 0xFFFF);
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000339}
340
Behdad Esfahbod3015c412009-05-20 06:01:16 -0400341HB_INTERNAL unsigned short
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400342_hb_buffer_allocate_lig_id (hb_buffer_t *buffer)
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000343{
Behdad Esfahbodc968fc22009-05-25 04:04:24 -0400344 return ++buffer->max_lig_id;
Behdad Esfahbod9f8da382006-03-31 12:28:09 +0000345}
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400346
347
348unsigned int
349hb_buffer_get_len (hb_buffer_t *buffer)
350{
351 return buffer->in_length;
352}
353
354/* Return value valid as long as buffer not modified */
355hb_glyph_info_t *
356hb_buffer_get_glyph_infos (hb_buffer_t *buffer)
357{
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400358 return (hb_glyph_info_t *) buffer->in_string;
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400359}
360
361/* Return value valid as long as buffer not modified */
362hb_glyph_position_t *
363hb_buffer_get_glyph_positions (hb_buffer_t *buffer)
364{
365 if (buffer->in_length && !buffer->positions)
366 hb_buffer_clear_positions (buffer);
367
Behdad Esfahbodf1322e52009-08-01 22:53:04 -0400368 return (hb_glyph_position_t *) buffer->positions;
Behdad Esfahbod11fbb542009-08-01 22:19:06 -0400369}
Behdad Esfahbodfbaf8ff2009-08-10 20:59:25 -0400370
371
372void
373hb_buffer_reverse (hb_buffer_t *buffer)
374{
375 unsigned int i, j;
376
377 for (i = 0, j = buffer->in_length - 1; i < buffer->in_length / 2; i++, j--) {
378 hb_internal_glyph_info_t t;
379
380 t = buffer->in_string[i];
381 buffer->in_string[i] = buffer->in_string[j];
382 buffer->in_string[j] = t;
383 }
384
385 if (buffer->positions) {
386 for (i = 0, j = buffer->in_length - 1; i < buffer->in_length / 2; i++, j--) {
387 hb_internal_glyph_position_t t;
388
389 t = buffer->positions[i];
390 buffer->positions[i] = buffer->positions[j];
391 buffer->positions[j] = t;
392 }
393 }
394}