Index: Source/platform/fonts/harfbuzz/HarfBuzzFaceSkia.cpp |
diff --git a/Source/platform/fonts/harfbuzz/HarfBuzzFaceSkia.cpp b/Source/platform/fonts/harfbuzz/HarfBuzzFaceSkia.cpp |
index e619155b602307d25a5d950c40bc8623187f74e5..368bd84382bedf53978b92853bf54ac79c1ec08f 100644 |
--- a/Source/platform/fonts/harfbuzz/HarfBuzzFaceSkia.cpp |
+++ b/Source/platform/fonts/harfbuzz/HarfBuzzFaceSkia.cpp |
@@ -55,6 +55,7 @@ struct HarfBuzzFontData { |
: m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry) |
{ } |
SkPaint m_paint; |
+ RefPtr<SimpleFontData> m_simpleFontData; |
WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; |
}; |
@@ -121,39 +122,44 @@ static hb_bool_t harfBuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontD |
return true; |
} |
-static hb_position_t harfBuzzGetGlyphHorizontalKerning(hb_font_t*, void* fontData, hb_codepoint_t leftGlyph, hb_codepoint_t rightGlyph, void*) |
+static hb_bool_t harfBuzzGetGlyphVerticalOrigin(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) |
{ |
HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData); |
- if (hbFontData->m_paint.isVerticalText()) { |
- // We don't support cross-stream kerning |
- return 0; |
- } |
- |
- SkTypeface* typeface = hbFontData->m_paint.getTypeface(); |
+ const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->verticalData(); |
+ if (!verticalData) |
+ return false; |
- const uint16_t glyphs[2] = { static_cast<uint16_t>(leftGlyph), static_cast<uint16_t>(rightGlyph) }; |
- int32_t kerningAdjustments[1] = { 0 }; |
+ float result[] = { 0, 0 }; |
+ Glyph theGlyph = glyph; |
+ verticalData->getVerticalTranslationsForGlyphs(hbFontData->m_simpleFontData.get(), &theGlyph, 1, result); |
+ *x = SkiaScalarToHarfBuzzPosition(-result[0]); |
+ *y = SkiaScalarToHarfBuzzPosition(-result[1]); |
+ return true; |
+} |
- if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) { |
- SkScalar upm = SkIntToScalar(typeface->getUnitsPerEm()); |
- SkScalar size = hbFontData->m_paint.getTextSize(); |
- return SkiaScalarToHarfBuzzPosition(SkScalarMulDiv(SkIntToScalar(kerningAdjustments[0]), size, upm)); |
- } |
+static hb_position_t harfBuzzGetGlyphVerticalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) |
+{ |
+ HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData); |
+ const OpenTypeVerticalData* verticalData = hbFontData->m_simpleFontData->verticalData(); |
+ if (!verticalData) |
+ return SkiaScalarToHarfBuzzPosition(hbFontData->m_simpleFontData->fontMetrics().height()); |
- return 0; |
+ Glyph theGlyph = glyph; |
+ float advanceHeight = verticalData->advanceHeight(hbFontData->m_simpleFontData.get(), theGlyph); |
+ return SkiaScalarToHarfBuzzPosition(SkFloatToScalar(advanceHeight)); |
} |
-static hb_position_t harfBuzzGetGlyphVerticalKerning(hb_font_t*, void* fontData, hb_codepoint_t topGlyph, hb_codepoint_t bottomGlyph, void*) |
+static hb_position_t harfBuzzGetGlyphHorizontalKerning(hb_font_t*, void* fontData, hb_codepoint_t leftGlyph, hb_codepoint_t rightGlyph, void*) |
{ |
HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData); |
- if (!hbFontData->m_paint.isVerticalText()) { |
+ if (hbFontData->m_paint.isVerticalText()) { |
// We don't support cross-stream kerning |
return 0; |
} |
SkTypeface* typeface = hbFontData->m_paint.getTypeface(); |
- const uint16_t glyphs[2] = { static_cast<uint16_t>(topGlyph), static_cast<uint16_t>(bottomGlyph) }; |
+ const uint16_t glyphs[2] = { static_cast<uint16_t>(leftGlyph), static_cast<uint16_t>(rightGlyph) }; |
int32_t kerningAdjustments[1] = { 0 }; |
if (typeface->getKerningPairAdjustments(glyphs, 2, kerningAdjustments)) { |
@@ -185,7 +191,8 @@ static hb_font_funcs_t* harfBuzzSkiaGetFontFuncs() |
hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyphHorizontalAdvance, 0, 0); |
hb_font_funcs_set_glyph_h_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyphHorizontalKerning, 0, 0); |
hb_font_funcs_set_glyph_h_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyphHorizontalOrigin, 0, 0); |
- hb_font_funcs_set_glyph_v_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyphVerticalKerning, 0, 0); |
+ hb_font_funcs_set_glyph_v_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyphVerticalAdvance, 0, 0); |
+ hb_font_funcs_set_glyph_v_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyphVerticalOrigin, 0, 0); |
hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetGlyphExtents, 0, 0); |
hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs); |
} |
@@ -229,6 +236,9 @@ hb_font_t* HarfBuzzFace::createFont() |
{ |
HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCacheEntry); |
m_platformData->setupPaint(&hbFontData->m_paint); |
+ // FIXME: We should be using an existing SimpleFontData instance here, |
+ // or move the fontMetrics() implementation to FontPlatformData. |
+ hbFontData->m_simpleFontData = SimpleFontData::create(*m_platformData); |
hb_font_t* font = hb_font_create(m_face); |
hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfBuzzFontData); |
float size = m_platformData->size(); |