OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2009 Red Hat, Inc. | 2 * Copyright © 2009 Red Hat, Inc. |
3 * Copyright © 2011 Google, Inc. | 3 * Copyright © 2011 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return (GUnicodeScript) i; | 185 return (GUnicodeScript) i; |
186 | 186 |
187 if (unlikely (script == HB_SCRIPT_INVALID)) | 187 if (unlikely (script == HB_SCRIPT_INVALID)) |
188 return G_UNICODE_SCRIPT_INVALID_CODE; | 188 return G_UNICODE_SCRIPT_INVALID_CODE; |
189 | 189 |
190 return G_UNICODE_SCRIPT_UNKNOWN; | 190 return G_UNICODE_SCRIPT_UNKNOWN; |
191 #endif | 191 #endif |
192 } | 192 } |
193 | 193 |
194 | 194 |
195 static unsigned int | 195 static hb_unicode_combining_class_t |
196 hb_glib_unicode_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED, | 196 hb_glib_unicode_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED, |
197 hb_codepoint_t unicode, | 197 hb_codepoint_t unicode, |
198 void *user_data HB_UNUSED) | 198 void *user_data HB_UNUSED) |
199 | 199 |
200 { | 200 { |
201 return g_unichar_combining_class (unicode); | 201 return (hb_unicode_combining_class_t) g_unichar_combining_class (unicode); |
202 } | 202 } |
203 | 203 |
204 static unsigned int | 204 static unsigned int |
205 hb_glib_unicode_eastasian_width (hb_unicode_funcs_t *ufuncs HB_UNUSED, | 205 hb_glib_unicode_eastasian_width (hb_unicode_funcs_t *ufuncs HB_UNUSED, |
206 hb_codepoint_t unicode, | 206 hb_codepoint_t unicode, |
207 void *user_data HB_UNUSED) | 207 void *user_data HB_UNUSED) |
208 { | 208 { |
209 return g_unichar_iswide (unicode) ? 2 : 1; | 209 return g_unichar_iswide (unicode) ? 2 : 1; |
210 } | 210 } |
211 | 211 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 hb_codepoint_t *ab, | 243 hb_codepoint_t *ab, |
244 void *user_data HB_UNUSED) | 244 void *user_data HB_UNUSED) |
245 { | 245 { |
246 #if GLIB_CHECK_VERSION(2,29,12) | 246 #if GLIB_CHECK_VERSION(2,29,12) |
247 return g_unichar_compose (a, b, ab); | 247 return g_unichar_compose (a, b, ab); |
248 #endif | 248 #endif |
249 | 249 |
250 /* We don't ifdef-out the fallback code such that compiler always | 250 /* We don't ifdef-out the fallback code such that compiler always |
251 * sees it and makes sure it's compilable. */ | 251 * sees it and makes sure it's compilable. */ |
252 | 252 |
253 if (!a || !b) | |
254 return false; | |
255 | |
256 gchar utf8[12]; | 253 gchar utf8[12]; |
257 gchar *normalized; | 254 gchar *normalized; |
258 gint len; | 255 int len; |
259 hb_bool_t ret; | 256 hb_bool_t ret; |
260 | 257 |
261 len = g_unichar_to_utf8 (a, utf8); | 258 len = g_unichar_to_utf8 (a, utf8); |
262 len += g_unichar_to_utf8 (b, utf8 + len); | 259 len += g_unichar_to_utf8 (b, utf8 + len); |
263 normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFC); | 260 normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFC); |
264 len = g_utf8_strlen (normalized, -1); | 261 len = g_utf8_strlen (normalized, -1); |
265 if (unlikely (!len)) | 262 if (unlikely (!len)) |
266 return false; | 263 return false; |
267 | 264 |
268 if (len == 1) { | 265 if (len == 1) { |
(...skipping 16 matching lines...) Expand all Loading... |
285 { | 282 { |
286 #if GLIB_CHECK_VERSION(2,29,12) | 283 #if GLIB_CHECK_VERSION(2,29,12) |
287 return g_unichar_decompose (ab, a, b); | 284 return g_unichar_decompose (ab, a, b); |
288 #endif | 285 #endif |
289 | 286 |
290 /* We don't ifdef-out the fallback code such that compiler always | 287 /* We don't ifdef-out the fallback code such that compiler always |
291 * sees it and makes sure it's compilable. */ | 288 * sees it and makes sure it's compilable. */ |
292 | 289 |
293 gchar utf8[6]; | 290 gchar utf8[6]; |
294 gchar *normalized; | 291 gchar *normalized; |
295 gint len; | 292 int len; |
296 hb_bool_t ret; | 293 hb_bool_t ret; |
297 | 294 |
298 len = g_unichar_to_utf8 (ab, utf8); | 295 len = g_unichar_to_utf8 (ab, utf8); |
299 normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFD); | 296 normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFD); |
300 len = g_utf8_strlen (normalized, -1); | 297 len = g_utf8_strlen (normalized, -1); |
301 if (unlikely (!len)) | 298 if (unlikely (!len)) |
302 return false; | 299 return false; |
303 | 300 |
304 if (len == 1) { | 301 if (len == 1) { |
305 *a = g_utf8_get_char (normalized); | 302 *a = g_utf8_get_char (normalized); |
(...skipping 23 matching lines...) Expand all Loading... |
329 /* We expect that recomposed has exactly one character now. */ | 326 /* We expect that recomposed has exactly one character now. */ |
330 *a = g_utf8_get_char (recomposed); | 327 *a = g_utf8_get_char (recomposed); |
331 g_free (recomposed); | 328 g_free (recomposed); |
332 ret = true; | 329 ret = true; |
333 } | 330 } |
334 | 331 |
335 g_free (normalized); | 332 g_free (normalized); |
336 return ret; | 333 return ret; |
337 } | 334 } |
338 | 335 |
| 336 static unsigned int |
| 337 hb_glib_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs, |
| 338 hb_codepoint_t u, |
| 339 hb_codepoint_t *decomposed, |
| 340 void *user_data HB_UNUSED
) |
| 341 { |
| 342 #if GLIB_CHECK_VERSION(2,29,12) |
| 343 return g_unichar_fully_decompose (u, TRUE, decomposed, HB_UNICODE_MAX_DECOMPOS
ITION_LEN); |
| 344 #endif |
339 | 345 |
340 extern HB_INTERNAL const hb_unicode_funcs_t _hb_glib_unicode_funcs; | 346 /* If the user doesn't have GLib >= 2.29.12 we have to perform |
341 const hb_unicode_funcs_t _hb_glib_unicode_funcs = { | 347 * a round trip to UTF-8 and the associated memory management dance. */ |
342 HB_OBJECT_HEADER_STATIC, | 348 gchar utf8[6]; |
| 349 gchar *utf8_decomposed, *c; |
| 350 gsize utf8_len, utf8_decomposed_len, i; |
343 | 351 |
344 NULL, /* parent */ | 352 /* Convert @u to UTF-8 and normalise it in NFKD mode. This performs the compat
ibility decomposition. */ |
345 true, /* immutable */ | 353 utf8_len = g_unichar_to_utf8 (u, utf8); |
346 { | 354 utf8_decomposed = g_utf8_normalize (utf8, utf8_len, G_NORMALIZE_NFKD); |
347 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_glib_unicode_##name, | 355 utf8_decomposed_len = g_utf8_strlen (utf8_decomposed, -1); |
348 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS | 356 |
349 #undef HB_UNICODE_FUNC_IMPLEMENT | 357 assert (utf8_decomposed_len <= HB_UNICODE_MAX_DECOMPOSITION_LEN); |
350 } | 358 |
351 }; | 359 for (i = 0, c = utf8_decomposed; i < utf8_decomposed_len; i++, c = g_utf8_next
_char (c)) |
| 360 *decomposed++ = g_utf8_get_char (c); |
| 361 |
| 362 g_free (utf8_decomposed); |
| 363 |
| 364 return utf8_decomposed_len; |
| 365 } |
352 | 366 |
353 hb_unicode_funcs_t * | 367 hb_unicode_funcs_t * |
354 hb_glib_get_unicode_funcs (void) | 368 hb_glib_get_unicode_funcs (void) |
355 { | 369 { |
| 370 static const hb_unicode_funcs_t _hb_glib_unicode_funcs = { |
| 371 HB_OBJECT_HEADER_STATIC, |
| 372 |
| 373 NULL, /* parent */ |
| 374 true, /* immutable */ |
| 375 { |
| 376 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_glib_unicode_##name, |
| 377 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS |
| 378 #undef HB_UNICODE_FUNC_IMPLEMENT |
| 379 } |
| 380 }; |
| 381 |
356 return const_cast<hb_unicode_funcs_t *> (&_hb_glib_unicode_funcs); | 382 return const_cast<hb_unicode_funcs_t *> (&_hb_glib_unicode_funcs); |
357 } | 383 } |
358 | 384 |
OLD | NEW |