mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
More work on style meta-data, and fix yet another default style issue.
This commit is contained in:
parent
07ce57c456
commit
03b94a92b5
2 changed files with 26 additions and 6 deletions
|
@ -30,17 +30,19 @@ var SvgExporter = this.SvgExporter = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAttributes(svg, attrs) {
|
function setAttributes(svg, attrs) {
|
||||||
for (var key in attrs) {
|
for (var key in attrs)
|
||||||
console.log(key + ', ' + attrs[key]);
|
|
||||||
svg.setAttribute(key, attrs[key]);
|
svg.setAttribute(key, attrs[key]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function exportGroup(group) {
|
function exportGroup(group) {
|
||||||
var svg = createElement('g'),
|
var svg = createElement('g'),
|
||||||
children = group._children;
|
children = group._children;
|
||||||
for (var i = 0, l = children.length; i < l; i++)
|
for (var i = 0, l = children.length; i < l; i++)
|
||||||
svg.appendChild(SvgExporter.exportItem(children[i]));
|
svg.appendChild(SvgExporter.exportItem(children[i]));
|
||||||
|
// Override default SVG style on groups, then apply style.
|
||||||
|
setAttributes(svg, {
|
||||||
|
fill: 'none'
|
||||||
|
});
|
||||||
applyStyle(group, svg);
|
applyStyle(group, svg);
|
||||||
return svg;
|
return svg;
|
||||||
}
|
}
|
||||||
|
@ -354,9 +356,9 @@ var SvgExporter = this.SvgExporter = new function() {
|
||||||
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
|
||||||
// (A layer or group which can have style values in SVG).
|
// (A layer or group which can have style values in SVG).
|
||||||
var value = style[entry.getter]();
|
var value = style[entry.get]();
|
||||||
if (value != null && (!parentStyle
|
if (value != null && (!parentStyle
|
||||||
|| !Base.equals(parentStyle[entry.getter](), value))) {
|
|| !Base.equals(parentStyle[entry.get](), value))) {
|
||||||
attrs[entry.attribute] = entry.type === 'color'
|
attrs[entry.attribute] = entry.type === 'color'
|
||||||
? value.toCssString()
|
? value.toCssString()
|
||||||
: entry.type === 'array'
|
: entry.type === 'array'
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Paper.js
|
||||||
|
*
|
||||||
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
||||||
|
* based on Scriptographer.org and designed to be largely API compatible.
|
||||||
|
* http://paperjs.org/
|
||||||
|
* http://scriptographer.org/
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
||||||
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||||
|
*
|
||||||
|
* Distributed under the MIT license. See LICENSE file for details.
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
var SvgStyles = Base.each({
|
var SvgStyles = Base.each({
|
||||||
fillColor: 'fill',
|
fillColor: 'fill',
|
||||||
strokeColor: 'stroke',
|
strokeColor: 'stroke',
|
||||||
|
@ -8,6 +24,7 @@ var SvgStyles = Base.each({
|
||||||
dashArray: 'stroke-dasharray',
|
dashArray: 'stroke-dasharray',
|
||||||
dashOffset: 'stroke-dashoffset'
|
dashOffset: 'stroke-dashoffset'
|
||||||
}, function(attr, prop) {
|
}, function(attr, prop) {
|
||||||
|
var part = Base.capitalize(prop);
|
||||||
this.attributes[attr] = this.properties[prop] = {
|
this.attributes[attr] = this.properties[prop] = {
|
||||||
type: /Color$/.test(prop)
|
type: /Color$/.test(prop)
|
||||||
? 'color'
|
? 'color'
|
||||||
|
@ -16,7 +33,8 @@ var SvgStyles = Base.each({
|
||||||
: 'value',
|
: 'value',
|
||||||
property: prop,
|
property: prop,
|
||||||
attribute: attr,
|
attribute: attr,
|
||||||
getter: 'get' + Base.capitalize(prop)
|
get: 'get' + part,
|
||||||
|
set: 'set' + part
|
||||||
};
|
};
|
||||||
}, {
|
}, {
|
||||||
properties: {},
|
properties: {},
|
||||||
|
|
Loading…
Reference in a new issue