| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 harf_buzz_skia_font_funcs, HarfBuzzGetGlyphVerticalAdvance, 0, 0); | 300 harf_buzz_skia_font_funcs, HarfBuzzGetGlyphVerticalAdvance, 0, 0); |
| 301 hb_font_funcs_set_glyph_v_origin_func(harf_buzz_skia_font_funcs, | 301 hb_font_funcs_set_glyph_v_origin_func(harf_buzz_skia_font_funcs, |
| 302 HarfBuzzGetGlyphVerticalOrigin, 0, 0); | 302 HarfBuzzGetGlyphVerticalOrigin, 0, 0); |
| 303 hb_font_funcs_set_glyph_extents_func(harf_buzz_skia_font_funcs, | 303 hb_font_funcs_set_glyph_extents_func(harf_buzz_skia_font_funcs, |
| 304 HarfBuzzGetGlyphExtents, 0, 0); | 304 HarfBuzzGetGlyphExtents, 0, 0); |
| 305 hb_font_funcs_make_immutable(harf_buzz_skia_font_funcs); | 305 hb_font_funcs_make_immutable(harf_buzz_skia_font_funcs); |
| 306 } | 306 } |
| 307 return harf_buzz_skia_font_funcs; | 307 return harf_buzz_skia_font_funcs; |
| 308 } | 308 } |
| 309 | 309 |
| 310 #if !OS(MACOSX) | |
| 311 static hb_blob_t* HarfBuzzSkiaGetTable(hb_face_t* face, | 310 static hb_blob_t* HarfBuzzSkiaGetTable(hb_face_t* face, |
| 312 hb_tag_t tag, | 311 hb_tag_t tag, |
| 313 void* user_data) { | 312 void* user_data) { |
| 314 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(user_data); | 313 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(user_data); |
| 315 | 314 |
| 316 const size_t table_size = typeface->getTableSize(tag); | 315 const size_t table_size = typeface->getTableSize(tag); |
| 317 if (!table_size) { | 316 if (!table_size) { |
| 318 return nullptr; | 317 return nullptr; |
| 319 } | 318 } |
| 320 | 319 |
| 321 char* buffer = reinterpret_cast<char*>(WTF::Partitions::FastMalloc( | 320 char* buffer = reinterpret_cast<char*>(WTF::Partitions::FastMalloc( |
| 322 table_size, WTF_HEAP_PROFILER_TYPE_NAME(HarfBuzzFontData))); | 321 table_size, WTF_HEAP_PROFILER_TYPE_NAME(HarfBuzzFontData))); |
| 323 if (!buffer) | 322 if (!buffer) |
| 324 return nullptr; | 323 return nullptr; |
| 325 size_t actual_size = typeface->getTableData(tag, 0, table_size, buffer); | 324 size_t actual_size = typeface->getTableData(tag, 0, table_size, buffer); |
| 326 if (table_size != actual_size) { | 325 if (table_size != actual_size) { |
| 327 WTF::Partitions::FastFree(buffer); | 326 WTF::Partitions::FastFree(buffer); |
| 328 return nullptr; | 327 return nullptr; |
| 329 } | 328 } |
| 330 return hb_blob_create(const_cast<char*>(buffer), table_size, | 329 return hb_blob_create(const_cast<char*>(buffer), table_size, |
| 331 HB_MEMORY_MODE_WRITABLE, buffer, | 330 HB_MEMORY_MODE_WRITABLE, buffer, |
| 332 WTF::Partitions::FastFree); | 331 WTF::Partitions::FastFree); |
| 333 } | 332 } |
| 334 #endif | |
| 335 | 333 |
| 336 #if !OS(MACOSX) | |
| 337 static void DeleteTypefaceStream(void* stream_asset_ptr) { | 334 static void DeleteTypefaceStream(void* stream_asset_ptr) { |
| 338 SkStreamAsset* stream_asset = | 335 SkStreamAsset* stream_asset = |
| 339 reinterpret_cast<SkStreamAsset*>(stream_asset_ptr); | 336 reinterpret_cast<SkStreamAsset*>(stream_asset_ptr); |
| 340 delete stream_asset; | 337 delete stream_asset; |
| 341 } | 338 } |
| 342 #endif | |
| 343 | 339 |
| 344 hb_face_t* HarfBuzzFace::CreateFace() { | 340 hb_face_t* HarfBuzzFace::CreateFace() { |
| 345 #if OS(MACOSX) | 341 #if OS(MACOSX) |
| 346 hb_face_t* face = hb_coretext_face_create(platform_data_->CgFont()); | 342 // hb_face_t needs to be instantiated using the CoreText constructor for |
| 347 #else | 343 // compatibility with AAT font, in which case HarfBuzz' CoreText backend is |
| 344 // used. If we encounter a FreeType backed SkTypeface, for variable fonts on |
| 345 // Mac OS < 10.12, follow the regular OpenType-only codepath below. |
| 346 if (platform_data_->CgFont()) { |
| 347 hb_face_t* face = hb_coretext_face_create(platform_data_->CgFont()); |
| 348 DCHECK(face); |
| 349 return face; |
| 350 } |
| 351 #endif |
| 348 hb_face_t* face = nullptr; | 352 hb_face_t* face = nullptr; |
| 349 | 353 |
| 350 DEFINE_STATIC_LOCAL(BooleanHistogram, zero_copy_success_histogram, | 354 DEFINE_STATIC_LOCAL(BooleanHistogram, zero_copy_success_histogram, |
| 351 ("Blink.Fonts.HarfBuzzFaceZeroCopyAccess")); | 355 ("Blink.Fonts.HarfBuzzFaceZeroCopyAccess")); |
| 352 SkTypeface* typeface = platform_data_->Typeface(); | 356 SkTypeface* typeface = platform_data_->Typeface(); |
| 353 CHECK(typeface); | 357 CHECK(typeface); |
| 354 int ttc_index = 0; | 358 int ttc_index = 0; |
| 355 SkStreamAsset* typeface_stream = typeface->openStream(&ttc_index); | 359 SkStreamAsset* typeface_stream = typeface->openStream(&ttc_index); |
| 356 if (typeface_stream && typeface_stream->getMemoryBase()) { | 360 if (typeface_stream && typeface_stream->getMemoryBase()) { |
| 357 std::unique_ptr<hb_blob_t, void (*)(hb_blob_t*)> face_blob( | 361 std::unique_ptr<hb_blob_t, void (*)(hb_blob_t*)> face_blob( |
| 358 hb_blob_create( | 362 hb_blob_create( |
| 359 reinterpret_cast<const char*>(typeface_stream->getMemoryBase()), | 363 reinterpret_cast<const char*>(typeface_stream->getMemoryBase()), |
| 360 typeface_stream->getLength(), HB_MEMORY_MODE_READONLY, | 364 typeface_stream->getLength(), HB_MEMORY_MODE_READONLY, |
| 361 typeface_stream, DeleteTypefaceStream), | 365 typeface_stream, DeleteTypefaceStream), |
| 362 hb_blob_destroy); | 366 hb_blob_destroy); |
| 363 face = hb_face_create(face_blob.get(), ttc_index); | 367 face = hb_face_create(face_blob.get(), ttc_index); |
| 364 } | 368 } |
| 365 | 369 |
| 366 // Fallback to table copies if there is no in-memory access. | 370 // Fallback to table copies if there is no in-memory access. |
| 367 if (!face) { | 371 if (!face) { |
| 368 face = hb_face_create_for_tables(HarfBuzzSkiaGetTable, | 372 face = hb_face_create_for_tables(HarfBuzzSkiaGetTable, |
| 369 platform_data_->Typeface(), 0); | 373 platform_data_->Typeface(), 0); |
| 370 zero_copy_success_histogram.Count(false); | 374 zero_copy_success_histogram.Count(false); |
| 371 } else { | 375 } else { |
| 372 zero_copy_success_histogram.Count(true); | 376 zero_copy_success_histogram.Count(true); |
| 373 } | 377 } |
| 374 #endif | 378 |
| 375 DCHECK(face); | 379 DCHECK(face); |
| 376 return face; | 380 return face; |
| 377 } | 381 } |
| 378 | 382 |
| 379 PassRefPtr<HbFontCacheEntry> CreateHbFontCacheEntry(hb_face_t* face) { | 383 PassRefPtr<HbFontCacheEntry> CreateHbFontCacheEntry(hb_face_t* face) { |
| 380 HbFontUniquePtr ot_font(hb_font_create(face)); | 384 HbFontUniquePtr ot_font(hb_font_create(face)); |
| 381 hb_ot_font_set_funcs(ot_font.get()); | 385 hb_ot_font_set_funcs(ot_font.get()); |
| 382 // Creating a sub font means that non-available functions | 386 // Creating a sub font means that non-available functions |
| 383 // are found from the parent. | 387 // are found from the parent. |
| 384 hb_font_t* unscaled_font = hb_font_create_sub_font(ot_font.get()); | 388 hb_font_t* unscaled_font = hb_font_create_sub_font(ot_font.get()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 hb_font_set_variations( | 425 hb_font_set_variations( |
| 422 unscaled_font_, reinterpret_cast<hb_variation_t*>(axis_values.data()), | 426 unscaled_font_, reinterpret_cast<hb_variation_t*>(axis_values.data()), |
| 423 axis_values.size()); | 427 axis_values.size()); |
| 424 } | 428 } |
| 425 } | 429 } |
| 426 | 430 |
| 427 return unscaled_font_; | 431 return unscaled_font_; |
| 428 } | 432 } |
| 429 | 433 |
| 430 } // namespace blink | 434 } // namespace blink |
| OLD | NEW |