2012-10-02 22:03:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Grigori Goronzy <greg@kinoho.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb.hh"
|
2012-10-02 22:03:18 +02:00
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-machinery.hh"
|
2012-10-02 22:03:18 +02:00
|
|
|
|
|
|
|
#include "ucdn.h"
|
|
|
|
|
|
|
|
static const hb_script_t ucdn_script_translate[] =
|
|
|
|
{
|
|
|
|
HB_SCRIPT_COMMON,
|
|
|
|
HB_SCRIPT_LATIN,
|
|
|
|
HB_SCRIPT_GREEK,
|
|
|
|
HB_SCRIPT_CYRILLIC,
|
|
|
|
HB_SCRIPT_ARMENIAN,
|
|
|
|
HB_SCRIPT_HEBREW,
|
|
|
|
HB_SCRIPT_ARABIC,
|
|
|
|
HB_SCRIPT_SYRIAC,
|
|
|
|
HB_SCRIPT_THAANA,
|
|
|
|
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
|
|
|
HB_SCRIPT_PALMYRENE,
|
|
|
|
HB_SCRIPT_PAU_CIN_HAU,
|
|
|
|
HB_SCRIPT_PSALTER_PAHLAVI,
|
|
|
|
HB_SCRIPT_SIDDHAM,
|
|
|
|
HB_SCRIPT_TIRHUTA,
|
|
|
|
HB_SCRIPT_WARANG_CITI,
|
2015-07-08 23:28:11 +02:00
|
|
|
HB_SCRIPT_AHOM,
|
|
|
|
HB_SCRIPT_ANATOLIAN_HIEROGLYPHS,
|
|
|
|
HB_SCRIPT_HATRAN,
|
|
|
|
HB_SCRIPT_MULTANI,
|
|
|
|
HB_SCRIPT_OLD_HUNGARIAN,
|
|
|
|
HB_SCRIPT_SIGNWRITING,
|
2016-07-21 10:23:33 +02:00
|
|
|
HB_SCRIPT_ADLAM,
|
|
|
|
HB_SCRIPT_BHAIKSUKI,
|
|
|
|
HB_SCRIPT_MARCHEN,
|
|
|
|
HB_SCRIPT_NEWA,
|
|
|
|
HB_SCRIPT_OSAGE,
|
|
|
|
HB_SCRIPT_TANGUT,
|
2017-10-02 17:15:46 +02:00
|
|
|
HB_SCRIPT_MASARAM_GONDI,
|
|
|
|
HB_SCRIPT_NUSHU,
|
|
|
|
HB_SCRIPT_SOYOMBO,
|
|
|
|
HB_SCRIPT_ZANABAZAR_SQUARE,
|
2018-06-06 02:59:31 +02:00
|
|
|
HB_SCRIPT_DOGRA,
|
|
|
|
HB_SCRIPT_GUNJALA_GONDI,
|
|
|
|
HB_SCRIPT_HANIFI_ROHINGYA,
|
|
|
|
HB_SCRIPT_MAKASAR,
|
|
|
|
HB_SCRIPT_MEDEFAIDRIN,
|
|
|
|
HB_SCRIPT_OLD_SOGDIAN,
|
|
|
|
HB_SCRIPT_SOGDIAN,
|
2012-10-02 22:03:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static hb_unicode_combining_class_t
|
2017-10-13 11:01:55 +02:00
|
|
|
hb_ucdn_combining_class(hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
2012-12-06 00:46:04 +01:00
|
|
|
void *user_data HB_UNUSED)
|
2012-10-02 22:03:18 +02:00
|
|
|
{
|
|
|
|
return (hb_unicode_combining_class_t) ucdn_get_combining_class(unicode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_unicode_general_category_t
|
2017-10-13 11:01:55 +02:00
|
|
|
hb_ucdn_general_category(hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
2012-12-06 00:46:04 +01:00
|
|
|
void *user_data HB_UNUSED)
|
2012-10-02 22:03:18 +02:00
|
|
|
{
|
|
|
|
return (hb_unicode_general_category_t)ucdn_get_general_category(unicode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_codepoint_t
|
2017-10-13 11:01:55 +02:00
|
|
|
hb_ucdn_mirroring(hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
2012-12-06 00:46:04 +01:00
|
|
|
void *user_data HB_UNUSED)
|
2012-10-02 22:03:18 +02:00
|
|
|
{
|
|
|
|
return ucdn_mirror(unicode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_script_t
|
2017-10-13 11:01:55 +02:00
|
|
|
hb_ucdn_script(hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
2012-12-06 00:46:04 +01:00
|
|
|
void *user_data HB_UNUSED)
|
2012-10-02 22:03:18 +02:00
|
|
|
{
|
|
|
|
return ucdn_script_translate[ucdn_get_script(unicode)];
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t
|
2017-10-13 11:01:55 +02:00
|
|
|
hb_ucdn_compose(hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2012-12-06 00:46:04 +01:00
|
|
|
hb_codepoint_t a, hb_codepoint_t b, hb_codepoint_t *ab,
|
|
|
|
void *user_data HB_UNUSED)
|
2012-10-02 22:03:18 +02:00
|
|
|
{
|
|
|
|
return ucdn_compose(ab, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t
|
2017-10-13 11:01:55 +02:00
|
|
|
hb_ucdn_decompose(hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2012-12-06 00:46:04 +01:00
|
|
|
hb_codepoint_t ab, hb_codepoint_t *a, hb_codepoint_t *b,
|
|
|
|
void *user_data HB_UNUSED)
|
2012-10-02 22:03:18 +02:00
|
|
|
{
|
|
|
|
return ucdn_decompose(ab, a, b);
|
|
|
|
}
|
|
|
|
|
2017-10-27 23:26:45 +02:00
|
|
|
|
2018-11-21 18:32:48 +01:00
|
|
|
#if HB_USE_ATEXIT
|
2018-12-17 19:01:01 +01:00
|
|
|
static void free_static_ucdn_funcs ();
|
2018-10-01 08:10:29 +02:00
|
|
|
#endif
|
2018-03-30 02:30:28 +02:00
|
|
|
|
2018-08-12 22:39:01 +02:00
|
|
|
static struct hb_ucdn_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_t<hb_ucdn_unicode_funcs_lazy_loader_t>
|
2012-10-02 22:03:18 +02:00
|
|
|
{
|
2018-12-17 19:01:01 +01:00
|
|
|
static hb_unicode_funcs_t *create ()
|
2017-10-27 23:26:45 +02:00
|
|
|
{
|
2018-08-12 22:39:01 +02:00
|
|
|
hb_unicode_funcs_t *funcs = hb_unicode_funcs_create (nullptr);
|
2012-10-02 22:03:18 +02:00
|
|
|
|
2018-10-09 06:56:33 +02:00
|
|
|
hb_unicode_funcs_set_combining_class_func (funcs, hb_ucdn_combining_class, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_general_category_func (funcs, hb_ucdn_general_category, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_mirroring_func (funcs, hb_ucdn_mirroring, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_script_func (funcs, hb_ucdn_script, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_compose_func (funcs, hb_ucdn_compose, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_decompose_func (funcs, hb_ucdn_decompose, nullptr, nullptr);
|
2017-10-27 23:26:45 +02:00
|
|
|
|
|
|
|
hb_unicode_funcs_make_immutable (funcs);
|
|
|
|
|
2018-11-21 18:32:48 +01:00
|
|
|
#if HB_USE_ATEXIT
|
2018-08-12 22:39:01 +02:00
|
|
|
atexit (free_static_ucdn_funcs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return funcs;
|
|
|
|
}
|
|
|
|
} static_ucdn_funcs;
|
2017-10-27 23:26:45 +02:00
|
|
|
|
2018-11-21 18:32:48 +01:00
|
|
|
#if HB_USE_ATEXIT
|
2018-08-12 22:39:01 +02:00
|
|
|
static
|
2018-12-17 19:01:01 +01:00
|
|
|
void free_static_ucdn_funcs ()
|
2018-08-12 22:39:01 +02:00
|
|
|
{
|
2018-08-13 02:19:55 +02:00
|
|
|
static_ucdn_funcs.free_instance ();
|
2018-08-12 22:39:01 +02:00
|
|
|
}
|
2017-10-27 23:26:45 +02:00
|
|
|
#endif
|
2012-10-02 22:03:18 +02:00
|
|
|
|
2018-08-12 22:39:01 +02:00
|
|
|
extern "C" HB_INTERNAL
|
2018-10-02 20:09:19 +02:00
|
|
|
hb_unicode_funcs_t *
|
2018-12-17 19:01:01 +01:00
|
|
|
hb_ucdn_get_unicode_funcs ();
|
2018-10-02 20:09:19 +02:00
|
|
|
|
2018-08-12 22:39:01 +02:00
|
|
|
hb_unicode_funcs_t *
|
2018-12-17 19:01:01 +01:00
|
|
|
hb_ucdn_get_unicode_funcs ()
|
2018-08-12 22:39:01 +02:00
|
|
|
{
|
2018-08-13 19:30:41 +02:00
|
|
|
return static_ucdn_funcs.get_unconst ();
|
2012-10-02 22:03:18 +02:00
|
|
|
}
|