Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp

Issue 2080243002: Access font tables in memory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not oversimplify fallback case Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include <hb-ot.h> 43 #include <hb-ot.h>
44 #include <hb.h> 44 #include <hb.h>
45 #if OS(MACOSX) 45 #if OS(MACOSX)
46 #include <hb-coretext.h> 46 #include <hb-coretext.h>
47 #endif 47 #endif
48 48
49 #include <SkPaint.h> 49 #include <SkPaint.h>
50 #include <SkPath.h> 50 #include <SkPath.h>
51 #include <SkPoint.h> 51 #include <SkPoint.h>
52 #include <SkRect.h> 52 #include <SkRect.h>
53 #include <SkStream.h>
53 #include <SkTypeface.h> 54 #include <SkTypeface.h>
54 55
55 56
56 namespace blink { 57 namespace blink {
57 58
58 struct HbFontDeleter { 59 struct HbFontDeleter {
59 void operator()(hb_font_t* font) 60 void operator()(hb_font_t* font)
60 { 61 {
61 if (font) 62 if (font)
62 hb_font_destroy(font); 63 hb_font_destroy(font);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 return nullptr; 305 return nullptr;
305 size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer); 306 size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer);
306 if (tableSize != actualSize) { 307 if (tableSize != actualSize) {
307 WTF::Partitions::fastFree(buffer); 308 WTF::Partitions::fastFree(buffer);
308 return nullptr; 309 return nullptr;
309 } 310 }
310 return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_W RITABLE, buffer, WTF::Partitions::fastFree); 311 return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_W RITABLE, buffer, WTF::Partitions::fastFree);
311 } 312 }
312 #endif 313 #endif
313 314
315 #if !OS(MACOSX)
316 static void deleteTypefaceStream(void* streamAssetPtr)
317 {
318 SkStreamAsset* streamAsset = reinterpret_cast<SkStreamAsset*>(streamAssetPtr );
319 delete streamAsset;
320 }
321 #endif
322
314 hb_face_t* HarfBuzzFace::createFace() 323 hb_face_t* HarfBuzzFace::createFace()
315 { 324 {
316 #if OS(MACOSX) 325 #if OS(MACOSX)
317 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); 326 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont());
318 #else 327 #else
319 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0); 328 hb_face_t* face = nullptr;
329
330 SkTypeface* typeface = m_platformData->typeface();
331 SkStreamAsset* typefaceStream = typeface->openStream(0);
332 if (typefaceStream->getMemoryBase()) {
333 std::unique_ptr<hb_blob_t, void(*)(hb_blob_t*)> faceBlob(hb_blob_create(
334 reinterpret_cast<const char*>(typefaceStream->getMemoryBase()),
335 typefaceStream->getLength(),
336 HB_MEMORY_MODE_READONLY,
337 typefaceStream,
338 deleteTypefaceStream),
339 hb_blob_destroy);
340 face = hb_face_create(faceBlob.get(), 0);
behdad 2016/06/23 13:27:36 Instead of 0, you need the TTC index of the face.
341 }
342
343 // Fallback to table copies if there is no in-memory access.
344 if (!face)
345 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platformData->t ypeface(), 0);
320 #endif 346 #endif
321 ASSERT(face); 347 ASSERT(face);
322 return face; 348 return face;
323 } 349 }
324 350
325 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) 351 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face)
326 { 352 {
327 HbFontUniquePtr otFont(hb_font_create(face)); 353 HbFontUniquePtr otFont(hb_font_create(face));
328 hb_ot_font_set_funcs(otFont.get()); 354 hb_ot_font_set_funcs(otFont.get());
329 // Creating a sub font means that non-available functions 355 // Creating a sub font means that non-available functions
330 // are found from the parent. 356 // are found from the parent.
331 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); 357 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get());
332 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ; 358 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ;
333 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr); 359 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr);
334 return cacheEntry; 360 return cacheEntry;
335 } 361 }
336 362
337 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st 363 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st
338 { 364 {
339 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); 365 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint);
340 m_harfBuzzFontData->m_rangeSet = rangeSet; 366 m_harfBuzzFontData->m_rangeSet = rangeSet;
341 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData).get(); 367 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData).get();
342 ASSERT(m_harfBuzzFontData->m_simpleFontData); 368 ASSERT(m_harfBuzzFontData->m_simpleFontData);
343 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); 369 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size());
344 hb_font_set_scale(m_unscaledFont, scale, scale); 370 hb_font_set_scale(m_unscaledFont, scale, scale);
345 return m_unscaledFont; 371 return m_unscaledFont;
346 } 372 }
347 373
348 } // namespace blink 374 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698