From c0af193c8e25c4f11d23b8893e9ce1c2d2615bb2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 15 Apr 2011 19:26:24 -0400 Subject: [PATCH] Change buffer default properties to invalid This includes HB_DIRECTION_INVALID and HB_SCRIPT_INVALID. The INVALID will cause a "guess whatever from the text" in hb_shape(). While it's not ideal, it works better than the previous defaults at least (HB_DIRECTION_LTR and HB_SCRIPT_COMMON). --- src/hb-buffer-private.hh | 9 +++------ src/hb-buffer.cc | 32 ++++++++++++++++++++------------ src/hb-view.c | 6 ++---- test/test-buffer.c | 4 ++-- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 4b1ff12e6..2b063b70a 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -94,8 +94,6 @@ struct _hb_buffer_t { /* Buffer contents */ - unsigned int allocated; /* Length of allocated arrays */ - hb_bool_t have_output; /* Whether we have an output buffer going on */ hb_bool_t have_positions; /* Whether we have positions */ hb_bool_t in_error; /* Allocation failed */ @@ -104,14 +102,13 @@ struct _hb_buffer_t { unsigned int len; /* Length of ->info and ->pos arrays */ unsigned int out_len; /* Length of ->out array if have_output */ + unsigned int serial; + + unsigned int allocated; /* Length of allocated arrays */ hb_glyph_info_t *info; hb_glyph_info_t *out_info; hb_glyph_position_t *pos; - /* Other stuff */ - - unsigned int serial; - /* Methods */ inline unsigned int backtrack_len (void) const diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 4020d2ce6..b71aa57f6 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -37,7 +37,12 @@ HB_BEGIN_DECLS static hb_buffer_t _hb_buffer_nil = { HB_REFERENCE_COUNT_INVALID, /* ref_count */ - &_hb_unicode_funcs_nil /* unicode */ + &_hb_unicode_funcs_nil, /* unicode */ + { + HB_DIRECTION_INVALID, + HB_SCRIPT_INVALID, + NULL, + }, }; /* Here is how the buffer works internally: @@ -138,7 +143,7 @@ hb_buffer_create (unsigned int pre_alloc_size) if (pre_alloc_size) _hb_buffer_ensure (buffer, pre_alloc_size); - buffer->unicode = &_hb_unicode_funcs_nil; + hb_buffer_reset (buffer); return buffer; } @@ -231,19 +236,22 @@ hb_buffer_get_language (hb_buffer_t *buffer) void hb_buffer_reset (hb_buffer_t *buffer) { - buffer->have_output = FALSE; - buffer->have_positions = FALSE; - buffer->in_error = FALSE; - buffer->len = 0; - buffer->out_len = 0; - buffer->i = 0; - buffer->out_info = buffer->info; - buffer->serial = 0; + hb_unicode_funcs_destroy (buffer->unicode); + buffer->unicode = _hb_buffer_nil.unicode; buffer->props = _hb_buffer_nil.props; - hb_unicode_funcs_destroy (buffer->unicode); - buffer->unicode = _hb_buffer_nil.unicode; + buffer->have_output = FALSE; + buffer->have_positions = FALSE; + buffer->in_error = FALSE; + + buffer->i = 0; + buffer->len = 0; + buffer->out_len = 0; + + buffer->serial = 0; + + buffer->out_info = buffer->info; } hb_bool_t diff --git a/src/hb-view.c b/src/hb-view.c index 87d9b3087..d7e41fdce 100644 --- a/src/hb-view.c +++ b/src/hb-view.c @@ -355,10 +355,8 @@ _hb_cr_text_glyphs (cairo_t *cr, hb_buffer_add_utf8 (hb_buffer, text, len, 0, len); if (script) hb_buffer_set_script (hb_buffer, hb_script_from_string (script)); - else - hb_buffer_set_script (hb_buffer, HB_SCRIPT_INVALID); - hb_buffer_set_direction (hb_buffer, HB_DIRECTION_INVALID); - hb_buffer_set_language (hb_buffer, hb_language_from_string (language)); + if (language) + hb_buffer_set_language (hb_buffer, hb_language_from_string (language)); hb_shape (hb_font, hb_face, hb_buffer, features, num_features); diff --git a/test/test-buffer.c b/test/test-buffer.c index 4316f171c..dad2eacc1 100644 --- a/test/test-buffer.c +++ b/test/test-buffer.c @@ -100,8 +100,8 @@ test_buffer_properties (Fixture *fixture, gconstpointer user_data) { /* TODO check unicode_funcs */ - g_assert (hb_buffer_get_direction (fixture->b) == HB_DIRECTION_LTR); - g_assert (hb_buffer_get_script (fixture->b) == HB_SCRIPT_COMMON); + g_assert (hb_buffer_get_direction (fixture->b) == HB_DIRECTION_INVALID); + g_assert (hb_buffer_get_script (fixture->b) == HB_SCRIPT_INVALID); g_assert (hb_buffer_get_language (fixture->b) == NULL); hb_buffer_set_direction (fixture->b, HB_DIRECTION_RTL);