mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -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));
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return getValue(svg, 'r');
|
||||
}
|
||||
|
@ -358,14 +370,7 @@ new function() {
|
|||
return item;
|
||||
var entry = SvgStyles.attributes[name];
|
||||
if (entry) {
|
||||
item._style[entry.set](value === 'none'
|
||||
? null
|
||||
: entry.type === 'number'
|
||||
? parseFloat(value, 10)
|
||||
: entry.type === 'array'
|
||||
? value.split(/[\s,]+/g).map(parseFloat)
|
||||
: entry.type === 'color' && getDefinition(value)
|
||||
|| value);
|
||||
item._style[entry.set](convertStringTo(value, entry.type));
|
||||
} else {
|
||||
switch (name) {
|
||||
case 'id':
|
||||
|
|
Loading…
Reference in a new issue