mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-06-06 02:04:20 -04:00
Start removing dependencies on SVG baseVal.
This commit is contained in:
parent
8cd57743c8
commit
e9fb78aa08
4 changed files with 34 additions and 21 deletions
|
@ -119,6 +119,7 @@ var paper = new function() {
|
||||||
|
|
||||||
/*#*/ if (options.svg) {
|
/*#*/ if (options.svg) {
|
||||||
/*#*/ include('svg/SVGStyles.js');
|
/*#*/ include('svg/SVGStyles.js');
|
||||||
|
/*#*/ include('svg/SVGNamespaces.js');
|
||||||
/*#*/ include('svg/SVGExport.js');
|
/*#*/ include('svg/SVGExport.js');
|
||||||
/*#*/ include('svg/SVGImport.js');
|
/*#*/ include('svg/SVGImport.js');
|
||||||
/*#*/ } // options.svg
|
/*#*/ } // options.svg
|
||||||
|
|
|
@ -15,16 +15,12 @@
|
||||||
* Paper.js DOM to a SVG DOM.
|
* Paper.js DOM to a SVG DOM.
|
||||||
*/
|
*/
|
||||||
new function() {
|
new function() {
|
||||||
var formatter = Formatter.instance,
|
var formatter = Formatter.instance;
|
||||||
namespaces = {
|
|
||||||
href: 'http://www.w3.org/1999/xlink',
|
|
||||||
xlink: 'http://www.w3.org/2000/xmlns'
|
|
||||||
};
|
|
||||||
|
|
||||||
function setAttributes(node, attrs) {
|
function setAttributes(node, attrs) {
|
||||||
for (var key in attrs) {
|
for (var key in attrs) {
|
||||||
var val = attrs[key],
|
var val = attrs[key],
|
||||||
namespace = namespaces[key];
|
namespace = SVGNamespaces[key];
|
||||||
if (typeof val === 'number')
|
if (typeof val === 'number')
|
||||||
val = formatter.number(val);
|
val = formatter.number(val);
|
||||||
if (namespace) {
|
if (namespace) {
|
||||||
|
|
|
@ -20,22 +20,22 @@ 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(node, key, allowNull, index) {
|
function getValue(node, key, allowNull, index) {
|
||||||
// node[key].baseVal will even be set if the node did not define the
|
var namespace = SVGNamespaces[key];
|
||||||
// attribute, so if allowNull is true, we need to also check
|
var value = namespace
|
||||||
// node.getAttribute(key) == null
|
? node.getAttributeNS(namespace, key)
|
||||||
var base = (!allowNull || node.getAttribute(key) != null)
|
: node.getAttribute(key);
|
||||||
&& node[key] && node[key].baseVal;
|
|
||||||
// Note: String values are unfortunately not stored in base.value, but
|
// Note: String values are unfortunately not stored in base.value, but
|
||||||
// in base directly, so we need to check both, also on item lists, using
|
// in base directly, so we need to check both, also on item lists, using
|
||||||
// Base.pick(base.value, base)
|
// Base.pick(base.value, base)
|
||||||
return base
|
if (index != null && value != null) {
|
||||||
? index !== undefined
|
var values = value.split(',');
|
||||||
// Item list? Look up by index:
|
value = values[index];
|
||||||
? index < base.numberOfItems
|
if (value == null)
|
||||||
? Base.pick((base = base.getItem(index)).value, base)
|
value = values[values.length - 1];
|
||||||
: null
|
}
|
||||||
: Base.pick(base.value, base)
|
if (/^[\d.+-]/.test(value))
|
||||||
: null;
|
value = parseFloat(value);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPoint(node, x, y, allowNull, index) {
|
function getPoint(node, x, y, allowNull, index) {
|
||||||
|
@ -273,9 +273,9 @@ new function() {
|
||||||
|
|
||||||
function applyTransform(item, value, name, node) {
|
function applyTransform(item, value, name, node) {
|
||||||
// http://www.w3.org/TR/SVG/types.html#DataTypeTransformList
|
// http://www.w3.org/TR/SVG/types.html#DataTypeTransformList
|
||||||
var transforms = node[name].baseVal,
|
var transforms = node[name] && node[name].baseVal,
|
||||||
matrix = new Matrix();
|
matrix = new Matrix();
|
||||||
for (var i = 0, l = transforms.numberOfItems; i < l; i++) {
|
for (var i = 0, l = transforms && transforms.numberOfItems; i < l; i++) {
|
||||||
var mx = transforms.getItem(i).matrix;
|
var mx = transforms.getItem(i).matrix;
|
||||||
matrix.concatenate(
|
matrix.concatenate(
|
||||||
new Matrix(mx.a, mx.b, mx.c, mx.d, mx.e, mx.f));
|
new Matrix(mx.a, mx.b, mx.c, mx.d, mx.e, mx.f));
|
||||||
|
|
16
src/svg/SVGNamespaces.js
Normal file
16
src/svg/SVGNamespaces.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||||
|
* http://paperjs.org/
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||||
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||||
|
*
|
||||||
|
* Distributed under the MIT license. See LICENSE file for details.
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var SVGNamespaces = {
|
||||||
|
href: 'http://www.w3.org/1999/xlink',
|
||||||
|
xlink: 'http://www.w3.org/2000/xmlns'
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue