mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -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,10 +30,8 @@ var SvgExporter = this.SvgExporter = new function() {
|
|||
}
|
||||
|
||||
function setAttributes(svg, attrs) {
|
||||
for (var key in attrs) {
|
||||
console.log(key + ', ' + attrs[key]);
|
||||
for (var key in attrs)
|
||||
svg.setAttribute(key, attrs[key]);
|
||||
}
|
||||
}
|
||||
|
||||
function exportGroup(group) {
|
||||
|
@ -41,6 +39,10 @@ var SvgExporter = this.SvgExporter = new function() {
|
|||
children = group._children;
|
||||
for (var i = 0, l = children.length; i < l; i++)
|
||||
svg.appendChild(SvgExporter.exportItem(children[i]));
|
||||
// Override default SVG style on groups, then apply style.
|
||||
setAttributes(svg, {
|
||||
fill: 'none'
|
||||
});
|
||||
applyStyle(group, svg);
|
||||
return svg;
|
||||
}
|
||||
|
@ -354,9 +356,9 @@ var SvgExporter = this.SvgExporter = new function() {
|
|||
Base.each(SvgStyles.properties, function(entry) {
|
||||
// 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).
|
||||
var value = style[entry.getter]();
|
||||
var value = style[entry.get]();
|
||||
if (value != null && (!parentStyle
|
||||
|| !Base.equals(parentStyle[entry.getter](), value))) {
|
||||
|| !Base.equals(parentStyle[entry.get](), value))) {
|
||||
attrs[entry.attribute] = entry.type === 'color'
|
||||
? value.toCssString()
|
||||
: 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({
|
||||
fillColor: 'fill',
|
||||
strokeColor: 'stroke',
|
||||
|
@ -8,6 +24,7 @@ var SvgStyles = Base.each({
|
|||
dashArray: 'stroke-dasharray',
|
||||
dashOffset: 'stroke-dashoffset'
|
||||
}, function(attr, prop) {
|
||||
var part = Base.capitalize(prop);
|
||||
this.attributes[attr] = this.properties[prop] = {
|
||||
type: /Color$/.test(prop)
|
||||
? 'color'
|
||||
|
@ -16,7 +33,8 @@ var SvgStyles = Base.each({
|
|||
: 'value',
|
||||
property: prop,
|
||||
attribute: attr,
|
||||
getter: 'get' + Base.capitalize(prop)
|
||||
get: 'get' + part,
|
||||
set: 'set' + part
|
||||
};
|
||||
}, {
|
||||
properties: {},
|
||||
|
|
Loading…
Reference in a new issue