#include "hb.hh"
#ifdef HAVE_GLIB
#include "hb-glib.h"
#include "hb-machinery.hh"
hb_script_t
hb_glib_script_to_script (GUnicodeScript script)
{
return (hb_script_t) g_unicode_script_to_iso15924 (script);
}
GUnicodeScript
hb_glib_script_from_script (hb_script_t script)
{
return g_unicode_script_from_iso15924 (script);
}
static hb_unicode_combining_class_t
hb_glib_unicode_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED,
hb_codepoint_t unicode,
void *user_data HB_UNUSED)
{
return (hb_unicode_combining_class_t) g_unichar_combining_class (unicode);
}
static hb_unicode_general_category_t
hb_glib_unicode_general_category (hb_unicode_funcs_t *ufuncs HB_UNUSED,
hb_codepoint_t unicode,
void *user_data HB_UNUSED)
{
return (hb_unicode_general_category_t) g_unichar_type (unicode);
}
static hb_codepoint_t
hb_glib_unicode_mirroring (hb_unicode_funcs_t *ufuncs HB_UNUSED,
hb_codepoint_t unicode,
void *user_data HB_UNUSED)
{
g_unichar_get_mirror_char (unicode, &unicode);
return unicode;
}
static hb_script_t
hb_glib_unicode_script (hb_unicode_funcs_t *ufuncs HB_UNUSED,
hb_codepoint_t unicode,
void *user_data HB_UNUSED)
{
return hb_glib_script_to_script (g_unichar_get_script (unicode));
}
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);
#else
return false;
#endif
}
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);
#else
return false;
#endif
}
static inline void free_static_glib_funcs ();
static struct hb_glib_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_t<hb_glib_unicode_funcs_lazy_loader_t>
{
static hb_unicode_funcs_t *create ()
{
hb_unicode_funcs_t *funcs = hb_unicode_funcs_create (nullptr);
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);
hb_unicode_funcs_make_immutable (funcs);
hb_atexit (free_static_glib_funcs);
return funcs;
}
} static_glib_funcs;
static inline
void free_static_glib_funcs ()
{
static_glib_funcs.free_instance ();
}
hb_unicode_funcs_t *
hb_glib_get_unicode_funcs ()
{
return static_glib_funcs.get_unconst ();
}
#if GLIB_CHECK_VERSION(2,31,10)
static void
_hb_g_bytes_unref (void *data)
{
g_bytes_unref ((GBytes *) data);
}
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),
_hb_g_bytes_unref);
}
#endif
#endif