Bug 478445 and bug 499628. strokeText needs to not re-stroke the current path. r=vlad, a=vlad
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 30 Nov 2010 13:19:56 -0500
changeset 58483 e02412c90d50e3b944c4214f94ff2bfe458a50fe
parent 58482 c5136e816bde486f6693971d67bcaaec00dd967d
child 58484 57aa15b3fce9791d75aa2169f7411f1091845fa1
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersvlad, vlad
bugs478445, 499628
milestone2.0b8pre
Bug 478445 and bug 499628. strokeText needs to not re-stroke the current path. r=vlad, a=vlad
content/canvas/src/nsCanvasRenderingContext2D.cpp
layout/reftests/canvas/reftest.list
layout/reftests/canvas/strokeText-path-ref.html
layout/reftests/canvas/strokeText-path.html
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -2794,19 +2794,21 @@ nsCanvasRenderingContext2D::DrawOrMeasur
             ShadowFinalize(blur);
         }
 
         processor.mThebes = mThebes;
     }
 
     gfxContextPathAutoSaveRestore pathSR(mThebes, PR_FALSE);
 
-    // back up path if stroking
-    if (aOp == nsCanvasRenderingContext2D::TEXT_DRAW_OPERATION_STROKE)
+    // back up and clear path if stroking
+    if (aOp == nsCanvasRenderingContext2D::TEXT_DRAW_OPERATION_STROKE) {
         pathSR.Save();
+        mThebes->NewPath();
+    }
     // doUseIntermediateSurface is mutually exclusive to op == STROKE
     else {
         if (doUseIntermediateSurface) {
             mThebes->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
 
             // don't want operators to be applied twice
             mThebes->SetOperator(gfxContext::OPERATOR_SOURCE);
         }
--- a/layout/reftests/canvas/reftest.list
+++ b/layout/reftests/canvas/reftest.list
@@ -34,8 +34,10 @@ asserts-if(cocoaWidget,0-2) == size-chan
 == text-no-frame-test.html text-no-frame-ref.html
 == text-no-frame-2-test.html text-not-in-doc-ref.html
 == text-not-in-doc-test.html text-not-in-doc-ref.html
 
 == text-bidi-ltr-test.html text-bidi-ltr-ref.html
 == text-bidi-rtl-test.html text-bidi-rtl-ref.html
 
 != text-font-lang.html text-font-lang-notref.html
+
+== strokeText-path.html strokeText-path-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/canvas/strokeText-path-ref.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <script type="text/javascript"><!--
+window.onload = function () {
+  var canvas = document.getElementById('testCanvas'),
+      context = canvas.getContext('2d');
+
+  // draw some text
+  context.font = 'bold 40px sans-serif';
+  context.strokeText("Hello world!", 10, 50);
+};
+      // --></script>
+  </head>
+  <body>
+    <p>You should see only see "Hello world!" below, without any additional 
+    line. JavaScript is required.</p>
+
+    <p><canvas id="testCanvas" width="400" height="300">You need Canvas 
+    support.</canvas></p>
+
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/canvas/strokeText-path.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <script type="text/javascript"><!--
+window.onload = function () {
+  var canvas = document.getElementById('testCanvas'),
+      context = canvas.getContext('2d');
+
+  // draw a path
+  context.beginPath();
+  context.moveTo(10, 10);
+  context.lineTo(200, 10);
+  context.lineTo(200, 200);
+  context.stroke();
+  context.closePath();
+
+  context.clearRect(0, 0, canvas.width, canvas.height);
+
+  // draw some text
+  context.font = 'bold 40px sans-serif';
+  context.strokeText("Hello world!", 10, 50);
+};
+      // --></script>
+  </head>
+  <body>
+    <p>You should see only see "Hello world!" below, without any additional 
+    line. JavaScript is required.</p>
+
+    <p><canvas id="testCanvas" width="400" height="300">You need Canvas 
+    support.</canvas></p>
+
+  </body>
+</html>