unicode: Cleanup implementation

This commit is contained in:
Behdad Esfahbod 2011-04-20 02:00:47 -04:00
parent ecfb773829
commit fb194b8794
10 changed files with 246 additions and 253 deletions

View File

@ -24,8 +24,8 @@ HBSOURCES = \
hb-ot-head-private.hh \ hb-ot-head-private.hh \
hb-private.h \ hb-private.h \
hb-shape.cc \ hb-shape.cc \
hb-unicode.c \ hb-unicode.cc \
hb-unicode-private.h \ hb-unicode-private.hh \
$(NULL) $(NULL)
HBHEADERS = \ HBHEADERS = \
hb.h \ hb.h \
@ -65,7 +65,7 @@ if HAVE_GLIB
HBCFLAGS += $(GLIB_CFLAGS) HBCFLAGS += $(GLIB_CFLAGS)
HBLIBS += $(GLIB_LIBS) HBLIBS += $(GLIB_LIBS)
HBSOURCES += \ HBSOURCES += \
hb-glib.c \ hb-glib.cc \
$(NULL) $(NULL)
HBHEADERS += \ HBHEADERS += \
hb-glib.h \ hb-glib.h \
@ -76,7 +76,7 @@ if HAVE_ICU
HBCFLAGS += $(ICU_CFLAGS) HBCFLAGS += $(ICU_CFLAGS)
HBLIBS += $(ICU_LIBS) HBLIBS += $(ICU_LIBS)
HBSOURCES += \ HBSOURCES += \
hb-icu.c \ hb-icu.cc \
$(NULL) $(NULL)
HBHEADERS += \ HBHEADERS += \
hb-icu.h \ hb-icu.h \

View File

@ -30,7 +30,7 @@
#include "hb-private.h" #include "hb-private.h"
#include "hb-buffer.h" #include "hb-buffer.h"
#include "hb-unicode-private.h" #include "hb-unicode-private.hh"
HB_BEGIN_DECLS HB_BEGIN_DECLS

View File

@ -28,20 +28,28 @@
#include "hb-glib.h" #include "hb-glib.h"
#include "hb-unicode-private.h" #include "hb-unicode-private.hh"
#include <glib.h> #include <glib.h>
HB_BEGIN_DECLS HB_BEGIN_DECLS
static hb_codepoint_t static unsigned int
hb_glib_get_mirroring (hb_unicode_funcs_t *ufuncs, 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, hb_codepoint_t unicode,
void *user_data) void *user_data)
{ {
g_unichar_get_mirror_char (unicode, &unicode); return g_unichar_iswide (unicode) ? 2 : 1;
return unicode;
} }
static hb_unicode_general_category_t static hb_unicode_general_category_t
@ -50,7 +58,17 @@ hb_glib_get_general_category (hb_unicode_funcs_t *ufuncs,
void *user_data) 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 static hb_script_t
@ -167,7 +185,7 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs,
MATCH_SCRIPT (LISU); /* Lisu */ MATCH_SCRIPT (LISU); /* Lisu */
MATCH_SCRIPT (MEETEI_MAYEK); /* Mtei */ MATCH_SCRIPT (MEETEI_MAYEK); /* Mtei */
MATCH_SCRIPT (OLD_SOUTH_ARABIAN); /* Sarb */ 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 */ MATCH_SCRIPT (OLD_TURKIC); /* Orkh */
#else #else
MATCH_SCRIPT2(OLD_TURKISH, OLD_TURKIC);/* Orkh */ MATCH_SCRIPT2(OLD_TURKISH, OLD_TURKIC);/* Orkh */
@ -190,33 +208,16 @@ hb_glib_get_script (hb_unicode_funcs_t *ufuncs,
return HB_SCRIPT_UNKNOWN; 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 = { static hb_unicode_funcs_t glib_ufuncs = {
HB_REFERENCE_COUNT_INVALID, /* ref_count */ HB_REFERENCE_COUNT_INVALID, /* ref_count */
NULL, NULL, /* parent */
TRUE, /* immutable */ TRUE, /* immutable */
{ {
hb_glib_get_general_category, NULL, NULL, hb_glib_get_combining_class,
hb_glib_get_combining_class, NULL, NULL, hb_glib_get_eastasian_width,
hb_glib_get_mirroring, NULL, NULL, hb_glib_get_general_category,
hb_glib_get_script, NULL, NULL, hb_glib_get_mirroring,
hb_glib_get_eastasian_width, NULL, NULL hb_glib_get_script
} }
}; };

View File

@ -29,7 +29,7 @@
#include "hb-icu.h" #include "hb-icu.h"
#include "hb-unicode-private.h" #include "hb-unicode-private.hh"
#include <unicode/uversion.h> #include <unicode/uversion.h>
#include <unicode/uchar.h> #include <unicode/uchar.h>
@ -38,14 +38,6 @@
HB_BEGIN_DECLS 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 static unsigned int
hb_icu_get_combining_class (hb_unicode_funcs_t *ufuncs, hb_icu_get_combining_class (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t unicode, hb_codepoint_t unicode,
@ -125,6 +117,14 @@ hb_icu_get_general_category (hb_unicode_funcs_t *ufuncs,
return HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED; 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 static hb_script_t
hb_icu_get_script (hb_unicode_funcs_t *ufuncs, hb_icu_get_script (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t unicode, hb_codepoint_t unicode,
@ -264,14 +264,14 @@ hb_icu_get_script (hb_unicode_funcs_t *ufuncs,
static hb_unicode_funcs_t icu_ufuncs = { static hb_unicode_funcs_t icu_ufuncs = {
HB_REFERENCE_COUNT_INVALID, /* ref_count */ HB_REFERENCE_COUNT_INVALID, /* ref_count */
NULL, NULL, /* parent */
TRUE, /* immutable */ TRUE, /* immutable */
{ {
hb_icu_get_general_category, NULL, NULL, hb_icu_get_combining_class,
hb_icu_get_combining_class, NULL, NULL, hb_icu_get_eastasian_width,
hb_icu_get_mirroring, NULL, NULL, hb_icu_get_general_category,
hb_icu_get_script, NULL, NULL, hb_icu_get_mirroring,
hb_icu_get_eastasian_width, NULL, NULL hb_icu_get_script
} }
}; };

View File

@ -143,16 +143,13 @@ is_variation_selector (hb_codepoint_t unicode)
static void static void
hb_set_unicode_props (hb_ot_shape_context_t *c) 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_funcs_t *unicode = c->buffer->unicode;
hb_unicode_get_combining_class_func_t get_combining_class = c->buffer->unicode->v.get_combining_class;
hb_glyph_info_t *info = c->buffer->info; hb_glyph_info_t *info = c->buffer->info;
unsigned int count = c->buffer->len; unsigned int count = c->buffer->len;
for (unsigned int i = 1; i < count; i++) { for (unsigned int i = 1; i < count; i++) {
info[i].general_category() = get_general_category (c->buffer->unicode, info[i].codepoint, info[i].general_category() = unicode->get_general_category (info[i].codepoint);
c->buffer->unicode->v.get_general_category_data); info[i].combining_class() = unicode->get_combining_class (info[i].codepoint);
info[i].combining_class() = get_combining_class (c->buffer->unicode, info[i].codepoint,
c->buffer->unicode->v.get_combining_class_data);
} }
} }
@ -193,7 +190,7 @@ hb_reset_glyph_infos (hb_ot_shape_context_t *c)
static void static void
hb_mirror_chars (hb_ot_shape_context_t *c) 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)) if (HB_DIRECTION_IS_FORWARD (c->target_direction))
return; return;
@ -202,8 +199,7 @@ hb_mirror_chars (hb_ot_shape_context_t *c)
unsigned int count = c->buffer->len; unsigned int count = c->buffer->len;
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
hb_codepoint_t codepoint = get_mirroring (c->buffer->unicode, c->buffer->info[i].codepoint, hb_codepoint_t codepoint = unicode->get_mirroring (c->buffer->info[i].codepoint);
c->buffer->unicode->v.get_mirroring_data);
if (likely (codepoint == 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 */ c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to before setting user-feature masks */
else else

View File

@ -74,10 +74,10 @@ hb_shape (hb_font_t *font,
/* If script is set to INVALID, guess from buffer contents */ /* If script is set to INVALID, guess from buffer contents */
if (buffer->props.script == HB_SCRIPT_INVALID) { 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; unsigned int count = buffer->len;
for (unsigned int i = 0; i < count; i++) { 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 && if (likely (script != HB_SCRIPT_COMMON &&
script != HB_SCRIPT_INHERITED && script != HB_SCRIPT_INHERITED &&
script != HB_SCRIPT_UNKNOWN)) { script != HB_SCRIPT_UNKNOWN)) {

View File

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2009 Red Hat, Inc. * Copyright (C) 2009 Red Hat, Inc.
* Copyright © 2011 Codethink Limited * Copyright © 2011 Codethink Limited
* Copyright (C) 2010 Google, Inc.
* *
* This is part of HarfBuzz, a text shaping library. * This is part of HarfBuzz, a text shaping library.
* *
@ -24,10 +25,11 @@
* *
* Red Hat Author(s): Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
* Codethink Author(s): Ryan Lortie * Codethink Author(s): Ryan Lortie
* Google Author(s): Behdad Esfahbod
*/ */
#ifndef HB_UNICODE_PRIVATE_H #ifndef HB_UNICODE_PRIVATE_HH
#define HB_UNICODE_PRIVATE_H #define HB_UNICODE_PRIVATE_HH
#include "hb-private.h" #include "hb-private.h"
@ -46,27 +48,44 @@ struct _hb_unicode_funcs_t {
hb_bool_t immutable; 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 { struct {
hb_unicode_get_general_category_func_t get_general_category; hb_unicode_get_combining_class_func_t combining_class;
void *get_general_category_data; hb_unicode_get_eastasian_width_func_t eastasian_width;
hb_destroy_func_t get_general_category_destroy; 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; struct {
void *get_combining_class_data; void *combining_class;
hb_destroy_func_t get_combining_class_destroy; void *eastasian_width;
void *general_category;
void *mirroring;
void *script;
} user_data;
hb_unicode_get_mirroring_func_t get_mirroring; struct {
void *get_mirroring_data; hb_destroy_func_t combining_class;
hb_destroy_func_t get_mirroring_destroy; hb_destroy_func_t eastasian_width;
hb_destroy_func_t general_category;
hb_unicode_get_script_func_t get_script; hb_destroy_func_t mirroring;
void *get_script_data; hb_destroy_func_t script;
hb_destroy_func_t get_script_destroy; } 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;
}; };
extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil; 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 HB_END_DECLS
#endif /* HB_UNICODE_PRIVATE_H */ #endif /* HB_UNICODE_PRIVATE_HH */

View File

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2009 Red Hat, Inc. * Copyright (C) 2009 Red Hat, Inc.
* Copyright © 2011 Codethink Limited * Copyright © 2011 Codethink Limited
* Copyright (C) 2010 Google, Inc.
* *
* This is part of HarfBuzz, a text shaping library. * This is part of HarfBuzz, a text shaping library.
* *
@ -24,11 +25,12 @@
* *
* Red Hat Author(s): Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
* Codethink Author(s): Ryan Lortie * Codethink Author(s): Ryan Lortie
* Google Author(s): Behdad Esfahbod
*/ */
#include "hb-private.h" #include "hb-private.h"
#include "hb-unicode-private.h" #include "hb-unicode-private.hh"
HB_BEGIN_DECLS HB_BEGIN_DECLS
@ -37,30 +39,6 @@ HB_BEGIN_DECLS
* hb_unicode_funcs_t * 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 static unsigned int
hb_unicode_get_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, hb_unicode_get_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
hb_codepoint_t unicode HB_UNUSED, hb_codepoint_t unicode HB_UNUSED,
@ -77,19 +55,45 @@ hb_unicode_get_eastasian_width_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
return 1; 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_unicode_funcs_t _hb_unicode_funcs_nil = {
HB_REFERENCE_COUNT_INVALID, /* ref_count */ HB_REFERENCE_COUNT_INVALID, /* ref_count */
NULL, /* parent */ NULL, /* parent */
TRUE, /* immutable */ TRUE, /* immutable */
{ {
hb_unicode_get_general_category_nil, NULL, NULL, hb_unicode_get_combining_class_nil,
hb_unicode_get_combining_class_nil, NULL, NULL, hb_unicode_get_eastasian_width_nil,
hb_unicode_get_mirroring_nil, NULL, NULL, hb_unicode_get_general_category_nil,
hb_unicode_get_script_nil, NULL, NULL, hb_unicode_get_mirroring_nil,
hb_unicode_get_eastasian_width_nil, NULL, NULL hb_unicode_get_script_nil,
} }
}; };
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)
{ {
@ -98,24 +102,21 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs)) if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
return &_hb_unicode_funcs_nil; return &_hb_unicode_funcs_nil;
if (parent != NULL) { if (parent != NULL)
ufuncs->parent = hb_unicode_funcs_reference (parent); {
hb_unicode_funcs_make_immutable (parent); 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. ufuncs->get = parent->get;
*
* We don't want to destroy the user_data twice and since we hold a /* We can safely copy user_data from parent since we hold a reference
* reference on our parent then we know that the user_data will * onto it and it's immutable. We should not copy the destroy notifiers
* survive for at least as long as we do anyway. * though. */
*/ ufuncs->user_data = parent->user_data;
ufuncs->v.get_general_category_destroy = NULL; }
ufuncs->v.get_combining_class_destroy = NULL; else
ufuncs->v.get_mirroring_destroy = NULL; {
ufuncs->v.get_script_destroy = NULL; ufuncs->get = _hb_unicode_funcs_nil.get;
ufuncs->v.get_eastasian_width_destroy = NULL;
} else {
ufuncs->v = _hb_unicode_funcs_nil.v;
} }
return ufuncs; return ufuncs;
@ -138,33 +139,20 @@ hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
{ {
HB_OBJECT_DO_DESTROY (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) if (ufuncs->parent != NULL)
hb_unicode_funcs_destroy (ufuncs->parent); 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); free (ufuncs);
} }
hb_unicode_funcs_t *
hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs)
{
return ufuncs->parent;
}
void void
hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs) 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; 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 \ void \
hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \ hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \
hb_unicode_get_##name##_func_t func, \ 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) \ if (ufuncs->immutable) \
return; \ return; \
\ \
if (func != NULL) { \ if (ufuncs->destroy.name) \
ufuncs->v.get_##name = func; \ ufuncs->destroy.name (ufuncs->user_data.name); \
ufuncs->v.get_##name##_data = user_data; \ \
ufuncs->v.get_##name##_destroy = destroy; \ if (func) { \
ufuncs->get.name = func; \
ufuncs->user_data.name = user_data; \
ufuncs->destroy.name = destroy; \
} else if (ufuncs->parent != NULL) { \ } else if (ufuncs->parent != NULL) { \
ufuncs->v.get_##name = ufuncs->parent->v.get_##name; \ ufuncs->get.name = ufuncs->parent->get.name; \
ufuncs->v.get_##name##_data = ufuncs->parent->v.get_##name##_data;; \ ufuncs->user_data.name = ufuncs->parent->user_data.name; \
ufuncs->v.get_##name##_destroy = NULL; \ ufuncs->destroy.name = NULL; \
} else { \ } else { \
ufuncs->v.get_##name = hb_unicode_get_##name##_nil; \ ufuncs->get.name = hb_unicode_get_##name##_nil; \
ufuncs->v.get_##name##_data = NULL; \ ufuncs->user_data.name = NULL; \
ufuncs->v.get_##name##_destroy = 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) IMPLEMENT (unsigned int, combining_class)
SETTER(general_category) IMPLEMENT (unsigned int, eastasian_width)
SETTER(script) IMPLEMENT (hb_unicode_general_category_t, general_category)
SETTER(combining_class) IMPLEMENT (hb_codepoint_t, mirroring)
SETTER(eastasian_width) IMPLEMENT (hb_script_t, script)
hb_codepoint_t #undef IMPLEMENT
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);
}
HB_END_DECLS HB_END_DECLS

View File

@ -68,39 +68,24 @@ hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs);
/* typedefs */ /* 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, typedef unsigned int (*hb_unicode_get_combining_class_func_t) (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t unicode, hb_codepoint_t unicode,
void *user_data); void *user_data);
typedef unsigned int (*hb_unicode_get_eastasian_width_func_t) (hb_unicode_funcs_t *ufuncs, typedef unsigned int (*hb_unicode_get_eastasian_width_func_t) (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t unicode, hb_codepoint_t unicode,
void *user_data); 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 */ /* 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 void
hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs, hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs,
hb_unicode_get_combining_class_func_t combining_class_func, 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, hb_unicode_get_eastasian_width_func_t eastasian_width_func,
void *user_data, hb_destroy_func_t destroy); 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 */ /* 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 unsigned int
hb_unicode_get_combining_class (hb_unicode_funcs_t *ufuncs, hb_unicode_get_combining_class (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t unicode); hb_codepoint_t unicode);
@ -134,6 +123,18 @@ unsigned int
hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs, hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
hb_codepoint_t unicode); 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 HB_END_DECLS

View File

@ -120,10 +120,14 @@ a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
static void static void
test_subclassing_nil (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); 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); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 2);
hb_unicode_funcs_destroy (uf); hb_unicode_funcs_destroy (uf);
g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1); 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, 'a'), ==, HB_SCRIPT_ARABIC);
g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN); 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 (aa), ==, 1);
g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1);
g_assert (!freed0 && !freed1); g_assert (!freed0 && !freed1);
@ -145,10 +148,14 @@ test_subclassing_nil (void)
static void static void
test_subclassing_glib (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); 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); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 0);
hb_unicode_funcs_destroy (uf); hb_unicode_funcs_destroy (uf);
g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 0); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 0);
@ -168,13 +175,15 @@ test_subclassing_glib (void)
static void static void
test_subclassing_deep (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); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 1);
hb_unicode_funcs_set_script_func (uf, simple_get_script, hb_unicode_funcs_set_script_func (uf, simple_get_script,
unique_pointer0, free_up); 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 (aa), ==, 1);
g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 2); g_assert_cmpint (hb_unicode_funcs_get_reference_count (uf), ==, 2);