michael@0: /* michael@0: * Copyright © 2009 Red Hat, Inc. michael@0: * Copyright © 2011 Codethink Limited michael@0: * Copyright © 2010,2011,2012 Google, Inc. michael@0: * michael@0: * This is part of HarfBuzz, a text shaping library. michael@0: * michael@0: * Permission is hereby granted, without written agreement and without michael@0: * license or royalty fees, to use, copy, modify, and distribute this michael@0: * software and its documentation for any purpose, provided that the michael@0: * above copyright notice and the following two paragraphs appear in michael@0: * all copies of this software. michael@0: * michael@0: * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR michael@0: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES michael@0: * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN michael@0: * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH michael@0: * DAMAGE. michael@0: * michael@0: * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, michael@0: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS michael@0: * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO michael@0: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. michael@0: * michael@0: * Red Hat Author(s): Behdad Esfahbod michael@0: * Codethink Author(s): Ryan Lortie michael@0: * Google Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #ifndef HB_UNICODE_PRIVATE_HH michael@0: #define HB_UNICODE_PRIVATE_HH michael@0: michael@0: #include "hb-private.hh" michael@0: #include "hb-object-private.hh" michael@0: michael@0: michael@0: extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256]; michael@0: michael@0: /* michael@0: * hb_unicode_funcs_t michael@0: */ michael@0: michael@0: #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (combining_class) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (general_category) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (mirroring) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (script) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (compose) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (decompose) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (decompose_compatibility) \ michael@0: /* ^--- Add new callbacks here */ michael@0: michael@0: /* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoint_t */ michael@0: #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_combining_class_t, combining_class) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \ michael@0: HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \ michael@0: /* ^--- Add new simple callbacks here */ michael@0: michael@0: struct hb_unicode_funcs_t { michael@0: hb_object_header_t header; michael@0: ASSERT_POD (); michael@0: michael@0: hb_unicode_funcs_t *parent; michael@0: michael@0: bool immutable; michael@0: michael@0: #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ michael@0: inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); } michael@0: HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE michael@0: #undef HB_UNICODE_FUNC_IMPLEMENT michael@0: michael@0: inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b, michael@0: hb_codepoint_t *ab) michael@0: { michael@0: *ab = 0; michael@0: if (unlikely (!a || !b)) return false; michael@0: return func.compose (this, a, b, ab, user_data.compose); michael@0: } michael@0: michael@0: inline hb_bool_t decompose (hb_codepoint_t ab, michael@0: hb_codepoint_t *a, hb_codepoint_t *b) michael@0: { michael@0: *a = ab; *b = 0; michael@0: return func.decompose (this, ab, a, b, user_data.decompose); michael@0: } michael@0: michael@0: inline unsigned int decompose_compatibility (hb_codepoint_t u, michael@0: hb_codepoint_t *decomposed) michael@0: { michael@0: unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_data.decompose_compatibility); michael@0: if (ret == 1 && u == decomposed[0]) { michael@0: decomposed[0] = 0; michael@0: return 0; michael@0: } michael@0: decomposed[ret] = 0; michael@0: return ret; michael@0: } michael@0: michael@0: michael@0: unsigned int michael@0: modified_combining_class (hb_codepoint_t unicode) michael@0: { michael@0: /* XXX This hack belongs to the Myanmar shaper. */ michael@0: if (unlikely (unicode == 0x1037)) unicode = 0x103A; michael@0: michael@0: /* XXX This hack belongs to the SEA shaper (for Tai Tham): michael@0: * Reorder SAKOT to ensure it comes after any tone marks. */ michael@0: if (unlikely (unicode == 0x1A60)) return 254; michael@0: michael@0: return _hb_modified_combining_class[combining_class (unicode)]; michael@0: } michael@0: michael@0: inline hb_bool_t michael@0: is_variation_selector (hb_codepoint_t unicode) michael@0: { michael@0: return unlikely (hb_in_ranges (unicode, michael@0: 0x180B, 0x180D, /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */ michael@0: 0xFE00, 0xFE0F, /* VARIATION SELECTOR-1..16 */ michael@0: 0xE0100, 0xE01EF)); /* VARIATION SELECTOR-17..256 */ michael@0: } michael@0: michael@0: /* Default_Ignorable codepoints: michael@0: * michael@0: * Note that as of Oct 2012 (Unicode 6.2), U+180E MONGOLIAN VOWEL SEPARATOR michael@0: * is NOT Default_Ignorable, but it really behaves in a way that it should michael@0: * be. That has been reported to the Unicode Technical Committee for michael@0: * consideration. As such, we include it here, since Uniscribe removes it. michael@0: * It *is* in Unicode 6.3 however. U+061C ARABIC LETTER MARK from Unicode michael@0: * 6.3 is also added manually. The new Unicode 6.3 bidi formatting michael@0: * characters are encoded in a block that was Default_Ignorable already. michael@0: * michael@0: * Note: While U+115F, U+1160, U+3164 and U+FFA0 are Default_Ignorable, michael@0: * we do NOT want to hide them, as the way Uniscribe has implemented them michael@0: * is with regular spacing glyphs, and that's the way fonts are made to work. michael@0: * As such, we make exceptions for those four. michael@0: * michael@0: * Gathered from: michael@0: * http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:DI:]&abb=on&ucd=on&esc=on michael@0: * michael@0: * Last updated to the page with the following versions: michael@0: * Version 3.6; ICU version: 50.0.1.0; Unicode version: 6.1.0.0 michael@0: * michael@0: * 4,167 Code Points michael@0: * michael@0: * [\u00AD\u034F\u115F\u1160\u17B4\u17B5\u180B-\u180D\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8\U0001D173-\U0001D17A\U000E0000-\U000E0FFF] michael@0: * michael@0: * 00AD ;SOFT HYPHEN michael@0: * 034F ;COMBINING GRAPHEME JOINER michael@0: * #115F ;HANGUL CHOSEONG FILLER michael@0: * #1160 ;HANGUL JUNGSEONG FILLER michael@0: * 17B4 ;KHMER VOWEL INHERENT AQ michael@0: * 17B5 ;KHMER VOWEL INHERENT AA michael@0: * 180B..180D ;MONGOLIAN FREE VARIATION SELECTOR THREE michael@0: * 200B..200F ;RIGHT-TO-LEFT MARK michael@0: * 202A..202E ;RIGHT-TO-LEFT OVERRIDE michael@0: * 2060..206F ;NOMINAL DIGIT SHAPES michael@0: * #3164 ;HANGUL FILLER michael@0: * FE00..FE0F ;VARIATION SELECTOR-16 michael@0: * FEFF ;ZERO WIDTH NO-BREAK SPACE michael@0: * #FFA0 ;HALFWIDTH HANGUL FILLER michael@0: * FFF0..FFF8 ; michael@0: * 1D173..1D17A ;MUSICAL SYMBOL END PHRASE michael@0: * E0000..E0FFF ; michael@0: */ michael@0: inline hb_bool_t michael@0: is_default_ignorable (hb_codepoint_t ch) michael@0: { michael@0: hb_codepoint_t plane = ch >> 16; michael@0: if (likely (plane == 0)) michael@0: { michael@0: /* BMP */ michael@0: hb_codepoint_t page = ch >> 8; michael@0: switch (page) { michael@0: case 0x00: return unlikely (ch == 0x00AD); michael@0: case 0x03: return unlikely (ch == 0x034F); michael@0: case 0x06: return unlikely (ch == 0x061C); michael@0: case 0x17: return hb_in_range (ch, 0x17B4, 0x17B5); michael@0: case 0x18: return hb_in_range (ch, 0x180B, 0x180E); michael@0: case 0x20: return hb_in_ranges (ch, 0x200B, 0x200F, michael@0: 0x202A, 0x202E, michael@0: 0x2060, 0x206F); michael@0: case 0xFE: return hb_in_range (ch, 0xFE00, 0xFE0F) || ch == 0xFEFF; michael@0: case 0xFF: return hb_in_range (ch, 0xFFF0, 0xFFF8); michael@0: default: return false; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: /* Other planes */ michael@0: switch (plane) { michael@0: case 0x01: return hb_in_range (ch, 0x0001D173, 0x0001D17A); michael@0: case 0x0E: return hb_in_range (ch, 0x000E0000, 0x000E0FFF); michael@0: default: return false; michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: struct { michael@0: #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name; michael@0: HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS michael@0: #undef HB_UNICODE_FUNC_IMPLEMENT michael@0: } func; michael@0: michael@0: struct { michael@0: #define HB_UNICODE_FUNC_IMPLEMENT(name) void *name; michael@0: HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS michael@0: #undef HB_UNICODE_FUNC_IMPLEMENT michael@0: } user_data; michael@0: michael@0: struct { michael@0: #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name; michael@0: HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS michael@0: #undef HB_UNICODE_FUNC_IMPLEMENT michael@0: } destroy; michael@0: }; michael@0: michael@0: michael@0: extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil; michael@0: michael@0: michael@0: /* Modified combining marks */ michael@0: michael@0: /* Hebrew michael@0: * michael@0: * We permute the "fixed-position" classes 10-26 into the order michael@0: * described in the SBL Hebrew manual: michael@0: * michael@0: * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf michael@0: * michael@0: * (as recommended by: michael@0: * http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html) michael@0: * michael@0: * More details here: michael@0: * https://bugzilla.mozilla.org/show_bug.cgi?id=662055 michael@0: */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */ michael@0: michael@0: /* michael@0: * Arabic michael@0: * michael@0: * Modify to move Shadda (ccc=33) before other marks. See: michael@0: * http://unicode.org/faq/normalization.html#8 michael@0: * http://unicode.org/faq/normalization.html#9 michael@0: */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */ michael@0: michael@0: /* Syriac */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */ michael@0: michael@0: /* Telugu michael@0: * michael@0: * Modify Telugu length marks (ccc=84, ccc=91). michael@0: * These are the only matras in the main Indic scripts range that have michael@0: * a non-zero ccc. That makes them reorder with the Halant that is michael@0: * ccc=9. Just zero them, we don't need them in our Indic shaper. michael@0: */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */ michael@0: michael@0: /* Thai michael@0: * michael@0: * Modify U+0E38 and U+0E39 (ccc=103) to be reordered before U+0E3A (ccc=9). michael@0: * Assign 3, which is unassigned otherwise. michael@0: * Uniscribe does this reordering too. michael@0: */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */ michael@0: michael@0: /* Lao */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */ michael@0: michael@0: /* Tibetan */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */ michael@0: #define HB_MODIFIED_COMBINING_CLASS_CCC132 132 /* sign u */ michael@0: michael@0: michael@0: /* Misc */ michael@0: michael@0: #define HB_UNICODE_GENERAL_CATEGORY_IS_MARK(gen_cat) \ michael@0: (FLAG (gen_cat) & \ michael@0: (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | \ michael@0: FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | \ michael@0: FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))) michael@0: michael@0: michael@0: #endif /* HB_UNICODE_PRIVATE_HH */