Bug 944704, part 3 - Fix stroke dashing for SVG ellipses so that the dashing starts from the correct point and progresses in the correct direction. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Fri, 13 Dec 2013 12:14:37 +0000
changeset 160399 53ddb97448dc4441ca668e857f5fdf6595ebb27b
parent 160398 756ce0d34c9fb68331915ca6c2cfef22cdb3277b
child 160400 88cdc2c5a4b2686619ea3e492070dd7397499f22
push id25831
push userryanvm@gmail.com
push dateFri, 13 Dec 2013 21:16:01 +0000
treeherdermozilla-central@9d593727eb94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs944704
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 944704, part 3 - Fix stroke dashing for SVG ellipses so that the dashing starts from the correct point and progresses in the correct direction. r=Bas
content/svg/content/src/SVGEllipseElement.cpp
layout/reftests/svg/reftest.list
layout/reftests/svg/stroke-dasharray-02.svg
--- a/content/svg/content/src/SVGEllipseElement.cpp
+++ b/content/svg/content/src/SVGEllipseElement.cpp
@@ -90,16 +90,25 @@ SVGEllipseElement::GetLengthInfo()
 }
 
 //----------------------------------------------------------------------
 // nsSVGPathGeometryElement methods
 
 void
 SVGEllipseElement::ConstructPath(gfxContext *aCtx)
 {
+  if (!aCtx->IsCairo()) {
+    RefPtr<Path> path = BuildPath();
+    if (path) {
+      gfxPath gfxpath(path);
+      aCtx->SetPath(&gfxpath);
+    }
+    return;
+  }
+
   float x, y, rx, ry;
 
   GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
 
   if (rx > 0.0f && ry > 0.0f) {
     aCtx->Ellipse(gfxPoint(x, y), gfxSize(2.0*rx, 2.0*ry));
   }
 }
@@ -111,15 +120,15 @@ SVGEllipseElement::BuildPath()
   GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
 
   if (rx <= 0.0f || ry <= 0.0f) {
     return nullptr;
   }
 
   RefPtr<PathBuilder> pathBuilder = CreatePathBuilder();
 
-  AppendEllipseToPath(pathBuilder, Point(x, y), Size(2.0*rx, 2.0*ry));
+  ArcToBezier(pathBuilder.get(), Point(x, y), Size(rx, ry), 0, Float(2*M_PI), false);
 
   return pathBuilder->Finish();
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -314,16 +314,17 @@ fuzzy-if(OSX==10.7,6,2) fuzzy-if(OSX==10
 fuzzy-if(cocoaWidget&&layersGPUAccelerated,1,3) == text-layout-06.svg text-layout-06-ref.svg
 == text-layout-07.svg text-layout-07-ref.svg
 == text-layout-08.svg text-layout-08-ref.svg
 == text-scale-01.svg text-scale-01-ref.svg
 HTTP(..) == text-scale-02.svg text-scale-02-ref.svg
 HTTP(..) == text-scale-03.svg text-scale-03-ref.svg
 == text-stroke-scaling-01.svg text-stroke-scaling-01-ref.svg
 fails-if(OSX==10.8) == stroke-dasharray-01.svg stroke-dasharray-01-ref.svg # bug 896487
+== stroke-dasharray-02.svg pass.svg
 == stroke-dasharray-and-pathLength-01.svg pass.svg
 == stroke-dasharray-and-text-01.svg stroke-dasharray-and-text-01-ref.svg 
 == stroke-dashoffset-01.svg pass.svg
 == stroke-linecap-square-w-zero-length-segs-01.svg pass.svg
 == stroke-linecap-square-w-zero-length-segs-02.svg pass.svg
 == textPath-01.svg textPath-01-ref.svg
 == textPath-02.svg pass.svg
 == textPath-03.svg pass.svg
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/stroke-dasharray-02.svg
@@ -0,0 +1,23 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+
+  <title>Test the start point and direction of dashing on circle and ellipse</title>
+
+  <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=944704 -->
+
+  <rect width="100%" height="100%" fill="lime"/>
+
+  <!-- Test ellipse element dashes cover two red circles -->
+  <circle cx="95" cy="211" r="8" fill="red"/>
+  <circle cx="47" cy="225" r="8" fill="red"/>
+  <ellipse cx="50" cy="200" rx="50" ry="25" fill="none" stroke="lime" stroke-width="25" stroke-dasharray="25 25 25 100000"/>
+
+  <!-- Sanity test to check that two circles cover ellipse element dashes (i.e. that the previous check didn't pass because the stroke was solid) -->
+  <ellipse cx="200" cy="200" rx="50" ry="25" fill="none" stroke="red" stroke-width="10" stroke-dasharray="10 40 10 100000"/>
+  <circle cx="250" cy="205" r="11" fill="lime"/>
+  <circle cx="206" cy="225" r="11" fill="lime"/>
+
+</svg>