From fbaf8ffa098bd2b6fb4f4bc2d04b360a319c4af5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 Aug 2009 20:59:25 -0400 Subject: [PATCH] [HB] Add hb_buffer_reverse() --- src/hb-buffer.c | 32 +++++++++++++++++++++++++++++--- src/hb-buffer.h | 7 +++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/hb-buffer.c b/src/hb-buffer.c index c197b905b..890a21bc9 100644 --- a/src/hb-buffer.c +++ b/src/hb-buffer.c @@ -65,7 +65,7 @@ hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size) if (!buffer->positions) 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])); } } @@ -136,7 +136,7 @@ hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size) if (buffer->out_string != buffer->in_string) { 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 { @@ -212,7 +212,8 @@ _hb_buffer_swap (hb_buffer_t *buffer) hb_internal_glyph_info_t *tmp_string; tmp_string = buffer->in_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; @@ -366,3 +367,28 @@ hb_buffer_get_glyph_positions (hb_buffer_t *buffer) 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; + } + } +} diff --git a/src/hb-buffer.h b/src/hb-buffer.h index 57f56bdd8..4240f6ab3 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -99,6 +99,11 @@ void hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size); +void +hb_buffer_reverse (hb_buffer_t *buffer); + + +/* Filling the buffer in */ void hb_buffer_add_glyph (hb_buffer_t *buffer, @@ -107,6 +112,8 @@ hb_buffer_add_glyph (hb_buffer_t *buffer, unsigned int cluster); +/* Getting glyphs out of the buffer */ + /* Return value valid as long as buffer not modified */ unsigned int hb_buffer_get_len (hb_buffer_t *buffer);