mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Svg Importer: getValue: make sure the attribute exists first.
This commit is contained in:
parent
30f63599f1
commit
661afca98f
3 changed files with 44 additions and 3 deletions
|
@ -11,7 +11,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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"
|
<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">
|
<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"/>
|
<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>
|
</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(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"/>
|
<use xlink:href="#circle" width="48" height="48" x="-24" y="-24" transform="matrix(1 0 0 -1 84 65)" overflow="visible"/>
|
||||||
</svg>
|
</svg>
|
||||||
<canvas id="canvas" width="500px" height="1000px"></canvas>
|
<canvas id="canvas" width="595px" height="841px"></canvas>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
38
examples/SVG Import/Viewbox.html
Normal file
38
examples/SVG Import/Viewbox.html
Normal 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>
|
|
@ -26,7 +26,10 @@ new function() {
|
||||||
// index is option, and if passed, causes a lookup in a list.
|
// index is option, and if passed, causes a lookup in a list.
|
||||||
|
|
||||||
function getValue(svg, key, allowNull, index) {
|
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
|
value = index !== undefined
|
||||||
? index < base.numberOfItems ? base.getItem(index).value : null
|
? index < base.numberOfItems ? base.getItem(index).value : null
|
||||||
: base.value;
|
: base.value;
|
||||||
|
|
Loading…
Reference in a new issue