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 |
(...skipping 12 matching lines...) Expand all Loading... |
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 | 30 #define hb_graphite2_shaper_font_data_t gr_font |
31 #include "hb-shaper-impl-private.hh" | 31 #include "hb-shaper-impl-private.hh" |
32 | 32 |
33 #include <graphite2/Font.h> | 33 #include "hb-graphite2.h" |
| 34 |
34 #include <graphite2/Segment.h> | 35 #include <graphite2/Segment.h> |
35 | 36 |
36 #include "hb-graphite2.h" | |
37 | |
38 #include "hb-ot-tag.h" | 37 #include "hb-ot-tag.h" |
39 | 38 |
40 | 39 |
41 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, face) | 40 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, face) |
42 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, font) | 41 HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, font) |
43 | 42 |
44 | 43 |
45 /* | 44 /* |
46 * shaper face data | 45 * shaper face data |
47 */ | 46 */ |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 gr_fref_set_feature_value (fref, features->value, feats); | 236 gr_fref_set_feature_value (fref, features->value, feats); |
238 features++; | 237 features++; |
239 } | 238 } |
240 | 239 |
241 gr_segment *seg = NULL; | 240 gr_segment *seg = NULL; |
242 const gr_slot *is; | 241 const gr_slot *is; |
243 unsigned int ci = 0, ic = 0; | 242 unsigned int ci = 0, ic = 0; |
244 float curradvx = 0., curradvy = 0.; | 243 float curradvx = 0., curradvy = 0.; |
245 | 244 |
246 unsigned int scratch_size; | 245 unsigned int scratch_size; |
247 char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); | 246 hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_
size); |
248 | 247 |
249 #define ALLOCATE_ARRAY(Type, name, len) \ | 248 uint32_t *chars = (uint32_t *) scratch; |
250 Type *name = (Type *) scratch; \ | |
251 scratch += (len) * sizeof ((name)[0]); \ | |
252 scratch_size -= (len) * sizeof ((name)[0]); | |
253 | |
254 ALLOCATE_ARRAY (uint32_t, chars, buffer->len); | |
255 | 249 |
256 for (unsigned int i = 0; i < buffer->len; ++i) | 250 for (unsigned int i = 0; i < buffer->len; ++i) |
257 chars[i] = buffer->info[i].codepoint; | 251 chars[i] = buffer->info[i].codepoint; |
258 | 252 |
259 hb_tag_t script_tag[2]; | 253 hb_tag_t script_tag[2]; |
260 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script
_tag[1]); | 254 hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script
_tag[1]); |
261 | 255 |
262 seg = gr_make_seg (grfont, grface, | 256 seg = gr_make_seg (grfont, grface, |
263 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1
], | 257 script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1
], |
264 feats, | 258 feats, |
265 gr_utf32, chars, buffer->len, | 259 gr_utf32, chars, buffer->len, |
266 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ?
1 : 0)); | 260 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ?
1 : 0)); |
267 | 261 |
268 if (unlikely (!seg)) { | 262 if (unlikely (!seg)) { |
269 if (feats) gr_featureval_destroy (feats); | 263 if (feats) gr_featureval_destroy (feats); |
270 return false; | 264 return false; |
271 } | 265 } |
272 | 266 |
273 unsigned int glyph_count = gr_seg_n_slots (seg); | 267 unsigned int glyph_count = gr_seg_n_slots (seg); |
274 if (unlikely (!glyph_count)) { | 268 if (unlikely (!glyph_count)) { |
275 if (feats) gr_featureval_destroy (feats); | 269 if (feats) gr_featureval_destroy (feats); |
276 gr_seg_destroy (seg); | 270 gr_seg_destroy (seg); |
277 return false; | 271 return false; |
278 } | 272 } |
279 | 273 |
280 scratch = (char *) buffer->get_scratch_buffer (&scratch_size); | 274 scratch = buffer->get_scratch_buffer (&scratch_size); |
281 while ((sizeof (hb_graphite2_cluster_t) * buffer->len + | 275 while ((DIV_CEIL (sizeof (hb_graphite2_cluster_t) * buffer->len, sizeof (*scra
tch)) + |
282 » sizeof (hb_codepoint_t) * glyph_count) > scratch_size) | 276 » DIV_CEIL (sizeof (hb_codepoint_t) * glyph_count, sizeof (*scratch))) >
scratch_size) |
283 { | 277 { |
284 buffer->ensure (buffer->allocated * 2); | 278 buffer->ensure (buffer->allocated * 2); |
285 if (unlikely (buffer->in_error)) { | 279 if (unlikely (buffer->in_error)) { |
286 if (feats) gr_featureval_destroy (feats); | 280 if (feats) gr_featureval_destroy (feats); |
287 gr_seg_destroy (seg); | 281 gr_seg_destroy (seg); |
288 return false; | 282 return false; |
289 } | 283 } |
290 scratch = (char *) buffer->get_scratch_buffer (&scratch_size); | 284 scratch = buffer->get_scratch_buffer (&scratch_size); |
| 285 } |
| 286 |
| 287 #define ALLOCATE_ARRAY(Type, name, len) \ |
| 288 Type *name = (Type *) scratch; \ |
| 289 { \ |
| 290 unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch))
; \ |
| 291 assert (_consumed <= scratch_size); \ |
| 292 scratch += _consumed; \ |
| 293 scratch_size -= _consumed; \ |
291 } | 294 } |
292 | 295 |
293 ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len); | 296 ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len); |
294 ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count); | 297 ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count); |
295 | 298 |
| 299 #undef ALLOCATE_ARRAY |
| 300 |
296 memset (clusters, 0, sizeof (clusters[0]) * buffer->len); | 301 memset (clusters, 0, sizeof (clusters[0]) * buffer->len); |
297 | 302 |
298 hb_codepoint_t *pg = gids; | 303 hb_codepoint_t *pg = gids; |
299 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i
s), ic++) | 304 for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (i
s), ic++) |
300 { | 305 { |
301 unsigned int before = gr_slot_before (is); | 306 unsigned int before = gr_slot_before (is); |
302 unsigned int after = gr_slot_after (is); | 307 unsigned int after = gr_slot_after (is); |
303 *pg = gr_slot_gid (is); | 308 *pg = gr_slot_gid (is); |
304 pg++; | 309 pg++; |
305 while (clusters[ci].base_char > before && ci) | 310 while (clusters[ci].base_char > before && ci) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx; | 366 pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx; |
362 | 367 |
363 if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) | 368 if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) |
364 hb_buffer_reverse_clusters (buffer); | 369 hb_buffer_reverse_clusters (buffer); |
365 | 370 |
366 if (feats) gr_featureval_destroy (feats); | 371 if (feats) gr_featureval_destroy (feats); |
367 gr_seg_destroy (seg); | 372 gr_seg_destroy (seg); |
368 | 373 |
369 return true; | 374 return true; |
370 } | 375 } |
OLD | NEW |