diff --git a/src/Makefile.am b/src/Makefile.am index 2fbf2785b..70c51d1e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,8 +24,8 @@ HBSOURCES = \ hb-ot-head-private.hh \ hb-private.h \ hb-shape.cc \ - hb-unicode.c \ - hb-unicode-private.h \ + hb-unicode.cc \ + hb-unicode-private.hh \ $(NULL) HBHEADERS = \ hb.h \ @@ -65,7 +65,7 @@ if HAVE_GLIB HBCFLAGS += $(GLIB_CFLAGS) HBLIBS += $(GLIB_LIBS) HBSOURCES += \ - hb-glib.c \ + hb-glib.cc \ $(NULL) HBHEADERS += \ hb-glib.h \ @@ -76,7 +76,7 @@ if HAVE_ICU HBCFLAGS += $(ICU_CFLAGS) HBLIBS += $(ICU_LIBS) HBSOURCES += \ - hb-icu.c \ + hb-icu.cc \ $(NULL) HBHEADERS += \ hb-icu.h \ diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 2b063b70a..dfcc45d61 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -30,7 +30,7 @@ #include "hb-private.h" #include "hb-buffer.h" -#include "hb-unicode-private.h" +#include "hb-unicode-private.hh" HB_BEGIN_DECLS diff --git a/src/hb-glib.c b/src/hb-glib.cc similarity index 95% rename from src/hb-glib.c rename to src/hb-glib.cc index 19056373d..5bebf5e95 100644 --- a/src/hb-glib.c +++ b/src/hb-glib.cc @@ -28,20 +28,28 @@ #include "hb-glib.h" -#include "hb-unicode-private.h" +#include "hb-unicode-private.hh" #include HB_BEGIN_DECLS -static hb_codepoint_t -hb_glib_get_mirroring (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode, - void *user_data) +static unsigned int +hb_glib_get_combining_class (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) + { - g_unichar_get_mirror_char (unicode, &unicode); - return unicode; + return g_unichar_combining_class (unicode); +} + +static unsigned int +hb_glib_get_eastasian_width (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) +{ + return g_unichar_iswide (unicode) ? 2 : 1; } static hb_unicode_general_category_t @@ -50,7 +58,17 @@ hb_glib_get_general_category (hb_unicode_funcs_t *ufuncs, void *user_data) { - return g_unichar_type (unicode); + /* hb_unicode_general_category_t and GUnicodeType are identical */ + return (hb_unicode_general_category_t) g_unichar_type (unicode); +} + +static hb_codepoint_t +hb_glib_get_mirroring (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) +{ + g_unichar_get_mirror_char (unicode, &unicode); + return unicode; } static hb_script_t @@ -167,7 +185,7 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs, MATCH_SCRIPT (LISU); /* Lisu */ MATCH_SCRIPT (MEETEI_MAYEK); /* Mtei */ MATCH_SCRIPT (OLD_SOUTH_ARABIAN); /* Sarb */ -#if GLIB_CHECK_VERSION(2,28,0) +#if GLIB_CHECK_VERSION(2,27,92) MATCH_SCRIPT (OLD_TURKIC); /* Orkh */ #else MATCH_SCRIPT2(OLD_TURKISH, OLD_TURKIC);/* Orkh */ @@ -190,33 +208,16 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs, return HB_SCRIPT_UNKNOWN; } -static unsigned int -hb_glib_get_combining_class (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode, - void *user_data) - -{ - return g_unichar_combining_class (unicode); -} - -static unsigned int -hb_glib_get_eastasian_width (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode, - void *user_data) -{ - return g_unichar_iswide (unicode) ? 2 : 1; -} - static hb_unicode_funcs_t glib_ufuncs = { HB_REFERENCE_COUNT_INVALID, /* ref_count */ - NULL, + NULL, /* parent */ TRUE, /* immutable */ { - hb_glib_get_general_category, NULL, NULL, - hb_glib_get_combining_class, NULL, NULL, - hb_glib_get_mirroring, NULL, NULL, - hb_glib_get_script, NULL, NULL, - hb_glib_get_eastasian_width, NULL, NULL + hb_glib_get_combining_class, + hb_glib_get_eastasian_width, + hb_glib_get_general_category, + hb_glib_get_mirroring, + hb_glib_get_script } }; diff --git a/src/hb-icu.c b/src/hb-icu.cc similarity index 97% rename from src/hb-icu.c rename to src/hb-icu.cc index 6bc3339de..4978bf587 100644 --- a/src/hb-icu.c +++ b/src/hb-icu.cc @@ -29,7 +29,7 @@ #include "hb-icu.h" -#include "hb-unicode-private.h" +#include "hb-unicode-private.hh" #include #include @@ -38,14 +38,6 @@ HB_BEGIN_DECLS -static hb_codepoint_t -hb_icu_get_mirroring (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode, - void *user_data) -{ - return u_charMirror(unicode); -} - static unsigned int hb_icu_get_combining_class (hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, @@ -125,6 +117,14 @@ hb_icu_get_general_category (hb_unicode_funcs_t *ufuncs, return HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED; } +static hb_codepoint_t +hb_icu_get_mirroring (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) +{ + return u_charMirror(unicode); +} + static hb_script_t hb_icu_get_script (hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, @@ -264,14 +264,14 @@ hb_icu_get_script (hb_unicode_funcs_t *ufuncs, static hb_unicode_funcs_t icu_ufuncs = { HB_REFERENCE_COUNT_INVALID, /* ref_count */ - NULL, + NULL, /* parent */ TRUE, /* immutable */ { - hb_icu_get_general_category, NULL, NULL, - hb_icu_get_combining_class, NULL, NULL, - hb_icu_get_mirroring, NULL, NULL, - hb_icu_get_script, NULL, NULL, - hb_icu_get_eastasian_width, NULL, NULL + hb_icu_get_combining_class, + hb_icu_get_eastasian_width, + hb_icu_get_general_category, + hb_icu_get_mirroring, + hb_icu_get_script } }; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 2ffb076ee..589dee3df 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -143,16 +143,13 @@ is_variation_selector (hb_codepoint_t unicode) static void hb_set_unicode_props (hb_ot_shape_context_t *c) { - hb_unicode_get_general_category_func_t get_general_category = c->buffer->unicode->v.get_general_category; - hb_unicode_get_combining_class_func_t get_combining_class = c->buffer->unicode->v.get_combining_class; + hb_unicode_funcs_t *unicode = c->buffer->unicode; hb_glyph_info_t *info = c->buffer->info; unsigned int count = c->buffer->len; for (unsigned int i = 1; i < count; i++) { - info[i].general_category() = get_general_category (c->buffer->unicode, info[i].codepoint, - c->buffer->unicode->v.get_general_category_data); - info[i].combining_class() = get_combining_class (c->buffer->unicode, info[i].codepoint, - c->buffer->unicode->v.get_combining_class_data); + info[i].general_category() = unicode->get_general_category (info[i].codepoint); + info[i].combining_class() = unicode->get_combining_class (info[i].codepoint); } } @@ -193,7 +190,7 @@ hb_reset_glyph_infos (hb_ot_shape_context_t *c) static void hb_mirror_chars (hb_ot_shape_context_t *c) { - hb_unicode_get_mirroring_func_t get_mirroring = c->buffer->unicode->v.get_mirroring; + hb_unicode_funcs_t *unicode = c->buffer->unicode; if (HB_DIRECTION_IS_FORWARD (c->target_direction)) return; @@ -202,8 +199,7 @@ hb_mirror_chars (hb_ot_shape_context_t *c) unsigned int count = c->buffer->len; for (unsigned int i = 0; i < count; i++) { - hb_codepoint_t codepoint = get_mirroring (c->buffer->unicode, c->buffer->info[i].codepoint, - c->buffer->unicode->v.get_mirroring_data); + hb_codepoint_t codepoint = unicode->get_mirroring (c->buffer->info[i].codepoint); if (likely (codepoint == c->buffer->info[i].codepoint)) c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to before setting user-feature masks */ else diff --git a/src/hb-shape.cc b/src/hb-shape.cc index 9d9bf25e6..2b536fad1 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -74,10 +74,10 @@ hb_shape (hb_font_t *font, /* If script is set to INVALID, guess from buffer contents */ if (buffer->props.script == HB_SCRIPT_INVALID) { - hb_unicode_get_script_func_t get_script = buffer->unicode->v.get_script; + hb_unicode_funcs_t *unicode = buffer->unicode; unsigned int count = buffer->len; for (unsigned int i = 0; i < count; i++) { - hb_script_t script = get_script (buffer->unicode, buffer->info[i].codepoint, buffer->unicode->v.get_script_data); + hb_script_t script = unicode->get_script (buffer->info[i].codepoint); if (likely (script != HB_SCRIPT_COMMON && script != HB_SCRIPT_INHERITED && script != HB_SCRIPT_UNKNOWN)) { diff --git a/src/hb-unicode-private.h b/src/hb-unicode-private.hh similarity index 53% rename from src/hb-unicode-private.h rename to src/hb-unicode-private.hh index 456d8de0e..67a60f5d1 100644 --- a/src/hb-unicode-private.h +++ b/src/hb-unicode-private.hh @@ -1,6 +1,7 @@ /* * Copyright (C) 2009 Red Hat, Inc. * Copyright © 2011 Codethink Limited + * Copyright (C) 2010 Google, Inc. * * This is part of HarfBuzz, a text shaping library. * @@ -24,10 +25,11 @@ * * Red Hat Author(s): Behdad Esfahbod * Codethink Author(s): Ryan Lortie + * Google Author(s): Behdad Esfahbod */ -#ifndef HB_UNICODE_PRIVATE_H -#define HB_UNICODE_PRIVATE_H +#ifndef HB_UNICODE_PRIVATE_HH +#define HB_UNICODE_PRIVATE_HH #include "hb-private.h" @@ -46,27 +48,44 @@ struct _hb_unicode_funcs_t { hb_bool_t immutable; +#define IMPLEMENT(return_type, name) \ + inline return_type \ + get_##name (hb_codepoint_t unicode) \ + { return this->get.name (this, unicode, this->user_data.name); } + + IMPLEMENT (unsigned int, combining_class) + IMPLEMENT (unsigned int, eastasian_width) + IMPLEMENT (hb_unicode_general_category_t, general_category) + IMPLEMENT (hb_codepoint_t, mirroring) + IMPLEMENT (hb_script_t, script) + +#undef IMPLEMENT + + /* Don't access these directly. Call get_*() instead. */ + struct { - hb_unicode_get_general_category_func_t get_general_category; - void *get_general_category_data; - hb_destroy_func_t get_general_category_destroy; + hb_unicode_get_combining_class_func_t combining_class; + hb_unicode_get_eastasian_width_func_t eastasian_width; + hb_unicode_get_general_category_func_t general_category; + hb_unicode_get_mirroring_func_t mirroring; + hb_unicode_get_script_func_t script; + } get; - hb_unicode_get_combining_class_func_t get_combining_class; - void *get_combining_class_data; - hb_destroy_func_t get_combining_class_destroy; + struct { + void *combining_class; + void *eastasian_width; + void *general_category; + void *mirroring; + void *script; + } user_data; - hb_unicode_get_mirroring_func_t get_mirroring; - void *get_mirroring_data; - hb_destroy_func_t get_mirroring_destroy; - - hb_unicode_get_script_func_t get_script; - void *get_script_data; - hb_destroy_func_t get_script_destroy; - - hb_unicode_get_eastasian_width_func_t get_eastasian_width; - void *get_eastasian_width_data; - hb_destroy_func_t get_eastasian_width_destroy; - } v; + struct { + hb_destroy_func_t combining_class; + hb_destroy_func_t eastasian_width; + hb_destroy_func_t general_category; + hb_destroy_func_t mirroring; + hb_destroy_func_t script; + } destroy; }; extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil; @@ -74,4 +93,4 @@ extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil; HB_END_DECLS -#endif /* HB_UNICODE_PRIVATE_H */ +#endif /* HB_UNICODE_PRIVATE_HH */ diff --git a/src/hb-unicode.c b/src/hb-unicode.cc similarity index 51% rename from src/hb-unicode.c rename to src/hb-unicode.cc index e047ef760..ddad8849a 100644 --- a/src/hb-unicode.c +++ b/src/hb-unicode.cc @@ -1,6 +1,7 @@ /* * Copyright (C) 2009 Red Hat, Inc. * Copyright © 2011 Codethink Limited + * Copyright (C) 2010 Google, Inc. * * This is part of HarfBuzz, a text shaping library. * @@ -24,11 +25,12 @@ * * Red Hat Author(s): Behdad Esfahbod * Codethink Author(s): Ryan Lortie + * Google Author(s): Behdad Esfahbod */ #include "hb-private.h" -#include "hb-unicode-private.h" +#include "hb-unicode-private.hh" HB_BEGIN_DECLS @@ -37,59 +39,61 @@ HB_BEGIN_DECLS * hb_unicode_funcs_t */ -static hb_codepoint_t -hb_unicode_get_mirroring_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, - hb_codepoint_t unicode HB_UNUSED, - void *user_data HB_UNUSED) -{ - return unicode; -} - -static hb_unicode_general_category_t -hb_unicode_get_general_category_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, - hb_codepoint_t unicode HB_UNUSED, - void *user_data HB_UNUSED) -{ - return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER; -} - -static hb_script_t -hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, - hb_codepoint_t unicode HB_UNUSED, - void *user_data HB_UNUSED) -{ - return HB_SCRIPT_UNKNOWN; -} - static unsigned int hb_unicode_get_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, - hb_codepoint_t unicode HB_UNUSED, - void *user_data HB_UNUSED) + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) { return 0; } static unsigned int hb_unicode_get_eastasian_width_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, - hb_codepoint_t unicode HB_UNUSED, - void *user_data HB_UNUSED) + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) { return 1; } +static hb_unicode_general_category_t +hb_unicode_get_general_category_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER; +} + +static hb_codepoint_t +hb_unicode_get_mirroring_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return unicode; +} + +static hb_script_t +hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return HB_SCRIPT_UNKNOWN; +} + + hb_unicode_funcs_t _hb_unicode_funcs_nil = { HB_REFERENCE_COUNT_INVALID, /* ref_count */ NULL, /* parent */ TRUE, /* immutable */ { - hb_unicode_get_general_category_nil, NULL, NULL, - hb_unicode_get_combining_class_nil, NULL, NULL, - hb_unicode_get_mirroring_nil, NULL, NULL, - hb_unicode_get_script_nil, NULL, NULL, - hb_unicode_get_eastasian_width_nil, NULL, NULL + hb_unicode_get_combining_class_nil, + hb_unicode_get_eastasian_width_nil, + hb_unicode_get_general_category_nil, + hb_unicode_get_mirroring_nil, + hb_unicode_get_script_nil, } }; + hb_unicode_funcs_t * hb_unicode_funcs_create (hb_unicode_funcs_t *parent) { @@ -98,24 +102,21 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent) if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs)) return &_hb_unicode_funcs_nil; - if (parent != NULL) { - ufuncs->parent = hb_unicode_funcs_reference (parent); + if (parent != NULL) + { hb_unicode_funcs_make_immutable (parent); - ufuncs->v = parent->v; + ufuncs->parent = hb_unicode_funcs_reference (parent); - /* Clear out the destroy notifies from our parent. - * - * We don't want to destroy the user_data twice and since we hold a - * reference on our parent then we know that the user_data will - * survive for at least as long as we do anyway. - */ - ufuncs->v.get_general_category_destroy = NULL; - ufuncs->v.get_combining_class_destroy = NULL; - ufuncs->v.get_mirroring_destroy = NULL; - ufuncs->v.get_script_destroy = NULL; - ufuncs->v.get_eastasian_width_destroy = NULL; - } else { - ufuncs->v = _hb_unicode_funcs_nil.v; + ufuncs->get = parent->get; + + /* We can safely copy user_data from parent since we hold a reference + * onto it and it's immutable. We should not copy the destroy notifiers + * though. */ + ufuncs->user_data = parent->user_data; + } + else + { + ufuncs->get = _hb_unicode_funcs_nil.get; } return ufuncs; @@ -138,33 +139,20 @@ hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs) { HB_OBJECT_DO_DESTROY (ufuncs); +#define DESTROY(name) if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name) + DESTROY (combining_class); + DESTROY (eastasian_width); + DESTROY (general_category); + DESTROY (mirroring); + DESTROY (script); +#undef DESTROY + if (ufuncs->parent != NULL) hb_unicode_funcs_destroy (ufuncs->parent); - if (ufuncs->v.get_general_category_destroy != NULL) - ufuncs->v.get_general_category_destroy (ufuncs->v.get_general_category_data); - - if (ufuncs->v.get_combining_class_destroy != NULL) - ufuncs->v.get_combining_class_destroy (ufuncs->v.get_combining_class_data); - - if (ufuncs->v.get_mirroring_destroy != NULL) - ufuncs->v.get_mirroring_destroy (ufuncs->v.get_mirroring_data); - - if (ufuncs->v.get_script_destroy != NULL) - ufuncs->v.get_script_destroy (ufuncs->v.get_script_data); - - if (ufuncs->v.get_eastasian_width_destroy != NULL) - ufuncs->v.get_eastasian_width_destroy (ufuncs->v.get_eastasian_width_data); - free (ufuncs); } -hb_unicode_funcs_t * -hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs) -{ - return ufuncs->parent; -} - void hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs) { @@ -180,8 +168,15 @@ hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs) return ufuncs->immutable; } +hb_unicode_funcs_t * +hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs) +{ + return ufuncs->parent; +} -#define SETTER(name) \ + +#define IMPLEMENT(return_type, name) \ + \ void \ hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \ hb_unicode_get_##name##_func_t func, \ @@ -191,66 +186,38 @@ hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \ if (ufuncs->immutable) \ return; \ \ - if (func != NULL) { \ - ufuncs->v.get_##name = func; \ - ufuncs->v.get_##name##_data = user_data; \ - ufuncs->v.get_##name##_destroy = destroy; \ + if (ufuncs->destroy.name) \ + ufuncs->destroy.name (ufuncs->user_data.name); \ + \ + if (func) { \ + ufuncs->get.name = func; \ + ufuncs->user_data.name = user_data; \ + ufuncs->destroy.name = destroy; \ } else if (ufuncs->parent != NULL) { \ - ufuncs->v.get_##name = ufuncs->parent->v.get_##name; \ - ufuncs->v.get_##name##_data = ufuncs->parent->v.get_##name##_data;; \ - ufuncs->v.get_##name##_destroy = NULL; \ + ufuncs->get.name = ufuncs->parent->get.name; \ + ufuncs->user_data.name = ufuncs->parent->user_data.name; \ + ufuncs->destroy.name = NULL; \ } else { \ - ufuncs->v.get_##name = hb_unicode_get_##name##_nil; \ - ufuncs->v.get_##name##_data = NULL; \ - ufuncs->v.get_##name##_destroy = NULL; \ + ufuncs->get.name = hb_unicode_get_##name##_nil; \ + ufuncs->user_data.name = NULL; \ + ufuncs->destroy.name = NULL; \ } \ +} \ + \ +return_type \ +hb_unicode_get_##name (hb_unicode_funcs_t *ufuncs, \ + hb_codepoint_t unicode) \ +{ \ + return ufuncs->get.name (ufuncs, unicode, ufuncs->user_data.name); \ } -SETTER(mirroring) -SETTER(general_category) -SETTER(script) -SETTER(combining_class) -SETTER(eastasian_width) +IMPLEMENT (unsigned int, combining_class) +IMPLEMENT (unsigned int, eastasian_width) +IMPLEMENT (hb_unicode_general_category_t, general_category) +IMPLEMENT (hb_codepoint_t, mirroring) +IMPLEMENT (hb_script_t, script) -hb_codepoint_t -hb_unicode_get_mirroring (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode) -{ - return ufuncs->v.get_mirroring (ufuncs, unicode, - ufuncs->v.get_mirroring_data); -} - -hb_unicode_general_category_t -hb_unicode_get_general_category (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode) -{ - return ufuncs->v.get_general_category (ufuncs, unicode, - ufuncs->v.get_general_category_data); -} - -hb_script_t -hb_unicode_get_script (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode) -{ - return ufuncs->v.get_script (ufuncs, unicode, - ufuncs->v.get_script_data); -} - -unsigned int -hb_unicode_get_combining_class (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode) -{ - return ufuncs->v.get_combining_class (ufuncs, unicode, - ufuncs->v.get_combining_class_data); -} - -unsigned int -hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode) -{ - return ufuncs->v.get_eastasian_width (ufuncs, unicode, - ufuncs->v.get_eastasian_width_data); -} +#undef IMPLEMENT HB_END_DECLS diff --git a/src/hb-unicode.h b/src/hb-unicode.h index 9785f3ee8..0b94aa320 100644 --- a/src/hb-unicode.h +++ b/src/hb-unicode.h @@ -68,39 +68,24 @@ hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs); /* typedefs */ -typedef hb_codepoint_t (*hb_unicode_get_mirroring_func_t) (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode, - void *user_data); -typedef hb_unicode_general_category_t (*hb_unicode_get_general_category_func_t) (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode, - void *user_data); -typedef hb_script_t (*hb_unicode_get_script_func_t) (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode, - void *user_data); typedef unsigned int (*hb_unicode_get_combining_class_func_t) (hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, void *user_data); typedef unsigned int (*hb_unicode_get_eastasian_width_func_t) (hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, void *user_data); +typedef hb_unicode_general_category_t (*hb_unicode_get_general_category_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); +typedef hb_codepoint_t (*hb_unicode_get_mirroring_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); +typedef hb_script_t (*hb_unicode_get_script_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); /* setters */ -void -hb_unicode_funcs_set_mirroring_func (hb_unicode_funcs_t *ufuncs, - hb_unicode_get_mirroring_func_t mirroring_func, - void *user_data, hb_destroy_func_t destroy); - -void -hb_unicode_funcs_set_general_category_func (hb_unicode_funcs_t *ufuncs, - hb_unicode_get_general_category_func_t general_category_func, - void *user_data, hb_destroy_func_t destroy); - -void -hb_unicode_funcs_set_script_func (hb_unicode_funcs_t *ufuncs, - hb_unicode_get_script_func_t script_func, - void *user_data, hb_destroy_func_t destroy); - void hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs, hb_unicode_get_combining_class_func_t combining_class_func, @@ -111,21 +96,25 @@ hb_unicode_funcs_set_eastasian_width_func (hb_unicode_funcs_t *ufuncs, hb_unicode_get_eastasian_width_func_t eastasian_width_func, void *user_data, hb_destroy_func_t destroy); +void +hb_unicode_funcs_set_general_category_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_get_general_category_func_t general_category_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_mirroring_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_get_mirroring_func_t mirroring_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_script_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_get_script_func_t script_func, + void *user_data, hb_destroy_func_t destroy); + + /* accessors */ -hb_codepoint_t -hb_unicode_get_mirroring (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode); - -hb_unicode_general_category_t -hb_unicode_get_general_category (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode); - -hb_script_t -hb_unicode_get_script (hb_unicode_funcs_t *ufuncs, - hb_codepoint_t unicode); - unsigned int hb_unicode_get_combining_class (hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode); @@ -134,6 +123,18 @@ unsigned int hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode); +hb_unicode_general_category_t +hb_unicode_get_general_category (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + +hb_codepoint_t +hb_unicode_get_mirroring (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + +hb_script_t +hb_unicode_get_script (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + HB_END_DECLS diff --git a/test/test-unicode.c b/test/test-unicode.c index f610c1dc8..c210d5428 100644 --- a/test/test-unicode.c +++ b/test/test-unicode.c @@ -120,10 +120,14 @@ a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs, static void test_subclassing_nil (void) { - hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL); + hb_unicode_funcs_t *uf, *aa; + + uf = hb_unicode_funcs_create (NULL); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1); - hb_unicode_funcs_t *aa = hb_unicode_funcs_create (uf); + + aa = hb_unicode_funcs_create (uf); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 2); + hb_unicode_funcs_destroy (uf); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1); @@ -133,7 +137,6 @@ test_subclassing_nil (void) g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC); g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN); - g_assert_cmpint (hb_unicode_funcs_get_reference_count (aa), ==, 1); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1); g_assert (!freed0 && !freed1); @@ -145,10 +148,14 @@ test_subclassing_nil (void) static void test_subclassing_glib (void) { - hb_unicode_funcs_t *uf = hb_glib_get_unicode_funcs (); + hb_unicode_funcs_t *uf, *aa; + + uf = hb_glib_get_unicode_funcs (); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 0); - hb_unicode_funcs_t *aa = hb_unicode_funcs_create (uf); + + aa = hb_unicode_funcs_create (uf); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 0); + hb_unicode_funcs_destroy (uf); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 0); @@ -168,13 +175,15 @@ test_subclassing_glib (void) static void test_subclassing_deep (void) { - hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL); + hb_unicode_funcs_t *uf, *aa; + + uf = hb_unicode_funcs_create (NULL); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1); hb_unicode_funcs_set_script_func (uf, simple_get_script, unique_pointer0, free_up); - hb_unicode_funcs_t *aa = hb_unicode_funcs_create (uf); + aa = hb_unicode_funcs_create (uf); g_assert_cmpint (hb_unicode_funcs_get_reference_count (aa), ==, 1); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 2);