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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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()), | |
Ilya Kulshin
2016/06/21 15:43:42
I'm not familiar with how harfbuzz handles object
drott
2016/06/22 07:19:48
Thanks for pointing that out. The hb_face_create()
| |
335 typefaceStream->getLength(), | |
336 HB_MEMORY_MODE_READONLY, | |
337 typefaceStream, | |
338 deleteTypefaceStream), | |
339 hb_blob_destroy); | |
340 face = hb_face_create(faceBlob.get(), 0); | |
341 } | |
342 | |
343 // Fallback to table copies if there is no in-memory access. | |
344 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platformData->typef ace(), 0); | |
Ilya Kulshin
2016/06/21 15:43:42
Doesn't this always overwrite |face| and ignore th
drott
2016/06/22 07:19:48
Oups, yes, my bad. There was an "if (face)" in my
| |
320 #endif | 345 #endif |
321 ASSERT(face); | 346 ASSERT(face); |
322 return face; | 347 return face; |
323 } | 348 } |
324 | 349 |
325 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) | 350 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) |
326 { | 351 { |
327 HbFontUniquePtr otFont(hb_font_create(face)); | 352 HbFontUniquePtr otFont(hb_font_create(face)); |
328 hb_ot_font_set_funcs(otFont.get()); | 353 hb_ot_font_set_funcs(otFont.get()); |
329 // Creating a sub font means that non-available functions | 354 // Creating a sub font means that non-available functions |
330 // are found from the parent. | 355 // are found from the parent. |
331 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); | 356 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); |
332 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ; | 357 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ; |
333 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr); | 358 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr); |
334 return cacheEntry; | 359 return cacheEntry; |
335 } | 360 } |
336 | 361 |
337 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st | 362 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st |
338 { | 363 { |
339 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); | 364 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
340 m_harfBuzzFontData->m_rangeSet = rangeSet; | 365 m_harfBuzzFontData->m_rangeSet = rangeSet; |
341 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData).get(); | 366 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData).get(); |
342 ASSERT(m_harfBuzzFontData->m_simpleFontData); | 367 ASSERT(m_harfBuzzFontData->m_simpleFontData); |
343 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); | 368 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
344 hb_font_set_scale(m_unscaledFont, scale, scale); | 369 hb_font_set_scale(m_unscaledFont, scale, scale); |
345 return m_unscaledFont; | 370 return m_unscaledFont; |
346 } | 371 } |
347 | 372 |
348 } // namespace blink | 373 } // namespace blink |
OLD | NEW |