gfx/harfbuzz/src/hb-ot-layout-private.hh

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright © 2007,2008,2009 Red Hat, Inc.
michael@0 3 * Copyright © 2012,2013 Google, Inc.
michael@0 4 *
michael@0 5 * This is part of HarfBuzz, a text shaping library.
michael@0 6 *
michael@0 7 * Permission is hereby granted, without written agreement and without
michael@0 8 * license or royalty fees, to use, copy, modify, and distribute this
michael@0 9 * software and its documentation for any purpose, provided that the
michael@0 10 * above copyright notice and the following two paragraphs appear in
michael@0 11 * all copies of this software.
michael@0 12 *
michael@0 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
michael@0 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
michael@0 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
michael@0 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
michael@0 17 * DAMAGE.
michael@0 18 *
michael@0 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
michael@0 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
michael@0 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
michael@0 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
michael@0 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
michael@0 24 *
michael@0 25 * Red Hat Author(s): Behdad Esfahbod
michael@0 26 * Google Author(s): Behdad Esfahbod
michael@0 27 */
michael@0 28
michael@0 29 #ifndef HB_OT_LAYOUT_PRIVATE_HH
michael@0 30 #define HB_OT_LAYOUT_PRIVATE_HH
michael@0 31
michael@0 32 #include "hb-private.hh"
michael@0 33
michael@0 34 #include "hb-font-private.hh"
michael@0 35 #include "hb-buffer-private.hh"
michael@0 36 #include "hb-set-private.hh"
michael@0 37
michael@0 38
michael@0 39 /*
michael@0 40 * GDEF
michael@0 41 */
michael@0 42
michael@0 43 typedef enum
michael@0 44 {
michael@0 45 /* The following three match LookupFlags::Ignore* numbers. */
michael@0 46 HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u,
michael@0 47 HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x04u,
michael@0 48 HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x08u,
michael@0 49
michael@0 50 /* The following are used internally; not derived from GDEF. */
michael@0 51 HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED = 0x10u,
michael@0 52 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED = 0x20u,
michael@0 53
michael@0 54 HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE = HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED |
michael@0 55 HB_OT_LAYOUT_GLYPH_PROPS_LIGATED
michael@0 56 } hb_ot_layout_glyph_class_mask_t;
michael@0 57
michael@0 58
michael@0 59 /*
michael@0 60 * GSUB/GPOS
michael@0 61 */
michael@0 62
michael@0 63 HB_INTERNAL hb_bool_t
michael@0 64 hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face,
michael@0 65 unsigned int lookup_index,
michael@0 66 const hb_codepoint_t *glyphs,
michael@0 67 unsigned int glyphs_length,
michael@0 68 hb_bool_t zero_context);
michael@0 69
michael@0 70
michael@0 71 /* Should be called before all the substitute_lookup's are done. */
michael@0 72 HB_INTERNAL void
michael@0 73 hb_ot_layout_substitute_start (hb_font_t *font,
michael@0 74 hb_buffer_t *buffer);
michael@0 75
michael@0 76
michael@0 77 struct hb_ot_layout_lookup_accelerator_t;
michael@0 78
michael@0 79 namespace OT {
michael@0 80 struct hb_apply_context_t;
michael@0 81 struct SubstLookup;
michael@0 82 }
michael@0 83
michael@0 84 HB_INTERNAL void
michael@0 85 hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c,
michael@0 86 const OT::SubstLookup &lookup,
michael@0 87 const hb_ot_layout_lookup_accelerator_t &accel);
michael@0 88
michael@0 89
michael@0 90 /* Should be called after all the substitute_lookup's are done */
michael@0 91 HB_INTERNAL void
michael@0 92 hb_ot_layout_substitute_finish (hb_font_t *font,
michael@0 93 hb_buffer_t *buffer);
michael@0 94
michael@0 95
michael@0 96 /* Should be called before all the position_lookup's are done. Resets positions to zero. */
michael@0 97 HB_INTERNAL void
michael@0 98 hb_ot_layout_position_start (hb_font_t *font,
michael@0 99 hb_buffer_t *buffer);
michael@0 100
michael@0 101 /* Should be called after all the position_lookup's are done */
michael@0 102 HB_INTERNAL void
michael@0 103 hb_ot_layout_position_finish (hb_font_t *font,
michael@0 104 hb_buffer_t *buffer);
michael@0 105
michael@0 106
michael@0 107
michael@0 108 /*
michael@0 109 * hb_ot_layout_t
michael@0 110 */
michael@0 111
michael@0 112 namespace OT {
michael@0 113 struct GDEF;
michael@0 114 struct GSUB;
michael@0 115 struct GPOS;
michael@0 116 }
michael@0 117
michael@0 118 struct hb_ot_layout_lookup_accelerator_t
michael@0 119 {
michael@0 120 template <typename TLookup>
michael@0 121 inline void init (const TLookup &lookup)
michael@0 122 {
michael@0 123 digest.init ();
michael@0 124 lookup.add_coverage (&digest);
michael@0 125 }
michael@0 126
michael@0 127 template <typename TLookup>
michael@0 128 inline void fini (const TLookup &lookup)
michael@0 129 {
michael@0 130 }
michael@0 131
michael@0 132 hb_set_digest_t digest;
michael@0 133 };
michael@0 134
michael@0 135 struct hb_ot_layout_t
michael@0 136 {
michael@0 137 hb_blob_t *gdef_blob;
michael@0 138 hb_blob_t *gsub_blob;
michael@0 139 hb_blob_t *gpos_blob;
michael@0 140
michael@0 141 const struct OT::GDEF *gdef;
michael@0 142 const struct OT::GSUB *gsub;
michael@0 143 const struct OT::GPOS *gpos;
michael@0 144
michael@0 145 unsigned int gsub_lookup_count;
michael@0 146 unsigned int gpos_lookup_count;
michael@0 147
michael@0 148 hb_ot_layout_lookup_accelerator_t *gsub_accels;
michael@0 149 hb_ot_layout_lookup_accelerator_t *gpos_accels;
michael@0 150 };
michael@0 151
michael@0 152
michael@0 153 HB_INTERNAL hb_ot_layout_t *
michael@0 154 _hb_ot_layout_create (hb_face_t *face);
michael@0 155
michael@0 156 HB_INTERNAL void
michael@0 157 _hb_ot_layout_destroy (hb_ot_layout_t *layout);
michael@0 158
michael@0 159
michael@0 160 #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot)
michael@0 161
michael@0 162
michael@0 163 /*
michael@0 164 * Buffer var routines.
michael@0 165 */
michael@0 166
michael@0 167 /* buffer var allocations, used during the entire shaping process */
michael@0 168 #define unicode_props0() var2.u8[0]
michael@0 169 #define unicode_props1() var2.u8[1]
michael@0 170
michael@0 171 /* buffer var allocations, used during the GSUB/GPOS processing */
michael@0 172 #define glyph_props() var1.u16[0] /* GDEF glyph properties */
michael@0 173 #define lig_props() var1.u8[2] /* GSUB/GPOS ligature tracking */
michael@0 174 #define syllable() var1.u8[3] /* GSUB/GPOS shaping boundaries */
michael@0 175
michael@0 176 /* unicode_props */
michael@0 177
michael@0 178 enum {
michael@0 179 MASK0_ZWJ = 0x20u,
michael@0 180 MASK0_ZWNJ = 0x40u,
michael@0 181 MASK0_IGNORABLE = 0x80u,
michael@0 182 MASK0_GEN_CAT = 0x1Fu
michael@0 183 };
michael@0 184
michael@0 185 inline void
michael@0 186 _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode)
michael@0 187 {
michael@0 188 /* XXX This shouldn't be inlined, or at least not while is_default_ignorable() is inline. */
michael@0 189 info->unicode_props0() = ((unsigned int) unicode->general_category (info->codepoint)) |
michael@0 190 (unicode->is_default_ignorable (info->codepoint) ? MASK0_IGNORABLE : 0) |
michael@0 191 (info->codepoint == 0x200C ? MASK0_ZWNJ : 0) |
michael@0 192 (info->codepoint == 0x200D ? MASK0_ZWJ : 0);
michael@0 193 info->unicode_props1() = unicode->modified_combining_class (info->codepoint);
michael@0 194 }
michael@0 195
michael@0 196 inline void
michael@0 197 _hb_glyph_info_set_general_category (hb_glyph_info_t *info,
michael@0 198 hb_unicode_general_category_t gen_cat)
michael@0 199 {
michael@0 200 info->unicode_props0() = (unsigned int) gen_cat | ((info->unicode_props0()) & ~MASK0_GEN_CAT);
michael@0 201 }
michael@0 202
michael@0 203 inline hb_unicode_general_category_t
michael@0 204 _hb_glyph_info_get_general_category (const hb_glyph_info_t *info)
michael@0 205 {
michael@0 206 return (hb_unicode_general_category_t) (info->unicode_props0() & MASK0_GEN_CAT);
michael@0 207 }
michael@0 208
michael@0 209 inline void
michael@0 210 _hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info,
michael@0 211 unsigned int modified_class)
michael@0 212 {
michael@0 213 info->unicode_props1() = modified_class;
michael@0 214 }
michael@0 215
michael@0 216 inline unsigned int
michael@0 217 _hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info)
michael@0 218 {
michael@0 219 return info->unicode_props1();
michael@0 220 }
michael@0 221
michael@0 222 inline hb_bool_t
michael@0 223 _hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info)
michael@0 224 {
michael@0 225 return !!(info->unicode_props0() & MASK0_IGNORABLE);
michael@0 226 }
michael@0 227
michael@0 228 inline hb_bool_t
michael@0 229 _hb_glyph_info_is_zwnj (const hb_glyph_info_t *info)
michael@0 230 {
michael@0 231 return !!(info->unicode_props0() & MASK0_ZWNJ);
michael@0 232 }
michael@0 233
michael@0 234 inline hb_bool_t
michael@0 235 _hb_glyph_info_is_zwj (const hb_glyph_info_t *info)
michael@0 236 {
michael@0 237 return !!(info->unicode_props0() & MASK0_ZWJ);
michael@0 238 }
michael@0 239
michael@0 240 inline void
michael@0 241 _hb_glyph_info_flip_joiners (hb_glyph_info_t *info)
michael@0 242 {
michael@0 243 info->unicode_props0() ^= MASK0_ZWNJ | MASK0_ZWJ;
michael@0 244 }
michael@0 245
michael@0 246 /* lig_props: aka lig_id / lig_comp
michael@0 247 *
michael@0 248 * When a ligature is formed:
michael@0 249 *
michael@0 250 * - The ligature glyph and any marks in between all the same newly allocated
michael@0 251 * lig_id,
michael@0 252 * - The ligature glyph will get lig_num_comps set to the number of components
michael@0 253 * - The marks get lig_comp > 0, reflecting which component of the ligature
michael@0 254 * they were applied to.
michael@0 255 * - This is used in GPOS to attach marks to the right component of a ligature
michael@0 256 * in MarkLigPos,
michael@0 257 * - Note that when marks are ligated together, much of the above is skipped
michael@0 258 * and the current lig_id reused.
michael@0 259 *
michael@0 260 * When a multiple-substitution is done:
michael@0 261 *
michael@0 262 * - All resulting glyphs will have lig_id = 0,
michael@0 263 * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively.
michael@0 264 * - This is used in GPOS to attach marks to the first component of a
michael@0 265 * multiple substitution in MarkBasePos.
michael@0 266 *
michael@0 267 * The numbers are also used in GPOS to do mark-to-mark positioning only
michael@0 268 * to marks that belong to the same component of the same ligature.
michael@0 269 */
michael@0 270
michael@0 271 static inline void
michael@0 272 _hb_glyph_info_clear_lig_props (hb_glyph_info_t *info)
michael@0 273 {
michael@0 274 info->lig_props() = 0;
michael@0 275 }
michael@0 276
michael@0 277 #define IS_LIG_BASE 0x10
michael@0 278
michael@0 279 static inline void
michael@0 280 _hb_glyph_info_set_lig_props_for_ligature (hb_glyph_info_t *info,
michael@0 281 unsigned int lig_id,
michael@0 282 unsigned int lig_num_comps)
michael@0 283 {
michael@0 284 info->lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F);
michael@0 285 }
michael@0 286
michael@0 287 static inline void
michael@0 288 _hb_glyph_info_set_lig_props_for_mark (hb_glyph_info_t *info,
michael@0 289 unsigned int lig_id,
michael@0 290 unsigned int lig_comp)
michael@0 291 {
michael@0 292 info->lig_props() = (lig_id << 5) | (lig_comp & 0x0F);
michael@0 293 }
michael@0 294
michael@0 295 static inline void
michael@0 296 _hb_glyph_info_set_lig_props_for_component (hb_glyph_info_t *info, unsigned int comp)
michael@0 297 {
michael@0 298 _hb_glyph_info_set_lig_props_for_mark (info, 0, comp);
michael@0 299 }
michael@0 300
michael@0 301 static inline unsigned int
michael@0 302 _hb_glyph_info_get_lig_id (const hb_glyph_info_t *info)
michael@0 303 {
michael@0 304 return info->lig_props() >> 5;
michael@0 305 }
michael@0 306
michael@0 307 static inline bool
michael@0 308 _hb_glyph_info_ligated_internal (const hb_glyph_info_t *info)
michael@0 309 {
michael@0 310 return !!(info->lig_props() & IS_LIG_BASE);
michael@0 311 }
michael@0 312
michael@0 313 static inline unsigned int
michael@0 314 _hb_glyph_info_get_lig_comp (const hb_glyph_info_t *info)
michael@0 315 {
michael@0 316 if (_hb_glyph_info_ligated_internal (info))
michael@0 317 return 0;
michael@0 318 else
michael@0 319 return info->lig_props() & 0x0F;
michael@0 320 }
michael@0 321
michael@0 322 static inline unsigned int
michael@0 323 _hb_glyph_info_get_lig_num_comps (const hb_glyph_info_t *info)
michael@0 324 {
michael@0 325 if ((info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) &&
michael@0 326 _hb_glyph_info_ligated_internal (info))
michael@0 327 return info->lig_props() & 0x0F;
michael@0 328 else
michael@0 329 return 1;
michael@0 330 }
michael@0 331
michael@0 332 static inline uint8_t
michael@0 333 _hb_allocate_lig_id (hb_buffer_t *buffer) {
michael@0 334 uint8_t lig_id = buffer->next_serial () & 0x07;
michael@0 335 if (unlikely (!lig_id))
michael@0 336 lig_id = _hb_allocate_lig_id (buffer); /* in case of overflow */
michael@0 337 return lig_id;
michael@0 338 }
michael@0 339
michael@0 340 /* glyph_props: */
michael@0 341
michael@0 342 inline void
michael@0 343 _hb_glyph_info_set_glyph_props (hb_glyph_info_t *info, unsigned int props)
michael@0 344 {
michael@0 345 info->glyph_props() = props;
michael@0 346 }
michael@0 347
michael@0 348 inline unsigned int
michael@0 349 _hb_glyph_info_get_glyph_props (const hb_glyph_info_t *info)
michael@0 350 {
michael@0 351 return info->glyph_props();
michael@0 352 }
michael@0 353
michael@0 354 inline bool
michael@0 355 _hb_glyph_info_is_base_glyph (const hb_glyph_info_t *info)
michael@0 356 {
michael@0 357 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH);
michael@0 358 }
michael@0 359
michael@0 360 inline bool
michael@0 361 _hb_glyph_info_is_ligature (const hb_glyph_info_t *info)
michael@0 362 {
michael@0 363 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE);
michael@0 364 }
michael@0 365
michael@0 366 inline bool
michael@0 367 _hb_glyph_info_is_mark (const hb_glyph_info_t *info)
michael@0 368 {
michael@0 369 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK);
michael@0 370 }
michael@0 371
michael@0 372 static inline bool
michael@0 373 _hb_glyph_info_substituted (const hb_glyph_info_t *info)
michael@0 374 {
michael@0 375 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED);
michael@0 376 }
michael@0 377
michael@0 378 static inline bool
michael@0 379 _hb_glyph_info_ligated (const hb_glyph_info_t *info)
michael@0 380 {
michael@0 381 return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATED);
michael@0 382 }
michael@0 383
michael@0 384 /* Allocation / deallocation. */
michael@0 385
michael@0 386 inline void
michael@0 387 _hb_buffer_allocate_unicode_vars (hb_buffer_t *buffer)
michael@0 388 {
michael@0 389 HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props0);
michael@0 390 HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props1);
michael@0 391 }
michael@0 392
michael@0 393 inline void
michael@0 394 _hb_buffer_deallocate_unicode_vars (hb_buffer_t *buffer)
michael@0 395 {
michael@0 396 HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props0);
michael@0 397 HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props1);
michael@0 398 }
michael@0 399
michael@0 400 inline void
michael@0 401 _hb_buffer_allocate_gsubgpos_vars (hb_buffer_t *buffer)
michael@0 402 {
michael@0 403 HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props);
michael@0 404 HB_BUFFER_ALLOCATE_VAR (buffer, lig_props);
michael@0 405 HB_BUFFER_ALLOCATE_VAR (buffer, syllable);
michael@0 406 }
michael@0 407
michael@0 408 inline void
michael@0 409 _hb_buffer_deallocate_gsubgpos_vars (hb_buffer_t *buffer)
michael@0 410 {
michael@0 411 HB_BUFFER_DEALLOCATE_VAR (buffer, syllable);
michael@0 412 HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props);
michael@0 413 HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_props);
michael@0 414 }
michael@0 415
michael@0 416 /* Make sure no one directly touches our props... */
michael@0 417 #undef unicode_props0
michael@0 418 #undef unicode_props1
michael@0 419 #undef lig_props
michael@0 420 #undef glyph_props
michael@0 421
michael@0 422
michael@0 423 #endif /* HB_OT_LAYOUT_PRIVATE_HH */

mercurial