diff options
author | claireho <chinglanho@gmail.com> | 2011-10-12 18:37:58 -0700 |
---|---|---|
committer | claireho <chinglanho@gmail.com> | 2011-10-17 10:15:59 -0700 |
commit | 295fd960c28a38cfa7a28d4b8f68f474394f7fb0 (patch) | |
tree | 0b67dc5791e552085f96df636b453745b9b0e48f /Source | |
parent | c13fe17594dff1d9e702affd7cba2561d6fa3bef (diff) | |
download | external_webkit-295fd960c28a38cfa7a28d4b8f68f474394f7fb0.zip external_webkit-295fd960c28a38cfa7a28d4b8f68f474394f7fb0.tar.gz external_webkit-295fd960c28a38cfa7a28d4b8f68f474394f7fb0.tar.bz2 |
Reapply CL for "Vertical Writing Mode" support.
Bug 5094208 - Browser does not handle Japanese text in vertical writing mode.
This changeset syncs up with Chrome's implementation for vertical text rendering. It
1. Adds fontOrientation and textOrientation to FontPlatformData.
2. Rotates the text in drawGlyphs for vertical writing mode.
Here are the changesets for Chrome's vertical writinig mode support:
1. http://trac.webkit.org/changeset/74232
2. http://trac.webkit.org/changeset/80610
3. http://trac.webkit.org/changeset/80654
This CL re-applies reverted CL136684(https://android-git.corp.google.com/g/#/c/136684/).
CL136684 was rollbacked because 2 constructors in FontPlatformDataAndroid.cpp
did not have the init for fontOrientation and textOrientation. That caused the
inconsistent comparison while FontCache.cpp tries to get the cached font and
falls into an infinite loop in HashTable.h:656
Change-Id: I45700dcc8c9266e1b5ae8e588205f24825ca4317
Diffstat (limited to 'Source')
6 files changed, 64 insertions, 18 deletions
diff --git a/Source/WebCore/platform/graphics/android/FontAndroid.cpp b/Source/WebCore/platform/graphics/android/FontAndroid.cpp index 6b4296b..3528d47 100644 --- a/Source/WebCore/platform/graphics/android/FontAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/FontAndroid.cpp @@ -183,8 +183,10 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font, SkScalar y = SkFloatToScalar(point.y()); const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from); const GlyphBufferAdvance* adv = glyphBuffer.advances(from); - SkAutoSTMalloc<32, SkPoint> storage(numGlyphs); + 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; @@ -221,12 +223,27 @@ 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); - x += SkFloatToScalar(adv[i].width()); 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()); } - canvas->drawPosText(glyphs, numGlyphs * sizeof(uint16_t), pos, paint); + if (!isVertical) + canvas->drawPosText(glyphs, numGlyphs * sizeof(uint16_t), pos, paint); } } diff --git a/Source/WebCore/platform/graphics/android/FontCacheAndroid.cpp b/Source/WebCore/platform/graphics/android/FontCacheAndroid.cpp index 20ffd17..4fc3b4e 100644 --- a/Source/WebCore/platform/graphics/android/FontCacheAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/FontCacheAndroid.cpp @@ -177,7 +177,9 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD result = new FontPlatformData(tf, fontDescription.computedSize(), (style & SkTypeface::kBold) && !tf->isBold(), - (style & SkTypeface::kItalic) && !tf->isItalic()); + (style & SkTypeface::kItalic) && !tf->isItalic(), + fontDescription.orientation(), + fontDescription.textOrientation()); } tf->unref(); diff --git a/Source/WebCore/platform/graphics/android/FontCustomPlatformData.cpp b/Source/WebCore/platform/graphics/android/FontCustomPlatformData.cpp index 72fac68..693386e 100644 --- a/Source/WebCore/platform/graphics/android/FontCustomPlatformData.cpp +++ b/Source/WebCore/platform/graphics/android/FontCustomPlatformData.cpp @@ -45,7 +45,8 @@ FontCustomPlatformData::~FontCustomPlatformData() // the unref is enough to release the font data... } -FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation, TextOrientation, FontWidthVariant, FontRenderingMode) +FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, + FontOrientation fontOrientation, TextOrientation textOrientation, FontWidthVariant, FontRenderingMode) { // turn bold/italic into fakeBold/fakeItalic if (m_typeface != NULL) { @@ -54,7 +55,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b if (m_typeface->isItalic() == italic) italic = false; } - return FontPlatformData(m_typeface, size, bold, italic); + return FontPlatformData(m_typeface, size, bold, italic, fontOrientation, textOrientation); } FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer) diff --git a/Source/WebCore/platform/graphics/android/FontDataAndroid.cpp b/Source/WebCore/platform/graphics/android/FontDataAndroid.cpp index 1f19b6d..c6dd174 100644 --- a/Source/WebCore/platform/graphics/android/FontDataAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/FontDataAndroid.cpp @@ -32,6 +32,7 @@ #include "SimpleFontData.h" #include "FloatRect.h" #include "FontDescription.h" +#include "SkFontHost.h" #include "SkPaint.h" #include "SkTypeface.h" #include "SkTime.h" @@ -57,6 +58,16 @@ void SimpleFontData::platformInit() m_fontMetrics.setXHeight(SkScalarToFloat(-skiaFontMetrics.fAscent) * 0.56f); // hack I stole from the window's port m_fontMetrics.setLineSpacing(a + d); m_fontMetrics.setLineGap(SkScalarToFloat(skiaFontMetrics.fLeading)); + + if (platformData().orientation() == Vertical && !isTextOrientationFallback()) { + static const uint32_t vheaTag = SkSetFourByteTag('v', 'h', 'e', 'a'); + static const uint32_t vorgTag = SkSetFourByteTag('V', 'O', 'R', 'G'); + const SkFontID fontID = m_platformData.uniqueID(); + size_t vheaSize = SkFontHost::GetTableSize(fontID, vheaTag); + size_t vorgSize = SkFontHost::GetTableSize(fontID, vorgTag); + if ((vheaSize > 0) || (vorgSize > 0)) + m_hasVerticalGlyphs = true; + } } void SimpleFontData::platformCharWidthInit() diff --git a/Source/WebCore/platform/graphics/android/FontPlatformData.h b/Source/WebCore/platform/graphics/android/FontPlatformData.h index 56ce6e9..5c3313e 100644 --- a/Source/WebCore/platform/graphics/android/FontPlatformData.h +++ b/Source/WebCore/platform/graphics/android/FontPlatformData.h @@ -31,6 +31,7 @@ #define FontPlatformData_h #include "FontOrientation.h" +#include "TextOrientation.h" #include <wtf/text/StringImpl.h> #ifndef NDEBUG @@ -52,7 +53,8 @@ public: FontPlatformData(); FontPlatformData(const FontPlatformData&); - FontPlatformData(SkTypeface*, float textSize, bool fakeBold, bool fakeItalic); + FontPlatformData(SkTypeface*, float textSize, bool fakeBold, bool fakeItalic, + FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight); FontPlatformData(const FontPlatformData& src, float textSize); FontPlatformData(float size, bool syntheticBold, bool syntheticOblique); FontPlatformData(const FontPlatformData& src, SkTypeface* typeface); @@ -65,9 +67,8 @@ public: return mTypeface == hashTableDeletedFontValue(); } - FontOrientation orientation() const { return Horizontal; } // FIXME: Implement. - void setOrientation(FontOrientation) { } // FIXME: Implement. - + FontOrientation orientation() const { return mOrientation; } + void setOrientation(FontOrientation orientation) { mOrientation = orientation; } FontPlatformData& operator=(const FontPlatformData&); bool operator==(const FontPlatformData& a) const; @@ -114,6 +115,8 @@ private: float mTextSize; bool mFakeBold; bool mFakeItalic; + FontOrientation mOrientation; + TextOrientation mTextOrientation; mutable RefPtr<RefCountedHarfbuzzFace> m_harfbuzzFace; static SkTypeface* hashTableDeletedFontValue() { diff --git a/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp b/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp index 8e77b5b..3c90246 100644 --- a/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp @@ -74,7 +74,8 @@ FontPlatformData::RefCountedHarfbuzzFace::~RefCountedHarfbuzzFace() } FontPlatformData::FontPlatformData() - : mTypeface(NULL), mTextSize(0), mFakeBold(false), mFakeItalic(false) + : mTypeface(NULL), mTextSize(0), mFakeBold(false), mFakeItalic(false), + mOrientation(Horizontal), mTextOrientation(TextOrientationVerticalRight) { inc_count(); trace(1); @@ -92,13 +93,17 @@ FontPlatformData::FontPlatformData(const FontPlatformData& src) mFakeBold = src.mFakeBold; mFakeItalic = src.mFakeItalic; m_harfbuzzFace = src.m_harfbuzzFace; + mOrientation = src.mOrientation; + mTextOrientation = src.mTextOrientation; inc_count(); trace(2); } -FontPlatformData::FontPlatformData(SkTypeface* tf, float textSize, bool fakeBold, bool fakeItalic) - : mTypeface(tf), mTextSize(textSize), mFakeBold(fakeBold), mFakeItalic(fakeItalic) +FontPlatformData::FontPlatformData(SkTypeface* tf, float textSize, bool fakeBold, bool fakeItalic, + FontOrientation orientation, TextOrientation textOrientation) + : mTypeface(tf), mTextSize(textSize), mFakeBold(fakeBold), mFakeItalic(fakeItalic), + mOrientation(orientation), mTextOrientation(textOrientation) { if (hashTableDeletedFontValue() != mTypeface) { SkSafeRef(mTypeface); @@ -110,7 +115,7 @@ FontPlatformData::FontPlatformData(SkTypeface* tf, float textSize, bool fakeBold FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize) : mTypeface(src.mTypeface), mTextSize(textSize), mFakeBold(src.mFakeBold), mFakeItalic(src.mFakeItalic), - m_harfbuzzFace(src.m_harfbuzzFace) + m_harfbuzzFace(src.m_harfbuzzFace), mOrientation(src.mOrientation), mTextOrientation(src.mTextOrientation) { if (hashTableDeletedFontValue() != mTypeface) { SkSafeRef(mTypeface); @@ -121,7 +126,8 @@ FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize) } FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) - : mTypeface(NULL), mTextSize(size), mFakeBold(bold), mFakeItalic(oblique) + : mTypeface(NULL), mTextSize(size), mFakeBold(bold), mFakeItalic(oblique), + mOrientation(Horizontal), mTextOrientation(TextOrientationVerticalRight) { inc_count(); trace(5); @@ -129,7 +135,8 @@ FontPlatformData::FontPlatformData(float size, bool bold, bool oblique) FontPlatformData::FontPlatformData(const FontPlatformData& src, SkTypeface* tf) : mTypeface(tf), mTextSize(src.mTextSize), mFakeBold(src.mFakeBold), - mFakeItalic(src.mFakeItalic) + mFakeItalic(src.mFakeItalic), mOrientation(src.mOrientation), + mTextOrientation(src.mTextOrientation) { if (hashTableDeletedFontValue() != mTypeface) { SkSafeRef(mTypeface); @@ -165,6 +172,8 @@ FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src) mFakeBold = src.mFakeBold; mFakeItalic = src.mFakeItalic; m_harfbuzzFace = src.m_harfbuzzFace; + mOrientation = src.mOrientation; + mTextOrientation = src.mTextOrientation; return *this; } @@ -204,7 +213,9 @@ bool FontPlatformData::operator==(const FontPlatformData& a) const return mTypeface == a.mTypeface && mTextSize == a.mTextSize && mFakeBold == a.mFakeBold && - mFakeItalic == a.mFakeItalic; + mFakeItalic == a.mFakeItalic && + mOrientation == a.mOrientation && + mTextOrientation == a.mTextOrientation; } unsigned FontPlatformData::hash() const @@ -219,7 +230,8 @@ unsigned FontPlatformData::hash() const uint32_t sizeAsInt = *reinterpret_cast<const uint32_t*>(&mTextSize); - h ^= 0x01010101 * (((int)mFakeBold << 1) | (int)mFakeItalic); + h ^= 0x01010101 * ((static_cast<int>(mTextOrientation) << 3) | (static_cast<int>(mOrientation) << 2) | + ((int)mFakeBold << 1) | (int)mFakeItalic); h ^= sizeAsInt; return h; } |