michael@0: /* michael@0: * Copyright © 2007,2008,2009 Red Hat, Inc. michael@0: * Copyright © 2012,2013 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: * Google Author(s): Behdad Esfahbod michael@0: */ michael@0: michael@0: #ifndef HB_OT_LAYOUT_PRIVATE_HH michael@0: #define HB_OT_LAYOUT_PRIVATE_HH michael@0: michael@0: #include "hb-private.hh" michael@0: michael@0: #include "hb-font-private.hh" michael@0: #include "hb-buffer-private.hh" michael@0: #include "hb-set-private.hh" michael@0: michael@0: michael@0: /* michael@0: * GDEF michael@0: */ michael@0: michael@0: typedef enum michael@0: { michael@0: /* The following three match LookupFlags::Ignore* numbers. */ michael@0: HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x02u, michael@0: HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x04u, michael@0: HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x08u, michael@0: michael@0: /* The following are used internally; not derived from GDEF. */ michael@0: HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED = 0x10u, michael@0: HB_OT_LAYOUT_GLYPH_PROPS_LIGATED = 0x20u, michael@0: michael@0: HB_OT_LAYOUT_GLYPH_PROPS_PRESERVE = HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED | michael@0: HB_OT_LAYOUT_GLYPH_PROPS_LIGATED michael@0: } hb_ot_layout_glyph_class_mask_t; michael@0: michael@0: michael@0: /* michael@0: * GSUB/GPOS michael@0: */ michael@0: michael@0: HB_INTERNAL hb_bool_t michael@0: hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, michael@0: unsigned int lookup_index, michael@0: const hb_codepoint_t *glyphs, michael@0: unsigned int glyphs_length, michael@0: hb_bool_t zero_context); michael@0: michael@0: michael@0: /* Should be called before all the substitute_lookup's are done. */ michael@0: HB_INTERNAL void michael@0: hb_ot_layout_substitute_start (hb_font_t *font, michael@0: hb_buffer_t *buffer); michael@0: michael@0: michael@0: struct hb_ot_layout_lookup_accelerator_t; michael@0: michael@0: namespace OT { michael@0: struct hb_apply_context_t; michael@0: struct SubstLookup; michael@0: } michael@0: michael@0: HB_INTERNAL void michael@0: hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c, michael@0: const OT::SubstLookup &lookup, michael@0: const hb_ot_layout_lookup_accelerator_t &accel); michael@0: michael@0: michael@0: /* Should be called after all the substitute_lookup's are done */ michael@0: HB_INTERNAL void michael@0: hb_ot_layout_substitute_finish (hb_font_t *font, michael@0: hb_buffer_t *buffer); michael@0: michael@0: michael@0: /* Should be called before all the position_lookup's are done. Resets positions to zero. */ michael@0: HB_INTERNAL void michael@0: hb_ot_layout_position_start (hb_font_t *font, michael@0: hb_buffer_t *buffer); michael@0: michael@0: /* Should be called after all the position_lookup's are done */ michael@0: HB_INTERNAL void michael@0: hb_ot_layout_position_finish (hb_font_t *font, michael@0: hb_buffer_t *buffer); michael@0: michael@0: michael@0: michael@0: /* michael@0: * hb_ot_layout_t michael@0: */ michael@0: michael@0: namespace OT { michael@0: struct GDEF; michael@0: struct GSUB; michael@0: struct GPOS; michael@0: } michael@0: michael@0: struct hb_ot_layout_lookup_accelerator_t michael@0: { michael@0: template michael@0: inline void init (const TLookup &lookup) michael@0: { michael@0: digest.init (); michael@0: lookup.add_coverage (&digest); michael@0: } michael@0: michael@0: template michael@0: inline void fini (const TLookup &lookup) michael@0: { michael@0: } michael@0: michael@0: hb_set_digest_t digest; michael@0: }; michael@0: michael@0: struct hb_ot_layout_t michael@0: { michael@0: hb_blob_t *gdef_blob; michael@0: hb_blob_t *gsub_blob; michael@0: hb_blob_t *gpos_blob; michael@0: michael@0: const struct OT::GDEF *gdef; michael@0: const struct OT::GSUB *gsub; michael@0: const struct OT::GPOS *gpos; michael@0: michael@0: unsigned int gsub_lookup_count; michael@0: unsigned int gpos_lookup_count; michael@0: michael@0: hb_ot_layout_lookup_accelerator_t *gsub_accels; michael@0: hb_ot_layout_lookup_accelerator_t *gpos_accels; michael@0: }; michael@0: michael@0: michael@0: HB_INTERNAL hb_ot_layout_t * michael@0: _hb_ot_layout_create (hb_face_t *face); michael@0: michael@0: HB_INTERNAL void michael@0: _hb_ot_layout_destroy (hb_ot_layout_t *layout); michael@0: michael@0: michael@0: #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot) michael@0: michael@0: michael@0: /* michael@0: * Buffer var routines. michael@0: */ michael@0: michael@0: /* buffer var allocations, used during the entire shaping process */ michael@0: #define unicode_props0() var2.u8[0] michael@0: #define unicode_props1() var2.u8[1] michael@0: michael@0: /* buffer var allocations, used during the GSUB/GPOS processing */ michael@0: #define glyph_props() var1.u16[0] /* GDEF glyph properties */ michael@0: #define lig_props() var1.u8[2] /* GSUB/GPOS ligature tracking */ michael@0: #define syllable() var1.u8[3] /* GSUB/GPOS shaping boundaries */ michael@0: michael@0: /* unicode_props */ michael@0: michael@0: enum { michael@0: MASK0_ZWJ = 0x20u, michael@0: MASK0_ZWNJ = 0x40u, michael@0: MASK0_IGNORABLE = 0x80u, michael@0: MASK0_GEN_CAT = 0x1Fu michael@0: }; michael@0: michael@0: inline void michael@0: _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode) michael@0: { michael@0: /* XXX This shouldn't be inlined, or at least not while is_default_ignorable() is inline. */ michael@0: info->unicode_props0() = ((unsigned int) unicode->general_category (info->codepoint)) | michael@0: (unicode->is_default_ignorable (info->codepoint) ? MASK0_IGNORABLE : 0) | michael@0: (info->codepoint == 0x200C ? MASK0_ZWNJ : 0) | michael@0: (info->codepoint == 0x200D ? MASK0_ZWJ : 0); michael@0: info->unicode_props1() = unicode->modified_combining_class (info->codepoint); michael@0: } michael@0: michael@0: inline void michael@0: _hb_glyph_info_set_general_category (hb_glyph_info_t *info, michael@0: hb_unicode_general_category_t gen_cat) michael@0: { michael@0: info->unicode_props0() = (unsigned int) gen_cat | ((info->unicode_props0()) & ~MASK0_GEN_CAT); michael@0: } michael@0: michael@0: inline hb_unicode_general_category_t michael@0: _hb_glyph_info_get_general_category (const hb_glyph_info_t *info) michael@0: { michael@0: return (hb_unicode_general_category_t) (info->unicode_props0() & MASK0_GEN_CAT); michael@0: } michael@0: michael@0: inline void michael@0: _hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info, michael@0: unsigned int modified_class) michael@0: { michael@0: info->unicode_props1() = modified_class; michael@0: } michael@0: michael@0: inline unsigned int michael@0: _hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info) michael@0: { michael@0: return info->unicode_props1(); michael@0: } michael@0: michael@0: inline hb_bool_t michael@0: _hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->unicode_props0() & MASK0_IGNORABLE); michael@0: } michael@0: michael@0: inline hb_bool_t michael@0: _hb_glyph_info_is_zwnj (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->unicode_props0() & MASK0_ZWNJ); michael@0: } michael@0: michael@0: inline hb_bool_t michael@0: _hb_glyph_info_is_zwj (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->unicode_props0() & MASK0_ZWJ); michael@0: } michael@0: michael@0: inline void michael@0: _hb_glyph_info_flip_joiners (hb_glyph_info_t *info) michael@0: { michael@0: info->unicode_props0() ^= MASK0_ZWNJ | MASK0_ZWJ; michael@0: } michael@0: michael@0: /* lig_props: aka lig_id / lig_comp michael@0: * michael@0: * When a ligature is formed: michael@0: * michael@0: * - The ligature glyph and any marks in between all the same newly allocated michael@0: * lig_id, michael@0: * - The ligature glyph will get lig_num_comps set to the number of components michael@0: * - The marks get lig_comp > 0, reflecting which component of the ligature michael@0: * they were applied to. michael@0: * - This is used in GPOS to attach marks to the right component of a ligature michael@0: * in MarkLigPos, michael@0: * - Note that when marks are ligated together, much of the above is skipped michael@0: * and the current lig_id reused. michael@0: * michael@0: * When a multiple-substitution is done: michael@0: * michael@0: * - All resulting glyphs will have lig_id = 0, michael@0: * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively. michael@0: * - This is used in GPOS to attach marks to the first component of a michael@0: * multiple substitution in MarkBasePos. michael@0: * michael@0: * The numbers are also used in GPOS to do mark-to-mark positioning only michael@0: * to marks that belong to the same component of the same ligature. michael@0: */ michael@0: michael@0: static inline void michael@0: _hb_glyph_info_clear_lig_props (hb_glyph_info_t *info) michael@0: { michael@0: info->lig_props() = 0; michael@0: } michael@0: michael@0: #define IS_LIG_BASE 0x10 michael@0: michael@0: static inline void michael@0: _hb_glyph_info_set_lig_props_for_ligature (hb_glyph_info_t *info, michael@0: unsigned int lig_id, michael@0: unsigned int lig_num_comps) michael@0: { michael@0: info->lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F); michael@0: } michael@0: michael@0: static inline void michael@0: _hb_glyph_info_set_lig_props_for_mark (hb_glyph_info_t *info, michael@0: unsigned int lig_id, michael@0: unsigned int lig_comp) michael@0: { michael@0: info->lig_props() = (lig_id << 5) | (lig_comp & 0x0F); michael@0: } michael@0: michael@0: static inline void michael@0: _hb_glyph_info_set_lig_props_for_component (hb_glyph_info_t *info, unsigned int comp) michael@0: { michael@0: _hb_glyph_info_set_lig_props_for_mark (info, 0, comp); michael@0: } michael@0: michael@0: static inline unsigned int michael@0: _hb_glyph_info_get_lig_id (const hb_glyph_info_t *info) michael@0: { michael@0: return info->lig_props() >> 5; michael@0: } michael@0: michael@0: static inline bool michael@0: _hb_glyph_info_ligated_internal (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->lig_props() & IS_LIG_BASE); michael@0: } michael@0: michael@0: static inline unsigned int michael@0: _hb_glyph_info_get_lig_comp (const hb_glyph_info_t *info) michael@0: { michael@0: if (_hb_glyph_info_ligated_internal (info)) michael@0: return 0; michael@0: else michael@0: return info->lig_props() & 0x0F; michael@0: } michael@0: michael@0: static inline unsigned int michael@0: _hb_glyph_info_get_lig_num_comps (const hb_glyph_info_t *info) michael@0: { michael@0: if ((info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) && michael@0: _hb_glyph_info_ligated_internal (info)) michael@0: return info->lig_props() & 0x0F; michael@0: else michael@0: return 1; michael@0: } michael@0: michael@0: static inline uint8_t michael@0: _hb_allocate_lig_id (hb_buffer_t *buffer) { michael@0: uint8_t lig_id = buffer->next_serial () & 0x07; michael@0: if (unlikely (!lig_id)) michael@0: lig_id = _hb_allocate_lig_id (buffer); /* in case of overflow */ michael@0: return lig_id; michael@0: } michael@0: michael@0: /* glyph_props: */ michael@0: michael@0: inline void michael@0: _hb_glyph_info_set_glyph_props (hb_glyph_info_t *info, unsigned int props) michael@0: { michael@0: info->glyph_props() = props; michael@0: } michael@0: michael@0: inline unsigned int michael@0: _hb_glyph_info_get_glyph_props (const hb_glyph_info_t *info) michael@0: { michael@0: return info->glyph_props(); michael@0: } michael@0: michael@0: inline bool michael@0: _hb_glyph_info_is_base_glyph (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH); michael@0: } michael@0: michael@0: inline bool michael@0: _hb_glyph_info_is_ligature (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE); michael@0: } michael@0: michael@0: inline bool michael@0: _hb_glyph_info_is_mark (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK); michael@0: } michael@0: michael@0: static inline bool michael@0: _hb_glyph_info_substituted (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_SUBSTITUTED); michael@0: } michael@0: michael@0: static inline bool michael@0: _hb_glyph_info_ligated (const hb_glyph_info_t *info) michael@0: { michael@0: return !!(info->glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATED); michael@0: } michael@0: michael@0: /* Allocation / deallocation. */ michael@0: michael@0: inline void michael@0: _hb_buffer_allocate_unicode_vars (hb_buffer_t *buffer) michael@0: { michael@0: HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props0); michael@0: HB_BUFFER_ALLOCATE_VAR (buffer, unicode_props1); michael@0: } michael@0: michael@0: inline void michael@0: _hb_buffer_deallocate_unicode_vars (hb_buffer_t *buffer) michael@0: { michael@0: HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props0); michael@0: HB_BUFFER_DEALLOCATE_VAR (buffer, unicode_props1); michael@0: } michael@0: michael@0: inline void michael@0: _hb_buffer_allocate_gsubgpos_vars (hb_buffer_t *buffer) michael@0: { michael@0: HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props); michael@0: HB_BUFFER_ALLOCATE_VAR (buffer, lig_props); michael@0: HB_BUFFER_ALLOCATE_VAR (buffer, syllable); michael@0: } michael@0: michael@0: inline void michael@0: _hb_buffer_deallocate_gsubgpos_vars (hb_buffer_t *buffer) michael@0: { michael@0: HB_BUFFER_DEALLOCATE_VAR (buffer, syllable); michael@0: HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props); michael@0: HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_props); michael@0: } michael@0: michael@0: /* Make sure no one directly touches our props... */ michael@0: #undef unicode_props0 michael@0: #undef unicode_props1 michael@0: #undef lig_props michael@0: #undef glyph_props michael@0: michael@0: michael@0: #endif /* HB_OT_LAYOUT_PRIVATE_HH */