2012-11-02 20:47:14 -04:00
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2012-09-30 17:51:50 -04:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
2012-09-30 17:51:50 -04:00
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
2012-09-13 20:45:27 -04:00
|
|
|
*/
|
|
|
|
|
2012-11-04 02:04:15 -05:00
|
|
|
/**
|
2012-11-06 16:07:18 -05:00
|
|
|
* A function scope holding all the functionality needed to convert a
|
|
|
|
* Paper.js DOM to a Paper.js DOM.
|
2012-11-04 02:04:15 -05:00
|
|
|
*/
|
2012-11-06 16:07:18 -05:00
|
|
|
new function() {
|
2012-10-24 23:21:59 -04:00
|
|
|
|
2012-11-14 04:31:08 -05:00
|
|
|
// Shortcut to Base.formatFloat
|
|
|
|
var formatFloat = Base.formatFloat;
|
2012-11-06 10:14:11 -05:00
|
|
|
|
2012-11-06 10:16:25 -05:00
|
|
|
function formatPoint(point) {
|
2012-11-14 04:31:08 -05:00
|
|
|
return formatFloat(point.x) + ',' + formatFloat(point.y);
|
2012-11-06 10:14:11 -05:00
|
|
|
}
|
|
|
|
|
2012-11-04 12:01:11 -05:00
|
|
|
function setAttributes(svg, attrs) {
|
2012-11-06 10:14:11 -05:00
|
|
|
for (var key in attrs) {
|
|
|
|
var val = attrs[key];
|
|
|
|
if (typeof val === 'number')
|
2012-11-14 04:31:08 -05:00
|
|
|
val = formatFloat(val);
|
2012-11-06 10:14:11 -05:00
|
|
|
svg.setAttribute(key, val);
|
|
|
|
}
|
2012-11-05 23:31:45 -05:00
|
|
|
return svg;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createElement(tag, attrs) {
|
|
|
|
return setAttributes(
|
|
|
|
document.createElementNS('http://www.w3.org/2000/svg', tag), attrs);
|
2012-11-04 12:01:11 -05:00
|
|
|
}
|
|
|
|
|
2012-11-05 23:50:31 -05:00
|
|
|
function getDistance(segments, index1, index2) {
|
|
|
|
return segments[index1]._point.getDistance(segments[index2]._point);
|
|
|
|
}
|
|
|
|
|
2012-12-09 18:46:21 -05:00
|
|
|
function getTransform(item, coordinates) {
|
|
|
|
var matrix = item._matrix,
|
2013-02-09 15:11:56 -05:00
|
|
|
trans = matrix.getTranslation(),
|
2012-12-09 18:46:21 -05:00
|
|
|
attrs = {};
|
|
|
|
if (coordinates) {
|
|
|
|
// If the item suppports x- and y- coordinates, we're taking out the
|
|
|
|
// translation part of the matrix and move it to x, y attributes, to
|
|
|
|
// produce more readable markup, and not have to use center points
|
|
|
|
// in rotate(). To do so, SVG requries us to inverse transform the
|
|
|
|
// translation point by the matrix itself, since they are provided
|
|
|
|
// in local coordinates.
|
2013-02-09 15:18:40 -05:00
|
|
|
matrix = matrix.shiftless();
|
2012-12-09 18:46:21 -05:00
|
|
|
var point = matrix._inverseTransform(trans);
|
|
|
|
attrs.x = point.x;
|
|
|
|
attrs.y = point.y;
|
|
|
|
trans = null;
|
|
|
|
}
|
2012-11-06 13:02:40 -05:00
|
|
|
if (matrix.isIdentity())
|
|
|
|
return attrs;
|
2013-02-09 15:11:56 -05:00
|
|
|
// See if we can decompose the matrix and can formulate it as a simple
|
2013-02-09 02:02:20 -05:00
|
|
|
// translate/scale/rotate command sequence.
|
2013-02-09 15:11:56 -05:00
|
|
|
var decomposed = matrix.decompose();
|
|
|
|
if (decomposed && !decomposed.shearing) {
|
2013-02-09 02:02:20 -05:00
|
|
|
var parts = [],
|
|
|
|
angle = decomposed.rotation,
|
|
|
|
scale = decomposed.scaling;
|
2012-12-15 05:20:37 -05:00
|
|
|
if (trans && !trans.isZero())
|
|
|
|
parts.push('translate(' + formatPoint(trans) + ')');
|
|
|
|
if (!Numerical.isZero(scale.x - 1) || !Numerical.isZero(scale.y - 1))
|
|
|
|
parts.push('scale(' + formatPoint(scale) +')');
|
2013-02-09 02:02:20 -05:00
|
|
|
if (angle)
|
|
|
|
parts.push('rotate(' + formatFloat(angle) + ')');
|
|
|
|
attrs.transform = parts.join(' ');
|
2012-11-06 13:02:40 -05:00
|
|
|
} else {
|
2013-02-09 02:02:20 -05:00
|
|
|
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
|
2012-11-06 13:02:40 -05:00
|
|
|
}
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
|
2012-11-06 14:00:58 -05:00
|
|
|
function getPath(path, segments) {
|
|
|
|
var parts = [],
|
|
|
|
style = path._style;
|
|
|
|
|
|
|
|
function addCurve(seg1, seg2, skipLine) {
|
|
|
|
var point1 = seg1._point,
|
|
|
|
point2 = seg2._point,
|
|
|
|
handle1 = seg1._handleOut,
|
|
|
|
handle2 = seg2._handleIn;
|
|
|
|
if (handle1.isZero() && handle2.isZero()) {
|
|
|
|
if (!skipLine) {
|
|
|
|
// L = lineto: moving to a point with drawing
|
|
|
|
parts.push('L' + formatPoint(point2));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// c = relative curveto: handle1, handle2 + end - start, end - start
|
|
|
|
var end = point2.subtract(point1);
|
|
|
|
parts.push('c' + formatPoint(handle1),
|
|
|
|
formatPoint(end.add(handle2)),
|
|
|
|
formatPoint(end));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parts.push('M' + formatPoint(segments[0]._point));
|
2012-11-06 14:28:50 -05:00
|
|
|
for (i = 0, l = segments.length - 1; i < l; i++)
|
2012-11-06 14:00:58 -05:00
|
|
|
addCurve(segments[i], segments[i + 1], false);
|
|
|
|
// We only need to draw the connecting curve if it is not a line, and if
|
|
|
|
// the path is cosed and has a stroke color, or if it is filled.
|
|
|
|
if (path._closed && style._strokeColor || style._fillColor)
|
|
|
|
addCurve(segments[segments.length - 1], segments[0], true);
|
|
|
|
if (path._closed)
|
|
|
|
parts.push('z');
|
|
|
|
return parts.join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
function determineAngle(path, segments, type, center) {
|
|
|
|
// If the object is a circle, ellipse, rectangle, or rounded rectangle,
|
2012-11-06 14:26:00 -05:00
|
|
|
// see if it is placed at an angle, by figuring out its topCenter point
|
|
|
|
// and measuring the angle to its center.
|
2012-11-06 14:00:58 -05:00
|
|
|
var topCenter = type === 'rect'
|
|
|
|
? segments[1]._point.add(segments[2]._point).divide(2)
|
|
|
|
: type === 'roundrect'
|
|
|
|
? segments[3]._point.add(segments[4]._point).divide(2)
|
|
|
|
: type === 'circle' || type === 'ellipse'
|
|
|
|
? segments[1]._point
|
|
|
|
: null;
|
2012-11-06 14:26:00 -05:00
|
|
|
var angle = topCenter && topCenter.subtract(center).getAngle() + 90;
|
|
|
|
return Numerical.isZero(angle || 0) ? 0 : angle;
|
2012-11-06 14:00:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function determineType(path, segments) {
|
|
|
|
// Returns true if the the two segment indices are the beggining of two
|
|
|
|
// lines and if the wto lines are parallel.
|
|
|
|
function isColinear(i, j) {
|
|
|
|
var seg1 = segments[i],
|
|
|
|
seg2 = seg1.getNext(),
|
|
|
|
seg3 = segments[j],
|
|
|
|
seg4 = seg3.getNext();
|
|
|
|
return seg1._handleOut.isZero() && seg2._handleIn.isZero()
|
|
|
|
&& seg3._handleOut.isZero() && seg4._handleIn.isZero()
|
|
|
|
&& seg2._point.subtract(seg1._point).isColinear(
|
|
|
|
seg4._point.subtract(seg3._point));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kappa, see: http://www.whizkidtech.redprince.net/bezier/circle/kappa/
|
|
|
|
var kappa = 4 * (Math.sqrt(2) - 1) / 3;
|
|
|
|
|
|
|
|
// Returns true if the segment at the given index is the beginning of
|
|
|
|
// a orthogonal arc segment. The code is looking at the length of the
|
|
|
|
// handles and their relation to the distance to the imaginary corner
|
|
|
|
// point. If the relation is kappa (see above), then it's an arc.
|
|
|
|
function isArc(i) {
|
|
|
|
var segment = segments[i],
|
|
|
|
next = segment.getNext(),
|
|
|
|
handle1 = segment._handleOut,
|
|
|
|
handle2 = next._handleIn;
|
|
|
|
if (handle1.isOrthogonal(handle2)) {
|
|
|
|
var from = segment._point,
|
|
|
|
to = next._point,
|
|
|
|
// Find hte corner point by intersecting the lines described
|
|
|
|
// by both handles:
|
|
|
|
corner = new Line(from, handle1).intersect(
|
|
|
|
new Line(to, handle2));
|
|
|
|
return corner && Numerical.isZero(handle1.getLength() /
|
|
|
|
corner.subtract(from).getLength() - kappa)
|
|
|
|
&& Numerical.isZero(handle2.getLength() /
|
|
|
|
corner.subtract(to).getLength() - kappa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if actually have any curves in the path. Differentiate
|
|
|
|
// between straight objects (line, polyline, rect, and polygon) and
|
|
|
|
// objects with curves(circle, ellipse, roundedRectangle).
|
|
|
|
if (path.isPolygon()) {
|
|
|
|
return segments.length === 4 && path._closed
|
|
|
|
&& isColinear(0, 2) && isColinear(1, 3)
|
|
|
|
? 'rect'
|
2012-12-09 21:04:56 -05:00
|
|
|
: segments.length === 0
|
|
|
|
? 'empty'
|
|
|
|
: segments.length >= 3
|
|
|
|
? path._closed ? 'polygon' : 'polyline'
|
|
|
|
: 'line';
|
2012-11-06 14:00:58 -05:00
|
|
|
} else if (path._closed) {
|
|
|
|
if (segments.length === 8
|
|
|
|
&& isArc(0) && isArc(2) && isArc(4) && isArc(6)
|
|
|
|
&& isColinear(1, 5) && isColinear(3, 7)) {
|
|
|
|
return 'roundrect';
|
|
|
|
} else if (segments.length === 4
|
|
|
|
&& isArc(0) && isArc(1) && isArc(2) && isArc(3)) {
|
|
|
|
// If the distance between (point0 and point2) and (point1
|
|
|
|
// and point3) are equal, then it is a circle
|
|
|
|
return Numerical.isZero(getDistance(segments, 0, 2)
|
|
|
|
- getDistance(segments, 1, 3))
|
|
|
|
? 'circle'
|
|
|
|
: 'ellipse';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'path';
|
|
|
|
}
|
|
|
|
|
2012-11-04 01:43:45 -05:00
|
|
|
function exportGroup(group) {
|
2012-11-06 13:02:40 -05:00
|
|
|
var attrs = getTransform(group),
|
2012-11-02 19:51:42 -04:00
|
|
|
children = group._children;
|
2012-11-06 13:02:40 -05:00
|
|
|
// Override default SVG style on groups, then apply style.
|
|
|
|
attrs.fill = 'none';
|
|
|
|
var svg = createElement('g', attrs);
|
2012-12-09 19:53:52 -05:00
|
|
|
for (var i = 0, l = children.length; i < l; i++) {
|
|
|
|
var child = children[i].exportSvg();
|
|
|
|
if (child)
|
|
|
|
svg.appendChild(child);
|
|
|
|
}
|
2012-11-06 13:02:40 -05:00
|
|
|
return svg;
|
2012-11-04 01:43:45 -05:00
|
|
|
}
|
|
|
|
|
2013-02-09 12:44:25 -05:00
|
|
|
function exportRaster(item) {
|
|
|
|
var attrs = getTransform(item, true),
|
|
|
|
size = item.getSize();
|
|
|
|
attrs.width = size.width;
|
|
|
|
attrs.height = size.height;
|
|
|
|
attrs.x -= size.width / 2;
|
|
|
|
attrs.y -= size.height / 2;
|
|
|
|
var svg = createElement('image', attrs);
|
|
|
|
svg.setAttributeNS('http://www.w3.org/1999/xlink','href', item.toDataURL());
|
|
|
|
return svg;
|
|
|
|
}
|
|
|
|
|
2012-11-05 23:50:31 -05:00
|
|
|
function exportText(item) {
|
2012-12-09 18:46:21 -05:00
|
|
|
var attrs = getTransform(item, true),
|
2012-11-06 13:02:40 -05:00
|
|
|
style = item._style;
|
2012-11-05 23:50:31 -05:00
|
|
|
if (style._font != null)
|
|
|
|
attrs['font-family'] = style._font;
|
|
|
|
if (style._fontSize != null)
|
|
|
|
attrs['font-size'] = style._fontSize;
|
|
|
|
var svg = createElement('text', attrs);
|
2012-11-06 13:02:40 -05:00
|
|
|
svg.textContent = item._content;
|
2012-11-05 23:50:31 -05:00
|
|
|
return svg;
|
2012-11-05 23:10:31 -05:00
|
|
|
}
|
|
|
|
|
2012-11-05 23:50:31 -05:00
|
|
|
function exportPath(path) {
|
|
|
|
var segments = path._segments,
|
2012-11-06 13:02:40 -05:00
|
|
|
center = path.getPosition(true),
|
2012-11-06 00:24:01 -05:00
|
|
|
type = determineType(path, segments),
|
2012-11-06 13:02:40 -05:00
|
|
|
angle = determineAngle(path, segments, type, center),
|
2012-11-06 02:27:02 -05:00
|
|
|
attrs;
|
2012-09-30 17:51:50 -04:00
|
|
|
switch (type) {
|
2012-12-09 21:04:56 -05:00
|
|
|
case 'empty':
|
|
|
|
return null;
|
2012-11-06 02:45:23 -05:00
|
|
|
case 'path':
|
|
|
|
attrs = {
|
2012-11-06 14:00:58 -05:00
|
|
|
d: getPath(path, segments)
|
2012-11-06 02:45:23 -05:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'polyline':
|
|
|
|
case 'polygon':
|
|
|
|
var parts = [];
|
2012-11-06 14:28:50 -05:00
|
|
|
for(i = 0, l = segments.length; i < l; i++)
|
2012-11-06 14:19:54 -05:00
|
|
|
parts.push(formatPoint(segments[i]._point));
|
2012-11-06 02:45:23 -05:00
|
|
|
attrs = {
|
|
|
|
points: parts.join(' ')
|
|
|
|
};
|
|
|
|
break;
|
2012-10-22 19:31:08 -04:00
|
|
|
case 'rect':
|
2012-11-05 23:31:45 -05:00
|
|
|
var width = getDistance(segments, 0, 3),
|
|
|
|
height = getDistance(segments, 0, 1),
|
2012-11-06 11:28:54 -05:00
|
|
|
// Counter-compensate the determined rotation angle
|
2012-11-06 13:02:40 -05:00
|
|
|
point = segments[1]._point.rotate(-angle, center);
|
2012-11-06 02:27:02 -05:00
|
|
|
attrs = {
|
|
|
|
x: point.x,
|
|
|
|
y: point.y,
|
2012-11-05 23:31:45 -05:00
|
|
|
width: width,
|
|
|
|
height: height
|
2012-11-06 02:27:02 -05:00
|
|
|
};
|
|
|
|
break;
|
2012-11-02 21:23:23 -04:00
|
|
|
case 'roundrect':
|
2012-11-06 10:46:59 -05:00
|
|
|
type = 'rect';
|
2012-11-05 23:50:31 -05:00
|
|
|
// d-variables and point are used to determine the rounded corners
|
|
|
|
// for the rounded rectangle
|
2012-11-06 00:16:36 -05:00
|
|
|
var width = getDistance(segments, 1, 6),
|
|
|
|
height = getDistance(segments, 0, 3),
|
2012-11-06 11:02:46 -05:00
|
|
|
// Subtract side lengths from total width and divide by 2 to get
|
|
|
|
// corner radius size
|
|
|
|
rx = (width - getDistance(segments, 0, 7)) / 2,
|
|
|
|
ry = (height - getDistance(segments, 1, 2)) / 2,
|
|
|
|
// Calculate topLeft corner point, by using sides vectors and
|
|
|
|
// subtracting normalized rx vector to calculate arc corner.
|
|
|
|
left = segments[3]._point, // top-left side point
|
|
|
|
right = segments[4]._point, // top-right side point
|
|
|
|
point = left.subtract(right.subtract(left).normalize(rx))
|
2012-11-06 11:28:54 -05:00
|
|
|
// Counter-compensate the determined rotation angle
|
2012-11-06 13:02:40 -05:00
|
|
|
.rotate(-angle, center);
|
2012-11-06 02:27:02 -05:00
|
|
|
attrs = {
|
2012-11-06 11:02:46 -05:00
|
|
|
x: point.x,
|
|
|
|
y: point.y,
|
2012-11-05 23:31:45 -05:00
|
|
|
width: width,
|
2012-11-06 00:16:36 -05:00
|
|
|
height: height,
|
|
|
|
rx: rx,
|
|
|
|
ry: ry
|
2012-11-06 02:27:02 -05:00
|
|
|
};
|
|
|
|
break;
|
2012-10-22 19:31:08 -04:00
|
|
|
case'line':
|
2012-11-05 23:31:45 -05:00
|
|
|
var first = segments[0]._point,
|
|
|
|
last = segments[segments.length - 1]._point;
|
2012-11-06 02:27:02 -05:00
|
|
|
attrs = {
|
2012-11-05 23:31:45 -05:00
|
|
|
x1: first._x,
|
|
|
|
y1: first._y,
|
|
|
|
x2: last._x,
|
|
|
|
y2: last._y
|
2012-11-06 02:27:02 -05:00
|
|
|
};
|
|
|
|
break;
|
2012-10-22 19:31:08 -04:00
|
|
|
case 'circle':
|
2012-11-06 13:02:40 -05:00
|
|
|
var radius = getDistance(segments, 0, 2) / 2;
|
2012-11-06 02:27:02 -05:00
|
|
|
attrs = {
|
2012-11-06 13:02:40 -05:00
|
|
|
cx: center.x,
|
|
|
|
cy: center.y,
|
2012-11-05 23:31:45 -05:00
|
|
|
r: radius
|
2012-11-06 02:27:02 -05:00
|
|
|
};
|
|
|
|
break;
|
2012-10-22 19:31:08 -04:00
|
|
|
case 'ellipse':
|
2012-11-06 00:19:53 -05:00
|
|
|
var rx = getDistance(segments, 2, 0) / 2,
|
2012-11-06 13:02:40 -05:00
|
|
|
ry = getDistance(segments, 3, 1) / 2;
|
2012-11-06 02:27:02 -05:00
|
|
|
attrs = {
|
2012-11-06 13:02:40 -05:00
|
|
|
cx: center.x,
|
|
|
|
cy: center.y,
|
2012-11-06 00:19:53 -05:00
|
|
|
rx: rx,
|
|
|
|
ry: ry
|
2012-11-06 02:27:02 -05:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
2012-11-06 02:45:23 -05:00
|
|
|
if (angle) {
|
2012-11-14 04:31:08 -05:00
|
|
|
attrs.transform = 'rotate(' + formatFloat(angle) + ','
|
2012-11-06 13:02:40 -05:00
|
|
|
+ formatPoint(center) + ')';
|
2012-09-30 17:51:50 -04:00
|
|
|
}
|
2012-11-06 13:02:40 -05:00
|
|
|
var svg = createElement(type, attrs);
|
2012-11-06 02:45:23 -05:00
|
|
|
return svg;
|
2012-11-04 01:43:45 -05:00
|
|
|
}
|
2012-09-13 20:45:27 -04:00
|
|
|
|
2012-11-06 14:00:58 -05:00
|
|
|
var exporters = {
|
|
|
|
group: exportGroup,
|
|
|
|
layer: exportGroup,
|
|
|
|
path: exportPath,
|
2013-02-09 12:44:25 -05:00
|
|
|
raster: exportRaster,
|
2012-11-06 14:00:58 -05:00
|
|
|
pointtext: exportText
|
|
|
|
// TODO:
|
|
|
|
// placedsymbol:
|
|
|
|
// compoundpath:
|
2013-02-09 12:44:25 -05:00
|
|
|
// gradients
|
2012-11-06 14:00:58 -05:00
|
|
|
};
|
2012-11-04 01:43:45 -05:00
|
|
|
|
2012-11-04 12:01:11 -05:00
|
|
|
function applyStyle(item, svg) {
|
|
|
|
var attrs = {},
|
|
|
|
style = item._style,
|
2012-11-05 12:05:32 -05:00
|
|
|
parent = item.getParent(),
|
2012-11-05 21:58:16 -05:00
|
|
|
parentStyle = parent && parent._style;
|
2012-11-04 12:01:11 -05:00
|
|
|
|
|
|
|
if (item._name != null)
|
2012-11-05 22:26:54 -05:00
|
|
|
attrs.id = item._name;
|
2012-11-04 12:01:11 -05:00
|
|
|
|
2012-11-05 21:58:16 -05:00
|
|
|
Base.each(SvgStyles.properties, function(entry) {
|
2012-11-04 12:01:11 -05:00
|
|
|
// 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).
|
2012-11-05 22:03:42 -05:00
|
|
|
var value = style[entry.get]();
|
2012-11-06 11:22:22 -05:00
|
|
|
if (!parentStyle || !Base.equals(parentStyle[entry.get](), value)) {
|
2012-12-01 15:44:54 -05:00
|
|
|
// Support for css-style rgba() values is not in SVG 1.1, so
|
|
|
|
// separate the alpha value of colors with alpha into the
|
|
|
|
// separate fill- / stroke-opacity attribute:
|
|
|
|
if (entry.type === 'color' && value != null && value.getAlpha() < 1)
|
|
|
|
attrs[entry.attribute + '-opacity'] = value.getAlpha();
|
2012-11-06 11:22:22 -05:00
|
|
|
attrs[entry.attribute] = value == null
|
|
|
|
? 'none'
|
|
|
|
: entry.type === 'color'
|
2012-12-08 23:09:24 -05:00
|
|
|
? value.toCss(true) // false for noAlpha, see above
|
2012-11-06 11:22:22 -05:00
|
|
|
: entry.type === 'array'
|
|
|
|
? value.join(',')
|
|
|
|
: entry.type === 'number'
|
2012-11-14 04:31:08 -05:00
|
|
|
? formatFloat(value)
|
2012-11-06 11:22:22 -05:00
|
|
|
: value;
|
2012-11-04 12:01:11 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-07 04:02:28 -05:00
|
|
|
if (item._opacity != null && item._opacity < 1)
|
2012-11-04 12:01:11 -05:00
|
|
|
attrs.opacity = item._opacity;
|
|
|
|
|
2012-11-07 04:02:28 -05:00
|
|
|
if (item._visibility != null && !item._visibility)
|
|
|
|
attrs.visibility = 'hidden';
|
2012-11-04 12:01:11 -05:00
|
|
|
|
2012-11-05 23:50:31 -05:00
|
|
|
return setAttributes(svg, attrs);
|
2012-11-04 12:01:11 -05:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:34:46 -05:00
|
|
|
Item.inject(/** @lends Item# */{
|
2012-11-04 01:43:45 -05:00
|
|
|
/**
|
2012-11-06 16:34:46 -05:00
|
|
|
* {@grouptitle SVG Conversion}
|
|
|
|
*
|
2012-11-06 16:07:18 -05:00
|
|
|
* Exports the item and all its child items as an SVG DOM, all contained
|
|
|
|
* in one top level SVG group node.
|
2012-11-04 01:43:45 -05:00
|
|
|
*
|
2012-11-06 16:07:18 -05:00
|
|
|
* @return {SVGSVGElement} the item converted to an SVG node
|
2012-11-04 01:43:45 -05:00
|
|
|
*/
|
2012-11-06 16:07:18 -05:00
|
|
|
exportSvg: function() {
|
2012-12-09 18:46:21 -05:00
|
|
|
var exporter = exporters[this._type],
|
|
|
|
svg = exporter && exporter(this, this._type);
|
2012-11-06 16:14:39 -05:00
|
|
|
return svg && applyStyle(this, svg);
|
2012-11-06 16:07:18 -05:00
|
|
|
}
|
|
|
|
});
|
2012-11-04 01:43:45 -05:00
|
|
|
|
2012-11-06 16:34:46 -05:00
|
|
|
Project.inject(/** @lends Project# */{
|
2012-11-06 16:07:18 -05:00
|
|
|
/**
|
2012-11-06 16:34:46 -05:00
|
|
|
* {@grouptitle SVG Conversion}
|
|
|
|
*
|
2012-11-06 16:07:18 -05:00
|
|
|
* Exports the project and all its layers and child items as an SVG DOM,
|
|
|
|
* all contained in one top level SVG group node.
|
|
|
|
*
|
|
|
|
* @return {SVGSVGElement} the project converted to an SVG node
|
|
|
|
*/
|
|
|
|
exportSvg: function() {
|
2012-11-06 16:14:39 -05:00
|
|
|
var svg = createElement('svg'),
|
|
|
|
layers = this.layers;
|
|
|
|
for (var i = 0, l = layers.length; i < l; i++)
|
|
|
|
svg.appendChild(layers[i].exportSvg());
|
|
|
|
return svg;
|
2012-11-04 01:43:45 -05:00
|
|
|
}
|
2012-11-06 16:07:18 -05:00
|
|
|
});
|
2012-11-02 19:19:45 -04:00
|
|
|
};
|