mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
More work on SvgStyles.
This commit is contained in:
parent
03b94a92b5
commit
6211bc7ed6
4 changed files with 55 additions and 75 deletions
|
@ -347,11 +347,8 @@ var SvgExporter = this.SvgExporter = new function() {
|
||||||
parent = item.getParent(),
|
parent = item.getParent(),
|
||||||
parentStyle = parent && parent._style;
|
parentStyle = parent && parent._style;
|
||||||
|
|
||||||
if (item._id != null)
|
|
||||||
attrs.id = item._id;
|
|
||||||
// Same thing as stroke color except with the item name
|
|
||||||
if (item._name != null)
|
if (item._name != null)
|
||||||
attrs.name = item._name;
|
attrs.id = item._name;
|
||||||
|
|
||||||
Base.each(SvgStyles.properties, function(entry) {
|
Base.each(SvgStyles.properties, function(entry) {
|
||||||
// Get a given style only if it differs from the value on the parent
|
// Get a given style only if it differs from the value on the parent
|
||||||
|
|
|
@ -262,39 +262,24 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
function applyAttributeOrStyle(svg, item, name, value) {
|
function applyAttributeOrStyle(svg, item, name, value) {
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return;
|
return;
|
||||||
switch (name) {
|
if (value === 'none')
|
||||||
case 'id':
|
value = null;
|
||||||
item.setName(value);
|
var entry = SvgStyles.attributes[name];
|
||||||
break;
|
if (entry) {
|
||||||
case 'fill':
|
var style = item._style;
|
||||||
if (value !== 'none')
|
if (entry.type === 'number') {
|
||||||
item.setFillColor(value);
|
value = parseFloat(value, 10);
|
||||||
break;
|
} else if (entry.type === 'array') {
|
||||||
case 'stroke':
|
|
||||||
if (value !== 'none')
|
|
||||||
item.setStrokeColor(value);
|
|
||||||
break;
|
|
||||||
case 'stroke-width':
|
|
||||||
item.setStrokeWidth(parseFloat(value, 10));
|
|
||||||
break;
|
|
||||||
case 'stroke-linecap':
|
|
||||||
item.setStrokeCap(value);
|
|
||||||
break;
|
|
||||||
case 'stroke-linejoin':
|
|
||||||
item.setStrokeJoin(value);
|
|
||||||
break;
|
|
||||||
case 'stroke-dasharray':
|
|
||||||
value = value.replace(/px/g, '').replace(/, /g, ',')
|
value = value.replace(/px/g, '').replace(/, /g, ',')
|
||||||
.replace(/ /g, ',').split(',');
|
.replace(/ /g, ',').split(',');
|
||||||
for (var i = 0, l = value.length; i < l; i++)
|
for (var i = 0, l = value.length; i < l; i++)
|
||||||
value[i] = parseFloat(value[i], 10);
|
value[i] = parseFloat(value[i], 10);
|
||||||
item.setDashArray(value);
|
}
|
||||||
break;
|
style[entry.set](value);
|
||||||
case 'stroke-dashoffset':
|
} else {
|
||||||
item.setDashOffset(parseFloat(value, 10));
|
switch (name) {
|
||||||
break;
|
case 'id':
|
||||||
case 'stroke-miterlimit':
|
item.setName(value);
|
||||||
item.setMiterLimit(parseFloat(value, 10));
|
|
||||||
break;
|
break;
|
||||||
case 'transform':
|
case 'transform':
|
||||||
applyTransform(svg, item);
|
applyTransform(svg, item);
|
||||||
|
@ -316,6 +301,7 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function applyTextStyle(svg, item, name, value) {
|
function applyTextStyle(svg, item, name, value) {
|
||||||
if (item instanceof TextItem) {
|
if (item instanceof TextItem) {
|
||||||
|
|
|
@ -15,24 +15,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var SvgStyles = Base.each({
|
var SvgStyles = Base.each({
|
||||||
fillColor: 'fill',
|
fillColor: ['fill', 'color'],
|
||||||
strokeColor: 'stroke',
|
strokeColor: ['stroke', 'color'],
|
||||||
strokeWidth: 'stroke-width',
|
strokeWidth: ['stroke-width', 'number'],
|
||||||
strokeCap: 'stroke-linecap',
|
strokeCap: ['stroke-linecap', 'string'],
|
||||||
strokeJoin: 'stroke-linejoin',
|
strokeJoin: ['stroke-linejoin', 'string'],
|
||||||
miterLimit: 'stroke-miterlimit',
|
miterLimit: ['stroke-miterlimit', 'number'],
|
||||||
dashArray: 'stroke-dasharray',
|
dashArray: ['stroke-dasharray', 'array'],
|
||||||
dashOffset: 'stroke-dashoffset'
|
dashOffset: ['stroke-dashoffset', 'number']
|
||||||
}, function(attr, prop) {
|
}, function(entry, key) {
|
||||||
var part = Base.capitalize(prop);
|
var part = Base.capitalize(key);
|
||||||
this.attributes[attr] = this.properties[prop] = {
|
this.attributes[entry[0]] = this.properties[key] = {
|
||||||
type: /Color$/.test(prop)
|
type: entry[1],
|
||||||
? 'color'
|
property: key,
|
||||||
: prop == 'dashArray'
|
attribute: entry[0],
|
||||||
? 'array'
|
|
||||||
: 'value',
|
|
||||||
property: prop,
|
|
||||||
attribute: attr,
|
|
||||||
get: 'get' + part,
|
get: 'get' + part,
|
||||||
set: 'set' + part
|
set: 'set' + part
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
/**
|
/**
|
||||||
* To shrink code, we automatically replace the long SVGPathSeg and SVGTransform
|
* To shrink code, we automatically replace the long SVGPathSeg and SVGTransform
|
||||||
* constants with their actual numeric values on preprocessing time, using
|
* constants with their actual numeric values on preprocessing time, using
|
||||||
* *#=* statements. To do so, we need their values defined, which happens here.
|
* prepro statements.
|
||||||
|
* To do so, we need their values defined, which happens here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
|
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
|
||||||
|
|
Loading…
Reference in a new issue