OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
| 3 * Copyright © 2012 Google, Inc. |
3 * | 4 * |
4 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
5 * | 6 * |
6 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 11 * all copies of this software. |
11 * | 12 * |
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
16 * DAMAGE. | 17 * DAMAGE. |
17 * | 18 * |
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO | 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
23 * | 24 * |
24 * Red Hat Author(s): Behdad Esfahbod | 25 * Red Hat Author(s): Behdad Esfahbod |
| 26 * Google Author(s): Behdad Esfahbod |
25 */ | 27 */ |
26 | 28 |
27 #ifndef HB_OT_LAYOUT_PRIVATE_HH | 29 #ifndef HB_OT_LAYOUT_PRIVATE_HH |
28 #define HB_OT_LAYOUT_PRIVATE_HH | 30 #define HB_OT_LAYOUT_PRIVATE_HH |
29 | 31 |
30 #include "hb-private.hh" | 32 #include "hb-private.hh" |
31 | 33 |
32 #include "hb-ot-layout.h" | 34 #include "hb-ot-layout.h" |
33 | 35 |
34 #include "hb-font-private.hh" | 36 #include "hb-font-private.hh" |
35 #include "hb-buffer-private.hh" | 37 #include "hb-buffer-private.hh" |
36 #include "hb-ot-shape-complex-private.hh" | 38 #include "hb-set-private.hh" |
37 | 39 |
38 | 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 #define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot) |
39 | 47 |
40 /* | 48 /* |
41 * GDEF | 49 * GDEF |
42 */ | 50 */ |
43 | 51 |
44 /* XXX cleanup */ | |
45 typedef enum { | 52 typedef enum { |
46 HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED = 0x0001, | 53 HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED = 0x0001, |
47 HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH = 0x0002, | 54 HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH = 0x0002, |
48 HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE = 0x0004, | 55 HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE = 0x0004, |
49 HB_OT_LAYOUT_GLYPH_CLASS_MARK = 0x0008, | 56 HB_OT_LAYOUT_GLYPH_CLASS_MARK = 0x0008, |
50 HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT = 0x0010 | 57 HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT = 0x0010 |
51 } hb_ot_layout_glyph_class_t; | 58 } hb_ot_layout_glyph_class_t; |
52 | 59 |
53 | 60 |
54 HB_INTERNAL unsigned int | 61 |
55 _hb_ot_layout_get_glyph_property (hb_face_t *face, | 62 /* |
56 » » » » hb_glyph_info_t *info); | 63 * GSUB/GPOS |
| 64 */ |
| 65 |
| 66 /* lig_id / lig_comp |
| 67 * |
| 68 * When a ligature is formed: |
| 69 * |
| 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. |
| 77 * |
| 78 * When a multiple-substitution is done: |
| 79 * |
| 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. |
| 84 * |
| 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. |
| 87 */ |
| 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) |
| 91 { |
| 92 info.lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F); |
| 93 } |
| 94 static inline void |
| 95 set_lig_props_for_mark (hb_glyph_info_t &info, unsigned int lig_id, unsigned int
lig_comp) |
| 96 { |
| 97 info.lig_props() = (lig_id << 5) | (lig_comp & 0x0F); |
| 98 } |
| 99 static inline void |
| 100 set_lig_props_for_component (hb_glyph_info_t &info, unsigned int comp) |
| 101 { |
| 102 set_lig_props_for_mark (info, 0, comp); |
| 103 } |
| 104 |
| 105 static inline unsigned int |
| 106 get_lig_id (const hb_glyph_info_t &info) |
| 107 { |
| 108 return info.lig_props() >> 5; |
| 109 } |
| 110 static inline bool |
| 111 is_a_ligature (const hb_glyph_info_t &info) |
| 112 { |
| 113 return !!(info.lig_props() & IS_LIG_BASE); |
| 114 } |
| 115 static inline unsigned int |
| 116 get_lig_comp (const hb_glyph_info_t &info) |
| 117 { |
| 118 if (is_a_ligature (info)) |
| 119 return 0; |
| 120 else |
| 121 return info.lig_props() & 0x0F; |
| 122 } |
| 123 static inline unsigned int |
| 124 get_lig_num_comps (const hb_glyph_info_t &info) |
| 125 { |
| 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; |
| 130 } |
| 131 |
| 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; |
| 137 } |
| 138 |
57 | 139 |
58 HB_INTERNAL hb_bool_t | 140 HB_INTERNAL hb_bool_t |
59 _hb_ot_layout_check_glyph_property (hb_face_t *face, | 141 hb_ot_layout_would_substitute_lookup_fast (hb_face_t *face, |
60 » » » » hb_glyph_info_t *ginfo, | 142 » » » » » unsigned int lookup_index, |
61 » » » » unsigned int lookup_props, | 143 » » » » » const hb_codepoint_t *glyphs, |
62 » » » » unsigned int *property_out); | 144 » » » » » unsigned int glyphs_length, |
| 145 » » » » » hb_bool_t zero_context); |
| 146 |
| 147 |
| 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); |
63 | 152 |
64 HB_INTERNAL hb_bool_t | 153 HB_INTERNAL hb_bool_t |
65 _hb_ot_layout_skip_mark (hb_face_t *face, | 154 hb_ot_layout_substitute_lookup (hb_font_t *font, |
66 » » » hb_glyph_info_t *ginfo, | 155 » » » » hb_buffer_t *buffer, |
67 » » » unsigned int lookup_props, | 156 » » » » unsigned int lookup_index, |
68 » » » unsigned int *property_out); | 157 » » » » hb_mask_t mask); |
| 158 |
| 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); |
| 163 |
| 164 |
| 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); |
| 169 |
| 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); |
| 175 |
| 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); |
69 | 181 |
70 | 182 |
71 | 183 |
72 /* | 184 /* |
73 * hb_ot_layout_t | 185 * hb_ot_layout_t |
74 */ | 186 */ |
75 | 187 |
| 188 namespace OT { |
| 189 struct GDEF; |
| 190 struct GSUB; |
| 191 struct GPOS; |
| 192 } |
| 193 |
76 struct hb_ot_layout_t | 194 struct hb_ot_layout_t |
77 { | 195 { |
78 hb_blob_t *gdef_blob; | 196 hb_blob_t *gdef_blob; |
79 hb_blob_t *gsub_blob; | 197 hb_blob_t *gsub_blob; |
80 hb_blob_t *gpos_blob; | 198 hb_blob_t *gpos_blob; |
81 | 199 |
82 const struct GDEF *gdef; | 200 const struct OT::GDEF *gdef; |
83 const struct GSUB *gsub; | 201 const struct OT::GSUB *gsub; |
84 const struct GPOS *gpos; | 202 const struct OT::GPOS *gpos; |
| 203 |
| 204 unsigned int gsub_lookup_count; |
| 205 unsigned int gpos_lookup_count; |
| 206 |
| 207 hb_set_digest_t *gsub_digests; |
| 208 hb_set_digest_t *gpos_digests; |
85 }; | 209 }; |
86 | 210 |
87 | 211 |
88 HB_INTERNAL hb_ot_layout_t * | 212 HB_INTERNAL hb_ot_layout_t * |
89 _hb_ot_layout_create (hb_face_t *face); | 213 _hb_ot_layout_create (hb_face_t *face); |
90 | 214 |
91 HB_INTERNAL void | 215 HB_INTERNAL void |
92 _hb_ot_layout_destroy (hb_ot_layout_t *layout); | 216 _hb_ot_layout_destroy (hb_ot_layout_t *layout); |
93 | 217 |
94 | 218 |
95 | 219 |
96 #endif /* HB_OT_LAYOUT_PRIVATE_HH */ | 220 #endif /* HB_OT_LAYOUT_PRIVATE_HH */ |
OLD | NEW |