From 96fdc04e5c6daafce3d45e7508418e4db94df44c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 6 Sep 2012 22:26:16 -0400 Subject: [PATCH] Add hb_buffer_[sg]et_content_type And hb_buffer_content_type_t and enum values. --- TODO | 1 + src/hb-buffer-private.hh | 2 ++ src/hb-buffer.cc | 34 ++++++++++++++++++++++++++++++++++ src/hb-buffer.h | 14 ++++++++++++++ src/hb-shape.cc | 5 +++++ 5 files changed, 56 insertions(+) diff --git a/TODO b/TODO index be3c7c6b8..d94d875cd 100644 --- a/TODO +++ b/TODO @@ -91,3 +91,4 @@ Tests to write: - hb_cache_t and relatives - hb_feature_to/from_string +- hb_buffer_[sg]et_contents diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 456e1b849..f5d64f3f8 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -92,6 +92,8 @@ struct hb_buffer_t { /* Buffer contents */ + hb_buffer_content_type_t content_type; + bool in_error; /* Allocation failed */ bool have_output; /* Whether we have an output buffer going on */ bool have_positions; /* Whether we have positions */ diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index f25a8bca4..fec9225b4 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -147,6 +147,7 @@ hb_buffer_t::reset (void) hb_segment_properties_t default_props = _HB_BUFFER_PROPS_DEFAULT; props = default_props; + content_type = HB_BUFFER_CONTENT_TYPE_INVALID; in_error = false; have_output = false; have_positions = false; @@ -446,6 +447,9 @@ hb_buffer_t::merge_out_clusters (unsigned int start, void hb_buffer_t::guess_properties (void) { + if (unlikely (!len)) return; + assert (content_type == HB_BUFFER_CONTENT_TYPE_UNICODE); + /* If script is set to INVALID, guess from buffer contents */ if (props.script == HB_SCRIPT_INVALID) { for (unsigned int i = 0; i < len; i++) { @@ -564,6 +568,7 @@ hb_buffer_get_empty (void) const_cast (&_hb_unicode_funcs_nil), _HB_BUFFER_PROPS_DEFAULT, + HB_BUFFER_CONTENT_TYPE_INVALID, true, /* in_error */ true, /* have_output */ true /* have_positions */ @@ -609,6 +614,20 @@ hb_buffer_get_user_data (hb_buffer_t *buffer, } +void +hb_buffer_set_content_type (hb_buffer_t *buffer, + hb_buffer_content_type_t content_type) +{ + buffer->content_type = content_type; +} + +hb_buffer_content_type_t +hb_buffer_get_content_type (hb_buffer_t *buffer) +{ + return buffer->content_type; +} + + void hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, hb_unicode_funcs_t *unicode) @@ -849,6 +868,11 @@ hb_buffer_add_utf8 (hb_buffer_t *buffer, unsigned int item_offset, int item_length) { + assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE || + (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)); + if (unlikely (hb_object_is_inert (buffer))) + return; + buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE; #define UTF_NEXT(S, E, U) hb_utf8_next (S, E, &(U)) ADD_UTF (uint8_t); #undef UTF_NEXT @@ -883,6 +907,11 @@ hb_buffer_add_utf16 (hb_buffer_t *buffer, unsigned int item_offset, int item_length) { + assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE || + (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)); + if (unlikely (hb_object_is_inert (buffer))) + return; + buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE; #define UTF_NEXT(S, E, U) hb_utf16_next (S, E, &(U)) ADD_UTF (uint16_t); #undef UTF_NEXT @@ -895,6 +924,11 @@ hb_buffer_add_utf32 (hb_buffer_t *buffer, unsigned int item_offset, int item_length) { + assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE || + (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)); + if (unlikely (hb_object_is_inert (buffer))) + return; + buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE; #define UTF_NEXT(S, E, U) ((U) = *(S), (S)+1) ADD_UTF (uint32_t); #undef UTF_NEXT diff --git a/src/hb-buffer.h b/src/hb-buffer.h index aebf4821a..d89dce3c1 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -62,6 +62,12 @@ typedef struct hb_glyph_position_t { hb_var_int_t var; } hb_glyph_position_t; +typedef enum { + HB_BUFFER_CONTENT_TYPE_INVALID = 0, + HB_BUFFER_CONTENT_TYPE_UNICODE, + HB_BUFFER_CONTENT_TYPE_GLYPHS +} hb_buffer_content_type_t; + hb_buffer_t * hb_buffer_create (void); @@ -87,6 +93,14 @@ hb_buffer_get_user_data (hb_buffer_t *buffer, hb_user_data_key_t *key); +void +hb_buffer_set_content_type (hb_buffer_t *buffer, + hb_buffer_content_type_t content_type); + +hb_buffer_content_type_t +hb_buffer_get_content_type (hb_buffer_t *buffer); + + void hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, hb_unicode_funcs_t *unicode_funcs); diff --git a/src/hb-shape.cc b/src/hb-shape.cc index 6619c194e..4d6482362 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -253,11 +253,16 @@ hb_shape_full (hb_font_t *font, if (unlikely (!buffer->len)) return true; + assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE); + buffer->guess_properties (); hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props, features, num_features, shaper_list); hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features); hb_shape_plan_destroy (shape_plan); + + if (res) + buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; return res; }