[HB] Add hb_buffer_reverse()

This commit is contained in:
Behdad Esfahbod 2009-08-10 20:59:25 -04:00
parent cbe5a4e08e
commit fbaf8ffa09
2 changed files with 36 additions and 3 deletions

View File

@ -65,7 +65,7 @@ hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size)
if (!buffer->positions) if (!buffer->positions)
buffer->positions = calloc (buffer->allocated, sizeof (buffer->positions[0])); buffer->positions = calloc (buffer->allocated, sizeof (buffer->positions[0]));
buffer->out_string = buffer->positions; buffer->out_string = (hb_internal_glyph_info_t *) buffer->positions;
memcpy (buffer->out_string, buffer->in_string, buffer->out_length * sizeof (buffer->out_string[0])); memcpy (buffer->out_string, buffer->in_string, buffer->out_length * sizeof (buffer->out_string[0]));
} }
} }
@ -136,7 +136,7 @@ hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size)
if (buffer->out_string != buffer->in_string) if (buffer->out_string != buffer->in_string)
{ {
buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0])); buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0]));
buffer->out_string = buffer->positions; buffer->out_string = (hb_internal_glyph_info_t *) buffer->positions;
} }
else else
{ {
@ -212,7 +212,8 @@ _hb_buffer_swap (hb_buffer_t *buffer)
hb_internal_glyph_info_t *tmp_string; hb_internal_glyph_info_t *tmp_string;
tmp_string = buffer->in_string; tmp_string = buffer->in_string;
buffer->in_string = buffer->out_string; buffer->in_string = buffer->out_string;
buffer->positions = buffer->out_string = tmp_string; buffer->out_string = tmp_string;
buffer->positions = (hb_internal_glyph_position_t *) buffer->out_string;
} }
tmp = buffer->in_length; tmp = buffer->in_length;
@ -366,3 +367,28 @@ hb_buffer_get_glyph_positions (hb_buffer_t *buffer)
return (hb_glyph_position_t *) buffer->positions; return (hb_glyph_position_t *) buffer->positions;
} }
void
hb_buffer_reverse (hb_buffer_t *buffer)
{
unsigned int i, j;
for (i = 0, j = buffer->in_length - 1; i < buffer->in_length / 2; i++, j--) {
hb_internal_glyph_info_t t;
t = buffer->in_string[i];
buffer->in_string[i] = buffer->in_string[j];
buffer->in_string[j] = t;
}
if (buffer->positions) {
for (i = 0, j = buffer->in_length - 1; i < buffer->in_length / 2; i++, j--) {
hb_internal_glyph_position_t t;
t = buffer->positions[i];
buffer->positions[i] = buffer->positions[j];
buffer->positions[j] = t;
}
}
}

View File

@ -99,6 +99,11 @@ void
hb_buffer_ensure (hb_buffer_t *buffer, hb_buffer_ensure (hb_buffer_t *buffer,
unsigned int size); unsigned int size);
void
hb_buffer_reverse (hb_buffer_t *buffer);
/* Filling the buffer in */
void void
hb_buffer_add_glyph (hb_buffer_t *buffer, hb_buffer_add_glyph (hb_buffer_t *buffer,
@ -107,6 +112,8 @@ hb_buffer_add_glyph (hb_buffer_t *buffer,
unsigned int cluster); unsigned int cluster);
/* Getting glyphs out of the buffer */
/* Return value valid as long as buffer not modified */ /* Return value valid as long as buffer not modified */
unsigned int unsigned int
hb_buffer_get_len (hb_buffer_t *buffer); hb_buffer_get_len (hb_buffer_t *buffer);