From 916ae1fb7445b6b919a72f195721d8dc09ddb1fc Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Wed, 14 Mar 2012 11:10:56 -0400 Subject: Draw vertical text using by setting verticalText flag in SkPaint. This approach replaces drawing each vertical character on a Path. The use of the verticalText flag requires an update to Skia's freetype implementation which in external/skia. bug: 5558851 Change-Id: If33288c348e3c51df2d8edc1ee4352de0ac521df --- .../platform/graphics/android/FontAndroid.cpp | 39 +++++++++++----------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'Source/WebCore/platform/graphics/android/FontAndroid.cpp') diff --git a/Source/WebCore/platform/graphics/android/FontAndroid.cpp b/Source/WebCore/platform/graphics/android/FontAndroid.cpp index ef7740c..9fa16b6 100644 --- a/Source/WebCore/platform/graphics/android/FontAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/FontAndroid.cpp @@ -88,6 +88,8 @@ static bool setupForText(SkPaint* paint, GraphicsContext* gc, if (!mode) return false; + paint->setVerticalText(font->platformData().orientation() == Vertical); + FloatSize shadowOffset; float shadowBlur; Color shadowColor; @@ -193,8 +195,6 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, const GlyphBufferAdvance* adv = glyphBuffer.advances(from); SkAutoSTMalloc<32, SkPoint> storage(numGlyphs), storage2(numGlyphs), storage3(numGlyphs); SkPoint* pos = storage.get(); - SkPoint* vPosBegin = storage2.get(); - SkPoint* vPosEnd = storage3.get(); SkCanvas* canvas = gc->platformContext()->mCanvas; @@ -202,6 +202,9 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, point.xy + [width, height, width, height, ...], so we have to convert */ + if (font->platformData().orientation() == Vertical) + y += SkFloatToScalar(font->fontMetrics().floatAscent(IdeographicBaseline) - font->fontMetrics().floatAscent()); + if (EmojiFont::IsAvailable()) { // set filtering, to make scaled images look nice(r) paint.setFilterBitmap(true); @@ -231,27 +234,25 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, localCount * sizeof(uint16_t), &pos[localIndex], paint); } else { - bool isVertical = font->platformData().orientation() == Vertical; for (int i = 0; i < numGlyphs; i++) { pos[i].set(x, y); y += SkFloatToScalar(adv[i].height()); - if (isVertical) { - SkScalar myWidth = SkFloatToScalar(adv[i].width()); - vPosBegin[i].set(x + myWidth, y); - vPosEnd[i].set(x + myWidth, y - myWidth); - x += myWidth; - - SkPath path; - path.reset(); - path.moveTo(vPosBegin[i]); - path.lineTo(vPosEnd[i]); - canvas->drawTextOnPath(glyphs + i, 2, path, 0, paint); - } - else - x += SkFloatToScalar(adv[i].width()); + x += SkFloatToScalar(adv[i].width()); } - if (!isVertical) - canvas->drawPosText(glyphs, numGlyphs * sizeof(uint16_t), pos, paint); + + if (font->platformData().orientation() == Vertical) { + canvas->save(); + canvas->rotate(-90); + SkMatrix rotator; + rotator.reset(); + rotator.setRotate(90); + rotator.mapPoints(pos, numGlyphs); + } + + canvas->drawPosText(glyphs, numGlyphs * sizeof(uint16_t), pos, paint); + + if (font->platformData().orientation() == Vertical) + canvas->restore(); } } -- cgit v1.1