add explicit freetype2 linking
[charfbuzz.git] / hb-glib.c
blob1468f247a5f2d3c48a0de2a9a9156e17fe4521dc
1 #ifdef HAVE_GLIB
2 /*
3 Port from c++ is protected by a GNU Lesser GPLv3
4 Copyright © 2013 Sylvain BERTRAND <sylvain.bertrand@gmail.com>
5 <sylware@legeek.net>
6 */
7 #include "hb.h"
8 #include "hb-private.h"
9 #include "hb-atomic-private.h"
10 #include "hb-glib.h"
11 #include "hb-unicode-private.h"
13 GUnicodeScript hb_glib_script_from_script(hb_script_t script)
15 return g_unicode_script_from_iso15924(script);
18 hb_script_t hb_glib_script_to_script(GUnicodeScript script)
20 return (hb_script_t) g_unicode_script_to_iso15924(script);
23 static hb_unicode_combining_class_t
24 hb_glib_unicode_combining_class(hb_unicode_funcs_t * ufuncs HB_UNUSED,
25 hb_codepoint_t unicode,
26 void *user_data HB_UNUSED)
28 return (hb_unicode_combining_class_t)
29 g_unichar_combining_class(unicode);
32 static unsigned int hb_glib_unicode_eastasian_width(hb_unicode_funcs_t *
33 ufuncs HB_UNUSED,
34 hb_codepoint_t unicode,
35 void *user_data HB_UNUSED)
37 return g_unichar_iswide(unicode) ? 2 : 1;
40 static hb_unicode_general_category_t
41 hb_glib_unicode_general_category(hb_unicode_funcs_t * ufuncs HB_UNUSED,
42 hb_codepoint_t unicode,
43 void *user_data HB_UNUSED)
45 /*hb_unicode_general_category_t and GUnicodeType are identical */
46 return (hb_unicode_general_category_t) g_unichar_type(unicode);
49 static hb_codepoint_t hb_glib_unicode_mirroring(hb_unicode_funcs_t *
50 ufuncs HB_UNUSED,
51 hb_codepoint_t unicode,
52 void *user_data HB_UNUSED)
54 g_unichar_get_mirror_char(unicode, &unicode);
55 return unicode;
58 static hb_script_t hb_glib_unicode_script(hb_unicode_funcs_t * ufuncs HB_UNUSED,
59 hb_codepoint_t unicode,
60 void *user_data HB_UNUSED)
62 return hb_glib_script_to_script(g_unichar_get_script(unicode));
65 static hb_bool_t hb_glib_unicode_compose(hb_unicode_funcs_t * ufuncs HB_UNUSED,
66 hb_codepoint_t a, hb_codepoint_t b,
67 hb_codepoint_t * ab,
68 void *user_data HB_UNUSED)
70 return g_unichar_compose(a, b, ab);
73 static hb_bool_t hb_glib_unicode_decompose(hb_unicode_funcs_t *
74 ufuncs HB_UNUSED, hb_codepoint_t ab,
75 hb_codepoint_t * a,
76 hb_codepoint_t * b,
77 void *user_data HB_UNUSED)
79 return g_unichar_decompose(ab, a, b);
82 static unsigned int hb_glib_unicode_decompose_compatibility(hb_unicode_funcs_t *
83 ufuncs HB_UNUSED,
84 hb_codepoint_t u,
85 hb_codepoint_t *
86 decomposed,
87 void *user_data
88 HB_UNUSED)
90 return g_unichar_fully_decompose(u, TRUE, decomposed,
91 HB_UNICODE_MAX_DECOMPOSITION_LEN);
94 /*XXX:should go in lib "global init"*/
95 static hb_unicode_funcs_t hb_glib_unicode_funcs = {
96 REF_CNT_INVALID_VAL, /*ref_cnt */
97 NULL, /*parent */
98 TRUE, /*immutable */
99 { /*func */
100 hb_glib_unicode_combining_class,
101 hb_glib_unicode_eastasian_width,
102 hb_glib_unicode_general_category,
103 hb_glib_unicode_mirroring,
104 hb_glib_unicode_script,
105 hb_glib_unicode_compose,
106 hb_glib_unicode_decompose,
107 hb_glib_unicode_decompose_compatibility},
108 { /*user_data */
109 NULL, /*combining_class */
110 NULL, /*eastasian_width */
111 NULL, /*general_category */
112 NULL, /*mirroring */
113 NULL, /*script */
114 NULL, /*compose */
115 NULL, /*decompose */
116 NULL /*decompose_compatibility */
118 { /*destroy */
119 NULL, /*combining_class */
120 NULL, /*eastasian_width */
121 NULL, /*general_category */
122 NULL, /*mirroring */
123 NULL, /*script */
124 NULL, /*compose */
125 NULL, /*decompose */
126 NULL /*decompose_compatibility */
130 hb_unicode_funcs_t *hb_glib_get_unicode_funcs(void)
132 return &hb_glib_unicode_funcs;
134 #endif