Commit d5c659a5 authored by Eric Domke's avatar Eric Domke
Browse files

Refactoring while working through W3C tests

- Adding W3C test cases and a test fixture
- Fixed support for CSS stylesheets (particularly when class names are
referenced)
- Refactoring unit calculations so that percentages and fractions
calculate more accurately
- SvgImage:
- Support PreserveAspectRatio attribute
- Support for referencing svg images
- Refactored text rendering to use the AttributeCollection inheritance
scheme
- Initial attempt at 'ex' unit support
- Added support for system color names
- Changed parsing of entities to support XML entities
- Supporting loading of a svg document directly from a XmlDocument with
requiring serializing the document as a string first.
- ...
parent 3aedd8e8
<svg viewBox="0 0 30 40" xmlns="http://www.w3.org/2000/svg" stroke="#404040" stroke-linejoin="round" stroke-linecap="round">
<rect width="30" height="40" fill="lime" stroke="none"/>
<rect x='.5' y='.5' width='29' height='39' fill='black' stroke='orange' stroke-width='2'/>
<g transform="scale(1.5) translate(2.5 5)">
<path fill="#fffa72" d="m 14.5,8.5 a 7,7 0 1 1 -14,0 7,7 0 1 1 14,0 z"/>
<path fill="#fff" d="m 11.53,8.56 -8.00,0 c 0,3 2,4 4,4 2.00,0 4.00,-1 4.00,-4 z"/>
<path fill="none" d="m 3.53,6.56 c 0,-2 3,-2 3,0"/>
<path fill="none" d="m 8.53,6.56 c 0,-2 3.00,-2 3.00,0"/>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!--======================================================================-->
<!--= Copyright 2000 World Wide Web Consortium, (Massachusetts =-->
<!--= Institute of Technology, Institut National de Recherche en =-->
<!--= Informatique et en Automatique, Keio University). All Rights =-->
<!--= Reserved. See http://www.w3.org/Consortium/Legal/. =-->
<!--======================================================================-->
<!-- ===================================================================== -->
<!-- -->
<!-- dom-eventListener-BE-04.svg -->
<!-- renamed for 1.1 suite to interact-dom-01-f.svg -->
<!-- -->
<!-- Tests DOM events support. The test uses ECMA Script -->
<!-- -->
<!-- Author : Vincent Hardy 06-08-2000 -->
<!-- 1.1 revision by Vincent Hardy -->
<!-- -->
<!-- History: -->
<!-- 06 08 2000, VH, created -->
<!-- 30-oct-2000, LH, corrected "\" to "/" in "text/ecmascript"; ser#2 -->
<!-- 16-nov-2000, CJ, corrected infinite loop in mutationEventDetected -->
<!-- 12-dec-2000, JF, replace mutation event logic with more explicit -->
<!-- test to ensure event listener is removed. -->
<!-- -->
<!-- ===================================================================== -->
<!--======================================================================-->
<!--= Note. After October 2000, revision history is kept as CVS 'commit' =-->
<!--= log messages, and therefore is no longer in the preceding preamble.=-->
<!--======================================================================-->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg-root" width="480" height="360" onload="initTest(evt)">
<SVGTestCase xmlns="http://www.w3.org/2000/02/svg/testSuite/description/">
<OperatorScript>
<Paragraph>
Verify basic support for DOM event listener registration. The root svg element
has an onload handler where a click event listener is registered on group element 'Start Button'.
</Paragraph>
<Paragraph>
If UI events listener registration is supported (and UI events),
when the user clicks on the button a text node is inserted reading "UI Event Listeners supported".
</Paragraph>
<Paragraph>
At the end of the test, the start test button in changed to pink,
and the click event listener is removed from the the start button.
</Paragraph>
<Paragraph>
Subsequent clicks on the start button should cause no effect if
the event listener has been removed successfully.
If additional lines of text appear in the document that say "UI Event Listeners supported",
then the implementation has not successfully removed the event listener.
</Paragraph>
<Paragraph>
After clicking at least once on the button,
the rendered image should be exactly as the reference image, except for
differences in text display.
</Paragraph>
</OperatorScript>
</SVGTestCase>
<title id="test-title">interact-dom-01-f</title>
<desc id="test-desc">Checks if DOM/ECMA Script binding is supported. Checks that the DOM API
supports event listener registration/unregistration.</desc>
<!--======================================================================-->
<!--Content of Test Case follows... =====================-->
<!--======================================================================-->
<g id="test-body-content">
<script type="text/ecmascript"><![CDATA[
var svg_ns = "http://www.w3.org/2000/svg"
var doc;
var content;
var startButton;
var buttonRect;
var yLocation = 100;
//
// onload handler for top level svg element. Sets a UI event listener for
// the test start button.
//
function initTest(evt){
// Get Document
var target = evt.target;
doc = target.ownerDocument;
content = doc.getElementById("test-body-content");
// Get start rect and add a UI listener
startButton = doc.getElementById("startButton");
buttonRect = doc.getElementById("buttonRect");
startButton.addEventListener("click", uiEventDetected, false);
}
//
// click handler for 'startButton' rect element.
//
function uiEventDetected(evt) {
//
// Add an element to show that UI event was detected
//
var newText = doc.createElementNS(svg_ns, 'text');
newText.setAttribute('x', '50');
newText.setAttribute('y', yLocation);
var message = "UI Event Listeners supported";
var textContent = doc.createTextNode(message);
newText.appendChild(textContent);
content.appendChild(newText);
startButton.removeEventListener("click", uiEventDetected, false);
// Make start button pink
buttonRect.setAttribute("fill", "#ff8888");
buttonRect.setAttribute("stroke", "black");
// If test does not successfully remove the event listener, then
// a second click will cause a subsequent text string to appear 50 units
// below the first new text string.
yLocation = yLocation + 50;
}
]]></script>
<!-- ===================================================================== -->
<!-- Start button -->
<!-- ===================================================================== -->
<g id="startButton">
<rect id="buttonRect" x="10" y="50" width="80" height="20" fill="#dddddd" stroke="black" />
<text x="15" y="65">Start Test</text>
</g>
</g>
<!--======================================================================-->
<!--Legend and frame: Title, suite and SVG document serialization====-->
<!--======================================================================-->
<g id="test-legend" fill="black" font-family="Helvetica" font-size="10" >
<rect x="10" y="300" width="275" height="50" fill="none" stroke="#000000" />
<path fill="none" stroke="#000000" d="M10 315 h275 M205 315 v35 M10 336 h195 M205 332 h80"/>
<text x="25" y="311">Scalable Vector Graphics (SVG) v1.1 Conformance Suite</text>
<a xlink:href="copyright-documents-19990405.html">
<text x="12" y="347" fill="blue" >Copyright 2002 W3C. All Rights Reserved.</text>
</a>
<text font-size="12" x="35" y="330">interact-dom-01-f</text>
<text font-size="10" x="210" y="327">$Revision: 1.1 $</text>
<text font-size="10" x="210" y="345">Release 1.0</text>
<rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000" />
</g>
</svg>
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!--======================================================================-->
<!--= Copyright 2000, 2002 World Wide Web Consortium, (Massachusetts =-->
<!--= Institute of Technology, Institut National de Recherche en =-->
<!--= Informatique et en Automatique, Keio University). All Rights =-->
<!--= Reserved. See http://www.w3.org/Consortium/Legal/. =-->
<!--======================================================================-->
<!--======================================================================-->
<!-- -->
<!-- interact-bubble-BE-04-target.svg -->
<!-- renamed for 1.1 suite to interact-order-01-f-targ.svg -->
<!-- renamed for 1.1 suite to interact-order-02-b-targ.svg -->
<!-- -->
<!-- File that just serves as hyperlink target for test case -->
<!-- interact-order-02-b.svg. -->
<!-- -->
<!-- Author : Jon Ferraiolo 06-Aug-2000 -->
<!-- 1.1 revision by Thomas DeWeese 5-Feb-2002 -->
<!-- -->
<!-- History: -->
<!-- 06-Aug-2000, JF: Serial#1 created. -->
<!-- -->
<!--======================================================================-->
<svg id="svg-root" width="80" height="60" viewBox="0 0 480 360"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" >
<title id="test-title">interact-order-02-b</title>
<desc id="test-desc">
File that just serves as hyperlink target for test case
interact-order-02-b.svg.
</desc>
<g>
<text style="font-family:Helvetica;font-size:40; text-anchor:middle">
<tspan x="240" y="40">
Hyperlink target for
</tspan>
<tspan x="240" y="85">
interact-order-02-b.svg
</tspan>
</text>
<a xlink:href="../svg/interact-order-02-b.svg">
<circle cx="240" cy="180" r="75" />
</a>
<text style="font-family:Helvetica;font-size:40; text-anchor:middle">
<tspan x="240" y="300">
Click to hyperlink back to
</tspan>
<tspan x="240" y="345">
interact-order-02-b.svg
</tspan>
</text>
</g>
</svg>
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!--======================================================================-->
<!--= Copyright 2000, 2002 World Wide Web Consortium, (Massachusetts =-->
<!--= Institute of Technology, Institut National de Recherche en =-->
<!--= Informatique et en Automatique, Keio University). All Rights =-->
<!--= Reserved. See http://www.w3.org/Consortium/Legal/. =-->
<!--======================================================================-->
<!--======================================================================-->
<!-- -->
<!-- interact-bubble-BE-04-target.svg -->
<!-- renamed for 1.1 suite to interact-order-01-f-targ.svg -->
<!-- renamed for 1.1 suite to interact-order-03-b-targ.svg -->
<!-- -->
<!-- File that just serves as hyperlink target for test case -->
<!-- interact-interact-order-03-b.svg. -->
<!-- -->
<!-- Author : Jon Ferraiolo 06-Aug-2000 -->
<!-- 1.1 revision by Thomas DeWeese 5-Feb-2002 -->
<!-- -->
<!-- History: -->
<!-- 06-Aug-2000, JF: Serial#1 created. -->
<!-- -->
<!--======================================================================-->
<svg id="svg-root" width="80" height="60" viewBox="0 0 480 360"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" >
<title id="test-title">interact-order-03-b</title>
<desc id="test-desc">
File that just serves as hyperlink target for test case
interact-order-03-b.svg.
</desc>
<g>
<text style="font-family:Helvetica;font-size:40; text-anchor:middle">
<tspan x="240" y="40">
Hyperlink target for
</tspan>
<tspan x="240" y="85">
interact-order-03-b.svg
</tspan>
</text>
<a xlink:href="../svg/interact-order-03-b.svg">
<circle cx="240" cy="180" r="75" />
</a>
<text style="font-family:Helvetica;font-size:40; text-anchor:middle">
<tspan x="240" y="300">
Click to hyperlink back to
</tspan>
<tspan x="240" y="345">
interact-order-03-b.svg
</tspan>
</text>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="level2.svg" width="100%" height="100%"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect width="100%" height="100%" fill="lime"/>
</svg>
<svg version="1.1" baseProfile="basic" 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="SVGWG" author="Lee Klosterman" status="accepted"
version="$Revision: 1.5 $" testname="$RCSfile: linking-uri-01-b.svg,v $">
<d:testDescription xmlns="http://www.w3.org/1999/xhtml" href="http://www.w3.org/TR/SVG11/linking.html#LinksIntoSVG">
<p>
Verify the capability to handle links to 'view' elements, and the
permissible attributes on those elements. All of the links in this
test case are <em>internal</em>, i.e., to 'view' elements in the same SVG file.
</p>
<p>
This test is identical to linking-uri-02-b except that the links there are external.
</p>
<p>
In the four quadrants of the initial picture are four graphical objects.
Clockwise from upper right, they are
a purple rectangle, blue ellipse, green polygon (pentagon), and yellow
circle. Each is labelled and tightly boxes with a rectangular frame.
These are identical to their counterparts in linking-uri-01-b.svg, in which
file each has an associated 'view' element, with attributes
per the labels in the initial picture.
</p>
<p>
In the center is a gray box with four lines of text, each of which says
"Go to" followed by Rectangle, Ellipse, Polygon, and Circle, respectively.
Each of these is contained within an 'a' element, whose xlink:href names
the respective 'view' element of the respective graphical object.
</p>
<p>
There are several reference images associated with this test case. The first
illustrates the correct initial state of the rendered SVG file, which should
also be the correct picture after the Rectangle link is executed.
The second, third, and fourth illustrate the correct images as described
above after respectively the Ellipse, Polygon, and Circle links are activated.
(Note. This harness does not yet provide access to multiple PNGs; the PNG for the
initial view is shown.)
</p>
<p>
The test uses the 'rect', 'circle', 'ellipse', and 'polygon' elements,
as well as basic fill (solid simple colors),
stroke (black and colored 1-pixel lines), font-family (Arial) and font-size properties.
</p>
</d:testDescription>
<d:operatorScript xmlns="http://www.w3.org/1999/xhtml">
<p>
In turn, activate each of the "Rectangle", "Ellipse", "Polygon" and "Circle" links
in the gray box in the middle of the document, navigating back (for example with
the Back button if in a browser) after activating each one.
</p>
</d:operatorScript>
<d:passCriteria xmlns="http://www.w3.org/1999/xhtml">
<p>
The test is passed if all of the sub-tests have the correct behavior:
</p>
<ul>
<li>After activating the "Rectangle" link, the whole of the linking-uri-01-b.svg
document must be displayed; that is, there will be no visual change. (The
'view' element has no attributes (other than id), so the correct view in
the frame is of the parent 'svg' element, which is the whole picture.)</li>
<li>After navigating back and activating the "Ellipse" link, the view must change so that it is
zoomed (uniformly scaled) and centered on the ellipse. The black rectangle
surrounding the ellipse must be just within the frame.</li>
<li>After navigating back and activating the "Circle" link, the view must change so that it is
zoomed and centered on the yellow circle. The view is scaled non-uniformly, however,
so that the circle is stretched horizontally ito an ellipse. The black rectangle
surrounding it must be just within the frame.</li>
<li>After navigating back and activating the "Polygon" link, the view must not change.</li>
</ul>
</d:passCriteria>
</d:SVGTestCase>
<title id="test-title">$RCSfile: linking-uri-01-b.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">
<text x="65" y="16" font-size="12">Link test of the 'view' element and its attributes, 1 of 2, internal.</text>
<g font-size="14">
<g transform="translate(-150,75)">
<rect x="300" y="55" width="125" height="85" fill="#aaa"/>
<a xlink:href="#rect-view">
<text x="310" y="70" fill="purple">Go to Rectangle</text>
</a>
<a xlink:href="#ellipse-view">
<text x="310" y="90" fill="blue">Go to Ellipse</text>
</a>
<a xlink:href="#circle-view">
<text x="310" y="110" fill="yellow">Go to Circle</text>
</a>
<a xlink:href="#polygon-view">
<text x="310" y="130" fill="green">Go to Polygon</text>
</a>
<text x="315" y="152" font-size="12">Click element's line</text>
<text x="315" y="164" font-size="12">to link to its view</text>
</g>
<!-- View with no attributes. Picture should not change. -->
<view id="rect-view"/>
<rect id="rect-object" fill="purple" x="295" y="36" width="135" height="68"/>
<text id="rect-label" x="362.5" y="116" text-anchor="middle">Rectangle</text>
<rect x="292" y="29" width="141" height="91" fill="none" stroke="black"/>
<text x="362.5" y="132" font-size="10" text-anchor="middle">No view attributes except id.</text>
<!-- Test viewBox. Should blow-up the ellipse in the frame. -->
<view id="ellipse-view" viewBox="295 216 150 82"/>
<ellipse id="ellipse-object" fill="blue" cx="370" cy="251" rx="72" ry="32"/>
<text id="ellipse-label" x="370" y="295" text-anchor="middle">Ellipse</text>
<rect x="295" y="216" width="150" height="82" fill="none" stroke="black"/>
<text x="315" y="212" font-size="10">viewBox, should fill frame.</text>
<!-- Test preserveAspectRatio. -->
<view id="circle-view" viewBox="36 29 98 91" preserveAspectRatio="none"/>
<circle id="circle-object" fill="yellow" cx="85" cy="68" r="36"/>
<text id="circle-label" x="85" y="116" text-anchor="middle">Circle</text>
<rect x="36" y="29" width="98" height="91" fill="none" stroke="black"/>
<text x="85" y="130" font-size="10" text-anchor="middle">viewBox &amp; non-uniform</text>
<text x="85" y="139" font-size="10" text-anchor="middle">preserveAspectRatio</text>
<!-- Test viewTarget attribute, no change to the viewport. -->
<view id="polygon-view" viewTarget="polygon-object"/>
<polygon id="polygon-object" fill="green" points="87,211 134,238 116,283 57,283 39,238 87,211"/>
<text id="polygon-label" x="85" y="295" text-anchor="middle">Polygon</text>
<rect x="36" y="208" width="100" height="89" fill="none" stroke="black"/>
<text x="85" y="195" font-size="10" text-anchor="middle">viewTarget, no</text>
<text x="85" y="204" font-size="10" text-anchor="middle">changes to viewport</text>
</g>
</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>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment