Modified: trunk/Source/WebCore/ChangeLog (133533 => 133534)
--- trunk/Source/WebCore/ChangeLog 2012-11-05 23:10:07 UTC (rev 133533)
+++ trunk/Source/WebCore/ChangeLog 2012-11-05 23:18:51 UTC (rev 133534)
@@ -1,3 +1,27 @@
+2012-11-05 Geoffrey Garen <[email protected]>
+
+ Cleaned up the Font class in preparation for optimizing kerning and ligatures
+ https://bugs.webkit.org/show_bug.cgi?id=101258
+
+ Reviewed by Dan Bernstein.
+
+ * platform/graphics/Font.h:
+ (WebCore::Font::typesettingFeatures):
+ (WebCore::Font::computeTypesettingFeatures): Compute and cache our
+ typesetting features instead of recomputing each time a client asks
+ for them. This makes the class interface easier to use because
+ "typesettingFeatures()" can appear in more than one _expression_ without
+ undue performance cost. This may also be a small speedup to code that
+ calls typesettingFeatures() often for other reasons.
+
+ * platform/graphics/Font.cpp:
+ (WebCore::Font::Font):
+ (WebCore::Font::operator=):
+ (WebCore::Font::update): Ditto.
+
+ (WebCore::Font::width): Unforked the width() function so all width-related
+ interfaces can benefit from optimization without duplicate code.
+
2012-11-05 Peng Huang <[email protected]>
Webkit does not handle some media keys correctly On Linux gtk platform.
Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (133533 => 133534)
--- trunk/Source/WebCore/platform/graphics/Font.cpp 2012-11-05 23:10:07 UTC (rev 133533)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp 2012-11-05 23:18:51 UTC (rev 133534)
@@ -75,6 +75,7 @@
, m_wordSpacing(0)
, m_isPlatformFont(false)
, m_needsTranscoding(false)
+ , m_typesettingFeatures(0)
{
}
@@ -84,6 +85,7 @@
, m_wordSpacing(wordSpacing)
, m_isPlatformFont(false)
, m_needsTranscoding(fontTranscoder().needsTranscoding(fd))
+ , m_typesettingFeatures(computeTypesettingFeatures())
{
}
@@ -92,6 +94,7 @@
, m_letterSpacing(0)
, m_wordSpacing(0)
, m_isPlatformFont(true)
+ , m_typesettingFeatures(computeTypesettingFeatures())
{
m_fontDescription.setUsePrinterFont(isPrinterFont);
m_fontDescription.setFontSmoothing(fontSmoothingMode);
@@ -106,6 +109,7 @@
, m_wordSpacing(other.m_wordSpacing)
, m_isPlatformFont(other.m_isPlatformFont)
, m_needsTranscoding(other.m_needsTranscoding)
+ , m_typesettingFeatures(computeTypesettingFeatures())
{
}
@@ -117,6 +121,7 @@
m_wordSpacing = other.m_wordSpacing;
m_isPlatformFont = other.m_isPlatformFont;
m_needsTranscoding = other.m_needsTranscoding;
+ m_typesettingFeatures = other.m_typesettingFeatures;
return *this;
}
@@ -148,6 +153,7 @@
if (!m_fontFallbackList)
m_fontFallbackList = FontFallbackList::create();
m_fontFallbackList->invalidate(fontSelector);
+ m_typesettingFeatures = computeTypesettingFeatures();
}
void Font::drawText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const
@@ -210,11 +216,7 @@
charsConsumed = run.length();
glyphName = "";
-
- if (codePath(run) != Complex)
- return floatWidthForSimpleText(run);
-
- return floatWidthForComplexText(run);
+ return width(run);
}
#if !(PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN)))
Modified: trunk/Source/WebCore/platform/graphics/Font.h (133533 => 133534)
--- trunk/Source/WebCore/platform/graphics/Font.h 2012-11-05 23:10:07 UTC (rev 133533)
+++ trunk/Source/WebCore/platform/graphics/Font.h 2012-11-05 23:18:51 UTC (rev 133534)
@@ -121,48 +121,8 @@
FontRenderingMode renderingMode() const { return m_fontDescription.renderingMode(); }
- TypesettingFeatures typesettingFeatures() const
- {
- TextRenderingMode textRenderingMode = m_fontDescription.textRenderingMode();
- TypesettingFeatures features = s_defaultTypesettingFeatures;
+ TypesettingFeatures typesettingFeatures() const { return m_typesettingFeatures; }
- switch(textRenderingMode) {
- case AutoTextRendering:
- break;
- case OptimizeSpeed:
- features &= ~(Kerning | Ligatures);
- break;
- case GeometricPrecision:
- case OptimizeLegibility:
- features |= Kerning | Ligatures;
- break;
- }
-
- switch (m_fontDescription.kerning()) {
- case FontDescription::NoneKerning:
- features &= ~Kerning;
- break;
- case FontDescription::NormalKerning:
- features |= Kerning;
- break;
- case FontDescription::AutoKerning:
- break;
- }
-
- switch (m_fontDescription.commonLigaturesState()) {
- case FontDescription::DisabledLigaturesState:
- features &= ~Ligatures;
- break;
- case FontDescription::EnabledLigaturesState:
- features |= Ligatures;
- break;
- case FontDescription::NormalLigaturesState:
- break;
- }
-
- return features;
- }
-
FontFamily& firstFamily() { return m_fontDescription.firstFamily(); }
const FontFamily& family() const { return m_fontDescription.family(); }
@@ -287,6 +247,48 @@
return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts();
}
+ TypesettingFeatures computeTypesettingFeatures() const
+ {
+ TextRenderingMode textRenderingMode = m_fontDescription.textRenderingMode();
+ TypesettingFeatures features = s_defaultTypesettingFeatures;
+
+ switch (textRenderingMode) {
+ case AutoTextRendering:
+ break;
+ case OptimizeSpeed:
+ features &= ~(Kerning | Ligatures);
+ break;
+ case GeometricPrecision:
+ case OptimizeLegibility:
+ features |= Kerning | Ligatures;
+ break;
+ }
+
+ switch (m_fontDescription.kerning()) {
+ case FontDescription::NoneKerning:
+ features &= ~Kerning;
+ break;
+ case FontDescription::NormalKerning:
+ features |= Kerning;
+ break;
+ case FontDescription::AutoKerning:
+ break;
+ }
+
+ switch (m_fontDescription.commonLigaturesState()) {
+ case FontDescription::DisabledLigaturesState:
+ features &= ~Ligatures;
+ break;
+ case FontDescription::EnabledLigaturesState:
+ features |= Ligatures;
+ break;
+ case FontDescription::NormalLigaturesState:
+ break;
+ }
+
+ return features;
+ }
+
#if PLATFORM(QT)
void initFormatForTextLayout(QTextLayout*) const;
#endif
@@ -299,6 +301,7 @@
short m_wordSpacing;
bool m_isPlatformFont;
bool m_needsTranscoding;
+ mutable TypesettingFeatures m_typesettingFeatures; // Caches values computed from m_fontDescription.
};
inline Font::~Font()