OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009,2010 Red Hat, Inc. | 2 * Copyright © 2009,2010 Red Hat, Inc. |
3 * Copyright (C) 2010 Google, Inc. | 3 * Copyright © 2010,2011 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
11 * all copies of this software. | 11 * all copies of this software. |
12 * | 12 * |
13 * 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 |
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
15 * 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 |
16 * 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 |
17 * DAMAGE. | 17 * DAMAGE. |
18 * | 18 * |
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | 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 | 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
24 * | 24 * |
25 * Red Hat Author(s): Behdad Esfahbod | 25 * Red Hat Author(s): Behdad Esfahbod |
26 * Google Author(s): Behdad Esfahbod | 26 * Google Author(s): Behdad Esfahbod |
27 */ | 27 */ |
28 | 28 |
29 #include "hb-ot-shape-private.hh" | 29 #include "hb-ot-shape-private.hh" |
30 #include "hb-ot-shape-complex-private.hh" | 30 #include "hb-ot-shape-complex-private.hh" |
31 | 31 |
32 HB_BEGIN_DECLS | 32 #include "hb-font-private.hh" |
33 | 33 |
34 | 34 |
35 /* XXX vertical */ | 35 |
36 hb_tag_t default_features[] = { | 36 hb_tag_t common_features[] = { |
| 37 HB_TAG('c','c','m','p'), |
| 38 HB_TAG('l','o','c','l'), |
| 39 HB_TAG('m','a','r','k'), |
| 40 HB_TAG('m','k','m','k'), |
| 41 HB_TAG('r','l','i','g'), |
| 42 }; |
| 43 |
| 44 hb_tag_t horizontal_features[] = { |
37 HB_TAG('c','a','l','t'), | 45 HB_TAG('c','a','l','t'), |
38 HB_TAG('c','c','m','p'), | |
39 HB_TAG('c','l','i','g'), | 46 HB_TAG('c','l','i','g'), |
40 HB_TAG('c','s','w','h'), | |
41 HB_TAG('c','u','r','s'), | 47 HB_TAG('c','u','r','s'), |
42 HB_TAG('k','e','r','n'), | 48 HB_TAG('k','e','r','n'), |
43 HB_TAG('l','i','g','a'), | 49 HB_TAG('l','i','g','a'), |
44 HB_TAG('l','o','c','l'), | 50 }; |
45 HB_TAG('m','a','r','k'), | 51 |
46 HB_TAG('m','k','m','k'), | 52 /* Note: |
47 HB_TAG('r','l','i','g') | 53 * Technically speaking, vrt2 and vert are mutually exclusive. |
| 54 * According to the spec, valt and vpal are also mutually exclusive. |
| 55 * But we apply them all for now. |
| 56 */ |
| 57 hb_tag_t vertical_features[] = { |
| 58 HB_TAG('v','a','l','t'), |
| 59 HB_TAG('v','e','r','t'), |
| 60 HB_TAG('v','k','r','n'), |
| 61 HB_TAG('v','p','a','l'), |
| 62 HB_TAG('v','r','t','2'), |
48 }; | 63 }; |
49 | 64 |
50 static void | 65 static void |
51 hb_ot_shape_collect_features (hb_ot_shape_plan_t *plan, | 66 hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, |
52 const hb_segment_properties_t *props, | 67 const hb_segment_properties_t *props, |
53 » » » const hb_feature_t *user_features, | 68 » » » const hb_feature_t *user_features, |
54 » » » unsigned int num_user_features) | 69 » » » unsigned int num_user_features) |
55 { | 70 { |
56 switch (props->direction) { | 71 switch (props->direction) { |
57 case HB_DIRECTION_LTR: | 72 case HB_DIRECTION_LTR: |
58 plan->map.add_bool_feature (HB_TAG ('l','t','r','a')); | 73 planner->map.add_bool_feature (HB_TAG ('l','t','r','a')); |
59 plan->map.add_bool_feature (HB_TAG ('l','t','r','m')); | 74 planner->map.add_bool_feature (HB_TAG ('l','t','r','m')); |
60 break; | 75 break; |
61 case HB_DIRECTION_RTL: | 76 case HB_DIRECTION_RTL: |
62 plan->map.add_bool_feature (HB_TAG ('r','t','l','a')); | 77 planner->map.add_bool_feature (HB_TAG ('r','t','l','a')); |
63 plan->map.add_bool_feature (HB_TAG ('r','t','l','m'), false); | 78 planner->map.add_bool_feature (HB_TAG ('r','t','l','m'), false); |
64 break; | 79 break; |
65 case HB_DIRECTION_TTB: | 80 case HB_DIRECTION_TTB: |
66 case HB_DIRECTION_BTT: | 81 case HB_DIRECTION_BTT: |
| 82 case HB_DIRECTION_INVALID: |
67 default: | 83 default: |
68 break; | 84 break; |
69 } | 85 } |
70 | 86 |
71 for (unsigned int i = 0; i < ARRAY_LENGTH (default_features); i++) | 87 #define ADD_FEATURES(array) \ |
72 plan->map.add_bool_feature (default_features[i]); | 88 HB_STMT_START { \ |
| 89 for (unsigned int i = 0; i < ARRAY_LENGTH (array); i++) \ |
| 90 planner->map.add_bool_feature (array[i]); \ |
| 91 } HB_STMT_END |
73 | 92 |
74 hb_ot_shape_complex_collect_features (plan, props); | 93 hb_ot_shape_complex_collect_features (planner->shaper, &planner->map, props); |
| 94 |
| 95 ADD_FEATURES (common_features); |
| 96 |
| 97 if (HB_DIRECTION_IS_HORIZONTAL (props->direction)) |
| 98 ADD_FEATURES (horizontal_features); |
| 99 else |
| 100 ADD_FEATURES (vertical_features); |
| 101 |
| 102 #undef ADD_FEATURES |
75 | 103 |
76 for (unsigned int i = 0; i < num_user_features; i++) { | 104 for (unsigned int i = 0; i < num_user_features; i++) { |
77 const hb_feature_t *feature = &user_features[i]; | 105 const hb_feature_t *feature = &user_features[i]; |
78 plan->map.add_feature (feature->tag, feature->value, (feature->start == 0 &&
feature->end == (unsigned int) -1)); | 106 planner->map.add_feature (feature->tag, feature->value, (feature->start == 0
&& feature->end == (unsigned int) -1)); |
79 } | 107 } |
80 } | 108 } |
81 | 109 |
82 | 110 |
83 static void | 111 static void |
84 hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) | 112 hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) |
85 { | 113 { |
86 hb_mask_t global_mask = c->plan->map.get_global_mask (); | 114 hb_mask_t global_mask = c->plan->map.get_global_mask (); |
87 c->buffer->reset_masks (global_mask); | 115 c->buffer->reset_masks (global_mask); |
88 | 116 |
89 hb_ot_shape_complex_setup_masks (c); /* BUFFER: Clobbers var2 */ | 117 hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer); |
90 | 118 |
91 for (unsigned int i = 0; i < c->num_user_features; i++) | 119 for (unsigned int i = 0; i < c->num_user_features; i++) |
92 { | 120 { |
93 const hb_feature_t *feature = &c->user_features[i]; | 121 const hb_feature_t *feature = &c->user_features[i]; |
94 if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { | 122 if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { |
95 unsigned int shift; | 123 unsigned int shift; |
96 hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift); | 124 hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift); |
97 c->buffer->set_masks (feature->value << shift, mask, feature->start, featu
re->end); | 125 c->buffer->set_masks (feature->value << shift, mask, feature->start, featu
re->end); |
98 } | 126 } |
99 } | 127 } |
100 } | 128 } |
101 | 129 |
102 | 130 |
103 static void | |
104 hb_ot_substitute_complex (hb_ot_shape_context_t *c) | |
105 { | |
106 if (!hb_ot_layout_has_substitution (c->face)) | |
107 return; | |
108 | |
109 c->plan->map.substitute (c->face, c->buffer); | |
110 | |
111 c->applied_substitute_complex = TRUE; | |
112 return; | |
113 } | |
114 | |
115 static void | |
116 hb_ot_position_complex (hb_ot_shape_context_t *c) | |
117 { | |
118 | |
119 if (!hb_ot_layout_has_positioning (c->face)) | |
120 return; | |
121 | |
122 c->plan->map.position (c->font, c->face, c->buffer); | |
123 | |
124 hb_ot_layout_position_finish (c->buffer); | |
125 | |
126 c->applied_position_complex = TRUE; | |
127 return; | |
128 } | |
129 | |
130 | |
131 /* Main shaper */ | 131 /* Main shaper */ |
132 | 132 |
133 /* Prepare */ | 133 /* Prepare */ |
134 | 134 |
135 static inline hb_bool_t | 135 void |
136 is_variation_selector (hb_codepoint_t unicode) | 136 _hb_set_unicode_props (hb_buffer_t *buffer) |
137 { | 137 { |
138 return unlikely ((unicode >= 0x180B && unicode <= 0x180D) || /* MONGOLIAN FR
EE VARIATION SELECTOR ONE..THREE */ | 138 unsigned int count = buffer->len; |
139 » » (unicode >= 0xFE00 && unicode <= 0xFE0F) || /* VARIATION SE
LECTOR-1..16 */ | 139 for (unsigned int i = 1; i < count; i++) |
140 » » (unicode >= 0xE0100 && unicode <= 0xE01EF)); /* VARIATION SE
LECTOR-17..256 */ | 140 hb_glyph_info_set_unicode_props (&buffer->info[i], buffer->unicode); |
141 } | 141 } |
142 | 142 |
143 static void | 143 static void |
144 hb_set_unicode_props (hb_ot_shape_context_t *c) | 144 hb_form_clusters (hb_buffer_t *buffer) |
145 { | 145 { |
146 hb_unicode_get_general_category_func_t get_general_category = c->buffer->unico
de->v.get_general_category; | 146 unsigned int count = buffer->len; |
147 hb_unicode_get_combining_class_func_t get_combining_class = c->buffer->unicode
->v.get_combining_class; | 147 for (unsigned int i = 1; i < count; i++) |
148 hb_glyph_info_t *info = c->buffer->info; | 148 if (FLAG (buffer->info[i].general_category()) & |
149 | 149 » (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | |
150 unsigned int count = c->buffer->len; | 150 » FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | |
151 for (unsigned int i = 1; i < count; i++) { | 151 » FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))) |
152 info[i].general_category() = get_general_category (info[i].codepoint); | 152 buffer->info[i].cluster = buffer->info[i - 1].cluster; |
153 info[i].combining_class() = get_combining_class (info[i].codepoint); | |
154 } | |
155 } | 153 } |
156 | 154 |
157 static void | 155 static void |
158 hb_form_clusters (hb_ot_shape_context_t *c) | 156 hb_ensure_native_direction (hb_buffer_t *buffer) |
159 { | 157 { |
160 unsigned int count = c->buffer->len; | 158 hb_direction_t direction = buffer->props.direction; |
161 for (unsigned int i = 1; i < count; i++) | |
162 if (c->buffer->info[i].general_category() == HB_CATEGORY_NON_SPACING_MARK) | |
163 c->buffer->info[i].cluster = c->buffer->info[i - 1].cluster; | |
164 } | |
165 | 159 |
166 static void | 160 /* TODO vertical: |
167 hb_ensure_native_direction (hb_ot_shape_context_t *c) | 161 * The only BTT vertical script is Ogham, but it's not clear to me whether Ope
nType |
168 { | 162 * Ogham fonts are supposed to be implemented BTT or not. Need to research th
at |
169 hb_direction_t direction = c->buffer->props.direction; | 163 * first. */ |
170 | 164 if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_hori
zontal_direction (buffer->props.script)) || |
171 /* TODO vertical */ | 165 (HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB)) |
172 if (HB_DIRECTION_IS_HORIZONTAL (direction) && | |
173 direction != _hb_script_get_horizontal_direction (c->buffer->props.script)
) | |
174 { | 166 { |
175 hb_buffer_reverse_clusters (c->buffer); | 167 hb_buffer_reverse_clusters (buffer); |
176 c->buffer->props.direction = HB_DIRECTION_REVERSE (c->buffer->props.directio
n); | 168 buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction); |
177 } | 169 } |
178 } | 170 } |
179 | 171 |
180 static void | |
181 hb_reset_glyph_infos (hb_ot_shape_context_t *c) | |
182 { | |
183 unsigned int count = c->buffer->len; | |
184 for (unsigned int i = 0; i < count; i++) | |
185 c->buffer->info[i].var1.u32 = c->buffer->info[i].var2.u32 = 0; | |
186 } | |
187 | |
188 | 172 |
189 /* Substitute */ | 173 /* Substitute */ |
190 | 174 |
191 static void | 175 static void |
192 hb_mirror_chars (hb_ot_shape_context_t *c) | 176 hb_mirror_chars (hb_ot_shape_context_t *c) |
193 { | 177 { |
194 hb_unicode_get_mirroring_func_t get_mirroring = c->buffer->unicode->v.get_mirr
oring; | 178 hb_unicode_funcs_t *unicode = c->buffer->unicode; |
195 | 179 |
196 if (HB_DIRECTION_IS_FORWARD (c->target_direction)) | 180 if (HB_DIRECTION_IS_FORWARD (c->target_direction)) |
197 return; | 181 return; |
198 | 182 |
199 hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m')); | 183 hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m')); |
200 | 184 |
201 unsigned int count = c->buffer->len; | 185 unsigned int count = c->buffer->len; |
202 for (unsigned int i = 0; i < count; i++) { | 186 for (unsigned int i = 0; i < count; i++) { |
203 hb_codepoint_t codepoint = get_mirroring (c->buffer->info[i].codepoint); | 187 hb_codepoint_t codepoint = hb_unicode_mirroring (unicode, c->buffer->info[i]
.codepoint); |
204 if (likely (codepoint == c->buffer->info[i].codepoint)) | 188 if (likely (codepoint == c->buffer->info[i].codepoint)) |
205 c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to befor
e setting user-feature masks */ | 189 c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to befor
e setting user-feature masks */ |
206 else | 190 else |
207 c->buffer->info[i].codepoint = codepoint; | 191 c->buffer->info[i].codepoint = codepoint; |
208 } | 192 } |
209 } | 193 } |
210 | 194 |
211 static void | 195 static void |
212 hb_map_glyphs (hb_font_t *font, | 196 hb_map_glyphs (hb_font_t *font, |
213 hb_face_t *face, | |
214 hb_buffer_t *buffer) | 197 hb_buffer_t *buffer) |
215 { | 198 { |
| 199 hb_codepoint_t glyph; |
| 200 |
216 if (unlikely (!buffer->len)) | 201 if (unlikely (!buffer->len)) |
217 return; | 202 return; |
218 | 203 |
219 buffer->clear_output (); | 204 buffer->clear_output (); |
| 205 |
220 unsigned int count = buffer->len - 1; | 206 unsigned int count = buffer->len - 1; |
221 for (buffer->i = 0; buffer->i < count;) { | 207 for (buffer->idx = 0; buffer->idx < count;) { |
222 if (unlikely (is_variation_selector (buffer->info[buffer->i + 1].codepoint))
) { | 208 if (unlikely (is_variation_selector (buffer->info[buffer->idx + 1].codepoint
))) { |
223 buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer-
>i].codepoint, buffer->info[buffer->i + 1].codepoint)); | 209 hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, buffer->info
[buffer->idx + 1].codepoint, &glyph); |
224 buffer->i++; | 210 buffer->replace_glyph (glyph); |
| 211 buffer->skip_glyph (); |
225 } else { | 212 } else { |
226 buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer-
>i].codepoint, 0)); | 213 hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, 0, &glyph); |
| 214 buffer->replace_glyph (glyph); |
227 } | 215 } |
228 } | 216 } |
229 if (likely (buffer->i < buffer->len)) | 217 if (likely (buffer->idx < buffer->len)) { |
230 buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i
].codepoint, 0)); | 218 hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, 0, &glyph); |
231 buffer->swap (); | 219 buffer->replace_glyph (glyph); |
| 220 } |
| 221 buffer->swap_buffers (); |
232 } | 222 } |
233 | 223 |
234 static void | 224 static void |
235 hb_substitute_default (hb_ot_shape_context_t *c) | 225 hb_substitute_default (hb_ot_shape_context_t *c) |
236 { | 226 { |
237 hb_map_glyphs (c->font, c->face, c->buffer); | 227 hb_ot_layout_substitute_start (c->buffer); |
| 228 |
| 229 hb_mirror_chars (c); |
| 230 |
| 231 hb_map_glyphs (c->font, c->buffer); |
238 } | 232 } |
239 | 233 |
240 static void | 234 static void |
| 235 hb_ot_substitute_complex (hb_ot_shape_context_t *c) |
| 236 { |
| 237 if (hb_ot_layout_has_substitution (c->face)) { |
| 238 c->plan->map.substitute (c->face, c->buffer); |
| 239 c->applied_substitute_complex = TRUE; |
| 240 } |
| 241 |
| 242 hb_ot_layout_substitute_finish (c->buffer); |
| 243 |
| 244 return; |
| 245 } |
| 246 |
| 247 static void |
241 hb_substitute_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) | 248 hb_substitute_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) |
242 { | 249 { |
243 /* TODO Arabic */ | 250 /* TODO Arabic */ |
244 } | 251 } |
245 | 252 |
246 | 253 |
247 /* Position */ | 254 /* Position */ |
248 | 255 |
249 static void | 256 static void |
250 hb_position_default (hb_ot_shape_context_t *c) | 257 hb_position_default (hb_ot_shape_context_t *c) |
251 { | 258 { |
252 hb_buffer_clear_positions (c->buffer); | 259 hb_ot_layout_position_start (c->buffer); |
253 | 260 |
254 unsigned int count = c->buffer->len; | 261 unsigned int count = c->buffer->len; |
255 for (unsigned int i = 0; i < count; i++) { | 262 for (unsigned int i = 0; i < count; i++) { |
256 hb_font_get_glyph_advance (c->font, c->face, c->buffer->info[i].codepoint, | 263 hb_font_get_glyph_advance_for_direction (c->font, c->buffer->info[i].codepoi
nt, |
257 » » » &c->buffer->pos[i].x_advance, | 264 » » » » » c->buffer->props.direction, |
258 » » » &c->buffer->pos[i].y_advance); | 265 » » » » » &c->buffer->pos[i].x_advance, |
| 266 » » » » » &c->buffer->pos[i].y_advance); |
| 267 hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].cod
epoint, |
| 268 » » » » » » c->buffer->props.direction, |
| 269 » » » » » » &c->buffer->pos[i].x_offset, |
| 270 » » » » » » &c->buffer->pos[i].y_offset); |
259 } | 271 } |
260 } | 272 } |
261 | 273 |
262 static void | 274 static void |
| 275 hb_ot_position_complex (hb_ot_shape_context_t *c) |
| 276 { |
| 277 |
| 278 if (hb_ot_layout_has_positioning (c->face)) |
| 279 { |
| 280 /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */ |
| 281 |
| 282 unsigned int count = c->buffer->len; |
| 283 for (unsigned int i = 0; i < count; i++) { |
| 284 hb_font_add_glyph_origin_for_direction (c->font, c->buffer->info[i].codepo
int, |
| 285 HB_DIRECTION_LTR, |
| 286 &c->buffer->pos[i].x_offset, |
| 287 &c->buffer->pos[i].y_offset); |
| 288 } |
| 289 |
| 290 c->plan->map.position (c->font, c->buffer); |
| 291 |
| 292 for (unsigned int i = 0; i < count; i++) { |
| 293 hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].c
odepoint, |
| 294 HB_DIRECTION_LTR, |
| 295 &c->buffer->pos[i].x_offset, |
| 296 &c->buffer->pos[i].y_offset); |
| 297 } |
| 298 |
| 299 c->applied_position_complex = TRUE; |
| 300 } |
| 301 |
| 302 hb_ot_layout_position_finish (c->buffer); |
| 303 |
| 304 return; |
| 305 } |
| 306 |
| 307 static void |
263 hb_position_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) | 308 hb_position_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) |
264 { | 309 { |
265 /* TODO Mark pos */ | 310 /* TODO Mark pos */ |
266 } | 311 } |
267 | 312 |
268 static void | 313 static void |
269 hb_truetype_kern (hb_ot_shape_context_t *c) | 314 hb_truetype_kern (hb_ot_shape_context_t *c) |
270 { | 315 { |
271 /* TODO Check for kern=0 */ | 316 /* TODO Check for kern=0 */ |
272 unsigned int count = c->buffer->len; | 317 unsigned int count = c->buffer->len; |
273 for (unsigned int i = 1; i < count; i++) { | 318 for (unsigned int i = 1; i < count; i++) { |
274 hb_position_t kern, kern1, kern2; | 319 hb_position_t x_kern, y_kern, kern1, kern2; |
275 kern = hb_font_get_kerning (c->font, c->face, c->buffer->info[i - 1].codepoi
nt, c->buffer->info[i].codepoint); | 320 hb_font_get_glyph_kerning_for_direction (c->font, |
276 kern1 = kern >> 1; | 321 » » » » » c->buffer->info[i - 1].codepoint, c
->buffer->info[i].codepoint, |
277 kern2 = kern - kern1; | 322 » » » » » c->buffer->props.direction, |
| 323 » » » » » &x_kern, &y_kern); |
| 324 |
| 325 kern1 = x_kern >> 1; |
| 326 kern2 = x_kern - kern1; |
278 c->buffer->pos[i - 1].x_advance += kern1; | 327 c->buffer->pos[i - 1].x_advance += kern1; |
279 c->buffer->pos[i].x_advance += kern2; | 328 c->buffer->pos[i].x_advance += kern2; |
280 c->buffer->pos[i].x_offset += kern2; | 329 c->buffer->pos[i].x_offset += kern2; |
| 330 |
| 331 kern1 = y_kern >> 1; |
| 332 kern2 = y_kern - kern1; |
| 333 c->buffer->pos[i - 1].y_advance += kern1; |
| 334 c->buffer->pos[i].y_advance += kern2; |
| 335 c->buffer->pos[i].y_offset += kern2; |
281 } | 336 } |
282 } | 337 } |
283 | 338 |
284 static void | 339 static void |
285 hb_position_complex_fallback_visual (hb_ot_shape_context_t *c) | 340 hb_position_complex_fallback_visual (hb_ot_shape_context_t *c) |
286 { | 341 { |
287 hb_truetype_kern (c); | 342 hb_truetype_kern (c); |
288 } | 343 } |
289 | 344 |
290 | 345 |
291 /* Do it! */ | 346 /* Do it! */ |
292 | 347 |
293 static void | 348 static void |
294 hb_ot_shape_execute_internal (hb_ot_shape_context_t *c) | 349 hb_ot_shape_execute_internal (hb_ot_shape_context_t *c) |
295 { | 350 { |
| 351 c->buffer->deallocate_var_all (); |
| 352 |
296 /* Save the original direction, we use it later. */ | 353 /* Save the original direction, we use it later. */ |
297 c->target_direction = c->buffer->props.direction; | 354 c->target_direction = c->buffer->props.direction; |
298 | 355 |
299 hb_reset_glyph_infos (c); /* BUFFER: Clear buffer var1 and var2 */ | 356 HB_BUFFER_ALLOCATE_VAR (c->buffer, general_category); |
| 357 HB_BUFFER_ALLOCATE_VAR (c->buffer, combining_class); |
300 | 358 |
301 hb_set_unicode_props (c); /* BUFFER: Set general_category and combining_class
in var1 */ | 359 _hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combini
ng_class */ |
302 | 360 |
303 hb_ensure_native_direction (c); | 361 hb_form_clusters (c->buffer); |
304 | 362 |
305 hb_form_clusters (c); | 363 hb_ensure_native_direction (c->buffer); |
306 | 364 |
307 hb_ot_shape_setup_masks (c); /* BUFFER: Clobbers var2 */ | 365 _hb_ot_shape_normalize (c); |
| 366 |
| 367 hb_ot_shape_setup_masks (c); |
308 | 368 |
309 /* SUBSTITUTE */ | 369 /* SUBSTITUTE */ |
310 { | 370 { |
311 /* Mirroring needs to see the original direction */ | |
312 hb_mirror_chars (c); | |
313 | |
314 hb_substitute_default (c); | 371 hb_substitute_default (c); |
315 | 372 |
316 hb_ot_substitute_complex (c); | 373 hb_ot_substitute_complex (c); |
317 | 374 |
318 if (!c->applied_substitute_complex) | 375 if (!c->applied_substitute_complex) |
319 hb_substitute_complex_fallback (c); | 376 hb_substitute_complex_fallback (c); |
320 } | 377 } |
321 | 378 |
322 /* POSITION */ | 379 /* POSITION */ |
323 { | 380 { |
324 hb_position_default (c); | 381 hb_position_default (c); |
325 | 382 |
326 hb_ot_position_complex (c); | 383 hb_ot_position_complex (c); |
327 | 384 |
328 hb_bool_t position_fallback = !c->applied_position_complex; | 385 hb_bool_t position_fallback = !c->applied_position_complex; |
329 if (position_fallback) | 386 if (position_fallback) |
330 hb_position_complex_fallback (c); | 387 hb_position_complex_fallback (c); |
331 | 388 |
332 if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) | 389 if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) |
333 hb_buffer_reverse (c->buffer); | 390 hb_buffer_reverse (c->buffer); |
334 | 391 |
335 if (position_fallback) | 392 if (position_fallback) |
336 hb_position_complex_fallback_visual (c); | 393 hb_position_complex_fallback_visual (c); |
337 } | 394 } |
338 | 395 |
| 396 HB_BUFFER_DEALLOCATE_VAR (c->buffer, combining_class); |
| 397 HB_BUFFER_DEALLOCATE_VAR (c->buffer, general_category); |
| 398 |
339 c->buffer->props.direction = c->target_direction; | 399 c->buffer->props.direction = c->target_direction; |
| 400 |
| 401 c->buffer->deallocate_var_all (); |
340 } | 402 } |
341 | 403 |
342 void | 404 static void |
343 hb_ot_shape_plan_internal (hb_ot_shape_plan_t *plan, | 405 hb_ot_shape_plan_internal (hb_ot_shape_plan_t *plan, |
344 hb_face_t *face, | 406 hb_face_t *face, |
345 const hb_segment_properties_t *props, | 407 const hb_segment_properties_t *props, |
346 const hb_feature_t *user_features, | 408 const hb_feature_t *user_features, |
347 unsigned int num_user_features) | 409 unsigned int num_user_features) |
348 { | 410 { |
349 plan->shaper = hb_ot_shape_complex_categorize (props); | 411 hb_ot_shape_planner_t planner; |
350 | 412 |
351 hb_ot_shape_collect_features (plan, props, user_features, num_user_features); | 413 planner.shaper = hb_ot_shape_complex_categorize (props); |
352 | 414 |
353 plan->map.compile (face, props); | 415 hb_ot_shape_collect_features (&planner, props, user_features, num_user_feature
s); |
| 416 |
| 417 planner.compile (face, props, *plan); |
354 } | 418 } |
355 | 419 |
356 void | 420 static void |
357 hb_ot_shape_execute (hb_ot_shape_plan_t *plan, | 421 hb_ot_shape_execute (hb_ot_shape_plan_t *plan, |
358 hb_font_t *font, | 422 hb_font_t *font, |
359 hb_face_t *face, | |
360 hb_buffer_t *buffer, | 423 hb_buffer_t *buffer, |
361 const hb_feature_t *user_features, | 424 const hb_feature_t *user_features, |
362 unsigned int num_user_features) | 425 unsigned int num_user_features) |
363 { | 426 { |
364 hb_ot_shape_context_t c = {plan, font, face, buffer, user_features, num_user_f
eatures}; | 427 hb_ot_shape_context_t c = {plan, font, font->face, buffer, user_features, num_
user_features}; |
365 hb_ot_shape_execute_internal (&c); | 428 hb_ot_shape_execute_internal (&c); |
366 } | 429 } |
367 | 430 |
368 void | 431 hb_bool_t |
369 hb_ot_shape (hb_font_t *font, | 432 hb_ot_shape (hb_font_t *font, |
370 » hb_face_t *face, | 433 » hb_buffer_t *buffer, |
371 » hb_buffer_t *buffer, | 434 » const hb_feature_t *features, |
372 » const hb_feature_t *user_features, | 435 » unsigned int num_features, |
373 » unsigned int num_user_features) | 436 » const char * const *shaper_options) |
374 { | 437 { |
375 hb_ot_shape_plan_t plan; | 438 hb_ot_shape_plan_t plan; |
376 | 439 |
377 hb_ot_shape_plan_internal (&plan, face, &buffer->props, user_features, num_use
r_features); | 440 buffer->guess_properties (); |
378 hb_ot_shape_execute (&plan, font, face, buffer, user_features, num_user_featur
es); | 441 |
| 442 hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_fe
atures); |
| 443 hb_ot_shape_execute (&plan, font, buffer, features, num_features); |
| 444 |
| 445 return TRUE; |
379 } | 446 } |
380 | 447 |
381 | 448 |
382 HB_END_DECLS | |
OLD | NEW |