Text-shadow with (0, 0) offset and radius = 0 is ugly
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Aug 2014 17:35:59 +0000 (17:35 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Aug 2014 17:35:59 +0000 (17:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135357

Reviewed by Darin Adler.

Source/WebCore:

Instead, check for this kind of shadow and don't draw it.

Test: fast/text/empty-shadow.html

* rendering/TextPainter.cpp:
(WebCore::isEmptyShadow): Does a shadow match these criteria?
(WebCore::paintTextWithShadows): If so, don't draw it.

LayoutTests:

Check that this kind of shadow ends up invisible.

* fast/text/empty-shadow-expected.html: Added
* fast/text/empty-shadow.html: Added

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

LayoutTests/ChangeLog
LayoutTests/fast/text/empty-shadow-expected.html [new file with mode: 0644]
LayoutTests/fast/text/empty-shadow.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/TextPainter.cpp

index 7d94108..6d12589 100644 (file)
@@ -1,3 +1,15 @@
+2014-07-28  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Text-shadow with (0, 0) offset and radius = 0 is ugly
+        https://bugs.webkit.org/show_bug.cgi?id=135357
+
+        Reviewed by Darin Adler.
+
+        Check that this kind of shadow ends up invisible.
+
+        * fast/text/empty-shadow-expected.html: Added
+        * fast/text/empty-shadow.html: Added
+
 2014-08-06  Mihnea Ovidenie  <mihnea@adobe.com>
 
         [CSSRegions] Move full screen tests into fast/regions/fullscreen
diff --git a/LayoutTests/fast/text/empty-shadow-expected.html b/LayoutTests/fast/text/empty-shadow-expected.html
new file mode 100644 (file)
index 0000000..ce2b96b
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that text drawn with text-shadows of radius 0 and (0, 0) offset are not drawn.
+This is a better outcome than them being drawn in an ugly way.
+This test is successful if the text below is completely invisible.
diff --git a/LayoutTests/fast/text/empty-shadow.html b/LayoutTests/fast/text/empty-shadow.html
new file mode 100644 (file)
index 0000000..427cdd8
--- /dev/null
@@ -0,0 +1,4 @@
+This tests that text drawn with text-shadows of radius 0 and (0, 0) offset are not drawn.
+This is a better outcome than them being drawn in an ugly way.
+This test is successful if the text below is completely invisible.
+<div style="color:#fff;text-shadow:0 0 #000">This is some text</div>
index 0d965bc..7028137 100644 (file)
@@ -1,3 +1,18 @@
+2014-07-28  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Text-shadow with (0, 0) offset and radius = 0 is ugly
+        https://bugs.webkit.org/show_bug.cgi?id=135357
+
+        Reviewed by Darin Adler.
+
+        Instead, check for this kind of shadow and don't draw it.
+
+        Test: fast/text/empty-shadow.html
+
+        * rendering/TextPainter.cpp:
+        (WebCore::isEmptyShadow): Does a shadow match these criteria?
+        (WebCore::paintTextWithShadows): If so, don't draw it.
+
 2014-08-06  Andy Estes  <aestes@apple.com>
 
         [iOS] QuickLook returns an invalid MIME type for some documents
index af34257..78e73e1 100644 (file)
@@ -60,6 +60,13 @@ static void drawTextOrEmphasisMarks(GraphicsContext& context, const Font& font,
         context.drawEmphasisMarks(font, textRun, emphasisMark, point + IntSize(0, emphasisMarkOffset), from, to);
 }
 
+static bool isEmptyShadow(const ShadowData* shadowPtr)
+{
+    if (!shadowPtr)
+        return true;
+    return shadow->location() == IntPoint() && !shadow->radius();
+}
+
 static void paintTextWithShadows(GraphicsContext* context, const Font& font, const TextRun& textRun, const AtomicString& emphasisMark,
     int emphasisMarkOffset, int startOffset, int endOffset, int truncationPoint, const FloatPoint& textOrigin, const FloatRect& boxRect,
     const ShadowData* shadow, bool stroked, bool horizontal)
@@ -72,7 +79,8 @@ static void paintTextWithShadows(GraphicsContext* context, const Font& font, con
 
     do {
         IntSize extraOffset;
-        if (shadow)
+        bool shadowIsEmpty = isEmptyShadow(shadow);
+        if (!shadowIsEmpty)
             extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, horizontal));
         else if (!opaque)
             context->setFillColor(fillColor, fillColorSpace);
@@ -91,7 +99,7 @@ static void paintTextWithShadows(GraphicsContext* context, const Font& font, con
 
         if (shadow->next() || stroked || !opaque)
             context->restore();
-        else
+        else if (!shadowIsEmpty)
             context->clearShadow();
 
         shadow = shadow->next();