[librsvg: 1/2] (#704): Circle/ellipse made out of a single Arc command does not work




commit e9c21332bdc5c6c6bb303ca72e721f0c5c2c1fb4
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri May 14 20:31:18 2021 -0500

    (#704): Circle/ellipse made out of a single Arc command does not work
    
    https://www.w3.org/TR/SVG2/paths.html#ArcOutOfRangeParameters says "If
    the endpoint (x, y) of the segment is identical to the current
    point (e.g., the endpoint of the previous segment), then this is
    equivalent to omitting the elliptical arc segment entirely.", but this
    is inconsistent with shapes-intro-02-f.svg from the SVG 1.1 test
    suite.  Also, tools in the wild are generating filled circles by doing
    just "Moveto Arc", with the end points of the arc being the same as
    the Moveto's.
    
    However, nothing in the endpoint-to-center parameterization algorithm
    in https://www.w3.org/TR/SVG2/implnote.html#ArcConversionEndpointToCenter,
    or in the subsequent section for out-of-range radii
    https://www.w3.org/TR/SVG2/implnote.html#ArcCorrectionOutOfRangeRadii,
    mention ignoring the Arc segment if its start/end endpoints are
    equal.  The algorithm still works.
    
    Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/704

 src/path_builder.rs                                |   5 -
 .../reftests/svg1.1/shapes-intro-01-t-ref.png      | Bin 0 -> 6700 bytes
 .../fixtures/reftests/svg1.1/shapes-intro-01-t.svg | 108 +++++++++++++++++++++
 .../reftests/svg1.1/shapes-intro-02-f-ref.png      | Bin 0 -> 12506 bytes
 .../fixtures/reftests/svg1.1/shapes-intro-02-f.svg |  89 +++++++++++++++++
 5 files changed, 197 insertions(+), 5 deletions(-)
---
diff --git a/src/path_builder.rs b/src/path_builder.rs
index f393e2c0..74d723fa 100644
--- a/src/path_builder.rs
+++ b/src/path_builder.rs
@@ -109,11 +109,6 @@ impl EllipticalArc {
             to: (x2, y2),
         } = self;
 
-        // If the end points are identical, omit the arc segment entirely.
-        if x1.approx_eq_cairo(x2) && y1.approx_eq_cairo(y2) {
-            return ArcParameterization::Omit;
-        }
-
         // Ensure radii are non-zero.
         // Otherwise this arc is treated as a line segment joining the end points.
         //
diff --git a/tests/fixtures/reftests/svg1.1/shapes-intro-01-t-ref.png 
b/tests/fixtures/reftests/svg1.1/shapes-intro-01-t-ref.png
new file mode 100644
index 00000000..289ab64f
Binary files /dev/null and b/tests/fixtures/reftests/svg1.1/shapes-intro-01-t-ref.png differ
diff --git a/tests/fixtures/reftests/svg1.1/shapes-intro-01-t.svg 
b/tests/fixtures/reftests/svg1.1/shapes-intro-01-t.svg
new file mode 100644
index 00000000..0060bf71
--- /dev/null
+++ b/tests/fixtures/reftests/svg1.1/shapes-intro-01-t.svg
@@ -0,0 +1,108 @@
+<svg version="1.1" baseProfile="tiny" id="svg-root"
+  width="100%" height="100%" viewBox="0 0 480 360"
+  xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/xlink";>
+  <!--======================================================================-->
+  <!--=  SVG 1.1 2nd Edition Test Case                                     =-->
+  <!--======================================================================-->
+  <!--=  Copyright 2009 World Wide Web Consortium, (Massachusetts          =-->
+  <!--=  Institute of Technology, European Research Consortium for         =-->
+  <!--=  Informatics and Mathematics (ERCIM), Keio University).            =-->
+  <!--=  All Rights Reserved.                                              =-->
+  <!--=  See http://www.w3.org/Consortium/Legal/.                          =-->
+  <!--======================================================================-->
+  <d:SVGTestCase xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/";
+    template-version="1.4" reviewer="CN" author="SH" status="accepted"
+    version="$Revision: 1.5 $" testname="$RCSfile: shapes-intro-01-t.svg,v $">
+    <d:testDescription xmlns="http://www.w3.org/1999/xhtml"; 
href="http://www.w3.org/TR/SVG11/shapes.html#Introduction";>
+        <p>
+          Tests the degenerate cases of the basic shapes.  The shapes are positioned
+          within the black rectangles.
+        </p>
+    </d:testDescription>
+    <d:operatorScript xmlns="http://www.w3.org/1999/xhtml";>
+      <p>Run the test. No interaction required.</p>
+    </d:operatorScript>
+    <d:passCriteria xmlns="http://www.w3.org/1999/xhtml";>
+      <p>The test passes if the 11 rectangles are empty.</p>
+    </d:passCriteria>
+  </d:SVGTestCase>
+  <title id="test-title">$RCSfile: shapes-intro-01-t.svg,v $</title>
+  <defs>
+    <font-face font-family="SVGFreeSansASCII" unicode-range="U+0-7F">
+      <font-face-src>
+        <font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/>
+      </font-face-src>
+    </font-face>
+  </defs>
+  <g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18">
+    <!-- ====================================================================== -->
+    <!-- Draw the boxes to contain the shapes and the text labels for the boxes -->
+    <!-- ====================================================================== -->
+    <g fill="none" stroke="#000000">
+      <!-- rects -->
+      <rect x="50" y="50" width="35" height="60"/>
+      <rect x="50" y="155" width="35" height="60"/>
+      <rect x="130" y="50" width="35" height="60"/>
+      <rect x="130" y="155" width="35" height="60"/>
+
+      <!-- circles -->
+      <rect x="210" y="50" width="60" height="60"/>
+      <rect x="210" y="155" width="60" height="60"/>
+
+      <!-- ellipses -->
+      <rect x="315" y="50" width="35" height="60"/>
+      <rect x="315" y="155" width="35" height="60"/>
+      <rect x="394" y="50" width="35" height="60"/>
+      <rect x="394" y="155" width="35" height="60"/>
+
+      <!-- line -->
+      <rect x="235" y="260" width="10" height="10"/>
+    </g>
+
+    <g font-family="Arial" font-size="8">
+      <text x="5" y="90">Stroked</text>
+      <text x="5" y="195">Unstroked</text>
+      <text x="50" y="135">Zero width rect</text>
+      <text x="130" y="135">Zero height rect</text>
+      <text x="210" y="135">Zero radius circle</text>
+      <text x="315" y="135">Zero x radius ellipse</text>
+      <text x="394" y="135">Zero y radius ellipse</text>
+      <text x="235" y="290">Zero length line</text>
+    </g>
+    <!-- ====================================================================== -->
+    <!-- Draw 4 rectangles, two with zero width, two with zero height           -->
+    <!-- (stroked and unstroked)                                                -->
+    <!-- ====================================================================== -->
+    <rect id="Zero-width-stroked-rect" fill="none" stroke="#000000" x="55" y="55" width="0" height="50"/>
+    <rect id="Zero-width-unstroked-rect" fill="#FF0000" stroke="none" x="55" y="160" width="0" height="50"/>
+    <rect id="Zero-height-stroked-rect" fill="#00FF00" stroke="#0000FF" x="135" y="55" width="25" 
height="0"/>
+    <rect id="Zero-height-rect" fill="#00FF00" stroke="none" x="135" y="160" width="25" height="0"/>
+    <!-- ====================================================================== -->
+    <!-- Draw two zero radius circles (stroked and unstroked)                   -->
+    <!-- ====================================================================== -->
+    <circle id="Zero-radius-stroked-circle" fill="none" stroke="#000000" cx="240" cy="80" r="0"/>
+    <circle id="Zero-radius-unstroked-circle" fill="#FF0000" stroke="none" cx="240" cy="185" r="0"/>
+    <!-- ====================================================================== -->
+    <!-- Draw 4 ellipses, two with a zero x radius, two with a zero y radius    -->
+    <!-- (stroked and unstroked)                                                -->
+    <!-- ====================================================================== -->
+    <ellipse id="Zero-x-radius-stroked-ellipse" fill="#00FF00" stroke="#0000FF" cx="332" cy="80" rx="0" 
ry="25"/>
+    <ellipse id="Zero-x-radius-unstroked-ellipse" fill="#00FF00" stroke="none" cx="332" cy="185" rx="0" 
ry="25"/>
+    <ellipse id="Zero-y-radius-stroked-ellipse" fill="none" stroke="#000000" cx="411" cy="80" rx="12" 
ry="0"/>
+    <ellipse id="Zero-y-radius-unstroked-ellipse" fill="#FF0000" stroke="none" cx="411" cy="185" rx="12" 
ry="0"/>
+    <!-- ====================================================================== -->
+    <!-- Draw a zero-length line                                                -->
+    <!-- ====================================================================== -->
+    <line id="Zero-length-line" stroke="#0000FF" x1="240" y1="265" x2="240" y2="265"/>
+  </g>
+  <g font-family="SVGFreeSansASCII,sans-serif" font-size="32">
+    <text id="revision" x="10" y="340" stroke="none" fill="black">$Revision: 1.5 $</text>
+  </g>
+  <rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000"/>
+  <!-- comment out this watermark once the test is approved -->
+  <!--<g id="draft-watermark">
+    <rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/>
+    <text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240"
+      text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text>
+  </g>-->
+</svg>
diff --git a/tests/fixtures/reftests/svg1.1/shapes-intro-02-f-ref.png 
b/tests/fixtures/reftests/svg1.1/shapes-intro-02-f-ref.png
new file mode 100644
index 00000000..212f637e
Binary files /dev/null and b/tests/fixtures/reftests/svg1.1/shapes-intro-02-f-ref.png differ
diff --git a/tests/fixtures/reftests/svg1.1/shapes-intro-02-f.svg 
b/tests/fixtures/reftests/svg1.1/shapes-intro-02-f.svg
new file mode 100644
index 00000000..668ced41
--- /dev/null
+++ b/tests/fixtures/reftests/svg1.1/shapes-intro-02-f.svg
@@ -0,0 +1,89 @@
+<svg id="svg-root" width="100%" height="100%"
+  viewBox="0 0 480 360" xmlns="http://www.w3.org/2000/svg";
+  xmlns:xlink="http://www.w3.org/1999/xlink";>
+  <!--======================================================================-->
+  <!--=  Copyright 2008 World Wide Web Consortium, (Massachusetts          =-->
+  <!--=  Institute of Technology, European Research Consortium for         =-->
+  <!--=  Informatics and Mathematics (ERCIM), Keio University).            =-->
+  <!--=  All Rights Reserved.                                              =-->
+  <!--=  See http://www.w3.org/Consortium/Legal/.                          =-->
+  <!--======================================================================-->
+  <d:SVGTestCase xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/";
+    template-version="1.4" reviewer="ED" author="Microsoft" status="accepted"
+    version="$Revision: 1.3 $" testname="$RCSfile: shapes-intro-02-f.svg,v $">
+    <d:testDescription xmlns="http://www.w3.org/1999/xhtml"; 
href="http://www.w3.org/TR/SVG11/shapes.html#Introduction";>
+      <p>
+        Test that basic shape elements are equivalent to a 'path' element that constructs the same shape.
+      </p>
+      <p>
+        For each basic shape, a 'path' reference element that is red is created.
+        A basic shape is then placed on top of the 'path' element. 
+        For each basic shape there's also a reverse test that uses the shape as a reference for the 'path' 
element.
+      </p>
+    </d:testDescription>
+    <d:operatorScript xmlns="http://www.w3.org/1999/xhtml";>
+      <p>
+        Run the test. No interaction required.
+      </p>
+    </d:operatorScript>
+    <d:passCriteria xmlns="http://www.w3.org/1999/xhtml";>
+      <p>
+        The test is passed if there is no red visible on the page.
+      </p>
+    </d:passCriteria>
+  </d:SVGTestCase>
+  <title id="test-title">$RCSfile: shapes-intro-02-f.svg,v $</title>
+  <defs>
+    <font-face
+      font-family="SVGFreeSansASCII"
+      unicode-range="U+0-7F">
+      <font-face-src>
+        <font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/>
+      </font-face-src>
+    </font-face>
+  </defs>
+  <g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18">
+
+    <path d="M35 25 L115 25 A 10 20 0 0 1 125 45 L 125 105 A 10 20 0 0 1 115 125 L 35 125 A 10 20 0 0 1 25 
105 L 25 45 A 10 20 0 0 1 35 25" fill="red" />
+    <rect x="25" y="25" rx="10" ry="20" width="100" height="100" fill="black" />
+    <rect x="130" y="25" rx="10" ry="20" width="100" height="100" fill="red" />
+    <path d="M140 25 L220 25 A 10 20 0 0 1 230 45 L 230 105 A 10 20 0 0 1 220 125 L 140 125 A 10 20 0 0 1 
130 105 L 130 45 A 10 20 0 0 1 140 25" fill="black" />
+
+    <path d="M300 125 A50 50 0 1 0 299.9999 125" fill="red" />
+    <circle cx="300" cy="75" r="50" fill="black" />
+    <circle cx="401" cy="75" r="50" fill="red" />
+    <path d="M401 125 A50 50 0 1 0 400.9999 125" fill="black" />
+
+    <path d="M60 305 A50 80 0 1 0 59.9999 305 Z" fill="red" />
+    <ellipse cx="60" cy="225" rx="50" ry="80" fill="black" />
+    <ellipse cx="161" cy="225" rx="50" ry="80" fill="red" />
+    <path d="M161 305 A50 80 0 1 0 160.9999 305 Z" fill="black" />
+
+    <path d="M220 150 L270 200 L220 250 Z" fill="red" />
+    <polygon points="220,150 270,200 220,250" fill="black" />
+    <polygon points="270,150 320,200 270,250" fill="red" />
+    <path d="M270 150 L320 200 L270 250 Z" fill="black" />
+
+    <path d="M350 250 L350 350 L400 350 L400 250 L450 250 L450 350" fill="none" stroke="red" 
stroke-width="10" />
+    <polyline fill="none" stroke="black" stroke-width="10" points="350,250 350,350 400,350 400,250 450,250 
450,350" />
+    <polyline fill="none" stroke="red" stroke-width="10" points="350,135 350,235 400,235 400,135 450,135 
450,235" />
+    <path d="M350 135 L350 235 L400 235 L400 135 L450 135 L450 235" fill="none" stroke="black" 
stroke-width="10" />
+
+    <path d="M225 275 L325 275" stroke-width="10" stroke="red" />
+    <line x1="225" y1="275" x2="325" y2="275" stroke-width="10" stroke="black" />
+    <line x1="225" y1="325" x2="325" y2="325" stroke-width="10" stroke="red" />
+    <path d="M225 325 L325 325" stroke-width="10" stroke="black" />
+
+  </g>
+  <g font-family="SVGFreeSansASCII,sans-serif" font-size="32">
+    <text id="revision" x="10" y="340" stroke="none"
+      fill="black">$Revision: 1.3 $</text>
+  </g>
+  <rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000"/>
+  <!-- comment out this watermark once the test is approved 
+  <g id="draft-watermark">
+    <rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/>
+    <text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240"
+      text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text>
+  </g> -->
+</svg>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]