OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2011 Martin Hosken | 2 * Copyright © 2011 Martin Hosken |
3 * Copyright © 2011 SIL International | 3 * Copyright © 2011 SIL International |
4 * Copyright © 2011,2012 Google, Inc. | 4 * Copyright © 2011,2012 Google, Inc. |
5 * | 5 * |
6 * This is part of HarfBuzz, a text shaping library. | 6 * This is part of HarfBuzz, a text shaping library. |
7 * | 7 * |
8 * Permission is hereby granted, without written agreement and without | 8 * Permission is hereby granted, without written agreement and without |
9 * license or royalty fees, to use, copy, modify, and distribute this | 9 * license or royalty fees, to use, copy, modify, and distribute this |
10 * software and its documentation for any purpose, provided that the | 10 * software and its documentation for any purpose, provided that the |
11 * above copyright notice and the following two paragraphs appear in | 11 * above copyright notice and the following two paragraphs appear in |
12 * all copies of this software. | 12 * all copies of this software. |
13 * | 13 * |
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | 14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | 15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | 16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | 17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
18 * DAMAGE. | 18 * DAMAGE. |
19 * | 19 * |
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | 21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | 22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO | 23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
25 * | 25 * |
26 * Google Author(s): Behdad Esfahbod | 26 * Google Author(s): Behdad Esfahbod |
27 */ | 27 */ |
28 | 28 |
29 #define HB_SHAPER graphite2 | 29 #define HB_SHAPER graphite2 |
30 #define hb_graphite2_shaper_font_data_t gr_font | |
31 #include "hb-shaper-impl-private.hh" | 30 #include "hb-shaper-impl-private.hh" |
32 | 31 |
33 #include "hb-graphite2.h" | 32 #include "hb-graphite2.h" |
34 | 33 |
35 #include <graphite2/Segment.h> | 34 #include <graphite2/Segment.h> |
36 | 35 |
37 | 36 |
38 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, face) | 37 HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, face) |
39 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, font) | 38 HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, font) |
40 | 39 |
41 | 40 |
42 /* | 41 /* |
43 * shaper face data | 42 * shaper face data |
44 */ | 43 */ |
45 | 44 |
46 typedef struct hb_graphite2_tablelist_t { | 45 typedef struct hb_graphite2_tablelist_t { |
47 struct hb_graphite2_tablelist_t *next; | 46 struct hb_graphite2_tablelist_t *next; |
48 hb_blob_t *blob; | 47 hb_blob_t *blob; |
49 unsigned int tag; | 48 unsigned int tag; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 { | 145 { |
147 if (unlikely (!hb_graphite2_shaper_face_data_ensure (face))) return NULL; | 146 if (unlikely (!hb_graphite2_shaper_face_data_ensure (face))) return NULL; |
148 return HB_SHAPER_DATA_GET (face)->grface; | 147 return HB_SHAPER_DATA_GET (face)->grface; |
149 } | 148 } |
150 | 149 |
151 | 150 |
152 /* | 151 /* |
153 * shaper font data | 152 * shaper font data |
154 */ | 153 */ |
155 | 154 |
156 static float hb_graphite2_get_advance (const void *hb_font, unsigned short gid) | 155 struct hb_graphite2_shaper_font_data_t {}; |
157 { | |
158 return ((hb_font_t *) hb_font)->get_glyph_h_advance (gid); | |
159 } | |
160 | 156 |
161 hb_graphite2_shaper_font_data_t * | 157 hb_graphite2_shaper_font_data_t * |
162 _hb_graphite2_shaper_font_data_create (hb_font_t *font) | 158 _hb_graphite2_shaper_font_data_create (hb_font_t *font HB_UNUSED) |
163 { | 159 { |
164 if (unlikely (!hb_graphite2_shaper_face_data_ensure (font->face))) return NULL
; | 160 return (hb_graphite2_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; |
165 | |
166 hb_face_t *face = font->face; | |
167 hb_graphite2_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); | |
168 | |
169 return gr_make_font_with_advance_fn (font->x_scale, font, &hb_graphite2_get_ad
vance, face_data->grface); | |
170 } | 161 } |
171 | 162 |
172 void | 163 void |
173 _hb_graphite2_shaper_font_data_destroy (hb_graphite2_shaper_font_data_t *data) | 164 _hb_graphite2_shaper_font_data_destroy (hb_graphite2_shaper_font_data_t *data HB
_UNUSED) |
174 { | 165 { |
175 gr_font_destroy (data); | |
176 } | 166 } |
177 | 167 |
178 /* | 168 /* |
179 * Since: 0.9.10 | 169 * Since: 0.9.10 |
180 */ | 170 */ |
181 gr_font * | 171 gr_font * |
182 hb_graphite2_font_get_gr_font (hb_font_t *font) | 172 hb_graphite2_font_get_gr_font (hb_font_t *font) |
183 { | 173 { |
184 if (unlikely (!hb_graphite2_shaper_font_data_ensure (font))) return NULL; | 174 return NULL; |
185 return HB_SHAPER_DATA_GET (font); | |
186 } | 175 } |
187 | 176 |
188 | 177 |
189 /* | 178 /* |
190 * shaper shape_plan data | 179 * shaper shape_plan data |
191 */ | 180 */ |
192 | 181 |
193 struct hb_graphite2_shaper_shape_plan_data_t {}; | 182 struct hb_graphite2_shaper_shape_plan_data_t {}; |
194 | 183 |
195 hb_graphite2_shaper_shape_plan_data_t * | 184 hb_graphite2_shaper_shape_plan_data_t * |
(...skipping 27 matching lines...) Expand all Loading... |
223 | 212 |
224 hb_bool_t | 213 hb_bool_t |
225 _hb_graphite2_shape (hb_shape_plan_t *shape_plan, | 214 _hb_graphite2_shape (hb_shape_plan_t *shape_plan, |
226 hb_font_t *font, | 215 hb_font_t *font, |
227 hb_buffer_t *buffer, | 216 hb_buffer_t *buffer, |
228 const hb_feature_t *features, | 217 const hb_feature_t *features, |
229 unsigned int num_features) | 218 unsigned int num_features) |
230 { | 219 { |
231 hb_face_t *face = font->face; | 220 hb_face_t *face = font->face; |
232 gr_face *grface = HB_SHAPER_DATA_GET (face)->grface; | 221 gr_face *grface = HB_SHAPER_DATA_GET (face)->grface; |
233 gr_font *grfont = HB_SHAPER_DATA_GET (font); | |
234 | 222 |
235 const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); | 223 const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); |
236 const char *lang_end = lang ? strchr (lang, '-') : NULL; | 224 const char *lang_end = lang ? strchr (lang, '-') : NULL; |
237 int lang_len = lang_end ? lang_end - lang : -1; | 225 int lang_len = lang_end ? lang_end - lang : -1; |
238 gr_feature_val *feats = gr_face_featureval_for_lang (grface, lang ? hb_tag_fro
m_string (lang, lang_len) : 0); | 226 gr_feature_val *feats = gr_face_featureval_for_lang (grface, lang ? hb_tag_fro
m_string (lang, lang_len) : 0); |
239 | 227 |
240 for (unsigned int i = 0; i < num_features; i++) | 228 for (unsigned int i = 0; i < num_features; i++) |
241 { | 229 { |
242 const gr_feature_ref *fref = gr_face_find_fref (grface, features[i].tag); | 230 const gr_feature_ref *fref = gr_face_find_fref (grface, features[i].tag); |
243 if (fref) | 231 if (fref) |
(...skipping 11 matching lines...) Expand all Loading... |
255 uint32_t *chars = (uint32_t *) scratch; | 243 uint32_t *chars = (uint32_t *) scratch; |
256 | 244 |
257 for (unsigned int i = 0; i < buffer->len; ++i) | 245 for (unsigned int i = 0; i < buffer->len; ++i) |
258 chars[i] = buffer->info[i].codepoint; | 246 chars[i] = buffer->info[i].codepoint; |
259 | 247 |
260 /* TODO ensure_native_direction. */ | 248 /* TODO ensure_native_direction. */ |
261 | 249 |
262 hb_tag_t script_tag[2]; | 250 hb_tag_t script_tag[2]; |
263 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script
_tag[1]); | 251 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script
_tag[1]); |
264 | 252 |
265 seg = gr_make_seg (grfont, grface, | 253 seg = gr_make_seg (NULL, grface, |
266 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1
], | 254 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1
], |
267 feats, | 255 feats, |
268 gr_utf32, chars, buffer->len, | 256 gr_utf32, chars, buffer->len, |
269 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ?
1 : 0)); | 257 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ?
1 : 0)); |
270 | 258 |
271 if (unlikely (!seg)) { | 259 if (unlikely (!seg)) { |
272 if (feats) gr_featureval_destroy (feats); | 260 if (feats) gr_featureval_destroy (feats); |
273 return false; | 261 return false; |
274 } | 262 } |
275 | 263 |
(...skipping 30 matching lines...) Expand all Loading... |
306 | 294 |
307 ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len); | 295 ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len); |
308 ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count); | 296 ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count); |
309 | 297 |
310 #undef ALLOCATE_ARRAY | 298 #undef ALLOCATE_ARRAY |
311 | 299 |
312 memset (clusters, 0, sizeof (clusters[0]) * buffer->len); | 300 memset (clusters, 0, sizeof (clusters[0]) * buffer->len); |
313 | 301 |
314 hb_codepoint_t *pg = gids; | 302 hb_codepoint_t *pg = gids; |
315 clusters[0].cluster = buffer->info[0].cluster; | 303 clusters[0].cluster = buffer->info[0].cluster; |
316 float curradv = HB_DIRECTION_IS_BACKWARD(buffer->props.direction) ? gr_slot_or
igin_X(gr_seg_first_slot(seg)) : 0.; | 304 float curradv = 0.; |
317 if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) | 305 if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) |
318 { | 306 { |
319 curradv = gr_slot_origin_X(gr_seg_first_slot(seg)); | 307 curradv = gr_slot_origin_X(gr_seg_first_slot(seg)); |
320 clusters[0].advance = gr_seg_advance_X(seg) - curradv; | 308 clusters[0].advance = gr_seg_advance_X(seg) - curradv; |
321 } | 309 } |
322 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i
s), ic++) | 310 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i
s), ic++) |
323 { | 311 { |
324 unsigned int before = gr_slot_before (is); | 312 unsigned int before = gr_slot_before (is); |
325 unsigned int after = gr_slot_after (is); | 313 unsigned int after = gr_slot_after (is); |
326 *pg = gr_slot_gid (is); | 314 *pg = gr_slot_gid (is); |
327 pg++; | 315 pg++; |
328 while (clusters[ci].base_char > before && ci) | 316 while (clusters[ci].base_char > before && ci) |
329 { | 317 { |
330 clusters[ci-1].num_chars += clusters[ci].num_chars; | 318 clusters[ci-1].num_chars += clusters[ci].num_chars; |
331 clusters[ci-1].num_glyphs += clusters[ci].num_glyphs; | 319 clusters[ci-1].num_glyphs += clusters[ci].num_glyphs; |
332 clusters[ci-1].advance += clusters[ci].advance; | 320 clusters[ci-1].advance += clusters[ci].advance; |
333 ci--; | 321 ci--; |
334 } | 322 } |
335 | 323 |
336 if (gr_slot_can_insert_before (is) && clusters[ci].num_chars && before >= cl
usters[ci].base_char + clusters[ci].num_chars) | 324 if (gr_slot_can_insert_before (is) && clusters[ci].num_chars && before >= cl
usters[ci].base_char + clusters[ci].num_chars) |
337 { | 325 { |
338 hb_graphite2_cluster_t *c = clusters + ci + 1; | 326 hb_graphite2_cluster_t *c = clusters + ci + 1; |
339 c->base_char = clusters[ci].base_char + clusters[ci].num_chars; | 327 c->base_char = clusters[ci].base_char + clusters[ci].num_chars; |
340 c->cluster = buffer->info[c->base_char].cluster; | 328 c->cluster = buffer->info[c->base_char].cluster; |
341 c->num_chars = before - c->base_char; | 329 c->num_chars = before - c->base_char; |
342 c->base_glyph = ic; | 330 c->base_glyph = ic; |
343 c->num_glyphs = 0; | 331 c->num_glyphs = 0; |
344 if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) | 332 if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) |
345 { | 333 c->advance = curradv - gr_slot_origin_X(is); |
346 ci++; | 334 else |
347 clusters[ci].advance = curradv - gr_slot_origin_X(is); | |
348 } else { | |
349 clusters[ci].advance = gr_slot_origin_X(is) - curradv; | 335 clusters[ci].advance = gr_slot_origin_X(is) - curradv; |
350 ci++; | 336 ci++; |
351 } | |
352 curradv = gr_slot_origin_X(is); | 337 curradv = gr_slot_origin_X(is); |
353 } | 338 } |
354 clusters[ci].num_glyphs++; | 339 clusters[ci].num_glyphs++; |
355 | 340 |
356 if (clusters[ci].base_char + clusters[ci].num_chars < after + 1) | 341 if (clusters[ci].base_char + clusters[ci].num_chars < after + 1) |
357 clusters[ci].num_chars = after + 1 - clusters[ci].base_char; | 342 clusters[ci].num_chars = after + 1 - clusters[ci].base_char; |
358 } | 343 } |
359 | 344 |
360 if (!HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) | 345 if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) |
| 346 clusters[ci].advance += curradv; |
| 347 else |
361 clusters[ci].advance = gr_seg_advance_X(seg) - curradv; | 348 clusters[ci].advance = gr_seg_advance_X(seg) - curradv; |
362 ci++; | 349 ci++; |
363 | 350 |
364 for (unsigned int i = 0; i < ci; ++i) | 351 for (unsigned int i = 0; i < ci; ++i) |
365 { | 352 { |
366 for (unsigned int j = 0; j < clusters[i].num_glyphs; ++j) | 353 for (unsigned int j = 0; j < clusters[i].num_glyphs; ++j) |
367 { | 354 { |
368 hb_glyph_info_t *info = &buffer->info[clusters[i].base_glyph + j]; | 355 hb_glyph_info_t *info = &buffer->info[clusters[i].base_glyph + j]; |
369 info->codepoint = gids[clusters[i].base_glyph + j]; | 356 info->codepoint = gids[clusters[i].base_glyph + j]; |
370 info->cluster = clusters[i].cluster; | 357 info->cluster = clusters[i].cluster; |
371 info->var1.i32 = clusters[i].advance; // all glyphs in the cluster get
the same advance | 358 info->var1.i32 = clusters[i].advance; // all glyphs in the cluster get
the same advance |
372 } | 359 } |
373 } | 360 } |
374 buffer->len = glyph_count; | 361 buffer->len = glyph_count; |
375 | 362 |
376 float yscale = font->y_scale / font->x_scale; | 363 unsigned int upem = hb_face_get_upem (face); |
| 364 float xscale = (float) font->x_scale / upem; |
| 365 float yscale = (float) font->y_scale / upem; |
| 366 yscale *= yscale / xscale; |
377 /* Positioning. */ | 367 /* Positioning. */ |
| 368 int currclus = -1; |
| 369 const hb_glyph_info_t *info = buffer->info; |
| 370 hb_glyph_position_t *pPos = hb_buffer_get_glyph_positions (buffer, NULL); |
378 if (!HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) | 371 if (!HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) |
379 { | 372 { |
380 int currclus = -1; | |
381 const hb_glyph_info_t *info = buffer->info; | |
382 hb_glyph_position_t *pPos = hb_buffer_get_glyph_positions (buffer, NULL); | |
383 curradvx = 0; | 373 curradvx = 0; |
384 for (is = gr_seg_first_slot (seg); is; pPos++, ++info, is = gr_slot_next_in_
segment (is)) | 374 for (is = gr_seg_first_slot (seg); is; pPos++, ++info, is = gr_slot_next_in_
segment (is)) |
385 { | 375 { |
386 pPos->x_offset = gr_slot_origin_X (is) - curradvx; | 376 pPos->x_offset = gr_slot_origin_X (is) * xscale - curradvx; |
387 pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy; | 377 pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy; |
388 if (info->cluster != currclus) { | 378 if (info->cluster != currclus) { |
389 pPos->x_advance = info->var1.i32; | 379 pPos->x_advance = info->var1.i32 * xscale; |
390 curradvx += pPos->x_advance; | 380 curradvx += pPos->x_advance; |
391 currclus = info->cluster; | 381 currclus = info->cluster; |
392 } else | 382 } else |
393 pPos->x_advance = 0.; | 383 pPos->x_advance = 0.; |
394 | 384 |
395 pPos->y_advance = gr_slot_advance_Y (is, grface, grfont) * yscale; | 385 pPos->y_advance = gr_slot_advance_Y (is, grface, NULL) * yscale; |
396 curradvy += pPos->y_advance; | 386 curradvy += pPos->y_advance; |
397 } | 387 } |
398 } | 388 } |
399 else | 389 else |
400 { | 390 { |
401 int currclus = -1; | |
402 const hb_glyph_info_t *info = buffer->info; | |
403 hb_glyph_position_t *pPos = hb_buffer_get_glyph_positions (buffer, NULL); | |
404 curradvx = gr_seg_advance_X(seg); | 391 curradvx = gr_seg_advance_X(seg); |
405 for (is = gr_seg_first_slot (seg); is; pPos++, info++, is = gr_slot_next_in_
segment (is)) | 392 for (is = gr_seg_first_slot (seg); is; pPos++, info++, is = gr_slot_next_in_
segment (is)) |
406 { | 393 { |
407 if (info->cluster != currclus) | 394 if (info->cluster != currclus) |
408 { | 395 { |
409 pPos->x_advance = info->var1.i32; | 396 pPos->x_advance = info->var1.i32 * xscale; |
410 if (currclus != -1) curradvx -= info[-1].var1.i32; | 397 curradvx -= pPos->x_advance; |
411 currclus = info->cluster; | 398 currclus = info->cluster; |
412 } else | 399 } else |
413 pPos->x_advance = 0.; | 400 pPos->x_advance = 0.; |
414 | 401 |
415 pPos->y_advance = gr_slot_advance_Y (is, grface, grfont) * yscale; | 402 pPos->y_advance = gr_slot_advance_Y (is, grface, NULL) * yscale; |
416 curradvy -= pPos->y_advance; | 403 curradvy -= pPos->y_advance; |
417 pPos->x_offset = gr_slot_origin_X (is) - curradvx + pPos->x_advance; | 404 pPos->x_offset = (gr_slot_origin_X (is) - info->var1.i32) * xscale - curra
dvx + pPos->x_advance; |
418 pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy; | 405 pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy; |
419 } | 406 } |
420 hb_buffer_reverse_clusters (buffer); | 407 hb_buffer_reverse_clusters (buffer); |
421 } | 408 } |
422 | 409 |
423 if (feats) gr_featureval_destroy (feats); | 410 if (feats) gr_featureval_destroy (feats); |
424 gr_seg_destroy (seg); | 411 gr_seg_destroy (seg); |
425 | 412 |
426 return true; | 413 return true; |
427 } | 414 } |
OLD | NEW |