hb-ot-shape-complex-private.hh 7.8 KB
Newer Older
1
/*
2
 * Copyright © 2010,2011,2012  Google, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#ifndef HB_OT_SHAPE_COMPLEX_PRIVATE_HH
#define HB_OT_SHAPE_COMPLEX_PRIVATE_HH

30
#include "hb-private.hh"
31

32
#include "hb-ot-map-private.hh"
33 34 35



36
/* buffer var allocations, used during the entire shaping process */
37 38 39
#define general_category() var1.u8[0] /* unicode general_category (hb_unicode_general_category_t) */
#define combining_class() var1.u8[1] /* unicode combining_class (uint8_t) */

40 41 42 43 44 45 46 47
/* buffer var allocations, used by complex shapers */
#define complex_var_persistent_u8_0()	var2.u8[0]
#define complex_var_persistent_u8_1()	var2.u8[1]
#define complex_var_persistent_u16()	var2.u16[0]
#define complex_var_temporary_u8_0()	var2.u8[2]
#define complex_var_temporary_u8_1()	var2.u8[3]
#define complex_var_temporary_u16()	var2.u16[1]

48

49 50 51 52 53 54
#define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \
  HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \
  HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \
  HB_COMPLEX_SHAPER_IMPLEMENT (indic) \
  /* ^--- Add new shapers here */

55
enum hb_ot_complex_shaper_t {
56 57
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) hb_ot_complex_shaper_##name,
  HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
B
Behdad Esfahbod 已提交
58 59
  /* Just here to avoid enum trailing comma: */
  hb_ot_complex_shaper_generic = hb_ot_complex_shaper_default
60
#undef HB_COMPLEX_SHAPER_IMPLEMENT
61 62
};

63 64 65
static inline hb_ot_complex_shaper_t
hb_ot_shape_complex_categorize (const hb_segment_properties_t *props)
{
66 67
  switch ((int) props->script)
  {
68 69 70
    default:
      return hb_ot_complex_shaper_default;

B
Minor  
Behdad Esfahbod 已提交
71
    /* Unicode-1.1 additions */
72
    case HB_SCRIPT_ARABIC:
73
    case HB_SCRIPT_MONGOLIAN:
B
Behdad Esfahbod 已提交
74
    case HB_SCRIPT_SYRIAC:
B
Minor  
Behdad Esfahbod 已提交
75 76 77 78 79 80 81

    /* Unicode-5.0 additions */
    case HB_SCRIPT_NKO:

    /* Unicode-6.0 additions */
    case HB_SCRIPT_MANDAIC:

82 83
      return hb_ot_complex_shaper_arabic;

84 85 86 87
#if 0
    /* Note:
     *
     * These disabled scripts are listed in ucd/IndicSyllabicCategory.txt, but according
88 89 90
     * to Martin Hosken and Jonathan Kew do not require complex shaping.
     *
     * TODO We should automate figuring out which scripts do not need complex shaping
91 92 93
     *
     * TODO We currently keep data for these scripts in our indic table.  Need to fix the
     * generator to not do that.
B
Behdad Esfahbod 已提交
94
     */
95

96

97
    /* Simple? */
98 99

    /* Unicode-3.2 additions */
B
Behdad Esfahbod 已提交
100
    case HB_SCRIPT_BUHID:
101
    case HB_SCRIPT_HANUNOO:
102 103

    /* Unicode-5.1 additions */
104 105
    case HB_SCRIPT_SAURASHTRA:

106 107 108 109 110 111 112 113
    /* Unicode-5.2 additions */
    case HB_SCRIPT_MEETEI_MAYEK:

    /* Unicode-6.0 additions */
    case HB_SCRIPT_BATAK:
    case HB_SCRIPT_BRAHMI:


114
    /* Simple */
115 116 117

    /* Unicode-1.1 additions */
    /* TODO These two need their own shaper I guess? */
118
    case HB_SCRIPT_LAO:
119 120 121 122 123 124
    case HB_SCRIPT_THAI:

    /* Unicode-2.0 additions */
    case HB_SCRIPT_TIBETAN:

    /* Unicode-3.2 additions */
125 126
    case HB_SCRIPT_TAGALOG:
    case HB_SCRIPT_TAGBANWA:
127 128 129

    /* Unicode-4.0 additions */
    case HB_SCRIPT_LIMBU:
130
    case HB_SCRIPT_TAI_LE:
131 132 133 134 135 136 137 138 139 140 141

    /* Unicode-4.1 additions */
    case HB_SCRIPT_SYLOTI_NAGRI:

    /* Unicode-5.0 additions */
    case HB_SCRIPT_PHAGS_PA:

    /* Unicode-5.1 additions */
    case HB_SCRIPT_KAYAH_LI:

    /* Unicode-5.2 additions */
142
    case HB_SCRIPT_TAI_VIET:
143

144 145

    /* May need Indic treatment in the future? */
146 147

    /* Unicode-3.0 additions */
148
    case HB_SCRIPT_MYANMAR:
149 150


151 152
#endif

153
    /* Unicode-1.1 additions */
154
    case HB_SCRIPT_BENGALI:
B
Behdad Esfahbod 已提交
155 156 157 158 159
    case HB_SCRIPT_DEVANAGARI:
    case HB_SCRIPT_GUJARATI:
    case HB_SCRIPT_GURMUKHI:
    case HB_SCRIPT_KANNADA:
    case HB_SCRIPT_MALAYALAM:
B
Minor  
Behdad Esfahbod 已提交
160
    case HB_SCRIPT_ORIYA:
161 162 163 164 165
    case HB_SCRIPT_TAMIL:
    case HB_SCRIPT_TELUGU:

    /* Unicode-3.0 additions */
    case HB_SCRIPT_KHMER:
B
Behdad Esfahbod 已提交
166
    case HB_SCRIPT_SINHALA:
167 168 169 170 171 172 173 174 175 176 177 178 179

    /* Unicode-4.1 additions */
    case HB_SCRIPT_BUGINESE:
    case HB_SCRIPT_KHAROSHTHI:
    case HB_SCRIPT_NEW_TAI_LUE:

    /* Unicode-5.0 additions */
    case HB_SCRIPT_BALINESE:

    /* Unicode-5.1 additions */
    case HB_SCRIPT_CHAM:
    case HB_SCRIPT_LEPCHA:
    case HB_SCRIPT_REJANG:
B
Behdad Esfahbod 已提交
180
    case HB_SCRIPT_SUNDANESE:
181 182 183 184

    /* Unicode-5.2 additions */
    case HB_SCRIPT_JAVANESE:
    case HB_SCRIPT_KAITHI:
B
Behdad Esfahbod 已提交
185
    case HB_SCRIPT_TAI_THAM:
186 187 188 189

    /* Unicode-6.1 additions */
    case HB_SCRIPT_CHAKMA:
    case HB_SCRIPT_SHARADA:
190
    case HB_SCRIPT_TAKRI:
191

B
Behdad Esfahbod 已提交
192 193
      return hb_ot_complex_shaper_indic;

194
    /* ^--- Add new shapers here */
195 196 197 198 199 200 201 202
  }
}



/*
 * collect_features()
 *
B
Behdad Esfahbod 已提交
203 204
 * Called during shape_plan().
 *
205
 * Shapers should use map to add their features and callbacks.
206 207
 */

208
typedef void hb_ot_shape_complex_collect_features_func_t (hb_ot_map_builder_t *map, const hb_segment_properties_t  *props);
209 210 211 212
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
  HB_INTERNAL hb_ot_shape_complex_collect_features_func_t _hb_ot_shape_complex_collect_features_##name;
  HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT
213 214

static inline void
215 216
hb_ot_shape_complex_collect_features (hb_ot_complex_shaper_t shaper,
				      hb_ot_map_builder_t *map,
217 218
				      const hb_segment_properties_t  *props)
{
219
  switch (shaper) {
B
Minor  
Behdad Esfahbod 已提交
220
    default:
221
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
    case hb_ot_complex_shaper_##name:	_hb_ot_shape_complex_collect_features_##name (map, props); return;
    HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT
  }
}


/*
 * prefer_decomposed()
 *
 * Called during shape_execute().
 *
 * Shapers should return TRUE if it prefers decomposed (NFD) input rather than precomposed (NFC).
 */

typedef bool hb_ot_shape_complex_prefer_decomposed_func_t (void);
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
  HB_INTERNAL hb_ot_shape_complex_prefer_decomposed_func_t _hb_ot_shape_complex_prefer_decomposed_##name;
  HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT

static inline bool
hb_ot_shape_complex_prefer_decomposed (hb_ot_complex_shaper_t shaper)
{
  switch (shaper) {
    default:
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
    case hb_ot_complex_shaper_##name:	return _hb_ot_shape_complex_prefer_decomposed_##name ();
250 251
    HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT
252 253 254 255
  }
}


B
Behdad Esfahbod 已提交
256 257 258 259
/* setup_masks()
 *
 * Called during shape_execute().
 *
260
 * Shapers should use map to get feature masks and set on buffer.
B
Behdad Esfahbod 已提交
261 262
 */

263
typedef void hb_ot_shape_complex_setup_masks_func_t (hb_ot_map_t *map, hb_buffer_t *buffer);
264 265 266 267
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
  HB_INTERNAL hb_ot_shape_complex_setup_masks_func_t _hb_ot_shape_complex_setup_masks_##name;
  HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT
B
Behdad Esfahbod 已提交
268 269

static inline void
270 271 272
hb_ot_shape_complex_setup_masks (hb_ot_complex_shaper_t shaper,
				 hb_ot_map_t *map,
				 hb_buffer_t *buffer)
B
Behdad Esfahbod 已提交
273
{
274
  switch (shaper) {
B
Minor  
Behdad Esfahbod 已提交
275
    default:
276
#define HB_COMPLEX_SHAPER_IMPLEMENT(name) \
277
    case hb_ot_complex_shaper_##name:	_hb_ot_shape_complex_setup_masks_##name (map, buffer); return;
278 279
    HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS
#undef HB_COMPLEX_SHAPER_IMPLEMENT
B
Behdad Esfahbod 已提交
280 281 282
  }
}

283 284 285


#endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */