| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 public: | 60 public: |
| 61 | 61 |
| 62 HarfBuzzFontData() | 62 HarfBuzzFontData() |
| 63 : m_paint() | 63 : m_paint() |
| 64 , m_simpleFontData(nullptr) | 64 , m_simpleFontData(nullptr) |
| 65 , m_rangeSet(nullptr) | 65 , m_rangeSet(nullptr) |
| 66 { | 66 { |
| 67 } | 67 } |
| 68 | 68 |
| 69 SkPaint m_paint; | 69 SkPaint m_paint; |
| 70 RefPtr<SimpleFontData> m_simpleFontData; | 70 SimpleFontData* m_simpleFontData; |
| 71 RefPtr<UnicodeRangeSet> m_rangeSet; | 71 RefPtr<UnicodeRangeSet> m_rangeSet; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // Though we have FontCache class, which provides the cache mechanism for | 74 // Though we have FontCache class, which provides the cache mechanism for |
| 75 // WebKit's font objects, we also need additional caching layer for HarfBuzz to | 75 // WebKit's font objects, we also need additional caching layer for HarfBuzz to |
| 76 // reduce the number of hb_font_t objects created. Without it, we would create | 76 // reduce the number of hb_font_t objects created. Without it, we would create |
| 77 // an hb_font_t object for every FontPlatformData object. But insted, we only | 77 // an hb_font_t object for every FontPlatformData object. But insted, we only |
| 78 // need one for each unique SkTypeface. | 78 // need one for each unique SkTypeface. |
| 79 // FIXME, crbug.com/609099: We should fix the FontCache to only keep one | 79 // FIXME, crbug.com/609099: We should fix the FontCache to only keep one |
| 80 // FontPlatformData object independent of size, then consider using this here. | 80 // FontPlatformData object independent of size, then consider using this here. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 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) | 194 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) |
| 195 { | 195 { |
| 196 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; | 196 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; |
| 197 const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->ver
ticalData(); | 197 const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->ver
ticalData(); |
| 198 if (!verticalData) | 198 if (!verticalData) |
| 199 return false; | 199 return false; |
| 200 | 200 |
| 201 float result[] = { 0, 0 }; | 201 float result[] = { 0, 0 }; |
| 202 Glyph theGlyph = glyph; | 202 Glyph theGlyph = glyph; |
| 203 verticalData->getVerticalTranslationsForGlyphs(hbFontData->m_simpleFontData.
get(), &theGlyph, 1, result); | 203 verticalData->getVerticalTranslationsForGlyphs(hbFontData->m_simpleFontData,
&theGlyph, 1, result); |
| 204 *x = SkiaScalarToHarfBuzzPosition(-result[0]); | 204 *x = SkiaScalarToHarfBuzzPosition(-result[0]); |
| 205 *y = SkiaScalarToHarfBuzzPosition(-result[1]); | 205 *y = SkiaScalarToHarfBuzzPosition(-result[1]); |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 static hb_position_t harfBuzzGetGlyphVerticalAdvance(hb_font_t* hbFont, void* fo
ntData, hb_codepoint_t glyph, void* userData) | 209 static hb_position_t harfBuzzGetGlyphVerticalAdvance(hb_font_t* hbFont, void* fo
ntData, hb_codepoint_t glyph, void* userData) |
| 210 { | 210 { |
| 211 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; | 211 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; |
| 212 const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->ver
ticalData(); | 212 const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->ver
ticalData(); |
| 213 if (!verticalData) | 213 if (!verticalData) |
| 214 return SkiaScalarToHarfBuzzPosition(hbFontData->m_simpleFontData->getFon
tMetrics().height()); | 214 return SkiaScalarToHarfBuzzPosition(hbFontData->m_simpleFontData->getFon
tMetrics().height()); |
| 215 | 215 |
| 216 Glyph theGlyph = glyph; | 216 Glyph theGlyph = glyph; |
| 217 float advanceHeight = -verticalData->advanceHeight(hbFontData->m_simpleFontD
ata.get(), theGlyph); | 217 float advanceHeight = -verticalData->advanceHeight(hbFontData->m_simpleFontD
ata, theGlyph); |
| 218 return SkiaScalarToHarfBuzzPosition(SkFloatToScalar(advanceHeight)); | 218 return SkiaScalarToHarfBuzzPosition(SkFloatToScalar(advanceHeight)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 static hb_position_t harfBuzzGetGlyphHorizontalKerning(hb_font_t*, void* fontDat
a, hb_codepoint_t leftGlyph, hb_codepoint_t rightGlyph, void*) | 221 static hb_position_t harfBuzzGetGlyphHorizontalKerning(hb_font_t*, void* fontDat
a, hb_codepoint_t leftGlyph, hb_codepoint_t rightGlyph, void*) |
| 222 { | 222 { |
| 223 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; | 223 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; |
| 224 if (hbFontData->m_paint.isVerticalText()) { | 224 if (hbFontData->m_paint.isVerticalText()) { |
| 225 // We don't support cross-stream kerning | 225 // We don't support cross-stream kerning |
| 226 return 0; | 226 return 0; |
| 227 } | 227 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); | 309 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); |
| 310 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont)
; | 310 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont)
; |
| 311 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo
ntData(), nullptr); | 311 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo
ntData(), nullptr); |
| 312 return cacheEntry; | 312 return cacheEntry; |
| 313 } | 313 } |
| 314 | 314 |
| 315 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con
st | 315 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con
st |
| 316 { | 316 { |
| 317 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); | 317 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
| 318 m_harfBuzzFontData->m_rangeSet = rangeSet; | 318 m_harfBuzzFontData->m_rangeSet = rangeSet; |
| 319 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF
ontPlatformData(m_platformData); | 319 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF
ontPlatformData(m_platformData).get(); |
| 320 ASSERT(m_harfBuzzFontData->m_simpleFontData); | 320 ASSERT(m_harfBuzzFontData->m_simpleFontData); |
| 321 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); | 321 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
| 322 hb_font_set_scale(m_unscaledFont, scale, scale); | 322 hb_font_set_scale(m_unscaledFont, scale, scale); |
| 323 return m_unscaledFont; | 323 return m_unscaledFont; |
| 324 } | 324 } |
| 325 | 325 |
| 326 } // namespace blink | 326 } // namespace blink |
| OLD | NEW |