Initial commit
[charfbuzz.git] / hb-glib.c
blob91eaa7075c5f9fe797de93912301d2e03d6b7248
1 // C99 port from c++ is protected by a GNU Lesser GPLv3
2 // Copyright © 2013 Sylvain BERTRAND <sylvain.bertrand@gmail.com>
3 // <sylware@legeek.net>
4 #include "hb.h"
5 #include "hb-private.h"
6 #include "hb-atomic-private.h"
7 #include "hb-glib.h"
8 #include "hb-unicode-private.h"
10 GUnicodeScript
11 hb_glib_script_from_script(hb_script_t script)
13 return g_unicode_script_from_iso15924(script);
16 hb_script_t
17 hb_glib_script_to_script(GUnicodeScript script)
19 return (hb_script_t)g_unicode_script_to_iso15924(script);
22 static hb_unicode_combining_class_t
23 hb_glib_unicode_combining_class(hb_unicode_funcs_t *ufuncs HB_UNUSED,
24 hb_codepoint_t unicode,
25 void *user_data HB_UNUSED)
28 return (hb_unicode_combining_class_t)g_unichar_combining_class(unicode);
31 static unsigned int
32 hb_glib_unicode_eastasian_width(hb_unicode_funcs_t *ufuncs HB_UNUSED,
33 hb_codepoint_t unicode,
34 void *user_data HB_UNUSED)
36 return g_unichar_iswide(unicode) ? 2 : 1;
39 static hb_unicode_general_category_t
40 hb_glib_unicode_general_category(hb_unicode_funcs_t *ufuncs HB_UNUSED,
41 hb_codepoint_t unicode,
42 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
50 hb_glib_unicode_mirroring(hb_unicode_funcs_t *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
59 hb_glib_unicode_script(hb_unicode_funcs_t *ufuncs HB_UNUSED,
60 hb_codepoint_t unicode,
61 void *user_data HB_UNUSED)
63 return hb_glib_script_to_script(g_unichar_get_script(unicode));
66 static hb_bool_t
67 hb_glib_unicode_compose(hb_unicode_funcs_t *ufuncs HB_UNUSED,
68 hb_codepoint_t a,
69 hb_codepoint_t b,
70 hb_codepoint_t *ab,
71 void *user_data HB_UNUSED)
73 return g_unichar_compose(a, b, ab);
76 static hb_bool_t
77 hb_glib_unicode_decompose(hb_unicode_funcs_t *ufuncs HB_UNUSED,
78 hb_codepoint_t ab,
79 hb_codepoint_t *a,
80 hb_codepoint_t *b,
81 void *user_data HB_UNUSED)
83 return g_unichar_decompose(ab, a, b);
86 static unsigned int
87 hb_glib_unicode_decompose_compatibility(hb_unicode_funcs_t *ufuncs HB_UNUSED,
88 hb_codepoint_t u,
89 hb_codepoint_t *decomposed,
90 void *user_data HB_UNUSED)
92 return g_unichar_fully_decompose(u,
93 TRUE,
94 decomposed,
95 HB_UNICODE_MAX_DECOMPOSITION_LEN);
98 static hb_unicode_funcs_t hb_glib_unicode_funcs = {
99 REF_CNT_INVALID_VAL,//ref_cnt
100 NULL,//parent
101 TRUE,//immutable
102 {//func
103 hb_glib_unicode_combining_class,
104 hb_glib_unicode_eastasian_width,
105 hb_glib_unicode_general_category,
106 hb_glib_unicode_mirroring,
107 hb_glib_unicode_script,
108 hb_glib_unicode_compose,
109 hb_glib_unicode_decompose,
110 hb_glib_unicode_decompose_compatibility
112 {//user_data
113 NULL,//combining_class
114 NULL,//eastasian_width
115 NULL,//general_category
116 NULL,//mirroring
117 NULL,//script
118 NULL,//compose
119 NULL,//decompose
120 NULL//decompose_compatibility
122 {//destroy
123 NULL,//combining_class
124 NULL,//eastasian_width
125 NULL,//general_category
126 NULL,//mirroring
127 NULL,//script
128 NULL,//compose
129 NULL,//decompose
130 NULL//decompose_compatibility
134 hb_unicode_funcs_t *
135 hb_glib_get_unicode_funcs(void)
137 return &hb_glib_unicode_funcs;