|
|
|
@ -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) |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
return unicode; |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
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) |
|
|
|
|
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) |
|
|
|
|
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 HB_SCRIPT_UNKNOWN; |
|
|
|
|
return unicode; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
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 0; |
|
|
|
|
return HB_SCRIPT_UNKNOWN; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
/* 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->parent = hb_unicode_funcs_reference (parent); |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
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 |