3 Port from c++ is protected by a GNU Lesser GPLv3
4 Copyright © 2013 Sylvain BERTRAND <sylvain.bertrand@gmail.com>
8 #include "hb-private.h"
9 #include "hb-atomic-private.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
*
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
*
51 hb_codepoint_t unicode
,
52 void *user_data HB_UNUSED
)
54 g_unichar_get_mirror_char(unicode
, &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
,
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
,
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
*
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 */
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
},
109 NULL
, /*combining_class */
110 NULL
, /*eastasian_width */
111 NULL
, /*general_category */
116 NULL
/*decompose_compatibility */
119 NULL
, /*combining_class */
120 NULL
, /*eastasian_width */
121 NULL
, /*general_category */
126 NULL
/*decompose_compatibility */
130 hb_unicode_funcs_t
*hb_glib_get_unicode_funcs(void)
132 return &hb_glib_unicode_funcs
;