| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright © 2009 Red Hat, Inc. | 2 * Copyright © 2009 Red Hat, Inc. |
| 3 * Copyright © 2011 Google, Inc. | 3 * Copyright © 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 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 unsigned int y_ppem; | 109 unsigned int y_ppem; |
| 110 | 110 |
| 111 hb_font_funcs_t *klass; | 111 hb_font_funcs_t *klass; |
| 112 void *user_data; | 112 void *user_data; |
| 113 hb_destroy_func_t destroy; | 113 hb_destroy_func_t destroy; |
| 114 | 114 |
| 115 struct hb_shaper_data_t shaper_data; | 115 struct hb_shaper_data_t shaper_data; |
| 116 | 116 |
| 117 | 117 |
| 118 /* Convert from font-space to user-space */ | 118 /* Convert from font-space to user-space */ |
| 119 inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scal
e); } | 119 inline int dir_scale (hb_direction_t direction) |
| 120 inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scal
e); } | 120 { return HB_DIRECTION_IS_VERTICAL(direction) ? y_scale : x_scale; } |
| 121 inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, x_scale); } |
| 122 inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, y_scale); } |
| 123 inline hb_position_t em_scale_dir (int16_t v, hb_direction_t direction) |
| 124 { return em_scale (v, dir_scale (direction)); } |
| 121 | 125 |
| 122 /* Convert from parent-font user-space to our user-space */ | 126 /* Convert from parent-font user-space to our user-space */ |
| 123 inline hb_position_t parent_scale_x_distance (hb_position_t v) { | 127 inline hb_position_t parent_scale_x_distance (hb_position_t v) { |
| 124 if (unlikely (parent && parent->x_scale != x_scale)) | 128 if (unlikely (parent && parent->x_scale != x_scale)) |
| 125 return (hb_position_t) (v * (int64_t) this->x_scale / this->parent->x_scal
e); | 129 return (hb_position_t) (v * (int64_t) this->x_scale / this->parent->x_scal
e); |
| 126 return v; | 130 return v; |
| 127 } | 131 } |
| 128 inline hb_position_t parent_scale_y_distance (hb_position_t v) { | 132 inline hb_position_t parent_scale_y_distance (hb_position_t v) { |
| 129 if (unlikely (parent && parent->y_scale != y_scale)) | 133 if (unlikely (parent && parent->y_scale != y_scale)) |
| 130 return (hb_position_t) (v * (int64_t) this->y_scale / this->parent->y_scal
e); | 134 return (hb_position_t) (v * (int64_t) this->y_scale / this->parent->y_scal
e); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (len == -1) len = strlen (name); | 289 if (len == -1) len = strlen (name); |
| 286 return klass->get.f.glyph_from_name (this, user_data, | 290 return klass->get.f.glyph_from_name (this, user_data, |
| 287 name, len, | 291 name, len, |
| 288 glyph, | 292 glyph, |
| 289 klass->user_data.glyph_from_name); | 293 klass->user_data.glyph_from_name); |
| 290 } | 294 } |
| 291 | 295 |
| 292 | 296 |
| 293 /* A bit higher-level, and with fallback */ | 297 /* A bit higher-level, and with fallback */ |
| 294 | 298 |
| 299 inline void get_h_extents_with_fallback (hb_font_extents_t *extents) |
| 300 { |
| 301 if (!get_font_h_extents (extents)) |
| 302 { |
| 303 extents->ascender = y_scale * .8; |
| 304 extents->descender = extents->ascender - y_scale; |
| 305 extents->line_gap = 0; |
| 306 } |
| 307 } |
| 308 inline void get_v_extents_with_fallback (hb_font_extents_t *extents) |
| 309 { |
| 310 if (!get_font_v_extents (extents)) |
| 311 { |
| 312 extents->ascender = x_scale / 2; |
| 313 extents->descender = extents->ascender - x_scale; |
| 314 extents->line_gap = 0; |
| 315 } |
| 316 } |
| 317 |
| 295 inline void get_extents_for_direction (hb_direction_t direction, | 318 inline void get_extents_for_direction (hb_direction_t direction, |
| 296 hb_font_extents_t *extents) | 319 hb_font_extents_t *extents) |
| 297 { | 320 { |
| 298 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { | 321 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) |
| 299 if (!get_font_h_extents (extents)) | 322 get_h_extents_with_fallback (extents); |
| 300 { | 323 else |
| 301 » extents->ascender = y_scale * .8; | 324 get_v_extents_with_fallback (extents); |
| 302 » extents->descender = y_scale - extents->ascender; | |
| 303 » extents->line_gap = 0; | |
| 304 } | |
| 305 } else { | |
| 306 if (!get_font_v_extents (extents)) | |
| 307 { | |
| 308 » extents->ascender = x_scale / 2; | |
| 309 » extents->descender = x_scale - extents->ascender; | |
| 310 » extents->line_gap = 0; | |
| 311 } | |
| 312 } | |
| 313 } | 325 } |
| 314 | 326 |
| 315 inline void get_glyph_advance_for_direction (hb_codepoint_t glyph, | 327 inline void get_glyph_advance_for_direction (hb_codepoint_t glyph, |
| 316 hb_direction_t direction, | 328 hb_direction_t direction, |
| 317 hb_position_t *x, hb_position_t *
y) | 329 hb_position_t *x, hb_position_t *
y) |
| 318 { | 330 { |
| 319 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { | 331 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { |
| 320 *x = get_glyph_h_advance (glyph); | 332 *x = get_glyph_h_advance (glyph); |
| 321 *y = 0; | 333 *y = 0; |
| 322 } else { | 334 } else { |
| 323 *x = 0; | 335 *x = 0; |
| 324 *y = get_glyph_v_advance (glyph); | 336 *y = get_glyph_v_advance (glyph); |
| 325 } | 337 } |
| 326 } | 338 } |
| 327 | 339 |
| 328 /* Internal only */ | |
| 329 inline void guess_v_origin_minus_h_origin (hb_codepoint_t glyph, | 340 inline void guess_v_origin_minus_h_origin (hb_codepoint_t glyph, |
| 330 hb_position_t *x, hb_position_t *y) | 341 hb_position_t *x, hb_position_t *y) |
| 331 { | 342 { |
| 332 *x = get_glyph_h_advance (glyph) / 2; | 343 *x = get_glyph_h_advance (glyph) / 2; |
| 333 | 344 |
| 334 /* TODO use font_extents.ascender */ | 345 /* TODO cache this somehow?! */ |
| 335 *y = y_scale; | 346 hb_font_extents_t extents; |
| 347 get_h_extents_with_fallback (&extents); |
| 348 *y = extents.ascender; |
| 349 } |
| 350 |
| 351 inline void get_glyph_h_origin_with_fallback (hb_codepoint_t glyph, |
| 352 » » » » » » hb_position_t *x, hb_position_t
*y) |
| 353 { |
| 354 if (!get_glyph_h_origin (glyph, x, y) && |
| 355 » get_glyph_v_origin (glyph, x, y)) |
| 356 { |
| 357 hb_position_t dx, dy; |
| 358 guess_v_origin_minus_h_origin (glyph, &dx, &dy); |
| 359 *x -= dx; *y -= dy; |
| 360 } |
| 361 } |
| 362 inline void get_glyph_v_origin_with_fallback (hb_codepoint_t glyph, |
| 363 » » » » » » hb_position_t *x, hb_position_t
*y) |
| 364 { |
| 365 if (!get_glyph_v_origin (glyph, x, y) && |
| 366 » get_glyph_h_origin (glyph, x, y)) |
| 367 { |
| 368 hb_position_t dx, dy; |
| 369 guess_v_origin_minus_h_origin (glyph, &dx, &dy); |
| 370 *x += dx; *y += dy; |
| 371 } |
| 336 } | 372 } |
| 337 | 373 |
| 338 inline void get_glyph_origin_for_direction (hb_codepoint_t glyph, | 374 inline void get_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 339 hb_direction_t direction, | 375 hb_direction_t direction, |
| 340 hb_position_t *x, hb_position_t *y
) | 376 hb_position_t *x, hb_position_t *y
) |
| 341 { | 377 { |
| 342 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) | 378 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) |
| 343 { | 379 get_glyph_h_origin_with_fallback (glyph, x, y); |
| 344 if (!get_glyph_h_origin (glyph, x, y) && | |
| 345 » get_glyph_v_origin (glyph, x, y)) | |
| 346 { | |
| 347 » hb_position_t dx, dy; | |
| 348 » guess_v_origin_minus_h_origin (glyph, &dx, &dy); | |
| 349 » *x -= dx; *y -= dy; | |
| 350 } | |
| 351 } | |
| 352 else | 380 else |
| 353 { | 381 get_glyph_v_origin_with_fallback (glyph, x, y); |
| 354 if (!get_glyph_v_origin (glyph, x, y) && | |
| 355 » get_glyph_h_origin (glyph, x, y)) | |
| 356 { | |
| 357 » hb_position_t dx, dy; | |
| 358 » guess_v_origin_minus_h_origin (glyph, &dx, &dy); | |
| 359 » *x += dx; *y += dy; | |
| 360 } | |
| 361 } | |
| 362 } | 382 } |
| 363 | 383 |
| 364 inline void add_glyph_h_origin (hb_codepoint_t glyph, | 384 inline void add_glyph_h_origin (hb_codepoint_t glyph, |
| 365 hb_position_t *x, hb_position_t *y) | 385 hb_position_t *x, hb_position_t *y) |
| 366 { | 386 { |
| 367 hb_position_t origin_x, origin_y; | 387 hb_position_t origin_x, origin_y; |
| 368 | 388 |
| 369 get_glyph_h_origin (glyph, &origin_x, &origin_y); | 389 get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y); |
| 370 | 390 |
| 371 *x += origin_x; | 391 *x += origin_x; |
| 372 *y += origin_y; | 392 *y += origin_y; |
| 373 } | 393 } |
| 374 inline void add_glyph_v_origin (hb_codepoint_t glyph, | 394 inline void add_glyph_v_origin (hb_codepoint_t glyph, |
| 375 hb_position_t *x, hb_position_t *y) | 395 hb_position_t *x, hb_position_t *y) |
| 376 { | 396 { |
| 377 hb_position_t origin_x, origin_y; | 397 hb_position_t origin_x, origin_y; |
| 378 | 398 |
| 379 get_glyph_v_origin (glyph, &origin_x, &origin_y); | 399 get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y); |
| 380 | 400 |
| 381 *x += origin_x; | 401 *x += origin_x; |
| 382 *y += origin_y; | 402 *y += origin_y; |
| 383 } | 403 } |
| 384 inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, | 404 inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 385 hb_direction_t direction, | 405 hb_direction_t direction, |
| 386 hb_position_t *x, hb_position_t *y
) | 406 hb_position_t *x, hb_position_t *y
) |
| 387 { | 407 { |
| 388 hb_position_t origin_x, origin_y; | 408 hb_position_t origin_x, origin_y; |
| 389 | 409 |
| 390 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); | 410 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); |
| 391 | 411 |
| 392 *x += origin_x; | 412 *x += origin_x; |
| 393 *y += origin_y; | 413 *y += origin_y; |
| 394 } | 414 } |
| 395 | 415 |
| 396 inline void subtract_glyph_h_origin (hb_codepoint_t glyph, | 416 inline void subtract_glyph_h_origin (hb_codepoint_t glyph, |
| 397 hb_position_t *x, hb_position_t *y) | 417 hb_position_t *x, hb_position_t *y) |
| 398 { | 418 { |
| 399 hb_position_t origin_x, origin_y; | 419 hb_position_t origin_x, origin_y; |
| 400 | 420 |
| 401 get_glyph_h_origin (glyph, &origin_x, &origin_y); | 421 get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y); |
| 402 | 422 |
| 403 *x -= origin_x; | 423 *x -= origin_x; |
| 404 *y -= origin_y; | 424 *y -= origin_y; |
| 405 } | 425 } |
| 406 inline void subtract_glyph_v_origin (hb_codepoint_t glyph, | 426 inline void subtract_glyph_v_origin (hb_codepoint_t glyph, |
| 407 hb_position_t *x, hb_position_t *y) | 427 hb_position_t *x, hb_position_t *y) |
| 408 { | 428 { |
| 409 hb_position_t origin_x, origin_y; | 429 hb_position_t origin_x, origin_y; |
| 410 | 430 |
| 411 get_glyph_v_origin (glyph, &origin_x, &origin_y); | 431 get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y); |
| 412 | 432 |
| 413 *x -= origin_x; | 433 *x -= origin_x; |
| 414 *y -= origin_y; | 434 *y -= origin_y; |
| 415 } | 435 } |
| 416 inline void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, | 436 inline void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, |
| 417 hb_direction_t direction, | 437 hb_direction_t direction, |
| 418 hb_position_t *x, hb_position
_t *y) | 438 hb_position_t *x, hb_position
_t *y) |
| 419 { | 439 { |
| 420 hb_position_t origin_x, origin_y; | 440 hb_position_t origin_x, origin_y; |
| 421 | 441 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 hb_codepoint_t unichar; | 517 hb_codepoint_t unichar; |
| 498 if (0 == strncmp (s, "uni", 3) && | 518 if (0 == strncmp (s, "uni", 3) && |
| 499 hb_codepoint_parse (s + 3, len - 3, 16, &unichar) && | 519 hb_codepoint_parse (s + 3, len - 3, 16, &unichar) && |
| 500 get_nominal_glyph (unichar, glyph)) | 520 get_nominal_glyph (unichar, glyph)) |
| 501 return true; | 521 return true; |
| 502 } | 522 } |
| 503 | 523 |
| 504 return false; | 524 return false; |
| 505 } | 525 } |
| 506 | 526 |
| 507 private: | |
| 508 inline hb_position_t em_scale (int16_t v, int scale) | 527 inline hb_position_t em_scale (int16_t v, int scale) |
| 509 { | 528 { |
| 510 int upem = face->get_upem (); | 529 int upem = face->get_upem (); |
| 511 int64_t scaled = v * (int64_t) scale; | 530 int64_t scaled = v * (int64_t) scale; |
| 512 scaled += scaled >= 0 ? upem/2 : -upem/2; /* Round. */ | 531 scaled += scaled >= 0 ? upem/2 : -upem/2; /* Round. */ |
| 513 return (hb_position_t) (scaled / upem); | 532 return (hb_position_t) (scaled / upem); |
| 514 } | 533 } |
| 515 }; | 534 }; |
| 516 | 535 |
| 517 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | 536 #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS |
| 518 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); | 537 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); |
| 519 #include "hb-shaper-list.hh" | 538 #include "hb-shaper-list.hh" |
| 520 #undef HB_SHAPER_IMPLEMENT | 539 #undef HB_SHAPER_IMPLEMENT |
| 521 #undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS | 540 #undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS |
| 522 | 541 |
| 523 | 542 |
| 524 #endif /* HB_FONT_PRIVATE_HH */ | 543 #endif /* HB_FONT_PRIVATE_HH */ |
| OLD | NEW |