Diff
Modified: trunk/LayoutTests/ChangeLog (173940 => 173941)
--- trunk/LayoutTests/ChangeLog 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/LayoutTests/ChangeLog 2014-09-25 02:32:06 UTC (rev 173941)
@@ -1,3 +1,22 @@
+2014-09-22 Myles C. Maxfield <[email protected]>
+
+ REGRESSION: Text with a zero offset, zero blur shadow vanishes
+ https://bugs.webkit.org/show_bug.cgi?id=136801
+
+ Reviewed by Darin Adler.
+
+ This test should be a comprehensive test of empty shadows. It tests every
+ combination of one and two shadows being empty, as well as transparent and
+ opaque text.
+
+ After updating fast/text/empty-shadow.html, fast/text/empty-shadow-with-color.html
+ is no longer necessary.
+
+ * fast/text/empty-shadow-expected.html:
+ * fast/text/empty-shadow-with-color-expected.html: Removed.
+ * fast/text/empty-shadow-with-color.html: Removed.
+ * fast/text/empty-shadow.html:
+
2014-09-24 Shivakumar JM <[email protected]>
Add New Test for overrideMimeType in XMLHttpRequest.
Modified: trunk/LayoutTests/fast/text/empty-shadow-expected.html (173940 => 173941)
--- trunk/LayoutTests/fast/text/empty-shadow-expected.html 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/LayoutTests/fast/text/empty-shadow-expected.html 2014-09-25 02:32:06 UTC (rev 173941)
@@ -1,3 +1,20 @@
-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.
+<p>This tests that text drawn with text-shadows of radius 0 and (0, 0) offset are not drawn.</p>
+<p>In the following tests, the actual text is green while the shadows are blue.</p>
+
+<div style="color: green;">
+<div style="text-shadow: 5px 5px blue;">Text with a single shadow.</div>
+<div>Text with one empty (undrawn) shadow.</div>
+<div style="text-shadow: 5px 5px blue, 10px 10px blue;">Text with two shadows</div>
+<div style="text-shadow: 5px 5px blue;">Text with two shadows: first drawn and second empty (undrawn).</div>
+<div style="text-shadow: 10px 10px blue;">Text with two shadows: first empty (undrawn) and second drawn.</div>
+<div>Text with two empty (undrawn) shadows.</div>
+</div>
+
+<div style="color: transparent;">
+<div style="text-shadow: 5px 5px blue;">Transparent text with a single shadow.</div>
+<div style="color: blue;">Transparent text with one empty shadow.</div>
+<div style="text-shadow: 5px 5px blue, 10px 10px blue;">Transparent text with two shadows</div>
+<div style="color: blue; text-shadow: 7px 7px blue;">Transparent text with two shadows: first drawn and second empty.</div>
+<div style="color: blue; text-shadow: 10px 10px blue;">Transparent text with two shadows: first drawn and second empty.</div>
+<div style="color: blue; position: relative;"><div style="position: absolute; left: 0px; top: 0px;">Transparent text with two empty shadows.</div><div style="position: absolute; left: 0px; top: 0px;">Transparent text with two empty shadows.</div></div>
+</div>
Deleted: trunk/LayoutTests/fast/text/empty-shadow-with-color-expected.html (173940 => 173941)
--- trunk/LayoutTests/fast/text/empty-shadow-with-color-expected.html 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/LayoutTests/fast/text/empty-shadow-with-color-expected.html 2014-09-25 02:32:06 UTC (rev 173941)
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<style>
-#test {
- color: green;
- font-size: 16px;
-}
-</style>
-</head>
-<body>
-This test makes sure that text drawn with an empty shadow is colored correctly. It passes if the following text is green.
-<div id="test">This should be green.</div>
-</body>
-</html>
Deleted: trunk/LayoutTests/fast/text/empty-shadow-with-color.html (173940 => 173941)
--- trunk/LayoutTests/fast/text/empty-shadow-with-color.html 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/LayoutTests/fast/text/empty-shadow-with-color.html 2014-09-25 02:32:06 UTC (rev 173941)
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<style>
-#test {
- color: green;
- font-size: 16px;
- text-shadow: red 20px 20px, red 0px 0px;
- overflow: hidden;
-}
-</style>
-</head>
-<body>
-This test makes sure that text drawn with an empty shadow is colored correctly. It passes if the following text is green.
-<div id="test">This should be green.</div>
-</body>
-</html>
Modified: trunk/LayoutTests/fast/text/empty-shadow.html (173940 => 173941)
--- trunk/LayoutTests/fast/text/empty-shadow.html 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/LayoutTests/fast/text/empty-shadow.html 2014-09-25 02:32:06 UTC (rev 173941)
@@ -1,4 +1,20 @@
-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>
+<p>This tests that text drawn with text-shadows of radius 0 and (0, 0) offset are not drawn.</p>
+<p>In the following tests, the actual text is green while the shadows are blue.</p>
+
+<div style="color: green;">
+<div style="text-shadow: 5px 5px blue;">Text with a single shadow.</div>
+<div style="text-shadow: 0px 0px blue;">Text with one empty (undrawn) shadow.</div>
+<div style="text-shadow: 5px 5px blue, 10px 10px blue;">Text with two shadows</div>
+<div style="text-shadow: 5px 5px blue, 0px 0px blue;">Text with two shadows: first drawn and second empty (undrawn).</div>
+<div style="text-shadow: 0px 0px blue, 10px 10px blue;">Text with two shadows: first empty (undrawn) and second drawn.</div>
+<div style="text-shadow: 0px 0px blue, 0px 0px blue;">Text with two empty (undrawn) shadows.</div>
+</div>
+
+<div style="color: transparent;">
+<div style="text-shadow: 5px 5px blue;">Transparent text with a single shadow.</div>
+<div style="text-shadow: 0px 0px blue;">Transparent text with one empty shadow.</div>
+<div style="text-shadow: 5px 5px blue, 10px 10px blue;">Transparent text with two shadows</div>
+<div style="text-shadow: 7px 7px blue, 0px 0px blue;">Transparent text with two shadows: first drawn and second empty.</div>
+<div style="text-shadow: 0px 0px blue, 10px 10px blue;">Transparent text with two shadows: first drawn and second empty.</div>
+<div style="text-shadow: 0px 0px blue, 0px 0px blue;">Transparent text with two empty shadows.</div>
+</div>
Modified: trunk/Source/WebCore/ChangeLog (173940 => 173941)
--- trunk/Source/WebCore/ChangeLog 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/Source/WebCore/ChangeLog 2014-09-25 02:32:06 UTC (rev 173941)
@@ -1,3 +1,38 @@
+2014-09-22 Myles C. Maxfield <[email protected]>
+
+ REGRESSION: Text with a zero offset, zero blur shadow vanishes
+ https://bugs.webkit.org/show_bug.cgi?id=136801
+
+ Reviewed by Darin Adler.
+
+ This patch performs some cleanup regarding TextPainter's shadow logic and handles an
+ additional case of empty shadows. Previously, there was tight coupling between
+ applyShadowToGraphicalContext() and paintTextWithShadows(), as they both used a
+ collection of variables to determine how shadows are to be drawn. This complexity has
+ been moved into a helper class, ShadowApplier, which performs what
+ applyShadowToGraphicsContext() used to do, and cleans up correctly in its destructor.
+ This removes the tight coupling mentioned earlier.
+
+ Test: fast/text/empty-shadow.html
+
+ * rendering/InlineTextBox.cpp:
+ (WebCore::InlineTextBox::applyShadowToGraphicsContext): Moved to ShadowApplier.
+ * rendering/InlineTextBox.h: Deleted applyShadowToGraphicsContext signature.
+ * rendering/TextPainter.cpp:
+ (WebCore::ShadowApplier::ShadowApplier): Perform the contents of applyShadowToGraphicsContext()
+ (WebCore::ShadowApplier::~ShadowApplier): Undo the work done previously
+ (WebCore::paintTextWithShadows): Create a ShadowApplier to do the relevant shadow work. In addition,
+ refactor some boolean flags to more meaningful ones with relation to the computation at hand.
+ (WebCore::isEmptyShadow): Moved to TextPainter.h, named shadowIsCompletelyCoveredByText()
+ * rendering/TextPainter.h:
+ (WebCore::ShadowApplier::ShadowApplier): Moved from InlineTextBox::applyShadowToGraphicsContext().
+ (WebCore::ShadowApplier::extraOffset): Getter.
+ (WebCore::ShadowApplier::~ShadowApplier): Moved from TextPainter::paintTextWithShadows().
+ (WebCore::isLastShadowIteration): Helper function.
+ (WebCore::shadowIsCompletelyCoveredByText): Determines whether or not we should not draw the shadow.
+ * rendering/svg/SVGInlineTextBox.cpp:
+ (WebCore::SVGInlineTextBox::paintTextWithShadows): Update to use ShadowApplier.
+
2014-09-24 Brian J. Burg <[email protected]>
Web Inspector: subtract elapsed time while debugger is paused from profile nodes
Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (173940 => 173941)
--- trunk/Source/WebCore/rendering/InlineTextBox.cpp 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp 2014-09-25 02:32:06 UTC (rev 173941)
@@ -424,34 +424,6 @@
return false;
}
-FloatSize InlineTextBox::applyShadowToGraphicsContext(GraphicsContext& context, const ShadowData* shadow, const FloatRect& textRect, bool stroked, bool opaque, bool horizontal, bool& didSaveContext)
-{
- if (!shadow)
- return FloatSize();
-
- FloatSize extraOffset;
- int shadowX = horizontal ? shadow->x() : shadow->y();
- int shadowY = horizontal ? shadow->y() : -shadow->x();
- FloatSize shadowOffset(shadowX, shadowY);
- int shadowRadius = shadow->radius();
- const Color& shadowColor = shadow->color();
-
- if (shadow->next() || stroked || !opaque) {
- FloatRect shadowRect(textRect);
- shadowRect.inflate(shadow->paintingExtent());
- shadowRect.move(shadowOffset);
- context.save();
- context.clip(shadowRect);
-
- extraOffset = FloatSize(0, 2 * textRect.height() + std::max(0.0f, shadowOffset.height()) + shadowRadius);
- shadowOffset -= extraOffset;
- didSaveContext = true;
- }
-
- context.setShadow(shadowOffset, shadowRadius, shadowColor, context.fillColorSpace());
- return extraOffset;
-}
-
static inline bool emphasisPositionHasNeitherLeftNorRight(TextEmphasisPosition emphasisPosition)
{
return !(emphasisPosition & TextEmphasisPositionLeft) && !(emphasisPosition & TextEmphasisPositionRight);
Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (173940 => 173941)
--- trunk/Source/WebCore/rendering/InlineTextBox.h 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h 2014-09-25 02:32:06 UTC (rev 173941)
@@ -154,9 +154,6 @@
virtual int offsetForPosition(float x, bool includePartialGlyphs = true) const;
virtual float positionForOffset(int offset) const;
- // Needs to be public, so the static paintTextWithShadows() function can use it.
- static FloatSize applyShadowToGraphicsContext(GraphicsContext&, const ShadowData*, const FloatRect& textRect, bool stroked, bool opaque, bool horizontal, bool& didSaveContext);
-
protected:
void paintCompositionBackground(GraphicsContext*, const FloatPoint& boxOrigin, const RenderStyle&, const Font&, int startPos, int endPos);
void paintDocumentMarkers(GraphicsContext*, const FloatPoint& boxOrigin, const RenderStyle&, const Font&, bool background);
Modified: trunk/Source/WebCore/rendering/TextPainter.cpp (173940 => 173941)
--- trunk/Source/WebCore/rendering/TextPainter.cpp 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/Source/WebCore/rendering/TextPainter.cpp 2014-09-25 02:32:06 UTC (rev 173941)
@@ -65,13 +65,54 @@
context.drawEmphasisMarks(font, textRun, emphasisMark, point + IntSize(0, emphasisMarkOffset), from, to);
}
-static bool isEmptyShadow(const ShadowData* shadow)
+ShadowApplier::ShadowApplier(GraphicsContext& context, const ShadowData* shadow, const FloatRect& textRect, bool lastShadowIterationShouldDrawText, bool opaque, FontOrientation orientation)
+ : m_context(context)
+ , m_shadow(shadow)
+ , m_onlyDrawsShadow(!isLastShadowIteration() || !lastShadowIterationShouldDrawText)
+ , m_avoidDrawingShadow(shadowIsCompletelyCoveredByText(opaque))
+ , m_nothingToDraw(shadow && m_avoidDrawingShadow && m_onlyDrawsShadow)
+ , m_didSaveContext(false)
{
- if (!shadow)
- return false;
- return shadow->location() == IntPoint() && !shadow->radius();
+ if (!shadow || m_nothingToDraw) {
+ m_shadow = nullptr;
+ return;
+ }
+
+ int shadowX = orientation == Horizontal ? shadow->x() : shadow->y();
+ int shadowY = orientation == Horizontal ? shadow->y() : -shadow->x();
+ FloatSize shadowOffset(shadowX, shadowY);
+ int shadowRadius = shadow->radius();
+ const Color& shadowColor = shadow->color();
+
+ // When drawing shadows, we usually clip the context to the area the shadow will reside, and then
+ // draw the text itself outside the clipped area (so only the shadow shows up). However, we can
+ // often draw the *last* shadow and the text itself in a single call.
+ if (m_onlyDrawsShadow) {
+ FloatRect shadowRect(textRect);
+ shadowRect.inflate(shadow->paintingExtent());
+ shadowRect.move(shadowOffset);
+ context.save();
+ context.clip(shadowRect);
+
+ m_didSaveContext = true;
+ m_extraOffset = FloatSize(0, 2 * textRect.height() + std::max(0.0f, shadowOffset.height()) + shadowRadius);
+ shadowOffset -= m_extraOffset;
+ }
+
+ if (!m_avoidDrawingShadow)
+ context.setShadow(shadowOffset, shadowRadius, shadowColor, context.fillColorSpace());
}
+ShadowApplier::~ShadowApplier()
+{
+ if (!m_shadow)
+ return;
+ if (m_onlyDrawsShadow)
+ m_context.restore();
+ else if (!m_avoidDrawingShadow)
+ m_context.clearShadow();
+}
+
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)
@@ -79,20 +120,19 @@
Color fillColor = context.fillColor();
ColorSpace fillColorSpace = context.fillColorSpace();
bool opaque = !fillColor.hasAlpha();
+ bool lastShadowIterationShouldDrawText = !stroked && opaque;
if (!opaque)
context.setFillColor(Color::black, fillColorSpace);
do {
- if (isEmptyShadow(shadow)) {
+ ShadowApplier shadowApplier(context, shadow, boxRect, lastShadowIterationShouldDrawText, opaque, horizontal ? Horizontal : Vertical);
+ if (shadowApplier.nothingToDraw()) {
shadow = shadow->next();
continue;
}
- IntSize extraOffset;
- bool didSaveContext = false;
- if (shadow)
- extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, horizontal, didSaveContext));
- else if (!opaque)
+ IntSize extraOffset = roundedIntSize(shadowApplier.extraOffset());
+ if (!shadow && !opaque)
context.setFillColor(fillColor, fillColorSpace);
if (startOffset <= endOffset)
@@ -107,13 +147,8 @@
if (!shadow)
break;
- if (didSaveContext)
- context.restore();
- else
- context.clearShadow();
-
shadow = shadow->next();
- } while (shadow || stroked || !opaque);
+ } while (shadow || !lastShadowIterationShouldDrawText);
}
void TextPainter::paintText()
Modified: trunk/Source/WebCore/rendering/TextPainter.h (173940 => 173941)
--- trunk/Source/WebCore/rendering/TextPainter.h 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/Source/WebCore/rendering/TextPainter.h 2014-09-25 02:32:06 UTC (rev 173941)
@@ -25,6 +25,7 @@
#include "AffineTransform.h"
#include "DashArray.h"
+#include "FontOrientation.h"
#include "RenderText.h"
namespace WebCore {
@@ -73,6 +74,34 @@
bool m_textBoxIsHorizontal;
};
+class ShadowApplier {
+public:
+ ShadowApplier(GraphicsContext&, const ShadowData*, const FloatRect& textRect, bool lastShadowIterationShouldDrawText = true, bool opaque = false, FontOrientation = Horizontal);
+ FloatSize extraOffset() const { return m_extraOffset; }
+ bool nothingToDraw() const { return m_nothingToDraw; }
+ bool didSaveContext() const { return m_didSaveContext; }
+ ~ShadowApplier();
+
+private:
+ bool isLastShadowIteration()
+ {
+ return m_shadow && !m_shadow->next();
+ }
+
+ bool shadowIsCompletelyCoveredByText(bool textIsOpaque)
+ {
+ return textIsOpaque && shadow && m_shadow->location() == IntPoint() && !m_shadow->radius();
+ }
+
+ FloatSize m_extraOffset;
+ GraphicsContext& m_context;
+ const ShadowData* m_shadow;
+ bool m_onlyDrawsShadow : 1;
+ bool m_avoidDrawingShadow : 1;
+ bool m_nothingToDraw : 1;
+ bool m_didSaveContext : 1;
+};
+
} // namespace WebCore
#endif // TextPainter_h
Modified: trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp (173940 => 173941)
--- trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp 2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp 2014-09-25 02:32:06 UTC (rev 173941)
@@ -37,6 +37,7 @@
#include "SVGResourcesCache.h"
#include "SVGRootInlineBox.h"
#include "SVGTextRunRenderingContext.h"
+#include "TextPainter.h"
namespace WebCore {
@@ -594,23 +595,17 @@
if (!prepareGraphicsContextForTextPainting(context, scalingFactor, textRun, style))
break;
- FloatSize extraOffset;
- bool didSaveContext = false;
- if (shadow)
- extraOffset = applyShadowToGraphicsContext(*context, shadow, shadowRect, false /* stroked */, true /* opaque */, true /* horizontal */, didSaveContext);
+ {
+ ShadowApplier shadowApplier(*context, shadow, shadowRect);
- context->save();
- context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor));
+ if (!shadowApplier.didSaveContext())
+ context->save();
+ context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor));
- scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition);
+ scaledFont.drawText(context, textRun, textOrigin + shadowApplier.extraOffset(), startPosition, endPosition);
- context->restore();
-
- if (shadow) {
- if (didSaveContext)
+ if (!shadowApplier.didSaveContext())
context->restore();
- else
- context->clearShadow();
}
restoreGraphicsContextAfterTextPainting(context, textRun);