From f9cd1014f8f4d0394b5e0e9eefc1e2af13c59cab Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 28 Jul 2009 15:43:34 -0400 Subject: [PATCH] Apply patch from Jonathan Kew --- src/hb-buffer.c | 75 ++++++++++++++++++++++++++++------------------------- src/hb-buffer.h | 6 ++++- src/hb-ot-layout.cc | 31 ++++++++++++++++++++++ src/hb-ot-layout.h | 15 +++++++++++ src/hb-private.h | 2 +- 5 files changed, 91 insertions(+), 38 deletions(-) diff --git a/src/hb-buffer.c b/src/hb-buffer.c index 308fb70..31b6c0f 100644 --- a/src/hb-buffer.c +++ b/src/hb-buffer.c @@ -53,41 +53,6 @@ /* Internal API */ static void -hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size) -{ - unsigned int new_allocated = buffer->allocated; - - if (size > new_allocated) - { - while (size > new_allocated) - new_allocated += (new_allocated >> 1) + 8; - - if (buffer->positions) - buffer->positions = realloc (buffer->positions, new_allocated * sizeof (buffer->positions[0])); - - buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0])); - - if (buffer->out_string != buffer->in_string) - { - buffer->alt_string = realloc (buffer->alt_string, new_allocated * sizeof (buffer->alt_string[0])); - buffer->out_string = buffer->alt_string; - } - else - { - buffer->out_string = buffer->in_string; - - if (buffer->alt_string) - { - free (buffer->alt_string); - buffer->alt_string = NULL; - } - } - - buffer->allocated = new_allocated; - } -} - -static void hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size) { hb_buffer_ensure (buffer, size); @@ -104,7 +69,7 @@ hb_buffer_ensure_separate (hb_buffer_t *buffer, unsigned int size) /* Public API */ hb_buffer_t * -hb_buffer_new (void) +hb_buffer_new (unsigned int allocation_size) { hb_buffer_t *buffer; @@ -119,6 +84,9 @@ hb_buffer_new (void) hb_buffer_clear (buffer); + if (allocation_size) + hb_buffer_ensure(buffer, allocation_size); + return buffer; } @@ -143,6 +111,41 @@ hb_buffer_clear (hb_buffer_t *buffer) } void +hb_buffer_ensure (hb_buffer_t *buffer, unsigned int size) +{ + unsigned int new_allocated = buffer->allocated; + + if (size > new_allocated) + { + while (size > new_allocated) + new_allocated += (new_allocated >> 1) + 8; + + if (buffer->positions) + buffer->positions = realloc (buffer->positions, new_allocated * sizeof (buffer->positions[0])); + + if (buffer->out_string != buffer->in_string) + { + buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0])); + buffer->alt_string = realloc (buffer->alt_string, new_allocated * sizeof (buffer->alt_string[0])); + buffer->out_string = buffer->alt_string; + } + else + { + buffer->in_string = realloc (buffer->in_string, new_allocated * sizeof (buffer->in_string[0])); + buffer->out_string = buffer->in_string; + + if (buffer->alt_string) + { + free (buffer->alt_string); + buffer->alt_string = NULL; + } + } + + buffer->allocated = new_allocated; + } +} + +void hb_buffer_add_glyph (hb_buffer_t *buffer, hb_codepoint_t glyph_index, unsigned int properties, diff --git a/src/hb-buffer.h b/src/hb-buffer.h index afdf642..197c921 100644 --- a/src/hb-buffer.h +++ b/src/hb-buffer.h @@ -76,7 +76,7 @@ typedef struct _hb_buffer_t { } hb_buffer_t; hb_buffer_t * -hb_buffer_new (void); +hb_buffer_new (unsigned int allocation_size); void hb_buffer_free (hb_buffer_t *buffer); @@ -85,6 +85,10 @@ void hb_buffer_clear (hb_buffer_t *buffer); void +hb_buffer_ensure (hb_buffer_t *buffer, + unsigned int size); + +void hb_buffer_add_glyph (hb_buffer_t *buffer, hb_codepoint_t glyph_index, unsigned int properties, diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 8cff03e..530e254 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -56,6 +56,18 @@ hb_ot_layout_create (void) return layout; } +hb_bool_t +hb_ot_layout_has_substitution (hb_ot_layout_t *layout) +{ + return layout->gsub != &Null(GSUB); +} + +hb_bool_t +hb_ot_layout_has_positioning (hb_ot_layout_t *layout) +{ + return layout->gpos != &Null(GPOS); +} + hb_ot_layout_t * hb_ot_layout_create_for_data (const char *font_data, int face_index) @@ -77,6 +89,25 @@ hb_ot_layout_create_for_data (const char *font_data, return layout; } +hb_ot_layout_t * +hb_ot_layout_create_for_tables (const char *gdef_data, + const char *gsub_data, + const char *gpos_data) +{ + hb_ot_layout_t *layout; + + if (HB_UNLIKELY (gdef_data == NULL && gsub_data == NULL && gpos_data == NULL)) + return hb_ot_layout_create (); + + layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t)); + + layout->gdef = &GDEF::get_for_data (gdef_data); + layout->gsub = &GSUB::get_for_data (gsub_data); + layout->gpos = &GPOS::get_for_data (gpos_data); + + return layout; +} + void hb_ot_layout_destroy (hb_ot_layout_t *layout) { diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 7759532..20bd1e4 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -45,6 +45,11 @@ hb_ot_layout_t * hb_ot_layout_create_for_data (const char *font_data, int face_index); +hb_ot_layout_t * +hb_ot_layout_create_for_tables (const char *gdef_data, + const char *gsub_data, + const char *gpos_data); + void hb_ot_layout_destroy (hb_ot_layout_t *layout); @@ -232,11 +237,21 @@ hb_ot_layout_feature_get_lookup_index (hb_ot_layout_t *layout, */ hb_bool_t +hb_ot_layout_has_substitution (hb_ot_layout_t *layout); + +hb_bool_t hb_ot_layout_substitute_lookup (hb_ot_layout_t *layout, hb_buffer_t *buffer, unsigned int lookup_index, hb_ot_layout_feature_mask_t mask); +/* + * GPOS + */ + +hb_bool_t +hb_ot_layout_has_positioning (hb_ot_layout_t *layout); + hb_bool_t hb_ot_layout_position_lookup (hb_ot_layout_t *layout, hb_buffer_t *buffer, diff --git a/src/hb-private.h b/src/hb-private.h index 0d1e1a7..6698a7c 100644 --- a/src/hb-private.h +++ b/src/hb-private.h @@ -27,7 +27,7 @@ #ifndef HB_PRIVATE_H #define HB_PRIVATE_H -#include +#include "hb-common.h" #include -- 2.7.4