2 * Copyright © 2007,2008,2009 Red Hat, Inc.
3 * Copyright © 2012 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
29 #ifndef HB_OT_LAYOUT_PRIVATE_HH
30 #define HB_OT_LAYOUT_PRIVATE_HH
32 #include "hb-private.hh"
34 #include "hb-ot-layout.h"
36 #include "hb-font-private.hh"
37 #include "hb-buffer-private.hh"
38 #include "hb-set-private.hh"
41 /* buffer var allocations, used during the GSUB/GPOS processing */
42 #define glyph_props() var1.u16[0] /* GDEF glyph properties */
43 #define syllable() var1.u8[2] /* GSUB/GPOS shaping boundaries */
44 #define lig_props() var1.u8[3] /* GSUB/GPOS ligature tracking */
46 #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot)
53 HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED = 0x0001,
54 HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH = 0x0002,
55 HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE = 0x0004,
56 HB_OT_LAYOUT_GLYPH_CLASS_MARK = 0x0008,
57 HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT = 0x0010
58 } hb_ot_layout_glyph_class_t;
68 * When a ligature is formed:
70 * - The ligature glyph and any marks in between all the same newly allocated
72 * - The ligature glyph will get lig_num_comps set to the number of components
73 * - The marks get lig_comp > 0, reflecting which component of the ligature
74 * they were applied to.
75 * - This is used in GPOS to attach marks to the right component of a ligature
78 * When a multiple-substitution is done:
80 * - All resulting glyphs will have lig_id = 0,
81 * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively.
82 * - This is used in GPOS to attach marks to the first component of a
83 * multiple substitution in MarkBasePos.
85 * The numbers are also used in GPOS to do mark-to-mark positioning only
86 * to marks that belong to the same component of a ligature in MarkMarPos.
88 #define IS_LIG_BASE 0x10
90 set_lig_props_for_ligature (hb_glyph_info_t &info, unsigned int lig_id, unsigned int lig_num_comps)
92 info.lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F);
95 set_lig_props_for_mark (hb_glyph_info_t &info, unsigned int lig_id, unsigned int lig_comp)
97 info.lig_props() = (lig_id << 5) | (lig_comp & 0x0F);
100 set_lig_props_for_component (hb_glyph_info_t &info, unsigned int comp)
102 set_lig_props_for_mark (info, 0, comp);
105 static inline unsigned int
106 get_lig_id (const hb_glyph_info_t &info)
108 return info.lig_props() >> 5;
111 is_a_ligature (const hb_glyph_info_t &info)
113 return !!(info.lig_props() & IS_LIG_BASE);
115 static inline unsigned int
116 get_lig_comp (const hb_glyph_info_t &info)
118 if (is_a_ligature (info))
121 return info.lig_props() & 0x0F;
123 static inline unsigned int
124 get_lig_num_comps (const hb_glyph_info_t &info)
126 if ((info.glyph_props() & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE) && is_a_ligature (info))
127 return info.lig_props() & 0x0F;
132 static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) {
133 uint8_t lig_id = buffer->next_serial () & 0x07;
134 if (unlikely (!lig_id))
135 lig_id = allocate_lig_id (buffer); /* in case of overflow */
140 HB_INTERNAL hb_bool_t
141 hb_ot_layout_would_substitute_lookup_fast (hb_face_t *face,
142 const hb_codepoint_t *glyphs,
143 unsigned int glyphs_length,
144 unsigned int lookup_index);
147 /* Should be called before all the substitute_lookup's are done. */
149 hb_ot_layout_substitute_start (hb_font_t *font,
150 hb_buffer_t *buffer);
152 HB_INTERNAL hb_bool_t
153 hb_ot_layout_substitute_lookup (hb_font_t *font,
155 unsigned int lookup_index,
158 /* Should be called after all the substitute_lookup's are done */
160 hb_ot_layout_substitute_finish (hb_font_t *font,
161 hb_buffer_t *buffer);
164 /* Should be called before all the position_lookup's are done. Resets positions to zero. */
166 hb_ot_layout_position_start (hb_font_t *font,
167 hb_buffer_t *buffer);
169 HB_INTERNAL hb_bool_t
170 hb_ot_layout_position_lookup (hb_font_t *font,
172 unsigned int lookup_index,
175 /* Should be called after all the position_lookup's are done */
177 hb_ot_layout_position_finish (hb_font_t *font,
179 hb_bool_t zero_width_attached_marks);
187 struct hb_ot_layout_t
189 hb_blob_t *gdef_blob;
190 hb_blob_t *gsub_blob;
191 hb_blob_t *gpos_blob;
193 const struct GDEF *gdef;
194 const struct GSUB *gsub;
195 const struct GPOS *gpos;
197 unsigned int gsub_lookup_count;
198 unsigned int gpos_lookup_count;
200 hb_set_digest_t *gsub_digests;
201 hb_set_digest_t *gpos_digests;
205 HB_INTERNAL hb_ot_layout_t *
206 _hb_ot_layout_create (hb_face_t *face);
209 _hb_ot_layout_destroy (hb_ot_layout_t *layout);
213 #endif /* HB_OT_LAYOUT_PRIVATE_HH */