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 /* buffer var allocations, used during the entire shaping process */
47 #define unicode_props0() var2.u8[0]
48 #define unicode_props1() var2.u8[1]
52 _hb_glyph_info_set_unicode_props (hb_glyph_info_t
*info
, hb_unicode_funcs_t
*unicode
)
54 info
->unicode_props0() = ((unsigned int) unicode
->general_category (info
->codepoint
)) |
55 (unicode
->is_default_ignorable (info
->codepoint
) ? 0x80 : 0) |
56 (info
->codepoint
== 0x200C ? 0x40 : 0) |
57 (info
->codepoint
== 0x200D ? 0x20 : 0);
58 info
->unicode_props1() = unicode
->modified_combining_class (info
->codepoint
);
61 inline hb_unicode_general_category_t
62 _hb_glyph_info_get_general_category (const hb_glyph_info_t
*info
)
64 return (hb_unicode_general_category_t
) (info
->unicode_props0() & 0x1F);
68 _hb_glyph_info_set_modified_combining_class (hb_glyph_info_t
*info
, unsigned int modified_class
)
70 info
->unicode_props1() = modified_class
;
74 _hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t
*info
)
76 return info
->unicode_props1();
80 _hb_glyph_info_is_default_ignorable (const hb_glyph_info_t
*info
)
82 return !!(info
->unicode_props0() & 0x80);
86 _hb_glyph_info_is_zwnj (const hb_glyph_info_t
*info
)
88 return !!(info
->unicode_props0() & 0x40);
92 _hb_glyph_info_is_zwj (const hb_glyph_info_t
*info
)
94 return !!(info
->unicode_props0() & 0x20);
98 #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot)
105 HB_OT_LAYOUT_GLYPH_PROPS_UNCLASSIFIED
= 1 << HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED
,
106 HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH
= 1 << HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH
,
107 HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE
= 1 << HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE
,
108 HB_OT_LAYOUT_GLYPH_PROPS_MARK
= 1 << HB_OT_LAYOUT_GLYPH_CLASS_MARK
,
109 HB_OT_LAYOUT_GLYPH_PROPS_COMPONENT
= 1 << HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT
110 } hb_ot_layout_glyph_class_mask_t
;
120 * When a ligature is formed:
122 * - The ligature glyph and any marks in between all the same newly allocated
124 * - The ligature glyph will get lig_num_comps set to the number of components
125 * - The marks get lig_comp > 0, reflecting which component of the ligature
126 * they were applied to.
127 * - This is used in GPOS to attach marks to the right component of a ligature
130 * When a multiple-substitution is done:
132 * - All resulting glyphs will have lig_id = 0,
133 * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively.
134 * - This is used in GPOS to attach marks to the first component of a
135 * multiple substitution in MarkBasePos.
137 * The numbers are also used in GPOS to do mark-to-mark positioning only
138 * to marks that belong to the same component of a ligature in MarkMarPos.
140 #define IS_LIG_BASE 0x10
142 set_lig_props_for_ligature (hb_glyph_info_t
&info
, unsigned int lig_id
, unsigned int lig_num_comps
)
144 info
.lig_props() = (lig_id
<< 5) | IS_LIG_BASE
| (lig_num_comps
& 0x0F);
147 set_lig_props_for_mark (hb_glyph_info_t
&info
, unsigned int lig_id
, unsigned int lig_comp
)
149 info
.lig_props() = (lig_id
<< 5) | (lig_comp
& 0x0F);
152 set_lig_props_for_component (hb_glyph_info_t
&info
, unsigned int comp
)
154 set_lig_props_for_mark (info
, 0, comp
);
157 static inline unsigned int
158 get_lig_id (const hb_glyph_info_t
&info
)
160 return info
.lig_props() >> 5;
163 is_a_ligature (const hb_glyph_info_t
&info
)
165 return !!(info
.lig_props() & IS_LIG_BASE
);
167 static inline unsigned int
168 get_lig_comp (const hb_glyph_info_t
&info
)
170 if (is_a_ligature (info
))
173 return info
.lig_props() & 0x0F;
175 static inline unsigned int
176 get_lig_num_comps (const hb_glyph_info_t
&info
)
178 if ((info
.glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE
) && is_a_ligature (info
))
179 return info
.lig_props() & 0x0F;
184 static inline uint8_t allocate_lig_id (hb_buffer_t
*buffer
) {
185 uint8_t lig_id
= buffer
->next_serial () & 0x07;
186 if (unlikely (!lig_id
))
187 lig_id
= allocate_lig_id (buffer
); /* in case of overflow */
192 HB_INTERNAL hb_bool_t
193 hb_ot_layout_lookup_would_substitute_fast (hb_face_t
*face
,
194 unsigned int lookup_index
,
195 const hb_codepoint_t
*glyphs
,
196 unsigned int glyphs_length
,
197 hb_bool_t zero_context
);
200 /* Should be called before all the substitute_lookup's are done. */
202 hb_ot_layout_substitute_start (hb_font_t
*font
,
203 hb_buffer_t
*buffer
);
205 HB_INTERNAL hb_bool_t
206 hb_ot_layout_substitute_lookup (hb_font_t
*font
,
208 unsigned int lookup_index
,
212 /* Should be called after all the substitute_lookup's are done */
214 hb_ot_layout_substitute_finish (hb_font_t
*font
,
215 hb_buffer_t
*buffer
);
218 /* Should be called before all the position_lookup's are done. Resets positions to zero. */
220 hb_ot_layout_position_start (hb_font_t
*font
,
221 hb_buffer_t
*buffer
);
223 HB_INTERNAL hb_bool_t
224 hb_ot_layout_position_lookup (hb_font_t
*font
,
226 unsigned int lookup_index
,
230 /* Should be called after all the position_lookup's are done */
232 hb_ot_layout_position_finish (hb_font_t
*font
,
233 hb_buffer_t
*buffer
);
247 struct hb_ot_layout_t
249 hb_blob_t
*gdef_blob
;
250 hb_blob_t
*gsub_blob
;
251 hb_blob_t
*gpos_blob
;
253 const struct OT::GDEF
*gdef
;
254 const struct OT::GSUB
*gsub
;
255 const struct OT::GPOS
*gpos
;
257 unsigned int gsub_lookup_count
;
258 unsigned int gpos_lookup_count
;
260 hb_set_digest_t
*gsub_digests
;
261 hb_set_digest_t
*gpos_digests
;
265 HB_INTERNAL hb_ot_layout_t
*
266 _hb_ot_layout_create (hb_face_t
*face
);
269 _hb_ot_layout_destroy (hb_ot_layout_t
*layout
);
273 #endif /* HB_OT_LAYOUT_PRIVATE_HH */