[API] Add hb_unicode_funcs_get_default()

This commit is contained in:
Behdad Esfahbod 2011-04-27 09:24:37 -04:00
parent 153142dac8
commit d4bee9f813
8 changed files with 50 additions and 14 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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)
{

View File

@ -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);

View File

@ -37,7 +37,7 @@
#include <math.h>
#include <locale.h>
#include <hb-glib.h>
#include <glib.h>
#include <cairo-ft.h>
#include <hb-ft.h>
@ -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);

View File

@ -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 ();