提交 d4bee9f8 编写于 作者: B Behdad Esfahbod

[API] Add hb_unicode_funcs_get_default()

上级 153142da
...@@ -37,7 +37,7 @@ HB_BEGIN_DECLS ...@@ -37,7 +37,7 @@ HB_BEGIN_DECLS
static hb_buffer_t _hb_buffer_nil = { static hb_buffer_t _hb_buffer_nil = {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
&_hb_unicode_funcs_nil, /* unicode */ &_hb_unicode_funcs_default,
{ {
HB_DIRECTION_INVALID, HB_DIRECTION_INVALID,
HB_SCRIPT_INVALID, HB_SCRIPT_INVALID,
...@@ -173,7 +173,7 @@ hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, ...@@ -173,7 +173,7 @@ hb_buffer_set_unicode_funcs (hb_buffer_t *buffer,
hb_unicode_funcs_t *unicode) hb_unicode_funcs_t *unicode)
{ {
if (!unicode) if (!unicode)
unicode = &_hb_unicode_funcs_nil; unicode = &_hb_unicode_funcs_default;
hb_unicode_funcs_reference (unicode); hb_unicode_funcs_reference (unicode);
hb_unicode_funcs_destroy (buffer->unicode); hb_unicode_funcs_destroy (buffer->unicode);
......
...@@ -220,7 +220,8 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs, ...@@ -220,7 +220,8 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs,
return hb_glib_script_to_script (g_unichar_get_script (unicode)); 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, HB_OBJECT_HEADER_STATIC,
NULL, /* parent */ NULL, /* parent */
...@@ -237,7 +238,7 @@ static hb_unicode_funcs_t glib_ufuncs = { ...@@ -237,7 +238,7 @@ static hb_unicode_funcs_t glib_ufuncs = {
hb_unicode_funcs_t * hb_unicode_funcs_t *
hb_glib_get_unicode_funcs (void) hb_glib_get_unicode_funcs (void)
{ {
return &glib_ufuncs; return &_hb_glib_unicode_funcs;
} }
......
...@@ -160,7 +160,8 @@ hb_icu_get_script (hb_unicode_funcs_t *ufuncs, ...@@ -160,7 +160,8 @@ hb_icu_get_script (hb_unicode_funcs_t *ufuncs,
return hb_icu_script_to_script (scriptCode); 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, HB_OBJECT_HEADER_STATIC,
NULL, /* parent */ NULL, /* parent */
...@@ -177,7 +178,7 @@ static hb_unicode_funcs_t icu_ufuncs = { ...@@ -177,7 +178,7 @@ static hb_unicode_funcs_t icu_ufuncs = {
hb_unicode_funcs_t * hb_unicode_funcs_t *
hb_icu_get_unicode_funcs (void) hb_icu_get_unicode_funcs (void)
{ {
return &icu_ufuncs; return &_hb_icu_unicode_funcs;
} }
......
...@@ -90,7 +90,18 @@ struct _hb_unicode_funcs_t { ...@@ -90,7 +90,18 @@ struct _hb_unicode_funcs_t {
} destroy; } 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; extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil;
#define _hb_unicode_funcs_default _hb_unicode_funcs_nil
#endif
HB_END_DECLS HB_END_DECLS
......
...@@ -80,6 +80,7 @@ hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, ...@@ -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_unicode_funcs_t _hb_unicode_funcs_nil = {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
...@@ -95,6 +96,12 @@ hb_unicode_funcs_t _hb_unicode_funcs_nil = { ...@@ -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_t *
hb_unicode_funcs_create (hb_unicode_funcs_t *parent) hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
{ {
......
...@@ -42,6 +42,14 @@ HB_BEGIN_DECLS ...@@ -42,6 +42,14 @@ HB_BEGIN_DECLS
typedef struct _hb_unicode_funcs_t hb_unicode_funcs_t; 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_t *
hb_unicode_funcs_create (hb_unicode_funcs_t *parent_funcs); hb_unicode_funcs_create (hb_unicode_funcs_t *parent_funcs);
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <math.h> #include <math.h>
#include <locale.h> #include <locale.h>
#include <hb-glib.h> #include <glib.h>
#include <cairo-ft.h> #include <cairo-ft.h>
#include <hb-ft.h> #include <hb-ft.h>
...@@ -348,18 +348,17 @@ _hb_cr_text_glyphs (cairo_t *cr, ...@@ -348,18 +348,17 @@ _hb_cr_text_glyphs (cairo_t *cr,
unsigned int num_glyphs, i; unsigned int num_glyphs, i;
hb_position_t x; hb_position_t x;
if (len < 0) hb_buffer = hb_buffer_create (0);
len = strlen (text);
hb_buffer = hb_buffer_create (len);
hb_buffer_set_unicode_funcs (hb_buffer, hb_glib_get_unicode_funcs ());
hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
if (script) if (script)
hb_buffer_set_script (hb_buffer, hb_script_from_string (script)); hb_buffer_set_script (hb_buffer, hb_script_from_string (script));
if (language) if (language)
hb_buffer_set_language (hb_buffer, hb_language_from_string (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); hb_shape (hb_font, hb_face, hb_buffer, features, num_features);
num_glyphs = hb_buffer_get_length (hb_buffer); num_glyphs = hb_buffer_get_length (hb_buffer);
......
...@@ -46,6 +46,14 @@ test_glib (void) ...@@ -46,6 +46,14 @@ test_glib (void)
g_assert_cmpint (hb_unicode_get_script (uf, 'd'), ==, HB_SCRIPT_LATIN); 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 gboolean freed0, freed1;
static int unique_pointer0[1]; static int unique_pointer0[1];
static int unique_pointer1[1]; static int unique_pointer1[1];
...@@ -191,12 +199,13 @@ main (int argc, char **argv) ...@@ -191,12 +199,13 @@ main (int argc, char **argv)
g_test_add_func ("/unicode/nil", test_nil); g_test_add_func ("/unicode/nil", test_nil);
g_test_add_func ("/unicode/glib", test_glib); 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/custom", test_custom);
g_test_add_func ("/unicode/subclassing/nil", test_subclassing_nil); 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/glib", test_subclassing_glib);
g_test_add_func ("/unicode/subclassing/deep", test_subclassing_deep); 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 */ /* XXX test glib & icu two-way script conversion */
return g_test_run (); return g_test_run ();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册