Enable LCD text in Skia on Mac
authorcaryclark@google.com <caryclark@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Sep 2011 22:21:00 +0000 (22:21 +0000)
committercaryclark@google.com <caryclark@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Sep 2011 22:21:00 +0000 (22:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68734

Reviewed by Stephen White.

No new tests. Existing layout tests are generated
with LCD text disabled for pixel comparisons.

Duplicate the logic in FontMac.mm to pass settings
for antialiasing and smoothing. Also disable smoothing
for DumpRenderTree.

* platform/graphics/skia/FontSkia.cpp:
(WebCore::setupPaint):
(WebCore::Font::drawGlyphs):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96366 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/skia/FontSkia.cpp

index d476b69..5ae670b 100644 (file)
@@ -1,3 +1,21 @@
+2011-09-29  Cary Clark  <caryclark@google.com>
+
+        Enable LCD text in Skia on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=68734
+
+        Reviewed by Stephen White.
+
+        No new tests. Existing layout tests are generated
+        with LCD text disabled for pixel comparisons.
+
+        Duplicate the logic in FontMac.mm to pass settings
+        for antialiasing and smoothing. Also disable smoothing
+        for DumpRenderTree.
+        * platform/graphics/skia/FontSkia.cpp:
+        (WebCore::setupPaint):
+        (WebCore::Font::drawGlyphs):
+
 2011-09-29  Varun Jain  <varunjain@google.com>
  
          Implement flick gesture in Chromium Gesture Recognizer
index 8b711f0..74b9f2c 100644 (file)
@@ -34,6 +34,7 @@
 #include "GlyphBuffer.h"
 #include "GraphicsContext.h"
 #include "PlatformContextSkia.h"
+#include "PlatformSupport.h"
 #include "SimpleFontData.h"
 
 #include "SkCanvas.h"
@@ -73,12 +74,12 @@ static void adjustTextRenderMode(SkPaint* paint, PlatformContextSkia* skiaContex
         paint->setLCDRenderText(false);
 }
 
-static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Font* font)
+static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Font* font, bool shouldAntialias, bool shouldSmoothFonts)
 {
     const FontPlatformData& platformData = fontData->platformData();
     const float textSize = platformData.m_size >= 0 ? platformData.m_size : 12;
 
-    paint->setAntiAlias(true);
+    paint->setAntiAlias(shouldAntialias);
     paint->setEmbeddedBitmapText(false);
     paint->setTextSize(SkFloatToScalar(textSize));
     SkTypeface* typeface = SkCreateTypefaceFromCTFont(platformData.ctFont());
@@ -87,7 +88,7 @@ static void setupPaint(SkPaint* paint, const SimpleFontData* fontData, const Fon
     paint->setFakeBoldText(platformData.m_syntheticBold);
     paint->setTextSkewX(platformData.m_syntheticOblique ? -SK_Scalar1 / 4 : 0);
     paint->setAutohinted(false); // freetype specific
-    paint->setLCDRenderText(font->fontDescription().fontSmoothing() == SubpixelAntialiased);
+    paint->setLCDRenderText(shouldSmoothFonts);
 }
 
 // TODO: This needs to be split into helper functions to better scope the
@@ -98,6 +99,27 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
                       const FloatPoint& point) const {
     COMPILE_ASSERT(sizeof(GlyphBufferGlyph) == sizeof(uint16_t), GlyphBufferGlyphSize_equals_uint16_t);
 
+    bool shouldSmoothFonts = true;
+    bool shouldAntialias = true;
+    
+    switch (fontDescription().fontSmoothing()) {
+    case Antialiased:
+        shouldSmoothFonts = false;
+        break;
+    case SubpixelAntialiased:
+        break;
+    case NoSmoothing:
+        shouldAntialias = false;
+        shouldSmoothFonts = false;
+        break;
+    case AutoSmoothing:
+        // For the AutoSmooth case, don't do anything! Keep the default settings.
+        break; 
+    }
+    
+    if (!shouldUseSmoothing() || PlatformSupport::layoutTestMode())
+        shouldSmoothFonts = false;
+
     const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from);
     SkScalar x = SkFloatToScalar(point.x());
     SkScalar y = SkFloatToScalar(point.y());
@@ -133,7 +155,7 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
     if (textMode & TextModeFill) {
         SkPaint paint;
         gc->platformContext()->setupPaintForFilling(&paint);
-        setupPaint(&paint, font, this);
+        setupPaint(&paint, font, this, shouldAntialias, shouldSmoothFonts);
         adjustTextRenderMode(&paint, gc->platformContext());
         paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
         paint.setColor(gc->fillColor().rgb());
@@ -156,7 +178,7 @@ void Font::drawGlyphs(GraphicsContext* gc, const SimpleFontData* font,
 
         SkPaint paint;
         gc->platformContext()->setupPaintForStroking(&paint, 0, 0);
-        setupPaint(&paint, font, this);
+        setupPaint(&paint, font, this, shouldAntialias, shouldSmoothFonts);
         adjustTextRenderMode(&paint, gc->platformContext());
         paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
         paint.setColor(gc->strokeColor().rgb());