Mailbox support for texture layers.
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-ot-layout-private.hh
blob70fda8ead8e4c82c75788238ee1cc1bbdcc9b763
1 /*
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
17 * DAMAGE.
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)
49 * GDEF
52 typedef enum {
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;
63 * GSUB/GPOS
66 /* lig_id / lig_comp
68 * When a ligature is formed:
70 * - The ligature glyph and any marks in between all the same newly allocated
71 * lig_id,
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
76 * in MarkLigPos.
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
89 static inline void
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);
94 static inline void
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);
99 static inline void
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;
110 static inline bool
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))
119 return 0;
120 else
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;
128 else
129 return 1;
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 */
136 return lig_id;
140 HB_INTERNAL hb_bool_t
141 hb_ot_layout_would_substitute_lookup_fast (hb_face_t *face,
142 unsigned int lookup_index,
143 const hb_codepoint_t *glyphs,
144 unsigned int glyphs_length,
145 hb_bool_t zero_context);
148 /* Should be called before all the substitute_lookup's are done. */
149 HB_INTERNAL void
150 hb_ot_layout_substitute_start (hb_font_t *font,
151 hb_buffer_t *buffer);
153 HB_INTERNAL hb_bool_t
154 hb_ot_layout_substitute_lookup (hb_font_t *font,
155 hb_buffer_t *buffer,
156 unsigned int lookup_index,
157 hb_mask_t mask);
159 /* Should be called after all the substitute_lookup's are done */
160 HB_INTERNAL void
161 hb_ot_layout_substitute_finish (hb_font_t *font,
162 hb_buffer_t *buffer);
165 /* Should be called before all the position_lookup's are done. Resets positions to zero. */
166 HB_INTERNAL void
167 hb_ot_layout_position_start (hb_font_t *font,
168 hb_buffer_t *buffer);
170 HB_INTERNAL hb_bool_t
171 hb_ot_layout_position_lookup (hb_font_t *font,
172 hb_buffer_t *buffer,
173 unsigned int lookup_index,
174 hb_mask_t mask);
176 /* Should be called after all the position_lookup's are done */
177 HB_INTERNAL void
178 hb_ot_layout_position_finish (hb_font_t *font,
179 hb_buffer_t *buffer,
180 hb_bool_t zero_width_attached_marks);
185 * hb_ot_layout_t
188 namespace OT {
189 struct GDEF;
190 struct GSUB;
191 struct GPOS;
194 struct hb_ot_layout_t
196 hb_blob_t *gdef_blob;
197 hb_blob_t *gsub_blob;
198 hb_blob_t *gpos_blob;
200 const struct OT::GDEF *gdef;
201 const struct OT::GSUB *gsub;
202 const struct OT::GPOS *gpos;
204 unsigned int gsub_lookup_count;
205 unsigned int gpos_lookup_count;
207 hb_set_digest_t *gsub_digests;
208 hb_set_digest_t *gpos_digests;
212 HB_INTERNAL hb_ot_layout_t *
213 _hb_ot_layout_create (hb_face_t *face);
215 HB_INTERNAL void
216 _hb_ot_layout_destroy (hb_ot_layout_t *layout);
220 #endif /* HB_OT_LAYOUT_PRIVATE_HH */