| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright © 2011,2014 Google, Inc. | 2 * Copyright © 2011,2014 Google, Inc. |
| 3 * | 3 * |
| 4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
| 5 * | 5 * |
| 6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
| 7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
| 8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
| 9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
| 10 * all copies of this software. | 10 * all copies of this software. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 extents->x_bearing = MIN (glyph_header.xMin, glyph_header.xMax); | 195 extents->x_bearing = MIN (glyph_header.xMin, glyph_header.xMax); |
| 196 extents->y_bearing = MAX (glyph_header.yMin, glyph_header.yMax); | 196 extents->y_bearing = MAX (glyph_header.yMin, glyph_header.yMax); |
| 197 extents->width = MAX (glyph_header.xMin, glyph_header.xMax) - extents->x
_bearing; | 197 extents->width = MAX (glyph_header.xMin, glyph_header.xMax) - extents->x
_bearing; |
| 198 extents->height = MIN (glyph_header.yMin, glyph_header.yMax) - extents->y
_bearing; | 198 extents->height = MIN (glyph_header.yMin, glyph_header.yMax) - extents->y
_bearing; |
| 199 | 199 |
| 200 return true; | 200 return true; |
| 201 } | 201 } |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj, |
| 205 hb_codepoint_t codepoint, |
| 206 hb_codepoint_t *glyph); |
| 207 |
| 208 template <typename Type> |
| 209 static inline bool get_glyph_from (const void *obj, |
| 210 hb_codepoint_t codepoint, |
| 211 hb_codepoint_t *glyph) |
| 212 { |
| 213 const Type *typed_obj = (const Type *) obj; |
| 214 return typed_obj->get_glyph (codepoint, glyph); |
| 215 } |
| 216 |
| 204 struct hb_ot_face_cmap_accelerator_t | 217 struct hb_ot_face_cmap_accelerator_t |
| 205 { | 218 { |
| 206 const OT::CmapSubtable *table; | 219 hb_cmap_get_glyph_func_t get_glyph_func; |
| 207 const OT::CmapSubtable *uvs_table; | 220 const void *get_glyph_data; |
| 221 OT::CmapSubtableFormat4::accelerator_t format4_accel; |
| 222 |
| 223 const OT::CmapSubtableFormat14 *uvs_table; |
| 208 hb_blob_t *blob; | 224 hb_blob_t *blob; |
| 209 | 225 |
| 210 inline void init (hb_face_t *face) | 226 inline void init (hb_face_t *face) |
| 211 { | 227 { |
| 212 this->blob = OT::Sanitizer<OT::cmap>::sanitize (face->reference_table (HB_OT
_TAG_cmap)); | 228 this->blob = OT::Sanitizer<OT::cmap>::sanitize (face->reference_table (HB_OT
_TAG_cmap)); |
| 213 const OT::cmap *cmap = OT::Sanitizer<OT::cmap>::lock_instance (this->blob); | 229 const OT::cmap *cmap = OT::Sanitizer<OT::cmap>::lock_instance (this->blob); |
| 214 const OT::CmapSubtable *subtable = NULL; | 230 const OT::CmapSubtable *subtable = NULL; |
| 215 const OT::CmapSubtable *subtable_uvs = NULL; | 231 const OT::CmapSubtableFormat14 *subtable_uvs = NULL; |
| 216 | 232 |
| 217 /* 32-bit subtables. */ | 233 /* 32-bit subtables. */ |
| 218 if (!subtable) subtable = cmap->find_subtable (3, 10); | 234 if (!subtable) subtable = cmap->find_subtable (3, 10); |
| 219 if (!subtable) subtable = cmap->find_subtable (0, 6); | 235 if (!subtable) subtable = cmap->find_subtable (0, 6); |
| 220 if (!subtable) subtable = cmap->find_subtable (0, 4); | 236 if (!subtable) subtable = cmap->find_subtable (0, 4); |
| 221 /* 16-bit subtables. */ | 237 /* 16-bit subtables. */ |
| 222 if (!subtable) subtable = cmap->find_subtable (3, 1); | 238 if (!subtable) subtable = cmap->find_subtable (3, 1); |
| 223 if (!subtable) subtable = cmap->find_subtable (0, 3); | 239 if (!subtable) subtable = cmap->find_subtable (0, 3); |
| 224 if (!subtable) subtable = cmap->find_subtable (0, 2); | 240 if (!subtable) subtable = cmap->find_subtable (0, 2); |
| 225 if (!subtable) subtable = cmap->find_subtable (0, 1); | 241 if (!subtable) subtable = cmap->find_subtable (0, 1); |
| 226 if (!subtable) subtable = cmap->find_subtable (0, 0); | 242 if (!subtable) subtable = cmap->find_subtable (0, 0); |
| 227 if (!subtable) subtable = cmap->find_subtable (3, 0); | 243 if (!subtable) subtable = cmap->find_subtable (3, 0); |
| 228 /* Meh. */ | 244 /* Meh. */ |
| 229 if (!subtable) subtable = &OT::Null(OT::CmapSubtable); | 245 if (!subtable) subtable = &OT::Null(OT::CmapSubtable); |
| 230 | 246 |
| 231 /* UVS subtable. */ | 247 /* UVS subtable. */ |
| 232 if (!subtable_uvs) subtable_uvs = cmap->find_subtable (0, 5); | 248 if (!subtable_uvs) |
| 249 { |
| 250 const OT::CmapSubtable *st = cmap->find_subtable (0, 5); |
| 251 if (st && st->u.format == 14) |
| 252 subtable_uvs = &st->u.format14; |
| 253 } |
| 233 /* Meh. */ | 254 /* Meh. */ |
| 234 if (!subtable_uvs) subtable_uvs = &OT::Null(OT::CmapSubtable); | 255 if (!subtable_uvs) subtable_uvs = &OT::Null(OT::CmapSubtableFormat14); |
| 235 | 256 |
| 236 this->table = subtable; | |
| 237 this->uvs_table = subtable_uvs; | 257 this->uvs_table = subtable_uvs; |
| 258 |
| 259 this->get_glyph_data = subtable; |
| 260 switch (subtable->u.format) { |
| 261 /* Accelerate format 4 and format 12. */ |
| 262 default: this->get_glyph_func = get_glyph_from<OT::CmapSubtable>;
break; |
| 263 case 12: this->get_glyph_func = get_glyph_from<OT::CmapSubtableFormat12>;
break; |
| 264 case 4: |
| 265 { |
| 266 this->format4_accel.init (&subtable->u.format4); |
| 267 this->get_glyph_data = &this->format4_accel; |
| 268 this->get_glyph_func = this->format4_accel.get_glyph_func; |
| 269 } |
| 270 break; |
| 271 } |
| 238 } | 272 } |
| 239 | 273 |
| 240 inline void fini (void) | 274 inline void fini (void) |
| 241 { | 275 { |
| 242 hb_blob_destroy (this->blob); | 276 hb_blob_destroy (this->blob); |
| 243 } | 277 } |
| 244 | 278 |
| 245 inline bool get_glyph (hb_codepoint_t unicode, | 279 inline bool get_nominal_glyph (hb_codepoint_t unicode, |
| 246 » » » hb_codepoint_t variation_selector, | 280 » » » » hb_codepoint_t *glyph) const |
| 247 » » » hb_codepoint_t *glyph) const | |
| 248 { | 281 { |
| 249 if (unlikely (variation_selector)) | 282 return this->get_glyph_func (this->get_glyph_data, unicode, glyph); |
| 283 } |
| 284 |
| 285 inline bool get_variation_glyph (hb_codepoint_t unicode, |
| 286 » » » » hb_codepoint_t variation_selector, |
| 287 » » » » hb_codepoint_t *glyph) const |
| 288 { |
| 289 switch (this->uvs_table->get_glyph_variant (unicode, |
| 290 » » » » » » variation_selector, |
| 291 » » » » » » glyph)) |
| 250 { | 292 { |
| 251 switch (this->uvs_table->get_glyph_variant (unicode, | 293 case OT::GLYPH_VARIANT_NOT_FOUND:»» return false; |
| 252 » » » » » » variation_selector, | 294 case OT::GLYPH_VARIANT_FOUND:» » return true; |
| 253 » » » » » » glyph)) | 295 case OT::GLYPH_VARIANT_USE_DEFAULT:» break; |
| 254 { | |
| 255 » case OT::GLYPH_VARIANT_NOT_FOUND:» return false; | |
| 256 » case OT::GLYPH_VARIANT_FOUND:» » return true; | |
| 257 » case OT::GLYPH_VARIANT_USE_DEFAULT:» break; | |
| 258 } | |
| 259 } | 296 } |
| 260 | 297 |
| 261 return this->table->get_glyph (unicode, glyph); | 298 return get_nominal_glyph (unicode, glyph); |
| 262 } | 299 } |
| 263 }; | 300 }; |
| 264 | 301 |
| 265 | 302 |
| 266 struct hb_ot_font_t | 303 struct hb_ot_font_t |
| 267 { | 304 { |
| 268 hb_ot_face_cmap_accelerator_t cmap; | 305 hb_ot_face_cmap_accelerator_t cmap; |
| 269 hb_ot_face_metrics_accelerator_t h_metrics; | 306 hb_ot_face_metrics_accelerator_t h_metrics; |
| 270 hb_ot_face_metrics_accelerator_t v_metrics; | 307 hb_ot_face_metrics_accelerator_t v_metrics; |
| 271 hb_ot_face_glyf_accelerator_t glyf; | 308 hb_ot_face_glyf_accelerator_t glyf; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 294 ot_font->cmap.fini (); | 331 ot_font->cmap.fini (); |
| 295 ot_font->h_metrics.fini (); | 332 ot_font->h_metrics.fini (); |
| 296 ot_font->v_metrics.fini (); | 333 ot_font->v_metrics.fini (); |
| 297 ot_font->glyf.fini (); | 334 ot_font->glyf.fini (); |
| 298 | 335 |
| 299 free (ot_font); | 336 free (ot_font); |
| 300 } | 337 } |
| 301 | 338 |
| 302 | 339 |
| 303 static hb_bool_t | 340 static hb_bool_t |
| 304 hb_ot_get_glyph (hb_font_t *font HB_UNUSED, | 341 hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED, |
| 305 » » void *font_data, | 342 » » » void *font_data, |
| 306 » » hb_codepoint_t unicode, | 343 » » » hb_codepoint_t unicode, |
| 307 » » hb_codepoint_t variation_selector, | 344 » » » hb_codepoint_t *glyph, |
| 308 » » hb_codepoint_t *glyph, | 345 » » » void *user_data HB_UNUSED) |
| 309 » » void *user_data HB_UNUSED) | |
| 310 | 346 |
| 311 { | 347 { |
| 312 const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; | 348 const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
| 313 return ot_font->cmap.get_glyph (unicode, variation_selector, glyph); | 349 return ot_font->cmap.get_nominal_glyph (unicode, glyph); |
| 350 } |
| 351 |
| 352 static hb_bool_t |
| 353 hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED, |
| 354 » » » void *font_data, |
| 355 » » » hb_codepoint_t unicode, |
| 356 » » » hb_codepoint_t variation_selector, |
| 357 » » » hb_codepoint_t *glyph, |
| 358 » » » void *user_data HB_UNUSED) |
| 359 { |
| 360 const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
| 361 return ot_font->cmap.get_variation_glyph (unicode, variation_selector, glyph); |
| 314 } | 362 } |
| 315 | 363 |
| 316 static hb_position_t | 364 static hb_position_t |
| 317 hb_ot_get_glyph_h_advance (hb_font_t *font HB_UNUSED, | 365 hb_ot_get_glyph_h_advance (hb_font_t *font HB_UNUSED, |
| 318 void *font_data, | 366 void *font_data, |
| 319 hb_codepoint_t glyph, | 367 hb_codepoint_t glyph, |
| 320 void *user_data HB_UNUSED) | 368 void *user_data HB_UNUSED) |
| 321 { | 369 { |
| 322 const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; | 370 const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
| 323 return font->em_scale_x (ot_font->h_metrics.get_advance (glyph)); | 371 return font->em_scale_x (ot_font->h_metrics.get_advance (glyph)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 { | 438 { |
| 391 retry: | 439 retry: |
| 392 hb_font_funcs_t *funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ot_fun
cs); | 440 hb_font_funcs_t *funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ot_fun
cs); |
| 393 | 441 |
| 394 if (unlikely (!funcs)) | 442 if (unlikely (!funcs)) |
| 395 { | 443 { |
| 396 funcs = hb_font_funcs_create (); | 444 funcs = hb_font_funcs_create (); |
| 397 | 445 |
| 398 hb_font_funcs_set_font_h_extents_func (funcs, hb_ot_get_font_h_extents, NULL
, NULL); | 446 hb_font_funcs_set_font_h_extents_func (funcs, hb_ot_get_font_h_extents, NULL
, NULL); |
| 399 hb_font_funcs_set_font_v_extents_func (funcs, hb_ot_get_font_v_extents, NULL
, NULL); | 447 hb_font_funcs_set_font_v_extents_func (funcs, hb_ot_get_font_v_extents, NULL
, NULL); |
| 400 hb_font_funcs_set_glyph_func (funcs, hb_ot_get_glyph, NULL, NULL); | 448 hb_font_funcs_set_nominal_glyph_func (funcs, hb_ot_get_nominal_glyph, NULL,
NULL); |
| 449 hb_font_funcs_set_variation_glyph_func (funcs, hb_ot_get_variation_glyph, NU
LL, NULL); |
| 401 hb_font_funcs_set_glyph_h_advance_func (funcs, hb_ot_get_glyph_h_advance, NU
LL, NULL); | 450 hb_font_funcs_set_glyph_h_advance_func (funcs, hb_ot_get_glyph_h_advance, NU
LL, NULL); |
| 402 hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ot_get_glyph_v_advance, NU
LL, NULL); | 451 hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ot_get_glyph_v_advance, NU
LL, NULL); |
| 403 //hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ot_get_glyph_h_origin, NU
LL, NULL); | 452 //hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ot_get_glyph_h_origin, NU
LL, NULL); |
| 404 //hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ot_get_glyph_v_origin, NU
LL, NULL); | 453 //hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ot_get_glyph_v_origin, NU
LL, NULL); |
| 405 //hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ot_get_glyph_h_kerning,
NULL, NULL); TODO | 454 //hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ot_get_glyph_h_kerning,
NULL, NULL); TODO |
| 406 //hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ot_get_glyph_v_kerning,
NULL, NULL); | 455 //hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ot_get_glyph_v_kerning,
NULL, NULL); |
| 407 hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, NULL,
NULL); | 456 hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, NULL,
NULL); |
| 408 //hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour
_point, NULL, NULL); TODO | 457 //hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour
_point, NULL, NULL); TODO |
| 409 //hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, NULL, NULL
); TODO | 458 //hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, NULL, NULL
); TODO |
| 410 //hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name,
NULL, NULL); TODO | 459 //hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name,
NULL, NULL); TODO |
| (...skipping 24 matching lines...) Expand all Loading... |
| 435 { | 484 { |
| 436 hb_ot_font_t *ot_font = _hb_ot_font_create (font->face); | 485 hb_ot_font_t *ot_font = _hb_ot_font_create (font->face); |
| 437 if (unlikely (!ot_font)) | 486 if (unlikely (!ot_font)) |
| 438 return; | 487 return; |
| 439 | 488 |
| 440 hb_font_set_funcs (font, | 489 hb_font_set_funcs (font, |
| 441 _hb_ot_get_font_funcs (), | 490 _hb_ot_get_font_funcs (), |
| 442 ot_font, | 491 ot_font, |
| 443 (hb_destroy_func_t) _hb_ot_font_destroy); | 492 (hb_destroy_func_t) _hb_ot_font_destroy); |
| 444 } | 493 } |
| OLD | NEW |