From 314905d7548d5be58354546d660754b807b6efb2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 20 Dec 2009 14:50:42 +0100 Subject: [PATCH] Explicitly track whether the buffer has positions --- src/hb-buffer-private.h | 3 ++- src/hb-buffer.c | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/hb-buffer-private.h b/src/hb-buffer-private.h index 6ba1a21a5..821a481c6 100644 --- a/src/hb-buffer-private.h +++ b/src/hb-buffer-private.h @@ -76,7 +76,8 @@ struct _hb_buffer_t { unsigned int allocated; - hb_bool_t have_output; /* weather we have an output buffer going on */ + hb_bool_t have_output; /* whether we have an output buffer going on */ + hb_bool_t have_positions; /* whether we have positions */ unsigned int in_length; unsigned int out_length; unsigned int in_pos; diff --git a/src/hb-buffer.c b/src/hb-buffer.c index 723b8bdb7..9d4d5180a 100644 --- a/src/hb-buffer.c +++ b/src/hb-buffer.c @@ -177,6 +177,7 @@ void hb_buffer_clear (hb_buffer_t *buffer) { buffer->have_output = FALSE; + buffer->have_positions = FALSE; buffer->in_length = 0; buffer->out_length = 0; buffer->in_pos = 0; @@ -241,6 +242,7 @@ void _hb_buffer_clear_output (hb_buffer_t *buffer) { buffer->have_output = TRUE; + buffer->have_positions = FALSE; buffer->out_length = 0; buffer->out_pos = 0; buffer->out_string = buffer->in_string; @@ -251,6 +253,7 @@ hb_buffer_clear_positions (hb_buffer_t *buffer) { _hb_buffer_clear_output (buffer); buffer->have_output = FALSE; + buffer->have_positions = TRUE; if (HB_UNLIKELY (!buffer->positions)) { @@ -420,23 +423,21 @@ _hb_buffer_add_output_glyph (hb_buffer_t *buffer, void _hb_buffer_next_glyph (hb_buffer_t *buffer) { - if (!buffer->have_output) + if (buffer->have_output) { - buffer->in_pos++; - return; - } + if (buffer->out_string != buffer->in_string) + { + hb_buffer_ensure (buffer, buffer->out_pos + 1); + buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; + } + else if (buffer->out_pos != buffer->in_pos) + buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; - if (buffer->out_string != buffer->in_string) - { - hb_buffer_ensure (buffer, buffer->out_pos + 1); - buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; + buffer->out_pos++; + buffer->out_length = buffer->out_pos; } - else if (buffer->out_pos != buffer->in_pos) - buffer->out_string[buffer->out_pos] = buffer->in_string[buffer->in_pos]; buffer->in_pos++; - buffer->out_pos++; - buffer->out_length = buffer->out_pos; } void @@ -470,7 +471,7 @@ hb_buffer_get_glyph_infos (hb_buffer_t *buffer) hb_glyph_position_t * hb_buffer_get_glyph_positions (hb_buffer_t *buffer) { - if (buffer->have_output || (buffer->in_length && !buffer->positions)) + if (!buffer->have_positions) hb_buffer_clear_positions (buffer); return (hb_glyph_position_t *) buffer->positions;