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
|
|
|
*/
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb.hh"
|
2009-08-11 05:35:05 +02:00
|
|
|
|
|
|
|
#include "hb-glib.h"
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-machinery.hh"
|
2009-08-11 05:35:05 +02:00
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
|
2018-10-27 13:40:43 +02:00
|
|
|
/**
|
|
|
|
* SECTION:hb-glib
|
|
|
|
* @title: hb-glib
|
|
|
|
* @short_description: GLib integration
|
|
|
|
* @include: hb-glib.h
|
|
|
|
*
|
|
|
|
* Functions for using HarfBuzz with the GLib library to provide Unicode data.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2011-07-21 03:58:14 +02:00
|
|
|
#if !GLIB_CHECK_VERSION(2,29,14)
|
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_KANNAD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_SCRIPT_OLD_TURKIC,
|
|
|
|
HB_SCRIPT_SAMARITAN,
|
|
|
|
HB_SCRIPT_TAI_VIET,
|
|
|
|
|
|
|
|
/* Unicode-6.0 additions */
|
|
|
|
HB_SCRIPT_BATAK,
|
|
|
|
HB_SCRIPT_BRAHMI,
|
2012-03-07 18:53:34 +01:00
|
|
|
HB_SCRIPT_MANDAIC,
|
|
|
|
|
|
|
|
/* Unicode-6.1 additions */
|
|
|
|
HB_SCRIPT_CHAKMA,
|
|
|
|
HB_SCRIPT_MEROITIC_CURSIVE,
|
|
|
|
HB_SCRIPT_MEROITIC_HIEROGLYPHS,
|
|
|
|
HB_SCRIPT_MIAO,
|
|
|
|
HB_SCRIPT_SHARADA,
|
|
|
|
HB_SCRIPT_SORA_SOMPENG,
|
|
|
|
HB_SCRIPT_TAKRI
|
2011-04-20 08:44:29 +02:00
|
|
|
};
|
2011-07-21 03:58:14 +02:00
|
|
|
#endif
|
2011-04-20 08:44:29 +02:00
|
|
|
|
|
|
|
hb_script_t
|
|
|
|
hb_glib_script_to_script (GUnicodeScript script)
|
|
|
|
{
|
2011-07-21 03:58:14 +02:00
|
|
|
#if GLIB_CHECK_VERSION(2,29,14)
|
|
|
|
return (hb_script_t) g_unicode_script_to_iso15924 (script);
|
|
|
|
#else
|
2011-04-20 08:44:29 +02:00
|
|
|
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;
|
2011-07-21 03:58:14 +02:00
|
|
|
#endif
|
2011-04-20 08:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GUnicodeScript
|
|
|
|
hb_glib_script_from_script (hb_script_t script)
|
|
|
|
{
|
2011-07-21 03:58:14 +02:00
|
|
|
#if GLIB_CHECK_VERSION(2,29,14)
|
|
|
|
return g_unicode_script_from_iso15924 (script);
|
|
|
|
#else
|
2011-04-20 08:44:29 +02:00
|
|
|
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;
|
2011-07-21 03:58:14 +02:00
|
|
|
#endif
|
2011-04-20 08:44:29 +02:00
|
|
|
}
|
|
|
|
|
2010-07-23 21:11:18 +02:00
|
|
|
|
2012-08-01 22:23:44 +02:00
|
|
|
static hb_unicode_combining_class_t
|
2011-07-21 03:51:37 +02:00
|
|
|
hb_glib_unicode_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
void *user_data HB_UNUSED)
|
2011-04-20 08:00:47 +02:00
|
|
|
|
2011-04-20 06:19:20 +02:00
|
|
|
{
|
2012-08-01 22:23:44 +02:00
|
|
|
return (hb_unicode_combining_class_t) g_unichar_combining_class (unicode);
|
2011-04-20 08:00:47 +02:00
|
|
|
}
|
|
|
|
|
2011-04-20 06:19:20 +02:00
|
|
|
static hb_unicode_general_category_t
|
2011-07-21 03:51:37 +02:00
|
|
|
hb_glib_unicode_general_category (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
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-07-21 03:51:37 +02:00
|
|
|
hb_glib_unicode_mirroring (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
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-07-21 03:51:37 +02:00
|
|
|
hb_glib_unicode_script (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
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-07-21 03:51:37 +02:00
|
|
|
static hb_bool_t
|
|
|
|
hb_glib_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t a,
|
|
|
|
hb_codepoint_t b,
|
|
|
|
hb_codepoint_t *ab,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
{
|
|
|
|
#if GLIB_CHECK_VERSION(2,29,12)
|
|
|
|
return g_unichar_compose (a, b, ab);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* We don't ifdef-out the fallback code such that compiler always
|
|
|
|
* sees it and makes sure it's compilable. */
|
|
|
|
|
|
|
|
gchar utf8[12];
|
|
|
|
gchar *normalized;
|
2012-08-04 02:23:40 +02:00
|
|
|
int len;
|
2011-07-21 03:51:37 +02:00
|
|
|
hb_bool_t ret;
|
|
|
|
|
|
|
|
len = g_unichar_to_utf8 (a, utf8);
|
|
|
|
len += g_unichar_to_utf8 (b, utf8 + len);
|
|
|
|
normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFC);
|
|
|
|
len = g_utf8_strlen (normalized, -1);
|
2011-08-07 06:59:12 +02:00
|
|
|
if (unlikely (!len))
|
2012-06-06 02:35:40 +02:00
|
|
|
return false;
|
2011-08-07 06:59:12 +02:00
|
|
|
|
2011-07-21 03:51:37 +02:00
|
|
|
if (len == 1) {
|
|
|
|
*ab = g_utf8_get_char (normalized);
|
2012-06-06 02:35:40 +02:00
|
|
|
ret = true;
|
2011-07-21 03:51:37 +02:00
|
|
|
} else {
|
2012-06-06 02:35:40 +02:00
|
|
|
ret = false;
|
2011-07-21 03:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (normalized);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t
|
|
|
|
hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
|
|
|
|
hb_codepoint_t ab,
|
|
|
|
hb_codepoint_t *a,
|
|
|
|
hb_codepoint_t *b,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
{
|
|
|
|
#if GLIB_CHECK_VERSION(2,29,12)
|
|
|
|
return g_unichar_decompose (ab, a, b);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* We don't ifdef-out the fallback code such that compiler always
|
|
|
|
* sees it and makes sure it's compilable. */
|
|
|
|
|
|
|
|
gchar utf8[6];
|
|
|
|
gchar *normalized;
|
2012-08-04 02:23:40 +02:00
|
|
|
int len;
|
2011-07-21 03:51:37 +02:00
|
|
|
hb_bool_t ret;
|
|
|
|
|
|
|
|
len = g_unichar_to_utf8 (ab, utf8);
|
|
|
|
normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFD);
|
|
|
|
len = g_utf8_strlen (normalized, -1);
|
2011-08-07 06:59:12 +02:00
|
|
|
if (unlikely (!len))
|
2012-06-06 02:35:40 +02:00
|
|
|
return false;
|
2011-08-07 06:59:12 +02:00
|
|
|
|
2011-07-21 03:51:37 +02:00
|
|
|
if (len == 1) {
|
|
|
|
*a = g_utf8_get_char (normalized);
|
|
|
|
*b = 0;
|
|
|
|
ret = *a != ab;
|
|
|
|
} else if (len == 2) {
|
2011-07-22 02:58:42 +02:00
|
|
|
*a = g_utf8_get_char (normalized);
|
|
|
|
*b = g_utf8_get_char (g_utf8_next_char (normalized));
|
2011-07-21 04:30:29 +02:00
|
|
|
/* Here's the ugly part: if ab decomposes to a single character and
|
|
|
|
* that character decomposes again, we have to detect that and undo
|
|
|
|
* the second part :-(. */
|
|
|
|
gchar *recomposed = g_utf8_normalize (normalized, -1, G_NORMALIZE_NFC);
|
2011-07-22 02:58:42 +02:00
|
|
|
hb_codepoint_t c = g_utf8_get_char (recomposed);
|
|
|
|
if (c != ab && c != *a) {
|
|
|
|
*a = c;
|
2011-07-21 04:30:29 +02:00
|
|
|
*b = 0;
|
|
|
|
}
|
|
|
|
g_free (recomposed);
|
2012-06-06 02:35:40 +02:00
|
|
|
ret = true;
|
2011-07-21 03:51:37 +02:00
|
|
|
} else {
|
|
|
|
/* If decomposed to more than two characters, take the last one,
|
|
|
|
* and recompose the rest to get the first component. */
|
|
|
|
gchar *end = g_utf8_offset_to_pointer (normalized, len - 1);
|
|
|
|
gchar *recomposed;
|
|
|
|
*b = g_utf8_get_char (end);
|
|
|
|
recomposed = g_utf8_normalize (normalized, end - normalized, G_NORMALIZE_NFC);
|
|
|
|
/* We expect that recomposed has exactly one character now. */
|
|
|
|
*a = g_utf8_get_char (recomposed);
|
|
|
|
g_free (recomposed);
|
2012-06-06 02:35:40 +02:00
|
|
|
ret = true;
|
2011-07-21 03:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (normalized);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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_glib_funcs ();
|
2018-08-14 22:50:24 +02:00
|
|
|
#endif
|
2017-10-27 23:26:45 +02:00
|
|
|
|
2018-08-12 22:39:01 +02:00
|
|
|
static struct hb_glib_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_t<hb_glib_unicode_funcs_lazy_loader_t>
|
2012-08-12 03:26:25 +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);
|
2017-10-27 23:26:45 +02:00
|
|
|
|
2018-10-09 06:56:33 +02:00
|
|
|
hb_unicode_funcs_set_combining_class_func (funcs, hb_glib_unicode_combining_class, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_general_category_func (funcs, hb_glib_unicode_general_category, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_mirroring_func (funcs, hb_glib_unicode_mirroring, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_script_func (funcs, hb_glib_unicode_script, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_compose_func (funcs, hb_glib_unicode_compose, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_decompose_func (funcs, hb_glib_unicode_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_glib_funcs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return funcs;
|
|
|
|
}
|
|
|
|
} static_glib_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_glib_funcs ()
|
2018-08-12 22:39:01 +02:00
|
|
|
{
|
2018-08-13 02:19:55 +02:00
|
|
|
static_glib_funcs.free_instance ();
|
2018-08-12 22:39:01 +02:00
|
|
|
}
|
2017-10-27 23:26:45 +02:00
|
|
|
#endif
|
2009-08-11 05:35:05 +02:00
|
|
|
|
2018-08-12 22:39:01 +02:00
|
|
|
hb_unicode_funcs_t *
|
2018-12-17 19:01:01 +01:00
|
|
|
hb_glib_get_unicode_funcs ()
|
2018-08-12 22:39:01 +02:00
|
|
|
{
|
2018-08-13 19:30:41 +02:00
|
|
|
return static_glib_funcs.get_unconst ();
|
2009-08-11 05:35:05 +02:00
|
|
|
}
|
2010-07-23 21:11:18 +02:00
|
|
|
|
2018-08-12 22:39:01 +02:00
|
|
|
|
|
|
|
|
Support building with older glib versions
It is desirable to be able to build against older versions of glib.
fd7a245 changed the configure check to require glib > 2.38 for
G_TEST_DIST. Before that, version 2.16 was required, but in fact,
since aafe395, G_PASTE is being used, which was introduced in 2.19.1.
And since 0ef179e2, hb-glib uses GBytes, which were introduced in
2.31.10.
2.19.1 is rather old, but 2.38 is rather new. For Firefox, building
against 2.22 is still supported, although we could probably get away
with bumping that to 2.28. Either way, GBytes is not available.
Arguably, if you build against a glib that doesn't support GBytes,
you're not going to use the hb_glib_blob_create function, so we hide
the function when building against such a glib.
As for G_TEST_DIST, when building against versions of glib that don't
support it, we can fallback to the previous behavior, which, AIUI, was
just making the test not work when building in a separate directory.
2016-09-30 11:15:37 +02:00
|
|
|
#if GLIB_CHECK_VERSION(2,31,10)
|
2017-10-11 15:51:31 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
_hb_g_bytes_unref (void *data)
|
|
|
|
{
|
|
|
|
g_bytes_unref ((GBytes *) data);
|
|
|
|
}
|
|
|
|
|
2015-06-01 13:22:01 +02:00
|
|
|
/**
|
2015-11-27 01:30:37 +01:00
|
|
|
* hb_glib_blob_create:
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.38
|
|
|
|
**/
|
2015-01-07 01:58:33 +01:00
|
|
|
hb_blob_t *
|
|
|
|
hb_glib_blob_create (GBytes *gbytes)
|
|
|
|
{
|
|
|
|
gsize size = 0;
|
|
|
|
gconstpointer data = g_bytes_get_data (gbytes, &size);
|
|
|
|
return hb_blob_create ((const char *) data,
|
|
|
|
size,
|
|
|
|
HB_MEMORY_MODE_READONLY,
|
|
|
|
g_bytes_ref (gbytes),
|
2017-10-11 15:51:31 +02:00
|
|
|
_hb_g_bytes_unref);
|
2015-01-07 01:58:33 +01:00
|
|
|
}
|
Support building with older glib versions
It is desirable to be able to build against older versions of glib.
fd7a245 changed the configure check to require glib > 2.38 for
G_TEST_DIST. Before that, version 2.16 was required, but in fact,
since aafe395, G_PASTE is being used, which was introduced in 2.19.1.
And since 0ef179e2, hb-glib uses GBytes, which were introduced in
2.31.10.
2.19.1 is rather old, but 2.38 is rather new. For Firefox, building
against 2.22 is still supported, although we could probably get away
with bumping that to 2.28. Either way, GBytes is not available.
Arguably, if you build against a glib that doesn't support GBytes,
you're not going to use the hb_glib_blob_create function, so we hide
the function when building against such a glib.
As for G_TEST_DIST, when building against versions of glib that don't
support it, we can fallback to the previous behavior, which, AIUI, was
just making the test not work when building in a separate directory.
2016-09-30 11:15:37 +02:00
|
|
|
#endif
|