From 7470315a3e782aa6192bbe64f7a3944266fb1521 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 1 Aug 2012 17:01:59 -0400 Subject: [PATCH] Move unicode accessors around --- src/hb-unicode-private.hh | 73 ++++++++++++++++++++++++++++++++++++++++++++++- src/hb-unicode.cc | 65 ++++------------------------------------- 2 files changed, 78 insertions(+), 60 deletions(-) diff --git a/src/hb-unicode-private.hh b/src/hb-unicode-private.hh index 6ec0a76..9185392 100644 --- a/src/hb-unicode-private.hh +++ b/src/hb-unicode-private.hh @@ -70,7 +70,78 @@ struct hb_unicode_funcs_t { bool immutable; - /* Don't access these directly. Call hb_unicode_*() instead. */ +#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ + inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); } +HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE +#undef HB_UNICODE_FUNC_IMPLEMENT + + inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b, + hb_codepoint_t *ab) + { + *ab = 0; + /* XXX, this belongs to indic normalizer. */ + if ((FLAG (general_category (a)) & + (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | + FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | + FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))) + return false; + /* XXX, add composition-exclusion exceptions to Indic shaper. */ + if (a == 0x09AF && b == 0x09BC) { *ab = 0x09DF; return true; } + return func.compose (this, a, b, ab, user_data.compose); + } + + inline hb_bool_t decompose (hb_codepoint_t ab, + hb_codepoint_t *a, hb_codepoint_t *b) + { + /* XXX FIXME, move these to complex shapers and propagage to normalizer.*/ + switch (ab) { + case 0x0AC9 : return false; + + case 0x0931 : return false; + case 0x0B94 : return false; + + /* These ones have Unicode decompositions, but we do it + * this way to be close to what Uniscribe does. */ + case 0x0DDA : *a = 0x0DD9; *b= 0x0DDA; return true; + case 0x0DDC : *a = 0x0DD9; *b= 0x0DDC; return true; + case 0x0DDD : *a = 0x0DD9; *b= 0x0DDD; return true; + case 0x0DDE : *a = 0x0DD9; *b= 0x0DDE; return true; + + case 0x0F77 : *a = 0x0FB2; *b= 0x0F81; return true; + case 0x0F79 : *a = 0x0FB3; *b= 0x0F81; return true; + case 0x17BE : *a = 0x17C1; *b= 0x17BE; return true; + case 0x17BF : *a = 0x17C1; *b= 0x17BF; return true; + case 0x17C0 : *a = 0x17C1; *b= 0x17C0; return true; + case 0x17C4 : *a = 0x17C1; *b= 0x17C4; return true; + case 0x17C5 : *a = 0x17C1; *b= 0x17C5; return true; + case 0x1925 : *a = 0x1920; *b= 0x1923; return true; + case 0x1926 : *a = 0x1920; *b= 0x1924; return true; + case 0x1B3C : *a = 0x1B42; *b= 0x1B3C; return true; + case 0x1112E : *a = 0x11127; *b= 0x11131; return true; + case 0x1112F : *a = 0x11127; *b= 0x11132; return true; +#if 0 + case 0x0B57 : *a = 0xno decomp, -> RIGHT; return true; + case 0x1C29 : *a = 0xno decomp, -> LEFT; return true; + case 0xA9C0 : *a = 0xno decomp, -> RIGHT; return true; + case 0x111BF : *a = 0xno decomp, -> ABOVE; return true; +#endif + } + *a = ab; *b = 0; + return func.decompose (this, ab, a, b, user_data.decompose); + } + + inline unsigned int decompose_compatibility (hb_codepoint_t u, + hb_codepoint_t *decomposed) + { + unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_data.decompose_compatibility); + if (ret == 1 && u == decomposed[0]) { + decomposed[0] = 0; + return 0; + } + decomposed[ret] = 0; + return ret; + } + struct { #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name; diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc index 288edf7..a94ea16 100644 --- a/src/hb-unicode.cc +++ b/src/hb-unicode.cc @@ -245,7 +245,7 @@ hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \ } \ } - HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS #undef HB_UNICODE_FUNC_IMPLEMENT @@ -255,9 +255,9 @@ return_type \ hb_unicode_##name (hb_unicode_funcs_t *ufuncs, \ hb_codepoint_t unicode) \ { \ - return ufuncs->func.name (ufuncs, unicode, ufuncs->user_data.name); \ + return ufuncs->name (unicode); \ } - HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE +HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE #undef HB_UNICODE_FUNC_IMPLEMENT hb_bool_t @@ -266,16 +266,7 @@ hb_unicode_compose (hb_unicode_funcs_t *ufuncs, hb_codepoint_t b, hb_codepoint_t *ab) { - *ab = 0; - /* XXX, this belongs to indic normalizer. */ - if ((FLAG (hb_unicode_general_category (ufuncs, a)) & - (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | - FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | - FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))) - return false; - /* XXX, add composition-exclusion exceptions to Indic shaper. */ - if (a == 0x09AF && b == 0x09BC) { *ab = 0x09DF; return true; } - return ufuncs->func.compose (ufuncs, a, b, ab, ufuncs->user_data.compose); + return ufuncs->compose (a, b, ab); } hb_bool_t @@ -284,41 +275,7 @@ hb_unicode_decompose (hb_unicode_funcs_t *ufuncs, hb_codepoint_t *a, hb_codepoint_t *b) { - /* XXX FIXME, move these to complex shapers and propagage to normalizer.*/ - switch (ab) { - case 0x0AC9 : return false; - - case 0x0931 : return false; - case 0x0B94 : return false; - - /* These ones have Unicode decompositions, but we do it - * this way to be close to what Uniscribe does. */ - case 0x0DDA : *a = 0x0DD9; *b= 0x0DDA; return true; - case 0x0DDC : *a = 0x0DD9; *b= 0x0DDC; return true; - case 0x0DDD : *a = 0x0DD9; *b= 0x0DDD; return true; - case 0x0DDE : *a = 0x0DD9; *b= 0x0DDE; return true; - - case 0x0F77 : *a = 0x0FB2; *b= 0x0F81; return true; - case 0x0F79 : *a = 0x0FB3; *b= 0x0F81; return true; - case 0x17BE : *a = 0x17C1; *b= 0x17BE; return true; - case 0x17BF : *a = 0x17C1; *b= 0x17BF; return true; - case 0x17C0 : *a = 0x17C1; *b= 0x17C0; return true; - case 0x17C4 : *a = 0x17C1; *b= 0x17C4; return true; - case 0x17C5 : *a = 0x17C1; *b= 0x17C5; return true; - case 0x1925 : *a = 0x1920; *b= 0x1923; return true; - case 0x1926 : *a = 0x1920; *b= 0x1924; return true; - case 0x1B3C : *a = 0x1B42; *b= 0x1B3C; return true; - case 0x1112E : *a = 0x11127; *b= 0x11131; return true; - case 0x1112F : *a = 0x11127; *b= 0x11132; return true; -#if 0 - case 0x0B57 : *a = 0xno decomp, -> RIGHT; return true; - case 0x1C29 : *a = 0xno decomp, -> LEFT; return true; - case 0xA9C0 : *a = 0xno decomp, -> RIGHT; return true; - case 0x111BF : *a = 0xno decomp, -> ABOVE; return true; -#endif - } - *a = ab; *b = 0; - return ufuncs->func.decompose (ufuncs, ab, a, b, ufuncs->user_data.decompose); + return ufuncs->decompose (ab, a, b); } unsigned int @@ -326,17 +283,7 @@ hb_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs, hb_codepoint_t u, hb_codepoint_t *decomposed) { - unsigned int ret = ufuncs->func.decompose_compatibility (ufuncs, u, - decomposed, - ufuncs->user_data.decompose_compatibility); - if (ret == 1 && u == decomposed[0]) { - decomposed[0] = 0; - return 0; - } - - decomposed[ret] = 0; - - return ret; + return ufuncs->decompose_compatibility (u, decomposed); } -- 2.7.4