- Revision
- 188148
- Author
- [email protected]
- Date
- 2015-08-07 12:40:45 -0700 (Fri, 07 Aug 2015)
Log Message
Shadows don't draw on fillText when using a gradient fill
https://bugs.webkit.org/show_bug.cgi?id=147758
<rdar://problem/20860912>
Reviewed by Myles Maxfield.
Source/WebCore:
Since we use a mask to render a pattern or gradient
into text, any shadow was being clipped out. Change
this to draw the shadow before the mask + fill operation,
using a technique similar to text-shadow.
Test: fast/canvas/gradient-text-with-shadow.html
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawTextInternal): Get the current shadow
style, paint the text with a transformed shadow offset so that we only
see the shadow and not the text, then combine with the existing pattern/gradient
fill.
LayoutTests:
New test that exercises shadows on gradient fills. This really
should be a ref test, but there is a very small rendering difference
caused by masking, so instead it uses JS to look for pixels of
the correct color.
* fast/canvas/gradient-text-with-shadow-expected.txt: Added.
* fast/canvas/gradient-text-with-shadow.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (188147 => 188148)
--- trunk/LayoutTests/ChangeLog 2015-08-07 19:34:13 UTC (rev 188147)
+++ trunk/LayoutTests/ChangeLog 2015-08-07 19:40:45 UTC (rev 188148)
@@ -1,3 +1,19 @@
+2015-08-06 Dean Jackson <[email protected]>
+
+ Shadows don't draw on fillText when using a gradient fill
+ https://bugs.webkit.org/show_bug.cgi?id=147758
+ <rdar://problem/20860912>
+
+ Reviewed by Myles Maxfield.
+
+ New test that exercises shadows on gradient fills. This really
+ should be a ref test, but there is a very small rendering difference
+ caused by masking, so instead it uses JS to look for pixels of
+ the correct color.
+
+ * fast/canvas/gradient-text-with-shadow-expected.txt: Added.
+ * fast/canvas/gradient-text-with-shadow.html: Added.
+
2015-08-07 Myles C. Maxfield <[email protected]>
Implement font-feature-settings
Added: trunk/LayoutTests/fast/canvas/gradient-text-with-shadow-expected.txt (0 => 188148)
--- trunk/LayoutTests/fast/canvas/gradient-text-with-shadow-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/canvas/gradient-text-with-shadow-expected.txt 2015-08-07 19:40:45 UTC (rev 188148)
@@ -0,0 +1 @@
+PASSED
Property changes on: trunk/LayoutTests/fast/canvas/gradient-text-with-shadow-expected.txt
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Added: trunk/LayoutTests/fast/canvas/gradient-text-with-shadow.html (0 => 188148)
--- trunk/LayoutTests/fast/canvas/gradient-text-with-shadow.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/gradient-text-with-shadow.html 2015-08-07 19:40:45 UTC (rev 188148)
@@ -0,0 +1,43 @@
+<script>
+
+if (window.testRunner)
+ testRunner.dumpAsText();
+
+function runTest() {
+
+ var canvas = document.querySelector("canvas");
+ var context = canvas.getContext('2d');
+
+ context.shadowOffsetX = 0;
+ context.shadowOffsetY = 10;
+ context.shadowBlur = 0;
+ context.shadowColor = "rgb(255, 0, 0)";
+
+ context.font = "80px sans-serif";
+
+ var gradient = context.createLinearGradient(0, 0, 0, 100);
+ gradient.addColorStop(0, "blue");
+ gradient.addColorStop(1, "blue");
+
+ context.fillStyle = gradient;
+ context.fillText("hello", 10, 95);
+
+ // If we correctly drew the shadow, there will be some
+ // red pixels along the bottom line of the canvas.
+
+ var buffer = context.getImageData(0, canvas.height - 1, canvas.width, 1);
+ var passed = false;
+ for (var i = 0; i < canvas.width; ++i) {
+ if (buffer.data[i * 4] > 0) {
+ passed = true;
+ break;
+ }
+ }
+ document.querySelector("p").textContent = passed ? "PASSED" : "FAILED";
+}
+
+window.addEventListener("load", runTest, false);
+
+</script>
+<canvas width="200" height="100"></canvas>
+<p></p>
\ No newline at end of file
Property changes on: trunk/LayoutTests/fast/canvas/gradient-text-with-shadow.html
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (188147 => 188148)
--- trunk/Source/WebCore/ChangeLog 2015-08-07 19:34:13 UTC (rev 188147)
+++ trunk/Source/WebCore/ChangeLog 2015-08-07 19:40:45 UTC (rev 188148)
@@ -1,3 +1,24 @@
+2015-08-06 Dean Jackson <[email protected]>
+
+ Shadows don't draw on fillText when using a gradient fill
+ https://bugs.webkit.org/show_bug.cgi?id=147758
+ <rdar://problem/20860912>
+
+ Reviewed by Myles Maxfield.
+
+ Since we use a mask to render a pattern or gradient
+ into text, any shadow was being clipped out. Change
+ this to draw the shadow before the mask + fill operation,
+ using a technique similar to text-shadow.
+
+ Test: fast/canvas/gradient-text-with-shadow.html
+
+ * html/canvas/CanvasRenderingContext2D.cpp:
+ (WebCore::CanvasRenderingContext2D::drawTextInternal): Get the current shadow
+ style, paint the text with a transformed shadow offset so that we only
+ see the shadow and not the text, then combine with the existing pattern/gradient
+ fill.
+
2015-08-07 Myles C. Maxfield <[email protected]>
Implement font-feature-settings
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (188147 => 188148)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2015-08-07 19:34:13 UTC (rev 188147)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2015-08-07 19:40:45 UTC (rev 188148)
@@ -2357,8 +2357,40 @@
#if USE(CG)
const CanvasStyle& drawStyle = fill ? state().m_fillStyle : state().m_strokeStyle;
if (drawStyle.canvasGradient() || drawStyle.canvasPattern()) {
+
IntRect maskRect = enclosingIntRect(textRect);
+ // If we have a shadow, we need to draw it before the mask operation.
+ // Follow a procedure similar to paintTextWithShadows in TextPainter.
+
+ if (shouldDrawShadows()) {
+ GraphicsContextStateSaver stateSaver(*c);
+
+ FloatSize offset = FloatSize(0, 2 * maskRect.height());
+
+ FloatSize shadowOffset;
+ float shadowRadius;
+ Color shadowColor;
+ ColorSpace shadowColorSpace;
+ c->getShadow(shadowOffset, shadowRadius, shadowColor, shadowColorSpace);
+
+ FloatRect shadowRect(maskRect);
+ shadowRect.inflate(shadowRadius * 1.4);
+ shadowRect.move(shadowOffset * -1);
+ c->clip(shadowRect);
+
+ shadowOffset += offset;
+
+ c->setLegacyShadow(shadowOffset, shadowRadius, shadowColor, shadowColorSpace);
+
+ if (fill)
+ c->setFillColor(Color::black, ColorSpaceDeviceRGB);
+ else
+ c->setStrokeColor(Color::black, ColorSpaceDeviceRGB);
+
+ c->drawBidiText(font, textRun, location + offset, FontCascade::UseFallbackIfFontNotReady);
+ }
+
std::unique_ptr<ImageBuffer> maskImage = c->createCompatibleBuffer(maskRect.size());
GraphicsContext* maskImageContext = maskImage->context();