<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[173941] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/173941">173941</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2014-09-24 19:32:06 -0700 (Wed, 24 Sep 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>REGRESSION: Text with a zero offset, zero blur shadow vanishes
https://bugs.webkit.org/show_bug.cgi?id=136801
Reviewed by Darin Adler.
Source/WebCore:
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.
LayoutTests:
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:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfasttextemptyshadowexpectedhtml">trunk/LayoutTests/fast/text/empty-shadow-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttextemptyshadowhtml">trunk/LayoutTests/fast/text/empty-shadow.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingInlineTextBoxcpp">trunk/Source/WebCore/rendering/InlineTextBox.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingInlineTextBoxh">trunk/Source/WebCore/rendering/InlineTextBox.h</a></li>
<li><a href="#trunkSourceWebCorerenderingTextPaintercpp">trunk/Source/WebCore/rendering/TextPainter.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingTextPainterh">trunk/Source/WebCore/rendering/TextPainter.h</a></li>
<li><a href="#trunkSourceWebCorerenderingsvgSVGInlineTextBoxcpp">trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextemptyshadowwithcolorexpectedhtml">trunk/LayoutTests/fast/text/empty-shadow-with-color-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttextemptyshadowwithcolorhtml">trunk/LayoutTests/fast/text/empty-shadow-with-color.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-09-25 02:17:20 UTC (rev 173940)
+++ trunk/LayoutTests/ChangeLog        2014-09-25 02:32:06 UTC (rev 173941)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2014-09-22 Myles C. Maxfield <mmaxfield@apple.com>
+
+ 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:
+
</ins><span class="cx"> 2014-09-24 Shivakumar JM <shiva.jm@samsung.com>
</span><span class="cx">
</span><span class="cx"> Add New Test for overrideMimeType in XMLHttpRequest.
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextemptyshadowexpectedhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/text/empty-shadow-expected.html (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><del>-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.
</del><ins>+<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>
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextemptyshadowwithcolorexpectedhtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/text/empty-shadow-with-color-expected.html (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,15 +0,0 @@
</span><del>-<!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>
</del></span></pre></div>
<a id="trunkLayoutTestsfasttextemptyshadowwithcolorhtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/text/empty-shadow-with-color.html (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,17 +0,0 @@
</span><del>-<!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>
</del></span></pre></div>
<a id="trunkLayoutTestsfasttextemptyshadowhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/text/empty-shadow.html (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,4 +1,20 @@
</span><del>-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>
</del><ins>+<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>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2014-09-22 Myles C. Maxfield <mmaxfield@apple.com>
+
+ 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.
+
</ins><span class="cx"> 2014-09-24 Brian J. Burg <burg@cs.washington.edu>
</span><span class="cx">
</span><span class="cx"> Web Inspector: subtract elapsed time while debugger is paused from profile nodes
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingInlineTextBoxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -424,34 +424,6 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-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;
-}
-
</del><span class="cx"> static inline bool emphasisPositionHasNeitherLeftNorRight(TextEmphasisPosition emphasisPosition)
</span><span class="cx"> {
</span><span class="cx"> return !(emphasisPosition & TextEmphasisPositionLeft) && !(emphasisPosition & TextEmphasisPositionRight);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingInlineTextBoxh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -154,9 +154,6 @@
</span><span class="cx"> virtual int offsetForPosition(float x, bool includePartialGlyphs = true) const;
</span><span class="cx"> virtual float positionForOffset(int offset) const;
</span><span class="cx">
</span><del>- // 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);
-
</del><span class="cx"> protected:
</span><span class="cx"> void paintCompositionBackground(GraphicsContext*, const FloatPoint& boxOrigin, const RenderStyle&, const Font&, int startPos, int endPos);
</span><span class="cx"> void paintDocumentMarkers(GraphicsContext*, const FloatPoint& boxOrigin, const RenderStyle&, const Font&, bool background);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingTextPaintercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/TextPainter.cpp (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -65,13 +65,54 @@
</span><span class="cx"> context.drawEmphasisMarks(font, textRun, emphasisMark, point + IntSize(0, emphasisMarkOffset), from, to);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool isEmptyShadow(const ShadowData* shadow)
</del><ins>+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)
</ins><span class="cx"> {
</span><del>- if (!shadow)
- return false;
- return shadow->location() == IntPoint() && !shadow->radius();
</del><ins>+ 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());
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ShadowApplier::~ShadowApplier()
+{
+ if (!m_shadow)
+ return;
+ if (m_onlyDrawsShadow)
+ m_context.restore();
+ else if (!m_avoidDrawingShadow)
+ m_context.clearShadow();
+}
+
</ins><span class="cx"> static void paintTextWithShadows(GraphicsContext& context, const Font& font, const TextRun& textRun, const AtomicString& emphasisMark,
</span><span class="cx"> int emphasisMarkOffset, int startOffset, int endOffset, int truncationPoint, const FloatPoint& textOrigin, const FloatRect& boxRect,
</span><span class="cx"> const ShadowData* shadow, bool stroked, bool horizontal)
</span><span class="lines">@@ -79,20 +120,19 @@
</span><span class="cx"> Color fillColor = context.fillColor();
</span><span class="cx"> ColorSpace fillColorSpace = context.fillColorSpace();
</span><span class="cx"> bool opaque = !fillColor.hasAlpha();
</span><ins>+ bool lastShadowIterationShouldDrawText = !stroked && opaque;
</ins><span class="cx"> if (!opaque)
</span><span class="cx"> context.setFillColor(Color::black, fillColorSpace);
</span><span class="cx">
</span><span class="cx"> do {
</span><del>- if (isEmptyShadow(shadow)) {
</del><ins>+ ShadowApplier shadowApplier(context, shadow, boxRect, lastShadowIterationShouldDrawText, opaque, horizontal ? Horizontal : Vertical);
+ if (shadowApplier.nothingToDraw()) {
</ins><span class="cx"> shadow = shadow->next();
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- IntSize extraOffset;
- bool didSaveContext = false;
- if (shadow)
- extraOffset = roundedIntSize(InlineTextBox::applyShadowToGraphicsContext(context, shadow, boxRect, stroked, opaque, horizontal, didSaveContext));
- else if (!opaque)
</del><ins>+ IntSize extraOffset = roundedIntSize(shadowApplier.extraOffset());
+ if (!shadow && !opaque)
</ins><span class="cx"> context.setFillColor(fillColor, fillColorSpace);
</span><span class="cx">
</span><span class="cx"> if (startOffset <= endOffset)
</span><span class="lines">@@ -107,13 +147,8 @@
</span><span class="cx"> if (!shadow)
</span><span class="cx"> break;
</span><span class="cx">
</span><del>- if (didSaveContext)
- context.restore();
- else
- context.clearShadow();
-
</del><span class="cx"> shadow = shadow->next();
</span><del>- } while (shadow || stroked || !opaque);
</del><ins>+ } while (shadow || !lastShadowIterationShouldDrawText);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void TextPainter::paintText()
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingTextPainterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/TextPainter.h (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx">
</span><span class="cx"> #include "AffineTransform.h"
</span><span class="cx"> #include "DashArray.h"
</span><ins>+#include "FontOrientation.h"
</ins><span class="cx"> #include "RenderText.h"
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -73,6 +74,34 @@
</span><span class="cx"> bool m_textBoxIsHorizontal;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+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;
+};
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span><span class="cx"> #endif // TextPainter_h
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingsvgSVGInlineTextBoxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp (173940 => 173941)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> #include "SVGResourcesCache.h"
</span><span class="cx"> #include "SVGRootInlineBox.h"
</span><span class="cx"> #include "SVGTextRunRenderingContext.h"
</span><ins>+#include "TextPainter.h"
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="lines">@@ -594,23 +595,17 @@
</span><span class="cx"> if (!prepareGraphicsContextForTextPainting(context, scalingFactor, textRun, style))
</span><span class="cx"> break;
</span><span class="cx">
</span><del>- FloatSize extraOffset;
- bool didSaveContext = false;
- if (shadow)
- extraOffset = applyShadowToGraphicsContext(*context, shadow, shadowRect, false /* stroked */, true /* opaque */, true /* horizontal */, didSaveContext);
</del><ins>+ {
+ ShadowApplier shadowApplier(*context, shadow, shadowRect);
</ins><span class="cx">
</span><del>- context->save();
- context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor));
</del><ins>+ if (!shadowApplier.didSaveContext())
+ context->save();
+ context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor));
</ins><span class="cx">
</span><del>- scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition);
</del><ins>+ scaledFont.drawText(context, textRun, textOrigin + shadowApplier.extraOffset(), startPosition, endPosition);
</ins><span class="cx">
</span><del>- context->restore();
-
- if (shadow) {
- if (didSaveContext)
</del><ins>+ if (!shadowApplier.didSaveContext())
</ins><span class="cx"> context->restore();
</span><del>- else
- context->clearShadow();
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> restoreGraphicsContextAfterTextPainting(context, textRun);
</span></span></pre>
</div>
</div>
</body>
</html>