1 /* 2 * Copyright 2007,2008,2009 Red Hat, Inc. 3 * Copyright 2012 Google, Inc. 4 * 5 * This is part of HarfBuzz, a text shaping library. 6 * 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. 12 * 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. 18 * 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. 24 * 25 * Red Hat Author(s): Behdad Esfahbod 26 * Google Author(s): Behdad Esfahbod 27 */ 28 29 #ifndef HB_OT_LAYOUT_PRIVATE_HH 30 #define HB_OT_LAYOUT_PRIVATE_HH 31 32 #include "hb-private.hh" 33 34 #include "hb-ot-layout.h" 35 36 #include "hb-font-private.hh" 37 #include "hb-buffer-private.hh" 38 #include "hb-set-private.hh" 39 40 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 */ 45 46 /* buffer var allocations, used during the entire shaping process */ 47 #define unicode_props0() var2.u8[0] 48 #define unicode_props1() var2.u8[1] 49 50 51 inline void 52 _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode) 53 { 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); 59 } 60 61 inline hb_unicode_general_category_t 62 _hb_glyph_info_get_general_category (const hb_glyph_info_t *info) 63 { 64 return (hb_unicode_general_category_t) (info->unicode_props0() & 0x1F); 65 } 66 67 inline void 68 _hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info, unsigned int modified_class) 69 { 70 info->unicode_props1() = modified_class; 71 } 72 73 inline unsigned int 74 _hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info) 75 { 76 return info->unicode_props1(); 77 } 78 79 inline hb_bool_t 80 _hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info) 81 { 82 return !!(info->unicode_props0() & 0x80); 83 } 84 85 inline hb_bool_t 86 _hb_glyph_info_is_zwnj (const hb_glyph_info_t *info) 87 { 88 return !!(info->unicode_props0() & 0x40); 89 } 90 91 inline hb_bool_t 92 _hb_glyph_info_is_zwj (const hb_glyph_info_t *info) 93 { 94 return !!(info->unicode_props0() & 0x20); 95 } 96 97 98 #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot) 99 100 /* 101 * GDEF 102 */ 103 104 typedef enum { 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; 111 112 113 114 /* 115 * GSUB/GPOS 116 */ 117 118 /* lig_id / lig_comp 119 * 120 * When a ligature is formed: 121 * 122 * - The ligature glyph and any marks in between all the same newly allocated 123 * lig_id, 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 128 * in MarkLigPos. 129 * 130 * When a multiple-substitution is done: 131 * 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. 136 * 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. 139 */ 140 #define IS_LIG_BASE 0x10 141 static inline void 142 set_lig_props_for_ligature (hb_glyph_info_t &info, unsigned int lig_id, unsigned int lig_num_comps) 143 { 144 info.lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F); 145 } 146 static inline void 147 set_lig_props_for_mark (hb_glyph_info_t &info, unsigned int lig_id, unsigned int lig_comp) 148 { 149 info.lig_props() = (lig_id << 5) | (lig_comp & 0x0F); 150 } 151 static inline void 152 set_lig_props_for_component (hb_glyph_info_t &info, unsigned int comp) 153 { 154 set_lig_props_for_mark (info, 0, comp); 155 } 156 157 static inline unsigned int 158 get_lig_id (const hb_glyph_info_t &info) 159 { 160 return info.lig_props() >> 5; 161 } 162 static inline bool 163 is_a_ligature (const hb_glyph_info_t &info) 164 { 165 return !!(info.lig_props() & IS_LIG_BASE); 166 } 167 static inline unsigned int 168 get_lig_comp (const hb_glyph_info_t &info) 169 { 170 if (is_a_ligature (info)) 171 return 0; 172 else 173 return info.lig_props() & 0x0F; 174 } 175 static inline unsigned int 176 get_lig_num_comps (const hb_glyph_info_t &info) 177 { 178 if ((info.glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) && is_a_ligature (info)) 179 return info.lig_props() & 0x0F; 180 else 181 return 1; 182 } 183 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 */ 188 return lig_id; 189 } 190 191 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); 198 199 200 /* Should be called before all the substitute_lookup's are done. */ 201 HB_INTERNAL void 202 hb_ot_layout_substitute_start (hb_font_t *font, 203 hb_buffer_t *buffer); 204 205 HB_INTERNAL hb_bool_t 206 hb_ot_layout_substitute_lookup (hb_font_t *font, 207 hb_buffer_t *buffer, 208 unsigned int lookup_index, 209 hb_mask_t mask, 210 hb_bool_t auto_zwj); 211 212 /* Should be called after all the substitute_lookup's are done */ 213 HB_INTERNAL void 214 hb_ot_layout_substitute_finish (hb_font_t *font, 215 hb_buffer_t *buffer); 216 217 218 /* Should be called before all the position_lookup's are done. Resets positions to zero. */ 219 HB_INTERNAL void 220 hb_ot_layout_position_start (hb_font_t *font, 221 hb_buffer_t *buffer); 222 223 HB_INTERNAL hb_bool_t 224 hb_ot_layout_position_lookup (hb_font_t *font, 225 hb_buffer_t *buffer, 226 unsigned int lookup_index, 227 hb_mask_t mask, 228 hb_bool_t auto_zwj); 229 230 /* Should be called after all the position_lookup's are done */ 231 HB_INTERNAL void 232 hb_ot_layout_position_finish (hb_font_t *font, 233 hb_buffer_t *buffer); 234 235 236 237 /* 238 * hb_ot_layout_t 239 */ 240 241 namespace OT { 242 struct GDEF; 243 struct GSUB; 244 struct GPOS; 245 } 246 247 struct hb_ot_layout_t 248 { 249 hb_blob_t *gdef_blob; 250 hb_blob_t *gsub_blob; 251 hb_blob_t *gpos_blob; 252 253 const struct OT::GDEF *gdef; 254 const struct OT::GSUB *gsub; 255 const struct OT::GPOS *gpos; 256 257 unsigned int gsub_lookup_count; 258 unsigned int gpos_lookup_count; 259 260 hb_set_digest_t *gsub_digests; 261 hb_set_digest_t *gpos_digests; 262 }; 263 264 265 HB_INTERNAL hb_ot_layout_t * 266 _hb_ot_layout_create (hb_face_t *face); 267 268 HB_INTERNAL void 269 _hb_ot_layout_destroy (hb_ot_layout_t *layout); 270 271 272 273 #endif /* HB_OT_LAYOUT_PRIVATE_HH */ 274