mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
SVG Importer: move string conversion code into seperate convertStringTo function for reuse.
This commit is contained in:
parent
f92e842644
commit
24ecf7840e
1 changed files with 13 additions and 8 deletions
|
@ -40,6 +40,18 @@ new function() {
|
||||||
return Size.create(getValue(svg, w, index), getValue(svg, h, index));
|
return Size.create(getValue(svg, w, index), getValue(svg, h, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converts a string value to the specified type
|
||||||
|
function convertStringTo(value, type) {
|
||||||
|
return (value === 'none'
|
||||||
|
? null
|
||||||
|
: type === 'number'
|
||||||
|
? parseFloat(value, 10)
|
||||||
|
: type === 'array'
|
||||||
|
? value.split(/[\s,]+/g).map(parseFloat)
|
||||||
|
: type === 'color' && getDefinition(value)
|
||||||
|
|| value);
|
||||||
|
}
|
||||||
|
|
||||||
function getSvgRadius(svg) {
|
function getSvgRadius(svg) {
|
||||||
return getValue(svg, 'r');
|
return getValue(svg, 'r');
|
||||||
}
|
}
|
||||||
|
@ -358,14 +370,7 @@ new function() {
|
||||||
return item;
|
return item;
|
||||||
var entry = SvgStyles.attributes[name];
|
var entry = SvgStyles.attributes[name];
|
||||||
if (entry) {
|
if (entry) {
|
||||||
item._style[entry.set](value === 'none'
|
item._style[entry.set](convertStringTo(value, entry.type));
|
||||||
? null
|
|
||||||
: entry.type === 'number'
|
|
||||||
? parseFloat(value, 10)
|
|
||||||
: entry.type === 'array'
|
|
||||||
? value.split(/[\s,]+/g).map(parseFloat)
|
|
||||||
: entry.type === 'color' && getDefinition(value)
|
|
||||||
|| value);
|
|
||||||
} else {
|
} else {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'id':
|
case 'id':
|
||||||
|
|
Loading…
Reference in a new issue