gfx/harfbuzz/src/hb-unicode-private.hh

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/harfbuzz/src/hb-unicode-private.hh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,318 @@
     1.4 +/*
     1.5 + * Copyright © 2009  Red Hat, Inc.
     1.6 + * Copyright © 2011  Codethink Limited
     1.7 + * Copyright © 2010,2011,2012  Google, Inc.
     1.8 + *
     1.9 + *  This is part of HarfBuzz, a text shaping library.
    1.10 + *
    1.11 + * Permission is hereby granted, without written agreement and without
    1.12 + * license or royalty fees, to use, copy, modify, and distribute this
    1.13 + * software and its documentation for any purpose, provided that the
    1.14 + * above copyright notice and the following two paragraphs appear in
    1.15 + * all copies of this software.
    1.16 + *
    1.17 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
    1.18 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
    1.19 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
    1.20 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
    1.21 + * DAMAGE.
    1.22 + *
    1.23 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
    1.24 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    1.25 + * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
    1.26 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
    1.27 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
    1.28 + *
    1.29 + * Red Hat Author(s): Behdad Esfahbod
    1.30 + * Codethink Author(s): Ryan Lortie
    1.31 + * Google Author(s): Behdad Esfahbod
    1.32 + */
    1.33 +
    1.34 +#ifndef HB_UNICODE_PRIVATE_HH
    1.35 +#define HB_UNICODE_PRIVATE_HH
    1.36 +
    1.37 +#include "hb-private.hh"
    1.38 +#include "hb-object-private.hh"
    1.39 +
    1.40 +
    1.41 +extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256];
    1.42 +
    1.43 +/*
    1.44 + * hb_unicode_funcs_t
    1.45 + */
    1.46 +
    1.47 +#define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \
    1.48 +  HB_UNICODE_FUNC_IMPLEMENT (combining_class) \
    1.49 +  HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \
    1.50 +  HB_UNICODE_FUNC_IMPLEMENT (general_category) \
    1.51 +  HB_UNICODE_FUNC_IMPLEMENT (mirroring) \
    1.52 +  HB_UNICODE_FUNC_IMPLEMENT (script) \
    1.53 +  HB_UNICODE_FUNC_IMPLEMENT (compose) \
    1.54 +  HB_UNICODE_FUNC_IMPLEMENT (decompose) \
    1.55 +  HB_UNICODE_FUNC_IMPLEMENT (decompose_compatibility) \
    1.56 +  /* ^--- Add new callbacks here */
    1.57 +
    1.58 +/* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoint_t */
    1.59 +#define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \
    1.60 +  HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_combining_class_t, combining_class) \
    1.61 +  HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \
    1.62 +  HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \
    1.63 +  HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \
    1.64 +  HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \
    1.65 +  /* ^--- Add new simple callbacks here */
    1.66 +
    1.67 +struct hb_unicode_funcs_t {
    1.68 +  hb_object_header_t header;
    1.69 +  ASSERT_POD ();
    1.70 +
    1.71 +  hb_unicode_funcs_t *parent;
    1.72 +
    1.73 +  bool immutable;
    1.74 +
    1.75 +#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \
    1.76 +  inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); }
    1.77 +HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE
    1.78 +#undef HB_UNICODE_FUNC_IMPLEMENT
    1.79 +
    1.80 +  inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b,
    1.81 +			    hb_codepoint_t *ab)
    1.82 +  {
    1.83 +    *ab = 0;
    1.84 +    if (unlikely (!a || !b)) return false;
    1.85 +    return func.compose (this, a, b, ab, user_data.compose);
    1.86 +  }
    1.87 +
    1.88 +  inline hb_bool_t decompose (hb_codepoint_t ab,
    1.89 +			      hb_codepoint_t *a, hb_codepoint_t *b)
    1.90 +  {
    1.91 +    *a = ab; *b = 0;
    1.92 +    return func.decompose (this, ab, a, b, user_data.decompose);
    1.93 +  }
    1.94 +
    1.95 +  inline unsigned int decompose_compatibility (hb_codepoint_t  u,
    1.96 +					       hb_codepoint_t *decomposed)
    1.97 +  {
    1.98 +    unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_data.decompose_compatibility);
    1.99 +    if (ret == 1 && u == decomposed[0]) {
   1.100 +      decomposed[0] = 0;
   1.101 +      return 0;
   1.102 +    }
   1.103 +    decomposed[ret] = 0;
   1.104 +    return ret;
   1.105 +  }
   1.106 +
   1.107 +
   1.108 +  unsigned int
   1.109 +  modified_combining_class (hb_codepoint_t unicode)
   1.110 +  {
   1.111 +    /* XXX This hack belongs to the Myanmar shaper. */
   1.112 +    if (unlikely (unicode == 0x1037)) unicode = 0x103A;
   1.113 +
   1.114 +    /* XXX This hack belongs to the SEA shaper (for Tai Tham):
   1.115 +     * Reorder SAKOT to ensure it comes after any tone marks. */
   1.116 +    if (unlikely (unicode == 0x1A60)) return 254;
   1.117 +
   1.118 +    return _hb_modified_combining_class[combining_class (unicode)];
   1.119 +  }
   1.120 +
   1.121 +  inline hb_bool_t
   1.122 +  is_variation_selector (hb_codepoint_t unicode)
   1.123 +  {
   1.124 +    return unlikely (hb_in_ranges<hb_codepoint_t> (unicode,
   1.125 +						   0x180B, 0x180D, /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */
   1.126 +						   0xFE00, 0xFE0F, /* VARIATION SELECTOR-1..16 */
   1.127 +						   0xE0100, 0xE01EF));  /* VARIATION SELECTOR-17..256 */
   1.128 +  }
   1.129 +
   1.130 +  /* Default_Ignorable codepoints:
   1.131 +   *
   1.132 +   * Note that as of Oct 2012 (Unicode 6.2), U+180E MONGOLIAN VOWEL SEPARATOR
   1.133 +   * is NOT Default_Ignorable, but it really behaves in a way that it should
   1.134 +   * be.  That has been reported to the Unicode Technical Committee for
   1.135 +   * consideration.  As such, we include it here, since Uniscribe removes it.
   1.136 +   * It *is* in Unicode 6.3 however.  U+061C ARABIC LETTER MARK from Unicode
   1.137 +   * 6.3 is also added manually.  The new Unicode 6.3 bidi formatting
   1.138 +   * characters are encoded in a block that was Default_Ignorable already.
   1.139 +   *
   1.140 +   * Note: While U+115F, U+1160, U+3164 and U+FFA0 are Default_Ignorable,
   1.141 +   * we do NOT want to hide them, as the way Uniscribe has implemented them
   1.142 +   * is with regular spacing glyphs, and that's the way fonts are made to work.
   1.143 +   * As such, we make exceptions for those four.
   1.144 +   *
   1.145 +   * Gathered from:
   1.146 +   * http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:DI:]&abb=on&ucd=on&esc=on
   1.147 +   *
   1.148 +   * Last updated to the page with the following versions:
   1.149 +   * Version 3.6; ICU version: 50.0.1.0; Unicode version: 6.1.0.0
   1.150 +   *
   1.151 +   * 4,167 Code Points
   1.152 +   *
   1.153 +   * [\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]
   1.154 +   *
   1.155 +   * 00AD ;SOFT HYPHEN
   1.156 +   * 034F ;COMBINING GRAPHEME JOINER
   1.157 +   * #115F ;HANGUL CHOSEONG FILLER
   1.158 +   * #1160 ;HANGUL JUNGSEONG FILLER
   1.159 +   * 17B4 ;KHMER VOWEL INHERENT AQ
   1.160 +   * 17B5 ;KHMER VOWEL INHERENT AA
   1.161 +   * 180B..180D ;MONGOLIAN FREE VARIATION SELECTOR THREE
   1.162 +   * 200B..200F ;RIGHT-TO-LEFT MARK
   1.163 +   * 202A..202E ;RIGHT-TO-LEFT OVERRIDE
   1.164 +   * 2060..206F ;NOMINAL DIGIT SHAPES
   1.165 +   * #3164 ;HANGUL FILLER
   1.166 +   * FE00..FE0F ;VARIATION SELECTOR-16
   1.167 +   * FEFF ;ZERO WIDTH NO-BREAK SPACE
   1.168 +   * #FFA0 ;HALFWIDTH HANGUL FILLER
   1.169 +   * FFF0..FFF8 ;<unassigned-FFF8>
   1.170 +   * 1D173..1D17A ;MUSICAL SYMBOL END PHRASE
   1.171 +   * E0000..E0FFF ;<unassigned-E0FFF>
   1.172 +   */
   1.173 +  inline hb_bool_t
   1.174 +  is_default_ignorable (hb_codepoint_t ch)
   1.175 +  {
   1.176 +    hb_codepoint_t plane = ch >> 16;
   1.177 +    if (likely (plane == 0))
   1.178 +    {
   1.179 +      /* BMP */
   1.180 +      hb_codepoint_t page = ch >> 8;
   1.181 +      switch (page) {
   1.182 +	case 0x00: return unlikely (ch == 0x00AD);
   1.183 +	case 0x03: return unlikely (ch == 0x034F);
   1.184 +	case 0x06: return unlikely (ch == 0x061C);
   1.185 +	case 0x17: return hb_in_range<hb_codepoint_t> (ch, 0x17B4, 0x17B5);
   1.186 +	case 0x18: return hb_in_range<hb_codepoint_t> (ch, 0x180B, 0x180E);
   1.187 +	case 0x20: return hb_in_ranges<hb_codepoint_t> (ch, 0x200B, 0x200F,
   1.188 +							    0x202A, 0x202E,
   1.189 +							    0x2060, 0x206F);
   1.190 +	case 0xFE: return hb_in_range<hb_codepoint_t> (ch, 0xFE00, 0xFE0F) || ch == 0xFEFF;
   1.191 +	case 0xFF: return hb_in_range<hb_codepoint_t> (ch, 0xFFF0, 0xFFF8);
   1.192 +	default: return false;
   1.193 +      }
   1.194 +    }
   1.195 +    else
   1.196 +    {
   1.197 +      /* Other planes */
   1.198 +      switch (plane) {
   1.199 +	case 0x01: return hb_in_range<hb_codepoint_t> (ch, 0x0001D173, 0x0001D17A);
   1.200 +	case 0x0E: return hb_in_range<hb_codepoint_t> (ch, 0x000E0000, 0x000E0FFF);
   1.201 +	default: return false;
   1.202 +      }
   1.203 +    }
   1.204 +  }
   1.205 +
   1.206 +
   1.207 +  struct {
   1.208 +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name;
   1.209 +    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
   1.210 +#undef HB_UNICODE_FUNC_IMPLEMENT
   1.211 +  } func;
   1.212 +
   1.213 +  struct {
   1.214 +#define HB_UNICODE_FUNC_IMPLEMENT(name) void *name;
   1.215 +    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
   1.216 +#undef HB_UNICODE_FUNC_IMPLEMENT
   1.217 +  } user_data;
   1.218 +
   1.219 +  struct {
   1.220 +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
   1.221 +    HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
   1.222 +#undef HB_UNICODE_FUNC_IMPLEMENT
   1.223 +  } destroy;
   1.224 +};
   1.225 +
   1.226 +
   1.227 +extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil;
   1.228 +
   1.229 +
   1.230 +/* Modified combining marks */
   1.231 +
   1.232 +/* Hebrew
   1.233 + *
   1.234 + * We permute the "fixed-position" classes 10-26 into the order
   1.235 + * described in the SBL Hebrew manual:
   1.236 + *
   1.237 + * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf
   1.238 + *
   1.239 + * (as recommended by:
   1.240 + *  http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html)
   1.241 + *
   1.242 + * More details here:
   1.243 + * https://bugzilla.mozilla.org/show_bug.cgi?id=662055
   1.244 + */
   1.245 +#define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */
   1.246 +#define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */
   1.247 +#define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */
   1.248 +#define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */
   1.249 +#define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */
   1.250 +#define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */
   1.251 +#define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */
   1.252 +#define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */
   1.253 +#define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */
   1.254 +#define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */
   1.255 +#define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */
   1.256 +#define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */
   1.257 +#define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */
   1.258 +#define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */
   1.259 +#define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */
   1.260 +#define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */
   1.261 +#define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */
   1.262 +
   1.263 +/*
   1.264 + * Arabic
   1.265 + *
   1.266 + * Modify to move Shadda (ccc=33) before other marks.  See:
   1.267 + * http://unicode.org/faq/normalization.html#8
   1.268 + * http://unicode.org/faq/normalization.html#9
   1.269 + */
   1.270 +#define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */
   1.271 +#define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */
   1.272 +#define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */
   1.273 +#define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */
   1.274 +#define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */
   1.275 +#define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */
   1.276 +#define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */
   1.277 +#define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */
   1.278 +#define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */
   1.279 +
   1.280 +/* Syriac */
   1.281 +#define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */
   1.282 +
   1.283 +/* Telugu
   1.284 + *
   1.285 + * Modify Telugu length marks (ccc=84, ccc=91).
   1.286 + * These are the only matras in the main Indic scripts range that have
   1.287 + * a non-zero ccc.  That makes them reorder with the Halant that is
   1.288 + * ccc=9.  Just zero them, we don't need them in our Indic shaper.
   1.289 + */
   1.290 +#define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */
   1.291 +#define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */
   1.292 +
   1.293 +/* Thai
   1.294 + *
   1.295 + * Modify U+0E38 and U+0E39 (ccc=103) to be reordered before U+0E3A (ccc=9).
   1.296 + * Assign 3, which is unassigned otherwise.
   1.297 + * Uniscribe does this reordering too.
   1.298 + */
   1.299 +#define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */
   1.300 +#define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */
   1.301 +
   1.302 +/* Lao */
   1.303 +#define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */
   1.304 +#define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */
   1.305 +
   1.306 +/* Tibetan */
   1.307 +#define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */
   1.308 +#define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */
   1.309 +#define HB_MODIFIED_COMBINING_CLASS_CCC132 132 /* sign u */
   1.310 +
   1.311 +
   1.312 +/* Misc */
   1.313 +
   1.314 +#define HB_UNICODE_GENERAL_CATEGORY_IS_MARK(gen_cat) \
   1.315 +	(FLAG (gen_cat) & \
   1.316 +	 (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | \
   1.317 +	  FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | \
   1.318 +	  FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))
   1.319 +
   1.320 +
   1.321 +#endif /* HB_UNICODE_PRIVATE_HH */

mercurial