Add hb_buffer_clear()

Which is like _reset(), but does NOT clear unicode-funcs.
This commit is contained in:
Behdad Esfahbod 2012-11-13 13:57:52 -08:00
parent da43a92b04
commit 82ecaff736
4 changed files with 41 additions and 1 deletions

View File

@ -133,6 +133,7 @@ struct hb_buffer_t {
/* Methods */
HB_INTERNAL void reset (void);
HB_INTERNAL void clear (void);
inline unsigned int backtrack_len (void) const
{ return have_output? out_len : idx; }

View File

@ -142,6 +142,15 @@ hb_buffer_t::reset (void)
hb_unicode_funcs_destroy (unicode);
unicode = hb_unicode_funcs_get_default ();
clear ();
}
void
hb_buffer_t::clear (void)
{
if (unlikely (hb_object_is_inert (this)))
return;
hb_segment_properties_t default_props = _HB_BUFFER_PROPS_DEFAULT;
props = default_props;
@ -722,6 +731,12 @@ hb_buffer_reset (hb_buffer_t *buffer)
buffer->reset ();
}
void
hb_buffer_clear (hb_buffer_t *buffer)
{
buffer->clear ();
}
hb_bool_t
hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size)
{

View File

@ -135,6 +135,10 @@ hb_buffer_get_language (hb_buffer_t *buffer);
void
hb_buffer_reset (hb_buffer_t *buffer);
/* Like reset, but does NOT clear unicode_funcs. */
void
hb_buffer_clear (hb_buffer_t *buffer);
/* Returns false if allocation failed */
hb_bool_t
hb_buffer_pre_allocate (hb_buffer_t *buffer,

View File

@ -128,7 +128,27 @@ test_buffer_properties (fixture_t *fixture, gconstpointer user_data)
g_assert (hb_buffer_get_language (b) == hb_language_from_string ("Fa", -1));
/* test reset clears properties */
/* test clear clears all properties but unicode_funcs */
hb_buffer_clear (b);
g_assert (hb_buffer_get_unicode_funcs (b) == ufuncs);
g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_INVALID);
g_assert (hb_buffer_get_script (b) == HB_SCRIPT_INVALID);
g_assert (hb_buffer_get_language (b) == NULL);
/* test reset clears all properties */
hb_buffer_set_direction (b, HB_DIRECTION_RTL);
g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_RTL);
hb_buffer_set_script (b, HB_SCRIPT_ARABIC);
g_assert (hb_buffer_get_script (b) == HB_SCRIPT_ARABIC);
hb_buffer_set_language (b, hb_language_from_string ("fa", -1));
g_assert (hb_buffer_get_language (b) == hb_language_from_string ("Fa", -1));
hb_buffer_reset (b);