| 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 30 matching lines...) Expand all Loading... |
| 41 #include "SkRect.h" | 41 #include "SkRect.h" |
| 42 #include "SkTypeface.h" | 42 #include "SkTypeface.h" |
| 43 #include "platform/fonts/FontCache.h" | 43 #include "platform/fonts/FontCache.h" |
| 44 #include "platform/fonts/FontPlatformData.h" | 44 #include "platform/fonts/FontPlatformData.h" |
| 45 #include "platform/fonts/SimpleFontData.h" | 45 #include "platform/fonts/SimpleFontData.h" |
| 46 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 46 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
| 47 #include "wtf/HashMap.h" | 47 #include "wtf/HashMap.h" |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 const hb_tag_t HarfBuzzFace::vertTag = HB_TAG('v', 'e', 'r', 't'); | |
| 52 | |
| 53 // Though we have FontCache class, which provides the cache mechanism for | 51 // Though we have FontCache class, which provides the cache mechanism for |
| 54 // WebKit's font objects, we also need additional caching layer for HarfBuzz | 52 // WebKit's font objects, we also need additional caching layer for HarfBuzz |
| 55 // to reduce the memory consumption because hb_face_t should be associated with | 53 // to reduce the memory consumption because hb_face_t should be associated with |
| 56 // underling font data (e.g. CTFontRef, FTFace). | 54 // underling font data (e.g. CTFontRef, FTFace). |
| 57 | 55 |
| 58 class FaceCacheEntry : public RefCounted<FaceCacheEntry> { | 56 class FaceCacheEntry : public RefCounted<FaceCacheEntry> { |
| 59 public: | 57 public: |
| 60 static PassRefPtr<FaceCacheEntry> create(hb_face_t* face) | 58 static PassRefPtr<FaceCacheEntry> create(hb_face_t* face) |
| 61 { | 59 { |
| 62 ASSERT(face); | 60 ASSERT(face); |
| 63 return adoptRef(new FaceCacheEntry(face)); | 61 return adoptRef(new FaceCacheEntry(face)); |
| 64 } | 62 } |
| 65 ~FaceCacheEntry() | 63 ~FaceCacheEntry() |
| 66 { | 64 { |
| 67 hb_face_destroy(m_face); | 65 hb_face_destroy(m_face); |
| 68 } | 66 } |
| 69 | 67 |
| 70 hb_face_t* face() { return m_face; } | 68 hb_face_t* face() { return m_face; } |
| 71 HashMap<uint32_t, uint16_t>* glyphCache() { return &m_glyphCache; } | |
| 72 | 69 |
| 73 private: | 70 private: |
| 74 explicit FaceCacheEntry(hb_face_t* face) | 71 explicit FaceCacheEntry(hb_face_t* face) |
| 75 : m_face(face) | 72 : m_face(face) |
| 76 { } | 73 { } |
| 77 | 74 |
| 78 hb_face_t* m_face; | 75 hb_face_t* m_face; |
| 79 HashMap<uint32_t, uint16_t> m_glyphCache; | |
| 80 }; | 76 }; |
| 81 | 77 |
| 82 typedef HashMap<uint64_t, RefPtr<FaceCacheEntry>, WTF::IntHash<uint64_t>, WTF::U
nsignedWithZeroKeyHashTraits<uint64_t>> HarfBuzzFaceCache; | 78 typedef HashMap<uint64_t, RefPtr<FaceCacheEntry>, WTF::IntHash<uint64_t>, WTF::U
nsignedWithZeroKeyHashTraits<uint64_t>> HarfBuzzFaceCache; |
| 83 | 79 |
| 84 static HarfBuzzFaceCache* harfBuzzFaceCache() | 80 static HarfBuzzFaceCache* harfBuzzFaceCache() |
| 85 { | 81 { |
| 86 DEFINE_STATIC_LOCAL(HarfBuzzFaceCache, s_harfBuzzFaceCache, ()); | 82 DEFINE_STATIC_LOCAL(HarfBuzzFaceCache, s_harfBuzzFaceCache, ()); |
| 87 return &s_harfBuzzFaceCache; | 83 return &s_harfBuzzFaceCache; |
| 88 } | 84 } |
| 89 | 85 |
| 90 HarfBuzzFace::HarfBuzzFace(FontPlatformData* platformData, uint64_t uniqueID) | 86 HarfBuzzFace::HarfBuzzFace(FontPlatformData* platformData, uint64_t uniqueID) |
| 91 : m_platformData(platformData) | 87 : m_platformData(platformData) |
| 92 , m_uniqueID(uniqueID) | 88 , m_uniqueID(uniqueID) |
| 93 { | 89 { |
| 94 HarfBuzzFaceCache::AddResult result = harfBuzzFaceCache()->add(m_uniqueID, n
ullptr); | 90 HarfBuzzFaceCache::AddResult result = harfBuzzFaceCache()->add(m_uniqueID, n
ullptr); |
| 95 if (result.isNewEntry) | 91 if (result.isNewEntry) |
| 96 result.storedValue->value = FaceCacheEntry::create(createFace()); | 92 result.storedValue->value = FaceCacheEntry::create(createFace()); |
| 97 result.storedValue->value->ref(); | 93 result.storedValue->value->ref(); |
| 98 m_face = result.storedValue->value->face(); | 94 m_face = result.storedValue->value->face(); |
| 99 m_glyphCacheForFaceCacheEntry = result.storedValue->value->glyphCache(); | 95 prepareHarfBuzzFontData(); |
| 100 } | 96 } |
| 101 | 97 |
| 102 HarfBuzzFace::~HarfBuzzFace() | 98 HarfBuzzFace::~HarfBuzzFace() |
| 103 { | 99 { |
| 104 HarfBuzzFaceCache::iterator result = harfBuzzFaceCache()->find(m_uniqueID); | 100 HarfBuzzFaceCache::iterator result = harfBuzzFaceCache()->find(m_uniqueID); |
| 105 ASSERT_WITH_SECURITY_IMPLICATION(result != harfBuzzFaceCache()->end()); | 101 ASSERT_WITH_SECURITY_IMPLICATION(result != harfBuzzFaceCache()->end()); |
| 106 ASSERT(result.get()->value->refCount() > 1); | 102 ASSERT(result.get()->value->refCount() > 1); |
| 107 result.get()->value->deref(); | 103 result.get()->value->deref(); |
| 108 if (result.get()->value->refCount() == 1) | 104 if (result.get()->value->refCount() == 1) |
| 109 harfBuzzFaceCache()->remove(m_uniqueID); | 105 harfBuzzFaceCache()->remove(m_uniqueID); |
| 110 } | 106 } |
| 111 | 107 |
| 108 // struct to carry user-pointer data for hb_font_t callback functions. |
| 112 struct HarfBuzzFontData { | 109 struct HarfBuzzFontData { |
| 113 USING_FAST_MALLOC(HarfBuzzFontData); | 110 USING_FAST_MALLOC(HarfBuzzFontData); |
| 114 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData); | 111 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData); |
| 115 public: | 112 public: |
| 116 HarfBuzzFontData(WTF::HashMap<uint32_t, uint16_t>* glyphCacheForFaceCacheEnt
ry, hb_face_t* face, unsigned rangeFrom, unsigned rangeTo) | 113 HarfBuzzFontData() |
| 117 : m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry) | 114 : m_rangeFrom(0) |
| 118 , m_face(face) | 115 , m_rangeTo(kMaxCodepoint) |
| 119 , m_hbOpenTypeFont(nullptr) | |
| 120 , m_rangeFrom(rangeFrom) | |
| 121 , m_rangeTo(rangeTo) | |
| 122 { } | 116 { } |
| 123 | 117 |
| 124 ~HarfBuzzFontData() | |
| 125 { | |
| 126 if (m_hbOpenTypeFont) | |
| 127 hb_font_destroy(m_hbOpenTypeFont); | |
| 128 } | |
| 129 | |
| 130 SkPaint m_paint; | 118 SkPaint m_paint; |
| 131 RefPtr<SimpleFontData> m_simpleFontData; | 119 RefPtr<SimpleFontData> m_simpleFontData; |
| 132 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; | |
| 133 hb_face_t* m_face; | |
| 134 hb_font_t* m_hbOpenTypeFont; | |
| 135 unsigned m_rangeFrom; | 120 unsigned m_rangeFrom; |
| 136 unsigned m_rangeTo; | 121 unsigned m_rangeTo; |
| 137 }; | 122 }; |
| 138 | 123 |
| 139 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) | 124 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) |
| 140 { | 125 { |
| 141 return SkScalarToFixed(value); | 126 return SkScalarToFixed(value); |
| 142 } | 127 } |
| 143 | 128 |
| 144 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) | 129 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 165 skBounds.set(ir); | 150 skBounds.set(ir); |
| 166 } | 151 } |
| 167 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to
be y-grows-up. | 152 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to
be y-grows-up. |
| 168 extents->x_bearing = SkiaScalarToHarfBuzzPosition(skBounds.fLeft); | 153 extents->x_bearing = SkiaScalarToHarfBuzzPosition(skBounds.fLeft); |
| 169 extents->y_bearing = SkiaScalarToHarfBuzzPosition(-skBounds.fTop); | 154 extents->y_bearing = SkiaScalarToHarfBuzzPosition(-skBounds.fTop); |
| 170 extents->width = SkiaScalarToHarfBuzzPosition(skBounds.width()); | 155 extents->width = SkiaScalarToHarfBuzzPosition(skBounds.width()); |
| 171 extents->height = SkiaScalarToHarfBuzzPosition(-skBounds.height()); | 156 extents->height = SkiaScalarToHarfBuzzPosition(-skBounds.height()); |
| 172 } | 157 } |
| 173 } | 158 } |
| 174 | 159 |
| 175 #if !defined(HB_VERSION_ATLEAST) | |
| 176 #define HB_VERSION_ATLEAST(major, minor, micro) 0 | |
| 177 #endif | |
| 178 | |
| 179 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin
t_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* user
Data) | 160 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin
t_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* user
Data) |
| 180 { | 161 { |
| 181 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; | 162 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; |
| 182 | 163 |
| 183 RELEASE_ASSERT(hbFontData); | 164 RELEASE_ASSERT(hbFontData); |
| 184 if (unicode < hbFontData->m_rangeFrom || unicode > hbFontData->m_rangeTo) | 165 if (unicode < hbFontData->m_rangeFrom || unicode > hbFontData->m_rangeTo) |
| 185 return false; | 166 return false; |
| 186 | 167 |
| 187 if (variationSelector) { | 168 return hb_font_get_glyph(hb_font_get_parent(hbFont), unicode, variationSelec
tor, glyph); |
| 188 #if !HB_VERSION_ATLEAST(0, 9, 28) | |
| 189 return false; | |
| 190 #else | |
| 191 // Skia does not support variation selectors, but hb does. | |
| 192 // We're not fully ready to switch to hb-ot-font yet, | |
| 193 // but are good enough to get glyph IDs for OpenType fonts. | |
| 194 if (!hbFontData->m_hbOpenTypeFont) { | |
| 195 hbFontData->m_hbOpenTypeFont = hb_font_create(hbFontData->m_face); | |
| 196 hb_ot_font_set_funcs(hbFontData->m_hbOpenTypeFont); | |
| 197 } | |
| 198 return hb_font_get_glyph(hbFontData->m_hbOpenTypeFont, unicode, variatio
nSelector, glyph); | |
| 199 // When not found, glyph_func should return false rather than fallback t
o the base. | |
| 200 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.html | |
| 201 #endif | |
| 202 } | |
| 203 | |
| 204 WTF::HashMap<uint32_t, uint16_t>::AddResult result = hbFontData->m_glyphCach
eForFaceCacheEntry->add(unicode, 0); | |
| 205 if (result.isNewEntry) { | |
| 206 SkPaint* paint = &hbFontData->m_paint; | |
| 207 paint->setTextEncoding(SkPaint::kUTF32_TextEncoding); | |
| 208 uint16_t glyph16; | |
| 209 paint->textToGlyphs(&unicode, sizeof(hb_codepoint_t), &glyph16); | |
| 210 result.storedValue->value = glyph16; | |
| 211 *glyph = glyph16; | |
| 212 } | |
| 213 *glyph = result.storedValue->value; | |
| 214 return !!*glyph; | |
| 215 } | 169 } |
| 216 | 170 |
| 217 static hb_position_t harfBuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void*
fontData, hb_codepoint_t glyph, void* userData) | 171 static hb_position_t harfBuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void*
fontData, hb_codepoint_t glyph, void* userData) |
| 218 { | 172 { |
| 219 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; | 173 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; |
| 220 hb_position_t advance = 0; | 174 hb_position_t advance = 0; |
| 221 | 175 |
| 222 SkiaGetGlyphWidthAndExtents(&hbFontData->m_paint, glyph, &advance, 0); | 176 SkiaGetGlyphWidthAndExtents(&hbFontData->m_paint, glyph, &advance, 0); |
| 223 return advance; | 177 return advance; |
| 224 } | 178 } |
| 225 | 179 |
| 226 static hb_bool_t harfBuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontD
ata, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) | |
| 227 { | |
| 228 // Just return true, following the way that HarfBuzz-FreeType | |
| 229 // implementation does. | |
| 230 return true; | |
| 231 } | |
| 232 | |
| 233 static hb_bool_t harfBuzzGetGlyphVerticalOrigin(hb_font_t* hbFont, void* fontDat
a, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) | 180 static hb_bool_t harfBuzzGetGlyphVerticalOrigin(hb_font_t* hbFont, void* fontDat
a, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) |
| 234 { | 181 { |
| 235 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; | 182 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; |
| 236 const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->ver
ticalData(); | 183 const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->ver
ticalData(); |
| 237 if (!verticalData) | 184 if (!verticalData) |
| 238 return false; | 185 return false; |
| 239 | 186 |
| 240 float result[] = { 0, 0 }; | 187 float result[] = { 0, 0 }; |
| 241 Glyph theGlyph = glyph; | 188 Glyph theGlyph = glyph; |
| 242 verticalData->getVerticalTranslationsForGlyphs(hbFontData->m_simpleFontData.
get(), &theGlyph, 1, result); | 189 verticalData->getVerticalTranslationsForGlyphs(hbFontData->m_simpleFontData.
get(), &theGlyph, 1, result); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 { | 238 { |
| 292 static hb_font_funcs_t* harfBuzzSkiaFontFuncs = 0; | 239 static hb_font_funcs_t* harfBuzzSkiaFontFuncs = 0; |
| 293 | 240 |
| 294 // We don't set callback functions which we can't support. | 241 // We don't set callback functions which we can't support. |
| 295 // HarfBuzz will use the fallback implementation if they aren't set. | 242 // HarfBuzz will use the fallback implementation if they aren't set. |
| 296 if (!harfBuzzSkiaFontFuncs) { | 243 if (!harfBuzzSkiaFontFuncs) { |
| 297 harfBuzzSkiaFontFuncs = hb_font_funcs_create(); | 244 harfBuzzSkiaFontFuncs = hb_font_funcs_create(); |
| 298 hb_font_funcs_set_glyph_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyph, 0,
0); | 245 hb_font_funcs_set_glyph_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyph, 0,
0); |
| 299 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe
tGlyphHorizontalAdvance, 0, 0); | 246 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe
tGlyphHorizontalAdvance, 0, 0); |
| 300 hb_font_funcs_set_glyph_h_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGe
tGlyphHorizontalKerning, 0, 0); | 247 hb_font_funcs_set_glyph_h_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGe
tGlyphHorizontalKerning, 0, 0); |
| 301 hb_font_funcs_set_glyph_h_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet
GlyphHorizontalOrigin, 0, 0); | |
| 302 hb_font_funcs_set_glyph_v_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe
tGlyphVerticalAdvance, 0, 0); | 248 hb_font_funcs_set_glyph_v_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe
tGlyphVerticalAdvance, 0, 0); |
| 303 hb_font_funcs_set_glyph_v_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet
GlyphVerticalOrigin, 0, 0); | 249 hb_font_funcs_set_glyph_v_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet
GlyphVerticalOrigin, 0, 0); |
| 304 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG
lyphExtents, 0, 0); | 250 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG
lyphExtents, 0, 0); |
| 305 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs); | 251 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs); |
| 306 } | 252 } |
| 307 return harfBuzzSkiaFontFuncs; | 253 return harfBuzzSkiaFontFuncs; |
| 308 } | 254 } |
| 309 | 255 |
| 310 #if !OS(MACOSX) | 256 #if !OS(MACOSX) |
| 311 static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user
Data) | 257 static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user
Data) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 323 size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer); | 269 size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer); |
| 324 if (tableSize != actualSize) { | 270 if (tableSize != actualSize) { |
| 325 WTF::Partitions::fastFree(buffer); | 271 WTF::Partitions::fastFree(buffer); |
| 326 return nullptr; | 272 return nullptr; |
| 327 } | 273 } |
| 328 | 274 |
| 329 return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_W
RITABLE, buffer, WTF::Partitions::fastFree); | 275 return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_W
RITABLE, buffer, WTF::Partitions::fastFree); |
| 330 } | 276 } |
| 331 #endif | 277 #endif |
| 332 | 278 |
| 333 static void destroyHarfBuzzFontData(void* userData) | |
| 334 { | |
| 335 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(userData)
; | |
| 336 delete hbFontData; | |
| 337 } | |
| 338 | |
| 339 hb_face_t* HarfBuzzFace::createFace() | 279 hb_face_t* HarfBuzzFace::createFace() |
| 340 { | 280 { |
| 341 #if OS(MACOSX) | 281 #if OS(MACOSX) |
| 342 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); | 282 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); |
| 343 #else | 283 #else |
| 344 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform
Data->typeface(), 0); | 284 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform
Data->typeface(), 0); |
| 345 #endif | 285 #endif |
| 346 ASSERT(face); | 286 ASSERT(face); |
| 347 return face; | 287 return face; |
| 348 } | 288 } |
| 349 | 289 |
| 350 hb_font_t* HarfBuzzFace::createFont(unsigned rangeFrom, unsigned rangeTo) const | 290 void HarfBuzzFace::prepareHarfBuzzFontData() |
| 351 { | 291 { |
| 352 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache
Entry, m_face, rangeFrom, rangeTo); | 292 m_harfBuzzFontData = adoptPtr(new HarfBuzzFontData()); |
| 353 m_platformData->setupPaint(&hbFontData->m_paint); | 293 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF
ontPlatformData(m_platformData); |
| 354 hbFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromFontPlatf
ormData(m_platformData); | 294 ASSERT(m_harfBuzzFontData->m_simpleFontData); |
| 355 ASSERT(hbFontData->m_simpleFontData); | 295 OwnPtr<hb_font_t> otFont = adoptPtr(hb_font_create(m_face)); |
| 356 hb_font_t* font = hb_font_create(m_face); | 296 hb_ot_font_set_funcs(otFont.get()); |
| 357 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB
uzzFontData); | 297 // Creating a sub font means that non-available functions |
| 358 float size = m_platformData->size(); | 298 // are found from the parent. |
| 359 int scale = SkiaScalarToHarfBuzzPosition(size); | 299 m_unscaledFont = adoptPtr(hb_font_create_sub_font(otFont.get())); |
| 360 hb_font_set_scale(font, scale, scale); | 300 hb_font_set_funcs(m_unscaledFont.get(), harfBuzzSkiaGetFontFuncs(), m_harfBu
zzFontData.get(), nullptr); |
| 361 hb_font_make_immutable(font); | 301 } |
| 362 return font; | 302 |
| 303 hb_font_t* HarfBuzzFace::getScaledFont(unsigned rangeFrom, unsigned rangeTo) |
| 304 { |
| 305 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
| 306 m_harfBuzzFontData->m_rangeFrom = rangeFrom; |
| 307 m_harfBuzzFontData->m_rangeTo = rangeTo; |
| 308 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
| 309 hb_font_set_scale(m_unscaledFont.get(), scale, scale); |
| 310 return m_unscaledFont.get(); |
| 363 } | 311 } |
| 364 | 312 |
| 365 } // namespace blink | 313 } // namespace blink |
| OLD | NEW |