2011-04-11 Justin Novosad <junov@chromium.org>
[WebKit-https.git] / Source / WebCore / platform / graphics / chromium / FontChromiumWin.cpp
index 4f0ba57..b1803ea 100644 (file)
@@ -374,21 +374,14 @@ bool Font::canExpandAroundIdeographsInComplexText()
     return false;
 }
 
-void Font::drawGlyphs(GraphicsContext* graphicsContext,
-                      const SimpleFontData* font,
-                      const GlyphBuffer& glyphBuffer,
-                      int from,
-                      int numGlyphs,
-                      const FloatPoint& point) const
-{
+static void drawGlyphsWin(GraphicsContext* graphicsContext,
+                          const SimpleFontData* font,
+                          const GlyphBuffer& glyphBuffer,
+                          int from,
+                          int numGlyphs,
+                          const FloatPoint& point) {
     graphicsContext->platformContext()->prepareForSoftwareDraw();
 
-    SkColor color = graphicsContext->platformContext()->effectiveFillColor();
-    unsigned char alpha = SkColorGetA(color);
-    // Skip 100% transparent text; no need to draw anything.
-    if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStroke)
-        return;
-
     TransparencyAwareGlyphPainter painter(graphicsContext, font, glyphBuffer, from, numGlyphs, point);
 
     // We draw the glyphs in chunks to avoid having to do a heap allocation for
@@ -449,6 +442,39 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext,
     }
 }
 
+void Font::drawGlyphs(GraphicsContext* graphicsContext,
+                      const SimpleFontData* font,
+                      const GlyphBuffer& glyphBuffer,
+                      int from,
+                      int numGlyphs,
+                      const FloatPoint& point) const
+{
+    SkColor color = graphicsContext->platformContext()->effectiveFillColor();
+    unsigned char alpha = SkColorGetA(color);
+    // Skip 100% transparent text; no need to draw anything.
+    if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStroke && !graphicsContext->hasShadow())
+        return;
+    if (!alpha || windowsCanHandleDrawTextShadow(graphicsContext) || !windowsCanHandleTextDrawingWithoutShadow(graphicsContext)) {
+        drawGlyphsWin(graphicsContext, font, glyphBuffer, from, numGlyphs, point);
+        return;
+    }
+    // Draw in two passes: skia for the shadow, GDI for foreground text
+    // pass1: shadow (will use skia)
+    graphicsContext->save();
+    graphicsContext->setFillColor(Color::transparent, graphicsContext->fillColorSpace());
+    drawGlyphsWin(graphicsContext, font, glyphBuffer, from, numGlyphs, point);
+    graphicsContext->restore();
+    // pass2: foreground text (will use GDI)
+    FloatSize shadowOffset;
+    float shadowBlur;
+    Color shadowColor;
+    ColorSpace shadowColorSpace;
+    graphicsContext->getShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace);
+    graphicsContext->setShadow(shadowOffset, shadowBlur, Color::transparent, shadowColorSpace);
+    drawGlyphsWin(graphicsContext, font, glyphBuffer, from, numGlyphs, point);
+    graphicsContext->setShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace);
+}
+
 FloatRect Font::selectionRectForComplexText(const TextRun& run,
                                             const FloatPoint& point,
                                             int h,