Svg Importer: getValue: make sure the attribute exists first.

This commit is contained in:
Jonathan Puckey 2012-11-10 15:45:11 +01:00
parent 30f63599f1
commit 661afca98f
3 changed files with 44 additions and 3 deletions

View file

@ -11,7 +11,7 @@
</head>
<body>
<svg version="1.1" id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="595.28px" height="841.89px" viewBox="0 0 595.28 841.89" enable-background="new 0 0 595.28 841.89" xml:space="preserve">
width="595px" height="841px" viewBox="0 0 595.28 841.89" enable-background="new 0 0 595.28 841.89" xml:space="preserve">
<symbol id="circle" viewBox="-24 -24 48 48">
<path fill="#FF0049" d="M24,0c0-13.255-10.745-24-24-24S-24-13.255-24,0s10.745,24,24,24S24,13.255,24,0z"/>
</symbol>
@ -20,6 +20,6 @@
<use xlink:href="#circle" width="48" height="48" x="-24" y="-24" transform="matrix(2.2415 -2.0119 -2.0119 -2.2415 176.9971 246.9941)" overflow="visible"/>
<use xlink:href="#circle" width="48" height="48" x="-24" y="-24" transform="matrix(1 0 0 -1 84 65)" overflow="visible"/>
</svg>
<canvas id="canvas" width="500px" height="1000px"></canvas>
<canvas id="canvas" width="595px" height="841px"></canvas>
</body>
</html>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Viewbox 1</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">
project.importSvg(document.getElementById('svg'));
</script>
</head>
<body>
<svg width="300px" height="200px"
viewBox="100 100 1500 1000" preserveAspectRatio="none"
xmlns="http://www.w3.org/2000/svg" version="1.1" id="svg">
<desc>Example ViewBox - uses the viewBox
attribute to automatically create an initial user coordinate
system which causes the graphic to scale to fit into the
viewport no matter what size the viewport is.</desc>
<!-- This rectangle goes from (0,0) to (1500,1000) in user space.
Because of the viewBox attribute above,
the rectangle will end up filling the entire area
reserved for the SVG content. -->
<rect x="0" y="0" width="1500" height="1000"
fill="yellow" stroke="blue" stroke-width="12" />
<!-- A large, red triangle -->
<path fill="red" d="M 750,100 L 250,900 L 1250,900 z"/>
<!-- A text string that spans most of the viewport -->
<text x="100" y="600" font-size="200" font-family="Verdana" >
Stretch to fit
</text>
</svg>
<canvas id="canvas" width="1500px" height="1000px"></canvas>
</body>
</html>

View file

@ -26,7 +26,10 @@ new function() {
// index is option, and if passed, causes a lookup in a list.
function getValue(svg, key, allowNull, index) {
var base = svg[key].baseVal,
var attribute = svg[key];
if (!attribute)
return;
var base = attribute.baseVal,
value = index !== undefined
? index < base.numberOfItems ? base.getItem(index).value : null
: base.value;