summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform
diff options
context:
space:
mode:
authorclaireho <chinglanho@gmail.com>2011-11-10 16:00:55 -0800
committerclaireho <chinglanho@gmail.com>2011-11-10 17:17:57 -0800
commitb5adac2453b428ee1e9386919a89a395dc507bd6 (patch)
treeb279de53ede817c5e47d147474ced9e61eb63abf /Source/WebCore/platform
parent53e0d336e8ff86f5e8a487fef8e16544dabcca1a (diff)
downloadexternal_webkit-b5adac2453b428ee1e9386919a89a395dc507bd6.zip
external_webkit-b5adac2453b428ee1e9386919a89a395dc507bd6.tar.gz
external_webkit-b5adac2453b428ee1e9386919a89a395dc507bd6.tar.bz2
Fix the scale for complex script fonts and re-ajust y position.
Bug 5445861 : complex joining characters positioned in wrong place. 1. Set font size and scale for harfbuzz object based on Chrome's CL:http://trac.webkit.org/changeset/77504. 2. Truncate harfbuzz value to pixels for y position. 3. Ran through the page_cycler/intl2 tests with 5 iterations. Change-Id: I38dcb07b2d23042e40781ea914c8c6e73f33c220
Diffstat (limited to 'Source/WebCore/platform')
-rw-r--r--Source/WebCore/platform/graphics/android/FontAndroid.cpp21
-rw-r--r--Source/WebCore/platform/graphics/android/FontPlatformData.h2
-rw-r--r--Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp42
3 files changed, 45 insertions, 20 deletions
diff --git a/Source/WebCore/platform/graphics/android/FontAndroid.cpp b/Source/WebCore/platform/graphics/android/FontAndroid.cpp
index d435ad7..852413f 100644
--- a/Source/WebCore/platform/graphics/android/FontAndroid.cpp
+++ b/Source/WebCore/platform/graphics/android/FontAndroid.cpp
@@ -735,6 +735,16 @@ void TextRunWalker::setupFontForScriptRun()
}
m_item.face = complexPlatformData->harfbuzzFace();
m_item.font->userData = const_cast<FontPlatformData*>(complexPlatformData);
+
+ int size = complexPlatformData->size();
+ m_item.font->x_ppem = size;
+ m_item.font->y_ppem = size;
+ // x_ and y_scale are the conversion factors from font design space (fEmSize) to 1/64th of device pixels in 16.16 format.
+ const int devicePixelFraction = 64;
+ const int multiplyFor16Dot16 = 1 << 16;
+ int scale = devicePixelFraction * size * multiplyFor16Dot16 / complexPlatformData->emSizeInFontUnits();
+ m_item.font->x_scale = scale;
+ m_item.font->y_scale = scale;
}
HB_FontRec* TextRunWalker::allocHarfbuzzFont()
@@ -743,13 +753,6 @@ HB_FontRec* TextRunWalker::allocHarfbuzzFont()
memset(font, 0, sizeof(HB_FontRec));
font->klass = &harfbuzzSkiaClass;
font->userData = 0;
- // The values which harfbuzzSkiaClass returns are already scaled to
- // pixel units, so we just set all these to one to disable further
- // scaling.
- font->x_ppem = 1;
- font->y_ppem = 1;
- font->x_scale = 1;
- font->y_scale = 1;
return font;
}
@@ -823,7 +826,9 @@ void TextRunWalker::setGlyphPositions(bool isRTL)
int i = isRTL ? m_item.num_glyphs - iter - 1 : iter;
m_glyphs16[i] = m_item.glyphs[i];
- m_positions[i].set(SkIntToScalar(m_offsetX + position), m_startingY + SkIntToScalar(m_item.offsets[i].y));
+ int offsetX = truncateFixedPointToInteger(m_item.offsets[i].x);
+ int offsetY = truncateFixedPointToInteger(m_item.offsets[i].y);
+ m_positions[i].set(SkIntToScalar(m_offsetX + position) + offsetX, m_startingY + offsetY);
int advance = truncateFixedPointToInteger(m_item.advances[i]);
// The first half of the conjunction works around the case where
diff --git a/Source/WebCore/platform/graphics/android/FontPlatformData.h b/Source/WebCore/platform/graphics/android/FontPlatformData.h
index 5c3313e..1e46971 100644
--- a/Source/WebCore/platform/graphics/android/FontPlatformData.h
+++ b/Source/WebCore/platform/graphics/android/FontPlatformData.h
@@ -82,6 +82,7 @@ public:
float size() const { return mTextSize; }
unsigned hash() const;
+ int emSizeInFontUnits() const;
bool isFixedPitch() const;
#ifndef NDEBUG
@@ -113,6 +114,7 @@ private:
SkTypeface* mTypeface;
float mTextSize;
+ mutable int mEmSizeInFontUnits;
bool mFakeBold;
bool mFakeItalic;
FontOrientation mOrientation;
diff --git a/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp b/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp
index 3c90246..c09120f 100644
--- a/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp
+++ b/Source/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp
@@ -33,6 +33,7 @@
#ifdef SUPPORT_COMPLEX_SCRIPTS
#include "HarfbuzzSkia.h"
#endif
+#include "SkAdvancedTypefaceMetrics.h"
#include "SkPaint.h"
#include "SkTypeface.h"
@@ -74,7 +75,7 @@ FontPlatformData::RefCountedHarfbuzzFace::~RefCountedHarfbuzzFace()
}
FontPlatformData::FontPlatformData()
- : mTypeface(NULL), mTextSize(0), mFakeBold(false), mFakeItalic(false),
+ : mTypeface(NULL), mTextSize(0), mEmSizeInFontUnits(0), mFakeBold(false), mFakeItalic(false),
mOrientation(Horizontal), mTextOrientation(TextOrientationVerticalRight)
{
inc_count();
@@ -87,10 +88,10 @@ FontPlatformData::FontPlatformData(const FontPlatformData& src)
SkSafeRef(src.mTypeface);
}
- mTypeface = src.mTypeface;
-
- mTextSize = src.mTextSize;
- mFakeBold = src.mFakeBold;
+ mTypeface = src.mTypeface;
+ mTextSize = src.mTextSize;
+ mEmSizeInFontUnits = src.mEmSizeInFontUnits;
+ mFakeBold = src.mFakeBold;
mFakeItalic = src.mFakeItalic;
m_harfbuzzFace = src.m_harfbuzzFace;
mOrientation = src.mOrientation;
@@ -102,7 +103,7 @@ FontPlatformData::FontPlatformData(const FontPlatformData& src)
FontPlatformData::FontPlatformData(SkTypeface* tf, float textSize, bool fakeBold, bool fakeItalic,
FontOrientation orientation, TextOrientation textOrientation)
- : mTypeface(tf), mTextSize(textSize), mFakeBold(fakeBold), mFakeItalic(fakeItalic),
+ : mTypeface(tf), mTextSize(textSize), mEmSizeInFontUnits(0), mFakeBold(fakeBold), mFakeItalic(fakeItalic),
mOrientation(orientation), mTextOrientation(textOrientation)
{
if (hashTableDeletedFontValue() != mTypeface) {
@@ -114,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),
+ : mTypeface(src.mTypeface), mTextSize(textSize), mEmSizeInFontUnits(src.mEmSizeInFontUnits), mFakeBold(src.mFakeBold), mFakeItalic(src.mFakeItalic),
m_harfbuzzFace(src.m_harfbuzzFace), mOrientation(src.mOrientation), mTextOrientation(src.mTextOrientation)
{
if (hashTableDeletedFontValue() != mTypeface) {
@@ -126,7 +127,7 @@ 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), mEmSizeInFontUnits(0), mFakeBold(bold), mFakeItalic(oblique),
mOrientation(Horizontal), mTextOrientation(TextOrientationVerticalRight)
{
inc_count();
@@ -134,7 +135,7 @@ FontPlatformData::FontPlatformData(float size, bool bold, bool oblique)
}
FontPlatformData::FontPlatformData(const FontPlatformData& src, SkTypeface* tf)
- : mTypeface(tf), mTextSize(src.mTextSize), mFakeBold(src.mFakeBold),
+ : mTypeface(tf), mTextSize(src.mTextSize), mEmSizeInFontUnits(0), mFakeBold(src.mFakeBold),
mFakeItalic(src.mFakeItalic), mOrientation(src.mOrientation),
mTextOrientation(src.mTextOrientation)
{
@@ -158,6 +159,22 @@ FontPlatformData::~FontPlatformData()
}
}
+int FontPlatformData::emSizeInFontUnits() const
+{
+ if (mEmSizeInFontUnits)
+ return mEmSizeInFontUnits;
+
+ SkAdvancedTypefaceMetrics* metrics = 0;
+ if (mTypeface)
+ metrics = mTypeface->getAdvancedTypefaceMetrics(SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo);
+ if (metrics) {
+ mEmSizeInFontUnits = metrics->fEmSize;
+ metrics->unref();
+ } else
+ mEmSizeInFontUnits = 1000; // default value copied from Skia.
+ return mEmSizeInFontUnits;
+}
+
FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
{
if (hashTableDeletedFontValue() != src.mTypeface) {
@@ -167,9 +184,10 @@ FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
SkSafeUnref(mTypeface);
}
- mTypeface = src.mTypeface;
- mTextSize = src.mTextSize;
- mFakeBold = src.mFakeBold;
+ mTypeface = src.mTypeface;
+ mEmSizeInFontUnits = src.mEmSizeInFontUnits;
+ mTextSize = src.mTextSize;
+ mFakeBold = src.mFakeBold;
mFakeItalic = src.mFakeItalic;
m_harfbuzzFace = src.m_harfbuzzFace;
mOrientation = src.mOrientation;