diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index cf4667181..7cf5adcd6 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -37,7 +37,7 @@ HB_BEGIN_DECLS static hb_buffer_t _hb_buffer_nil = { HB_OBJECT_HEADER_STATIC, - &_hb_unicode_funcs_nil, /* unicode */ + &_hb_unicode_funcs_default, { HB_DIRECTION_INVALID, HB_SCRIPT_INVALID, @@ -173,7 +173,7 @@ hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, hb_unicode_funcs_t *unicode) { if (!unicode) - unicode = &_hb_unicode_funcs_nil; + unicode = &_hb_unicode_funcs_default; hb_unicode_funcs_reference (unicode); hb_unicode_funcs_destroy (buffer->unicode); diff --git a/src/hb-glib.cc b/src/hb-glib.cc index 32cefa2c8..2bce1f9c2 100644 --- a/src/hb-glib.cc +++ b/src/hb-glib.cc @@ -220,7 +220,8 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs, return hb_glib_script_to_script (g_unichar_get_script (unicode)); } -static hb_unicode_funcs_t glib_ufuncs = { +extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_glib; +hb_unicode_funcs_t _hb_glib_unicode_funcs = { HB_OBJECT_HEADER_STATIC, NULL, /* parent */ @@ -237,7 +238,7 @@ static hb_unicode_funcs_t glib_ufuncs = { hb_unicode_funcs_t * hb_glib_get_unicode_funcs (void) { - return &glib_ufuncs; + return &_hb_glib_unicode_funcs; } diff --git a/src/hb-icu.cc b/src/hb-icu.cc index 2abd1403b..52645fd64 100644 --- a/src/hb-icu.cc +++ b/src/hb-icu.cc @@ -160,7 +160,8 @@ hb_icu_get_script (hb_unicode_funcs_t *ufuncs, return hb_icu_script_to_script (scriptCode); } -static hb_unicode_funcs_t icu_ufuncs = { +extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_icu; +hb_unicode_funcs_t _hb_icu_unicode_funcs = { HB_OBJECT_HEADER_STATIC, NULL, /* parent */ @@ -177,7 +178,7 @@ static hb_unicode_funcs_t icu_ufuncs = { hb_unicode_funcs_t * hb_icu_get_unicode_funcs (void) { - return &icu_ufuncs; + return &_hb_icu_unicode_funcs; } diff --git a/src/hb-unicode-private.hh b/src/hb-unicode-private.hh index 16836a04c..8337e4293 100644 --- a/src/hb-unicode-private.hh +++ b/src/hb-unicode-private.hh @@ -90,7 +90,18 @@ struct _hb_unicode_funcs_t { } destroy; }; + +#if HAVE_GLIB +extern HB_INTERNAL hb_unicode_funcs_t _hb_glib_unicode_funcs; +#define _hb_unicode_funcs_default _hb_glib_unicode_funcs +#elif HAVE_ICU +extern HB_INTERNAL hb_unicode_funcs_t _hb_icu_unicode_funcs; +#define _hb_unicode_funcs_default _hb_icu_unicode_funcs +#else extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil; +#define _hb_unicode_funcs_default _hb_unicode_funcs_nil +#endif + HB_END_DECLS diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc index ed0dc108d..b756461ba 100644 --- a/src/hb-unicode.cc +++ b/src/hb-unicode.cc @@ -80,6 +80,7 @@ hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, } +extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil; hb_unicode_funcs_t _hb_unicode_funcs_nil = { HB_OBJECT_HEADER_STATIC, @@ -95,6 +96,12 @@ hb_unicode_funcs_t _hb_unicode_funcs_nil = { }; +hb_unicode_funcs_t * +hb_unicode_funcs_get_default (void) +{ + return &_hb_unicode_funcs_default; +} + hb_unicode_funcs_t * hb_unicode_funcs_create (hb_unicode_funcs_t *parent) { diff --git a/src/hb-unicode.h b/src/hb-unicode.h index 47a78d46f..d558c2271 100644 --- a/src/hb-unicode.h +++ b/src/hb-unicode.h @@ -42,6 +42,14 @@ HB_BEGIN_DECLS typedef struct _hb_unicode_funcs_t hb_unicode_funcs_t; + +/* + * just give me the best implementation you've got there. + */ +hb_unicode_funcs_t * +hb_unicode_funcs_get_default (void); + + hb_unicode_funcs_t * hb_unicode_funcs_create (hb_unicode_funcs_t *parent_funcs); diff --git a/src/hb-view.c b/src/hb-view.c index ed2d515d1..783c559f7 100644 --- a/src/hb-view.c +++ b/src/hb-view.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include @@ -348,18 +348,17 @@ _hb_cr_text_glyphs (cairo_t *cr, unsigned int num_glyphs, i; hb_position_t x; - if (len < 0) - len = strlen (text); - hb_buffer = hb_buffer_create (len); + hb_buffer = hb_buffer_create (0); - hb_buffer_set_unicode_funcs (hb_buffer, hb_glib_get_unicode_funcs ()); - - hb_buffer_add_utf8 (hb_buffer, text, len, 0, len); if (script) hb_buffer_set_script (hb_buffer, hb_script_from_string (script)); if (language) hb_buffer_set_language (hb_buffer, hb_language_from_string (language)); + if (len < 0) + len = strlen (text); + hb_buffer_add_utf8 (hb_buffer, text, len, 0, len); + hb_shape (hb_font, hb_face, hb_buffer, features, num_features); num_glyphs = hb_buffer_get_length (hb_buffer); diff --git a/test/test-unicode.c b/test/test-unicode.c index 324fa1fc4..c69634110 100644 --- a/test/test-unicode.c +++ b/test/test-unicode.c @@ -46,6 +46,14 @@ test_glib (void) g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN); } +static void +test_default (void) +{ + hb_unicode_funcs_t *uf = hb_unicode_funcs_get_default (); + + g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN); +} + static gboolean freed0, freed1; static int unique_pointer0[1]; static int unique_pointer1[1]; @@ -191,12 +199,13 @@ main (int argc, char **argv) g_test_add_func ("/unicode/nil", test_nil); g_test_add_func ("/unicode/glib", test_glib); + g_test_add_func ("/unicode/default", test_default); g_test_add_func ("/unicode/custom", test_custom); g_test_add_func ("/unicode/subclassing/nil", test_subclassing_nil); g_test_add_func ("/unicode/subclassing/glib", test_subclassing_glib); g_test_add_func ("/unicode/subclassing/deep", test_subclassing_deep); - /* XXX test all methods for their defaults and various (glib, icu) implementations. */ + /* XXX test all methods for their defaults and various (glib, icu, default) implementations. */ /* XXX test glib & icu two-way script conversion */ return g_test_run ();