2009-08-11 05:35:05 +02:00
|
|
|
/*
|
2011-04-21 23:14:28 +02:00
|
|
|
* Copyright © 2009 Red Hat, Inc.
|
|
|
|
* Copyright © 2011 Google, Inc.
|
2009-08-11 05:35:05 +02:00
|
|
|
*
|
2010-04-22 06:11:43 +02:00
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
2009-08-11 05:35:05 +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-21 23:14:28 +02:00
|
|
|
* Google Author(s): Behdad Esfahbod
|
2009-08-11 05:35:05 +02:00
|
|
|
*/
|
|
|
|
|
2011-04-21 00:50:27 +02:00
|
|
|
#include "hb-private.hh"
|
2009-08-11 05:35:05 +02:00
|
|
|
|
|
|
|
#include "hb-glib.h"
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
#include "hb-unicode-private.hh"
|
2009-08-11 05:35:05 +02:00
|
|
|
|
2009-11-03 00:33:52 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
HB_BEGIN_DECLS
|
|
|
|
|
2011-04-20 08:44:29 +02:00
|
|
|
static const hb_script_t
|
|
|
|
glib_script_to_script[] =
|
|
|
|
{
|
|
|
|
HB_SCRIPT_COMMON,
|
|
|
|
HB_SCRIPT_INHERITED,
|
|
|
|
HB_SCRIPT_ARABIC,
|
|
|
|
HB_SCRIPT_ARMENIAN,
|
|
|
|
HB_SCRIPT_BENGALI,
|
|
|
|
HB_SCRIPT_BOPOMOFO,
|
|
|
|
HB_SCRIPT_CHEROKEE,
|
|
|
|
HB_SCRIPT_COPTIC,
|
|
|
|
HB_SCRIPT_CYRILLIC,
|
|
|
|
HB_SCRIPT_DESERET,
|
|
|
|
HB_SCRIPT_DEVANAGARI,
|
|
|
|
HB_SCRIPT_ETHIOPIC,
|
|
|
|
HB_SCRIPT_GEORGIAN,
|
|
|
|
HB_SCRIPT_GOTHIC,
|
|
|
|
HB_SCRIPT_GREEK,
|
|
|
|
HB_SCRIPT_GUJARATI,
|
|
|
|
HB_SCRIPT_GURMUKHI,
|
|
|
|
HB_SCRIPT_HAN,
|
|
|
|
HB_SCRIPT_HANGUL,
|
|
|
|
HB_SCRIPT_HEBREW,
|
|
|
|
HB_SCRIPT_HIRAGANA,
|
|
|
|
HB_SCRIPT_KANNADA,
|
|
|
|
HB_SCRIPT_KATAKANA,
|
|
|
|
HB_SCRIPT_KHMER,
|
|
|
|
HB_SCRIPT_LAO,
|
|
|
|
HB_SCRIPT_LATIN,
|
|
|
|
HB_SCRIPT_MALAYALAM,
|
|
|
|
HB_SCRIPT_MONGOLIAN,
|
|
|
|
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
|
|
|
hb_script_t
|
|
|
|
hb_glib_script_to_script (GUnicodeScript script)
|
|
|
|
{
|
|
|
|
if (likely ((unsigned int) script < ARRAY_LENGTH (glib_script_to_script)))
|
|
|
|
return glib_script_to_script[script];
|
|
|
|
|
|
|
|
if (unlikely (script == G_UNICODE_SCRIPT_INVALID_CODE))
|
|
|
|
return HB_SCRIPT_INVALID;
|
|
|
|
|
|
|
|
return HB_SCRIPT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
GUnicodeScript
|
|
|
|
hb_glib_script_from_script (hb_script_t script)
|
|
|
|
{
|
|
|
|
unsigned int count = ARRAY_LENGTH (glib_script_to_script);
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
if (glib_script_to_script[i] == script)
|
|
|
|
return (GUnicodeScript) i;
|
|
|
|
|
|
|
|
if (unlikely (script == HB_SCRIPT_INVALID))
|
|
|
|
return G_UNICODE_SCRIPT_INVALID_CODE;
|
|
|
|
|
|
|
|
return G_UNICODE_SCRIPT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
static unsigned int
|
2011-06-14 20:47:07 +02:00
|
|
|
hb_glib_get_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2011-04-20 08:00:47 +02:00
|
|
|
hb_codepoint_t unicode,
|
2011-06-14 20:47:07 +02:00
|
|
|
void *user_data HB_UNUSED)
|
2011-04-20 08:00:47 +02:00
|
|
|
|
2011-04-20 06:19:20 +02:00
|
|
|
{
|
2011-04-20 08:00:47 +02:00
|
|
|
return g_unichar_combining_class (unicode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
2011-06-14 20:47:07 +02:00
|
|
|
hb_glib_get_eastasian_width (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2011-04-20 08:00:47 +02:00
|
|
|
hb_codepoint_t unicode,
|
2011-06-14 20:47:07 +02:00
|
|
|
void *user_data HB_UNUSED)
|
2011-04-20 08:00:47 +02:00
|
|
|
{
|
|
|
|
return g_unichar_iswide (unicode) ? 2 : 1;
|
2011-04-20 06:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_unicode_general_category_t
|
2011-06-14 20:47:07 +02:00
|
|
|
hb_glib_get_general_category (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2011-04-20 06:19:20 +02:00
|
|
|
hb_codepoint_t unicode,
|
2011-06-14 20:47:07 +02:00
|
|
|
void *user_data HB_UNUSED)
|
2011-04-20 06:19:20 +02:00
|
|
|
|
|
|
|
{
|
2011-04-20 08:00:47 +02:00
|
|
|
/* hb_unicode_general_category_t and GUnicodeType are identical */
|
|
|
|
return (hb_unicode_general_category_t) g_unichar_type (unicode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_codepoint_t
|
2011-06-14 20:47:07 +02:00
|
|
|
hb_glib_get_mirroring (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2011-04-20 08:00:47 +02:00
|
|
|
hb_codepoint_t unicode,
|
2011-06-14 20:47:07 +02:00
|
|
|
void *user_data HB_UNUSED)
|
2011-04-20 08:00:47 +02:00
|
|
|
{
|
|
|
|
g_unichar_get_mirror_char (unicode, &unicode);
|
|
|
|
return unicode;
|
2011-04-20 06:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_script_t
|
2011-06-14 20:47:07 +02:00
|
|
|
hb_glib_get_script (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
2011-04-20 06:19:20 +02:00
|
|
|
hb_codepoint_t unicode,
|
2011-06-14 20:47:07 +02:00
|
|
|
void *user_data HB_UNUSED)
|
2011-04-20 06:19:20 +02:00
|
|
|
{
|
2011-04-20 08:44:29 +02:00
|
|
|
return hb_glib_script_to_script (g_unichar_get_script (unicode));
|
2011-04-20 06:19:20 +02:00
|
|
|
}
|
|
|
|
|
2011-04-27 15:24:37 +02:00
|
|
|
extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_glib;
|
|
|
|
hb_unicode_funcs_t _hb_glib_unicode_funcs = {
|
2011-04-22 00:24:02 +02:00
|
|
|
HB_OBJECT_HEADER_STATIC,
|
|
|
|
|
2011-04-20 08:00:47 +02:00
|
|
|
NULL, /* parent */
|
2009-08-20 19:07:50 +02:00
|
|
|
TRUE, /* immutable */
|
2010-05-24 19:02:32 +02:00
|
|
|
{
|
2011-04-20 08:00:47 +02:00
|
|
|
hb_glib_get_combining_class,
|
|
|
|
hb_glib_get_eastasian_width,
|
|
|
|
hb_glib_get_general_category,
|
|
|
|
hb_glib_get_mirroring,
|
2011-07-08 05:47:19 +02:00
|
|
|
hb_glib_get_script,
|
|
|
|
/* TODO
|
|
|
|
hb_glib_compose,
|
|
|
|
hb_glib_decompose,
|
|
|
|
*/
|
2010-05-24 19:02:32 +02:00
|
|
|
}
|
2009-08-20 19:07:50 +02:00
|
|
|
};
|
2009-08-11 05:35:05 +02:00
|
|
|
|
|
|
|
hb_unicode_funcs_t *
|
2009-08-11 05:40:28 +02:00
|
|
|
hb_glib_get_unicode_funcs (void)
|
2009-08-11 05:35:05 +02:00
|
|
|
{
|
2011-04-27 15:24:37 +02:00
|
|
|
return &_hb_glib_unicode_funcs;
|
2009-08-11 05:35:05 +02:00
|
|
|
}
|
2010-07-23 21:11:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
HB_END_DECLS
|