2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2011 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
35 #include "hb-machinery.hh"
41 * @short_description: GLib integration
44 * Functions for using HarfBuzz with the GLib library.
46 * HarfBuzz supports using GLib to provide Unicode data, by attaching
47 * GLib functions to the virtual methods in a #hb_unicode_funcs_t function
53 * hb_glib_script_to_script:
54 * @script: The GUnicodeScript identifier to query
56 * Fetches the #hb_script_t script that corresponds to the
57 * specified GUnicodeScript identifier.
59 * Return value: the #hb_script_t script found
64 hb_glib_script_to_script (GUnicodeScript script)
66 return (hb_script_t) g_unicode_script_to_iso15924 (script);
70 * hb_glib_script_from_script:
71 * @script: The #hb_script_t to query
73 * Fetches the GUnicodeScript identifier that corresponds to the
74 * specified #hb_script_t script.
76 * Return value: the GUnicodeScript identifier found
81 hb_glib_script_from_script (hb_script_t script)
83 return g_unicode_script_from_iso15924 (script);
87 static hb_unicode_combining_class_t
88 hb_glib_unicode_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED,
89 hb_codepoint_t unicode,
90 void *user_data HB_UNUSED)
93 return (hb_unicode_combining_class_t) g_unichar_combining_class (unicode);
96 static hb_unicode_general_category_t
97 hb_glib_unicode_general_category (hb_unicode_funcs_t *ufuncs HB_UNUSED,
98 hb_codepoint_t unicode,
99 void *user_data HB_UNUSED)
102 /* hb_unicode_general_category_t and GUnicodeType are identical */
103 return (hb_unicode_general_category_t) g_unichar_type (unicode);
106 static hb_codepoint_t
107 hb_glib_unicode_mirroring (hb_unicode_funcs_t *ufuncs HB_UNUSED,
108 hb_codepoint_t unicode,
109 void *user_data HB_UNUSED)
111 g_unichar_get_mirror_char (unicode, &unicode);
116 hb_glib_unicode_script (hb_unicode_funcs_t *ufuncs HB_UNUSED,
117 hb_codepoint_t unicode,
118 void *user_data HB_UNUSED)
120 return hb_glib_script_to_script (g_unichar_get_script (unicode));
124 hb_glib_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
128 void *user_data HB_UNUSED)
130 #if GLIB_CHECK_VERSION(2,29,12)
131 return g_unichar_compose (a, b, ab);
138 hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
142 void *user_data HB_UNUSED)
144 #if GLIB_CHECK_VERSION(2,29,12)
145 return g_unichar_decompose (ab, a, b);
152 static inline void free_static_glib_funcs ();
154 static struct hb_glib_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_t<hb_glib_unicode_funcs_lazy_loader_t>
156 static hb_unicode_funcs_t *create ()
158 hb_unicode_funcs_t *funcs = hb_unicode_funcs_create (nullptr);
160 hb_unicode_funcs_set_combining_class_func (funcs, hb_glib_unicode_combining_class, nullptr, nullptr);
161 hb_unicode_funcs_set_general_category_func (funcs, hb_glib_unicode_general_category, nullptr, nullptr);
162 hb_unicode_funcs_set_mirroring_func (funcs, hb_glib_unicode_mirroring, nullptr, nullptr);
163 hb_unicode_funcs_set_script_func (funcs, hb_glib_unicode_script, nullptr, nullptr);
164 hb_unicode_funcs_set_compose_func (funcs, hb_glib_unicode_compose, nullptr, nullptr);
165 hb_unicode_funcs_set_decompose_func (funcs, hb_glib_unicode_decompose, nullptr, nullptr);
167 hb_unicode_funcs_make_immutable (funcs);
169 hb_atexit (free_static_glib_funcs);
176 void free_static_glib_funcs ()
178 static_glib_funcs.free_instance ();
182 * hb_glib_get_unicode_funcs:
184 * Fetches a Unicode-functions structure that is populated
185 * with the appropriate GLib function for each method.
187 * Return value: (transfer none): a pointer to the #hb_unicode_funcs_t Unicode-functions structure
192 hb_glib_get_unicode_funcs ()
194 return static_glib_funcs.get_unconst ();
199 #if GLIB_CHECK_VERSION(2,31,10)
202 _hb_g_bytes_unref (void *data)
204 g_bytes_unref ((GBytes *) data);
208 * hb_glib_blob_create:
209 * @gbytes: the GBytes structure to work upon
211 * Creates an #hb_blob_t blob from the specified
212 * GBytes data structure.
214 * Return value: (transfer full): the new #hb_blob_t blob object
219 hb_glib_blob_create (GBytes *gbytes)
222 gconstpointer data = g_bytes_get_data (gbytes, &size);
223 return hb_blob_create ((const char *) data,
225 HB_MEMORY_MODE_READONLY,
226 g_bytes_ref (gbytes),