2009-08-11 02:05:16 +02:00
|
|
|
/*
|
2011-04-21 23:14:28 +02:00
|
|
|
* Copyright © 2009 Red Hat, Inc.
|
2011-04-20 06:19:20 +02:00
|
|
|
* Copyright © 2011 Codethink Limited
|
2011-04-21 23:14:28 +02:00
|
|
|
* Copyright © 2010,2011 Google, Inc.
|
2009-08-11 02:05:16 +02:00
|
|
|
*
|
2010-04-22 06:11:43 +02:00
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
2009-08-11 02:05:16 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Red Hat Author(s): Behdad Esfahbod
|
2011-04-20 06:19:20 +02:00
|
|
|
* Codethink Author(s): Ryan Lortie
|
2011-04-20 08:00:47 +02:00
|
|
|
* Google Author(s): Behdad Esfahbod
|
2009-08-11 02:05:16 +02:00
|
|
|
*/
|
|
|
|
|
2011-04-21 00:50:27 +02:00
|
|
|
#include "hb-private.hh"
|
2009-08-11 02:05:16 +02:00
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
#include "hb-unicode-private.hh"
|
2009-08-11 02:05:16 +02:00
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
HB_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
2009-08-11 02:05:16 +02:00
|
|
|
/*
|
|
|
|
* hb_unicode_funcs_t
|
|
|
|
*/
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
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)
|
2011-04-20 06:19:20 +02:00
|
|
|
{
|
2011-04-20 08:00:47 +02:00
|
|
|
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;
|
2011-04-20 06:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_unicode_general_category_t
|
|
|
|
hb_unicode_get_general_category_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2011-04-20 08:00:47 +02:00
|
|
|
hb_codepoint_t unicode HB_UNUSED,
|
|
|
|
void *user_data HB_UNUSED)
|
2011-04-20 06:19:20 +02:00
|
|
|
{
|
|
|
|
return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER;
|
|
|
|
}
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
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)
|
2011-04-20 06:19:20 +02:00
|
|
|
{
|
2011-04-20 08:00:47 +02:00
|
|
|
return unicode;
|
2011-04-20 06:19:20 +02:00
|
|
|
}
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
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)
|
2011-04-20 06:19:20 +02:00
|
|
|
{
|
2011-04-20 08:00:47 +02:00
|
|
|
return HB_SCRIPT_UNKNOWN;
|
2011-04-20 06:19:20 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 05:05:05 +02:00
|
|
|
|
2009-08-11 05:21:33 +02:00
|
|
|
hb_unicode_funcs_t _hb_unicode_funcs_nil = {
|
2011-04-22 00:24:02 +02:00
|
|
|
HB_OBJECT_HEADER_STATIC,
|
|
|
|
|
2011-04-20 06:19:20 +02:00
|
|
|
NULL, /* parent */
|
2009-08-11 05:25:28 +02:00
|
|
|
TRUE, /* immutable */
|
2010-05-24 18:46:21 +02:00
|
|
|
{
|
2011-04-20 08:00:47 +02:00
|
|
|
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,
|
2010-05-24 18:46:21 +02:00
|
|
|
}
|
2009-08-11 02:05:16 +02:00
|
|
|
};
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
|
2011-04-27 15:24:37 +02:00
|
|
|
hb_unicode_funcs_t *
|
|
|
|
hb_unicode_funcs_get_default (void)
|
|
|
|
{
|
|
|
|
return &_hb_unicode_funcs_default;
|
|
|
|
}
|
|
|
|
|
2009-08-11 02:05:16 +02:00
|
|
|
hb_unicode_funcs_t *
|
2011-04-20 06:19:20 +02:00
|
|
|
hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
|
2009-08-11 02:05:16 +02:00
|
|
|
{
|
|
|
|
hb_unicode_funcs_t *ufuncs;
|
|
|
|
|
2011-04-27 22:38:03 +02:00
|
|
|
if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ()))
|
2009-08-11 02:05:16 +02:00
|
|
|
return &_hb_unicode_funcs_nil;
|
|
|
|
|
2011-05-02 21:59:57 +02:00
|
|
|
if (!parent)
|
|
|
|
parent = &_hb_unicode_funcs_nil;
|
2011-04-20 08:00:47 +02:00
|
|
|
|
2011-05-02 21:59:57 +02:00
|
|
|
hb_unicode_funcs_make_immutable (parent);
|
|
|
|
ufuncs->parent = hb_unicode_funcs_reference (parent);
|
2011-04-20 08:00:47 +02:00
|
|
|
|
2011-05-02 21:59:57 +02:00
|
|
|
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;
|
2009-08-11 05:05:05 +02:00
|
|
|
|
2009-08-11 02:05:16 +02:00
|
|
|
return ufuncs;
|
|
|
|
}
|
|
|
|
|
2011-05-12 00:14:44 +02:00
|
|
|
hb_unicode_funcs_t *
|
|
|
|
hb_unicode_funcs_get_empty (void)
|
|
|
|
{
|
|
|
|
return &_hb_unicode_funcs_nil;
|
|
|
|
}
|
|
|
|
|
2009-08-11 02:05:16 +02:00
|
|
|
hb_unicode_funcs_t *
|
|
|
|
hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
|
|
|
|
{
|
2011-04-27 22:38:03 +02:00
|
|
|
return hb_object_reference (ufuncs);
|
2009-08-11 02:05:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
|
|
|
|
{
|
2011-04-27 22:38:03 +02:00
|
|
|
if (!hb_object_destroy (ufuncs)) return;
|
2009-08-11 02:05:16 +02:00
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
#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
|
|
|
|
|
2011-05-02 21:59:57 +02:00
|
|
|
hb_unicode_funcs_destroy (ufuncs->parent);
|
2011-04-20 06:19:20 +02:00
|
|
|
|
2009-08-11 02:05:16 +02:00
|
|
|
free (ufuncs);
|
|
|
|
}
|
|
|
|
|
2011-04-28 03:46:01 +02:00
|
|
|
hb_bool_t
|
|
|
|
hb_unicode_funcs_set_user_data (hb_unicode_funcs_t *ufuncs,
|
|
|
|
hb_user_data_key_t *key,
|
|
|
|
void * data,
|
|
|
|
hb_destroy_func_t destroy)
|
|
|
|
{
|
|
|
|
return hb_object_set_user_data (ufuncs, key, data, destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs,
|
|
|
|
hb_user_data_key_t *key)
|
|
|
|
{
|
|
|
|
return hb_object_get_user_data (ufuncs, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-11 05:25:28 +02:00
|
|
|
void
|
|
|
|
hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
|
|
|
|
{
|
2011-04-27 22:38:03 +02:00
|
|
|
if (hb_object_is_inert (ufuncs))
|
2009-08-11 05:25:28 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
ufuncs->immutable = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-04 23:01:01 +02:00
|
|
|
hb_bool_t
|
|
|
|
hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs)
|
|
|
|
{
|
|
|
|
return ufuncs->immutable;
|
|
|
|
}
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
hb_unicode_funcs_t *
|
|
|
|
hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs)
|
|
|
|
{
|
2011-05-02 21:59:57 +02:00
|
|
|
return ufuncs->parent ? ufuncs->parent : &_hb_unicode_funcs_nil;
|
2011-04-20 08:00:47 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 04:58:56 +02:00
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
#define IMPLEMENT(return_type, name) \
|
|
|
|
\
|
2011-04-20 06:19:20 +02:00
|
|
|
void \
|
|
|
|
hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \
|
|
|
|
hb_unicode_get_##name##_func_t func, \
|
|
|
|
void *user_data, \
|
|
|
|
hb_destroy_func_t destroy) \
|
|
|
|
{ \
|
|
|
|
if (ufuncs->immutable) \
|
|
|
|
return; \
|
|
|
|
\
|
2011-04-20 08:00:47 +02:00
|
|
|
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; \
|
2011-05-11 17:55:11 +02:00
|
|
|
} else { \
|
2011-04-20 08:00:47 +02:00
|
|
|
ufuncs->get.name = ufuncs->parent->get.name; \
|
|
|
|
ufuncs->user_data.name = ufuncs->parent->user_data.name; \
|
|
|
|
ufuncs->destroy.name = NULL; \
|
2011-04-20 06:19:20 +02:00
|
|
|
} \
|
2011-04-20 08:00:47 +02:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
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); \
|
2009-08-11 04:58:56 +02:00
|
|
|
}
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
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)
|
2009-12-20 15:29:16 +01:00
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
#undef IMPLEMENT
|
2009-12-20 15:29:16 +01:00
|
|
|
|
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
HB_END_DECLS
|