1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-ot-layout-private.hh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,423 @@ 1.4 +/* 1.5 + * Copyright © 2007,2008,2009 Red Hat, Inc. 1.6 + * Copyright © 2012,2013 Google, Inc. 1.7 + * 1.8 + * This is part of HarfBuzz, a text shaping library. 1.9 + * 1.10 + * Permission is hereby granted, without written agreement and without 1.11 + * license or royalty fees, to use, copy, modify, and distribute this 1.12 + * software and its documentation for any purpose, provided that the 1.13 + * above copyright notice and the following two paragraphs appear in 1.14 + * all copies of this software. 1.15 + * 1.16 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.17 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.18 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.19 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.20 + * DAMAGE. 1.21 + * 1.22 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.23 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.24 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.25 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.26 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.27 + * 1.28 + * Red Hat Author(s): Behdad Esfahbod 1.29 + * Google Author(s): Behdad Esfahbod 1.30 + */ 1.31 + 1.32 +#ifndef HB_OT_LAYOUT_PRIVATE_HH 1.33 +#define HB_OT_LAYOUT_PRIVATE_HH 1.34 + 1.35 +#include "hb-private.hh" 1.36 + 1.37 +#include "hb-font-private.hh" 1.38 +#include "hb-buffer-private.hh" 1.39 +#include "hb-set-private.hh" 1.40 + 1.41 + 1.42 +/* 1.43 + * GDEF 1.44 + */ 1.45 + 1.46 +typedef enum 1.47 +{ 1.48 + /* The following three match LookupFlags::Ignore* numbers. */ 1.49 + HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u, 1.50 + HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x04u, 1.51 + HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x08u, 1.52 + 1.53 + /* The following are used internally; not derived from GDEF. */ 1.54 + HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED = 0x10u, 1.55 + HB_OT_LAYOUT_GLYPH_PROPS_LIGATED = 0x20u, 1.56 + 1.57 + HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE = HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED | 1.58 + HB_OT_LAYOUT_GLYPH_PROPS_LIGATED 1.59 +} hb_ot_layout_glyph_class_mask_t; 1.60 + 1.61 + 1.62 +/* 1.63 + * GSUB/GPOS 1.64 + */ 1.65 + 1.66 +HB_INTERNAL hb_bool_t 1.67 +hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, 1.68 + unsigned int lookup_index, 1.69 + const hb_codepoint_t *glyphs, 1.70 + unsigned int glyphs_length, 1.71 + hb_bool_t zero_context); 1.72 + 1.73 + 1.74 +/* Should be called before all the substitute_lookup's are done. */ 1.75 +HB_INTERNAL void 1.76 +hb_ot_layout_substitute_start (hb_font_t *font, 1.77 + hb_buffer_t *buffer); 1.78 + 1.79 + 1.80 +struct hb_ot_layout_lookup_accelerator_t; 1.81 + 1.82 +namespace OT { 1.83 + struct hb_apply_context_t; 1.84 + struct SubstLookup; 1.85 +} 1.86 + 1.87 +HB_INTERNAL void 1.88 +hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c, 1.89 + const OT::SubstLookup &lookup, 1.90 + const hb_ot_layout_lookup_accelerator_t &accel); 1.91 + 1.92 + 1.93 +/* Should be called after all the substitute_lookup's are done */ 1.94 +HB_INTERNAL void 1.95 +hb_ot_layout_substitute_finish (hb_font_t *font, 1.96 + hb_buffer_t *buffer); 1.97 + 1.98 + 1.99 +/* Should be called before all the position_lookup's are done. Resets positions to zero. */ 1.100 +HB_INTERNAL void 1.101 +hb_ot_layout_position_start (hb_font_t *font, 1.102 + hb_buffer_t *buffer); 1.103 + 1.104 +/* Should be called after all the position_lookup's are done */ 1.105 +HB_INTERNAL void 1.106 +hb_ot_layout_position_finish (hb_font_t *font, 1.107 + hb_buffer_t *buffer); 1.108 + 1.109 + 1.110 + 1.111 +/* 1.112 + * hb_ot_layout_t 1.113 + */ 1.114 + 1.115 +namespace OT { 1.116 + struct GDEF; 1.117 + struct GSUB; 1.118 + struct GPOS; 1.119 +} 1.120 + 1.121 +struct hb_ot_layout_lookup_accelerator_t 1.122 +{ 1.123 + template <typename TLookup> 1.124 + inline void init (const TLookup &lookup) 1.125 + { 1.126 + digest.init (); 1.127 + lookup.add_coverage (&digest); 1.128 + } 1.129 + 1.130 + template <typename TLookup> 1.131 + inline void fini (const TLookup &lookup) 1.132 + { 1.133 + } 1.134 + 1.135 + hb_set_digest_t digest; 1.136 +}; 1.137 + 1.138 +struct hb_ot_layout_t 1.139 +{ 1.140 + hb_blob_t *gdef_blob; 1.141 + hb_blob_t *gsub_blob; 1.142 + hb_blob_t *gpos_blob; 1.143 + 1.144 + const struct OT::GDEF *gdef; 1.145 + const struct OT::GSUB *gsub; 1.146 + const struct OT::GPOS *gpos; 1.147 + 1.148 + unsigned int gsub_lookup_count; 1.149 + unsigned int gpos_lookup_count; 1.150 + 1.151 + hb_ot_layout_lookup_accelerator_t *gsub_accels; 1.152 + hb_ot_layout_lookup_accelerator_t *gpos_accels; 1.153 +}; 1.154 + 1.155 + 1.156 +HB_INTERNAL hb_ot_layout_t * 1.157 +_hb_ot_layout_create (hb_face_t *face); 1.158 + 1.159 +HB_INTERNAL void 1.160 +_hb_ot_layout_destroy (hb_ot_layout_t *layout); 1.161 + 1.162 + 1.163 +#define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot) 1.164 + 1.165 + 1.166 +/* 1.167 + * Buffer var routines. 1.168 + */ 1.169 + 1.170 +/* buffer var allocations, used during the entire shaping process */ 1.171 +#define unicode_props0() var2.u8[0] 1.172 +#define unicode_props1() var2.u8[1] 1.173 + 1.174 +/* buffer var allocations, used during the GSUB/GPOS processing */ 1.175 +#define glyph_props() var1.u16[0] /* GDEF glyph properties */ 1.176 +#define lig_props() var1.u8[2] /* GSUB/GPOS ligature tracking */ 1.177 +#define syllable() var1.u8[3] /* GSUB/GPOS shaping boundaries */ 1.178 + 1.179 +/* unicode_props */ 1.180 + 1.181 +enum { 1.182 + MASK0_ZWJ = 0x20u, 1.183 + MASK0_ZWNJ = 0x40u, 1.184 + MASK0_IGNORABLE = 0x80u, 1.185 + MASK0_GEN_CAT = 0x1Fu 1.186 +}; 1.187 + 1.188 +inline void 1.189 +_hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode) 1.190 +{ 1.191 + /* XXX This shouldn't be inlined, or at least not while is_default_ignorable() is inline. */ 1.192 + info->unicode_props0() = ((unsigned int) unicode->general_category (info->codepoint)) | 1.193 + (unicode->is_default_ignorable (info->codepoint) ? MASK0_IGNORABLE : 0) | 1.194 + (info->codepoint == 0x200C ? MASK0_ZWNJ : 0) | 1.195 + (info->codepoint == 0x200D ? MASK0_ZWJ : 0); 1.196 + info->unicode_props1() = unicode->modified_combining_class (info->codepoint); 1.197 +} 1.198 + 1.199 +inline void 1.200 +_hb_glyph_info_set_general_category (hb_glyph_info_t *info, 1.201 + hb_unicode_general_category_t gen_cat) 1.202 +{ 1.203 + info->unicode_props0() = (unsigned int) gen_cat | ((info->unicode_props0()) & ~MASK0_GEN_CAT); 1.204 +} 1.205 + 1.206 +inline hb_unicode_general_category_t 1.207 +_hb_glyph_info_get_general_category (const hb_glyph_info_t *info) 1.208 +{ 1.209 + return (hb_unicode_general_category_t) (info->unicode_props0() & MASK0_GEN_CAT); 1.210 +} 1.211 + 1.212 +inline void 1.213 +_hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info, 1.214 + unsigned int modified_class) 1.215 +{ 1.216 + info->unicode_props1() = modified_class; 1.217 +} 1.218 + 1.219 +inline unsigned int 1.220 +_hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info) 1.221 +{ 1.222 + return info->unicode_props1(); 1.223 +} 1.224 + 1.225 +inline hb_bool_t 1.226 +_hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info) 1.227 +{ 1.228 + return !!(info->unicode_props0() & MASK0_IGNORABLE); 1.229 +} 1.230 + 1.231 +inline hb_bool_t 1.232 +_hb_glyph_info_is_zwnj (const hb_glyph_info_t *info) 1.233 +{ 1.234 + return !!(info->unicode_props0() & MASK0_ZWNJ); 1.235 +} 1.236 + 1.237 +inline hb_bool_t 1.238 +_hb_glyph_info_is_zwj (const hb_glyph_info_t *info) 1.239 +{ 1.240 + return !!(info->unicode_props0() & MASK0_ZWJ); 1.241 +} 1.242 + 1.243 +inline void 1.244 +_hb_glyph_info_flip_joiners (hb_glyph_info_t *info) 1.245 +{ 1.246 + info->unicode_props0() ^= MASK0_ZWNJ | MASK0_ZWJ; 1.247 +} 1.248 + 1.249 +/* lig_props: aka lig_id / lig_comp 1.250 + * 1.251 + * When a ligature is formed: 1.252 + * 1.253 + * - The ligature glyph and any marks in between all the same newly allocated 1.254 + * lig_id, 1.255 + * - The ligature glyph will get lig_num_comps set to the number of components 1.256 + * - The marks get lig_comp > 0, reflecting which component of the ligature 1.257 + * they were applied to. 1.258 + * - This is used in GPOS to attach marks to the right component of a ligature 1.259 + * in MarkLigPos, 1.260 + * - Note that when marks are ligated together, much of the above is skipped 1.261 + * and the current lig_id reused. 1.262 + * 1.263 + * When a multiple-substitution is done: 1.264 + * 1.265 + * - All resulting glyphs will have lig_id = 0, 1.266 + * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively. 1.267 + * - This is used in GPOS to attach marks to the first component of a 1.268 + * multiple substitution in MarkBasePos. 1.269 + * 1.270 + * The numbers are also used in GPOS to do mark-to-mark positioning only 1.271 + * to marks that belong to the same component of the same ligature. 1.272 + */ 1.273 + 1.274 +static inline void 1.275 +_hb_glyph_info_clear_lig_props (hb_glyph_info_t *info) 1.276 +{ 1.277 + info->lig_props() = 0; 1.278 +} 1.279 + 1.280 +#define IS_LIG_BASE 0x10 1.281 + 1.282 +static inline void 1.283 +_hb_glyph_info_set_lig_props_for_ligature (hb_glyph_info_t *info, 1.284 + unsigned int lig_id, 1.285 + unsigned int lig_num_comps) 1.286 +{ 1.287 + info->lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F); 1.288 +} 1.289 + 1.290 +static inline void 1.291 +_hb_glyph_info_set_lig_props_for_mark (hb_glyph_info_t *info, 1.292 + unsigned int lig_id, 1.293 + unsigned int lig_comp) 1.294 +{ 1.295 + info->lig_props() = (lig_id << 5) | (lig_comp & 0x0F); 1.296 +} 1.297 + 1.298 +static inline void 1.299 +_hb_glyph_info_set_lig_props_for_component (hb_glyph_info_t *info, unsigned int comp) 1.300 +{ 1.301 + _hb_glyph_info_set_lig_props_for_mark (info, 0, comp); 1.302 +} 1.303 + 1.304 +static inline unsigned int 1.305 +_hb_glyph_info_get_lig_id (const hb_glyph_info_t *info) 1.306 +{ 1.307 + return info->lig_props() >> 5; 1.308 +} 1.309 + 1.310 +static inline bool 1.311 +_hb_glyph_info_ligated_internal (const hb_glyph_info_t *info) 1.312 +{ 1.313 + return !!(info->lig_props() & IS_LIG_BASE); 1.314 +} 1.315 + 1.316 +static inline unsigned int 1.317 +_hb_glyph_info_get_lig_comp (const hb_glyph_info_t *info) 1.318 +{ 1.319 + if (_hb_glyph_info_ligated_internal (info)) 1.320 + return 0; 1.321 + else 1.322 + return info->lig_props() & 0x0F; 1.323 +} 1.324 + 1.325 +static inline unsigned int 1.326 +_hb_glyph_info_get_lig_num_comps (const hb_glyph_info_t *info) 1.327 +{ 1.328 + if ((info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) && 1.329 + _hb_glyph_info_ligated_internal (info)) 1.330 + return info->lig_props() & 0x0F; 1.331 + else 1.332 + return 1; 1.333 +} 1.334 + 1.335 +static inline uint8_t 1.336 +_hb_allocate_lig_id (hb_buffer_t *buffer) { 1.337 + uint8_t lig_id = buffer->next_serial () & 0x07; 1.338 + if (unlikely (!lig_id)) 1.339 + lig_id = _hb_allocate_lig_id (buffer); /* in case of overflow */ 1.340 + return lig_id; 1.341 +} 1.342 + 1.343 +/* glyph_props: */ 1.344 + 1.345 +inline void 1.346 +_hb_glyph_info_set_glyph_props (hb_glyph_info_t *info, unsigned int props) 1.347 +{ 1.348 + info->glyph_props() = props; 1.349 +} 1.350 + 1.351 +inline unsigned int 1.352 +_hb_glyph_info_get_glyph_props (const hb_glyph_info_t *info) 1.353 +{ 1.354 + return info->glyph_props(); 1.355 +} 1.356 + 1.357 +inline bool 1.358 +_hb_glyph_info_is_base_glyph (const hb_glyph_info_t *info) 1.359 +{ 1.360 + return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH); 1.361 +} 1.362 + 1.363 +inline bool 1.364 +_hb_glyph_info_is_ligature (const hb_glyph_info_t *info) 1.365 +{ 1.366 + return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE); 1.367 +} 1.368 + 1.369 +inline bool 1.370 +_hb_glyph_info_is_mark (const hb_glyph_info_t *info) 1.371 +{ 1.372 + return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK); 1.373 +} 1.374 + 1.375 +static inline bool 1.376 +_hb_glyph_info_substituted (const hb_glyph_info_t *info) 1.377 +{ 1.378 + return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED); 1.379 +} 1.380 + 1.381 +static inline bool 1.382 +_hb_glyph_info_ligated (const hb_glyph_info_t *info) 1.383 +{ 1.384 + return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATED); 1.385 +} 1.386 + 1.387 +/* Allocation / deallocation. */ 1.388 + 1.389 +inline void 1.390 +_hb_buffer_allocate_unicode_vars (hb_buffer_t *buffer) 1.391 +{ 1.392 + HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props0); 1.393 + HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props1); 1.394 +} 1.395 + 1.396 +inline void 1.397 +_hb_buffer_deallocate_unicode_vars (hb_buffer_t *buffer) 1.398 +{ 1.399 + HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props0); 1.400 + HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props1); 1.401 +} 1.402 + 1.403 +inline void 1.404 +_hb_buffer_allocate_gsubgpos_vars (hb_buffer_t *buffer) 1.405 +{ 1.406 + HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props); 1.407 + HB_BUFFER_ALLOCATE_VAR (buffer, lig_props); 1.408 + HB_BUFFER_ALLOCATE_VAR (buffer, syllable); 1.409 +} 1.410 + 1.411 +inline void 1.412 +_hb_buffer_deallocate_gsubgpos_vars (hb_buffer_t *buffer) 1.413 +{ 1.414 + HB_BUFFER_DEALLOCATE_VAR (buffer, syllable); 1.415 + HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props); 1.416 + HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_props); 1.417 +} 1.418 + 1.419 +/* Make sure no one directly touches our props... */ 1.420 +#undef unicode_props0 1.421 +#undef unicode_props1 1.422 +#undef lig_props 1.423 +#undef glyph_props 1.424 + 1.425 + 1.426 +#endif /* HB_OT_LAYOUT_PRIVATE_HH */