Skip to content

Commit

Permalink
SVG: Rename 'SVG' prefix to 'Svg'
Browse files Browse the repository at this point in the history
- To make it clear it's not browser-provided functionality
- To reflect how DomElement / DomEvent are already named, for the same reason
  • Loading branch information
lehni committed Feb 1, 2016
1 parent 5198983 commit af59847
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/paper.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ var paper = function(window, undefined) {
/*#*/ }

/*#*/ if (__options.svg) {
/*#*/ include('svg/SVGNode.js');
/*#*/ include('svg/SVGStyles.js');
/*#*/ include('svg/SVGExport.js');
/*#*/ include('svg/SVGImport.js');
/*#*/ include('svg/SvgNode.js');
/*#*/ include('svg/SvgStyles.js');
/*#*/ include('svg/SvgExport.js');
/*#*/ include('svg/SvgImport.js');
/*#*/ }

/*#*/ if (__options.paperScript) {
Expand Down
42 changes: 21 additions & 21 deletions src/svg/SVGExport.js → src/svg/SvgExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ new function() {
function exportGroup(item, options) {
var attrs = getTransform(item._matrix),
children = item._children;
var node = SVGNode.create('g', attrs, formatter);
var node = SvgNode.create('g', attrs, formatter);
for (var i = 0, l = children.length; i < l; i++) {
var child = children[i];
var childNode = exportSVG(child, options);
if (childNode) {
if (child.isClipMask()) {
var clip = SVGNode.create('clipPath');
var clip = SvgNode.create('clipPath');
clip.appendChild(childNode);
setDefinition(child, clip, 'clip');
SVGNode.set(node, {
SvgNode.set(node, {
'clip-path': 'url(#' + clip.id + ')'
});
} else {
Expand All @@ -92,7 +92,7 @@ new function() {
attrs.height = size.height;
attrs.href = options.embedImages === false && image && image.src
|| item.toDataURL();
return SVGNode.create('image', attrs, formatter);
return SvgElement.create('image', attrs, formatter);
}

function exportPath(item, options) {
Expand Down Expand Up @@ -129,7 +129,7 @@ new function() {
type = 'path';
attrs.d = item.getPathData(null, options.precision);
}
return SVGNode.create(type, attrs, formatter);
return SvgElement.create(type, attrs, formatter);
}

function exportShape(item) {
Expand All @@ -156,15 +156,15 @@ new function() {
attrs.ry = radius.height;
}
}
return SVGNode.create(type, attrs, formatter);
return SvgElement.create(type, attrs, formatter);
}

function exportCompoundPath(item, options) {
var attrs = getTransform(item._matrix);
var data = item.getPathData(null, options.precision);
if (data)
attrs.d = data;
return SVGNode.create('path', attrs, formatter);
return SvgElement.create('path', attrs, formatter);
}

function exportSymbolItem(item, options) {
Expand All @@ -174,7 +174,7 @@ new function() {
definitionItem = definition._item,
bounds = definitionItem.getBounds();
if (!node) {
node = SVGNode.create('symbol', {
node = SvgElement.create('symbol', {
viewBox: formatter.rectangle(bounds)
});
node.appendChild(exportSVG(definitionItem, options));
Expand All @@ -186,15 +186,15 @@ new function() {
attrs.width = bounds.width;
attrs.height = bounds.height;
attrs.overflow = 'visible';
return SVGNode.create('use', attrs, formatter);
return SvgElement.create('use', attrs, formatter);
}

function exportGradient(color) {
// NOTE: As long as the fillTransform attribute is not implemented,
// we need to create a separate gradient object for each gradient,
// even when they share the same gradient defintion.
// http://www.svgopen.org/2011/papers/20-Separating_gradients_from_geometry/
// TODO: Implement gradient merging in SVGImport
// TODO: Implement gradient merging in SvgImport
var gradientNode = getDefinition(color, 'color');
if (!gradientNode) {
var gradient = color.getGradient(),
Expand Down Expand Up @@ -223,7 +223,7 @@ new function() {
};
}
attrs.gradientUnits = 'userSpaceOnUse';
gradientNode = SVGNode.create((radial ? 'radial' : 'linear')
gradientNode = SvgElement.create((radial ? 'radial' : 'linear')
+ 'Gradient', attrs, formatter);
var stops = gradient._stops;
for (var i = 0, l = stops.length; i < l; i++) {
Expand All @@ -239,15 +239,15 @@ new function() {
if (alpha < 1)
attrs['stop-opacity'] = alpha;
gradientNode.appendChild(
SVGNode.create('stop', attrs, formatter));
SvgElement.create('stop', attrs, formatter));
}
setDefinition(color, gradientNode, 'color');
}
return 'url(#' + gradientNode.id + ')';
}

function exportText(item) {
var node = SVGNode.create('text', getTransform(item._matrix, true),
var node = SvgElement.create('text', getTransform(item._matrix, true),
formatter);
node.textContent = item._content;
return node;
Expand All @@ -272,7 +272,7 @@ new function() {
if (item._name != null)
attrs.id = item._name;

Base.each(SVGStyles, function(entry) {
Base.each(SvgStyles, 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 get = entry.get,
Expand Down Expand Up @@ -313,7 +313,7 @@ new function() {
if (!item._visible)
attrs.visibility = 'hidden';

return SVGNode.set(node, attrs, formatter);
return SvgElement.set(node, attrs, formatter);
}

var definitions;
Expand Down Expand Up @@ -349,10 +349,10 @@ new function() {
// we actually have svgs.
if (!defs) {
if (!svg) {
svg = SVGNode.create('svg');
svg = SvgElement.create('svg');
svg.appendChild(node);
}
defs = svg.insertBefore( SVGNode.create('defs'),
defs = svg.insertBefore(SvgElement.create('defs'),
svg.firstChild);
}
defs.appendChild(definitions.svgs[i]);
Expand Down Expand Up @@ -401,21 +401,21 @@ new function() {
var children = this._children,
view = this.getView(),
size = view.getViewSize(),
node = SVGNode.create('svg', {
node = SvgElement.create('svg', {
x: 0,
y: 0,
width: size.width,
height: size.height,
version: '1.1',
xmlns: SVGNode.xmlns,
'xmlns:xlink': SVGNode.xlink
xmlns: SvgElement.xmlns,
'xmlns:xlink': SvgElement.xlink
}, formatter),
parent = node,
matrix = view._matrix;
// If the view has a transformation, wrap all layers in a group with
// that transformation applied to.
if (!matrix.isIdentity())
parent = node.appendChild( SVGNode.create('g',
parent = node.appendChild(SvgElement.create('g',
getTransform(matrix), formatter));
for (var i = 0, l = children.length; i < l; i++)
parent.appendChild(exportSVG(children[i], options, true));
Expand Down
8 changes: 4 additions & 4 deletions src/svg/SVGImport.js → src/svg/SvgImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ new function() {
// index is option, and if passed, causes a lookup in a list.

function getValue(node, name, isString, allowNull) {
var value = SVGNode.get(node, name);
var value = SvgElement.get(node, name);
// Interpret value as number. Never return NaN, but 0 instead.
// If the value is a sequence of numbers, parseFloat will
// return the first occurring number, which is enough for now.
Expand Down Expand Up @@ -186,7 +186,7 @@ new function() {
// at the end. This parent node also helps fix a bug on IE.
var body = document.body,
// No need to inherit styles on Node.js
parent = !paper.agent.node && SVGNode.create('svg');
parent = !paper.agent.node && SvgElement.create('svg');
if (parent) {
body.appendChild(parent);
// If no stroke-width is set, IE/Edge appears to have a
Expand Down Expand Up @@ -381,9 +381,9 @@ new function() {
// since transform needs to be applied after fill color, as transformations
// can affect gradient fills.
// Use Base.set() to control sequence of attributes and have all entries in
// SVGStyles (e.g. 'stroke') before the additional attributes below (e.g.
// SvgStyles (e.g. 'stroke') before the additional attributes below (e.g.
// 'stroke-opacity'). See issue #694.
var attributes = Base.set(Base.each(SVGStyles, function(entry) {
var attributes = Base.set(Base.each(SvgStyles, function(entry) {
this[entry.attribute] = function(item, value) {
item[entry.set](convertValue(value, entry.type, entry.fromSVG));
// When applying gradient colors to shapes, we need to offset
Expand Down
6 changes: 3 additions & 3 deletions src/svg/SVGNode.js → src/svg/SvgNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/

/**
* @name SVGNode
* @name SvgElement
* @namespace
* @private
*/
var SVGNode = new function() {
var SvgElement = new function() {
// SVG related namespaces
var svg = 'http://www.w3.org/2000/svg',
xmlns = 'http://www.w3.org/2000/xmlns',
Expand Down Expand Up @@ -53,7 +53,7 @@ var SVGNode = new function() {
return node;
}

return /** @lends SVGNode */{
return /** @lends SvgElement */{
// Export namespaces
svg: svg,
xmlns: xmlns,
Expand Down
2 changes: 1 addition & 1 deletion src/svg/SVGStyles.js → src/svg/SvgStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* All rights reserved.
*/

var SVGStyles = Base.each({
var SvgStyles = Base.each({
// Fill
fillColor: ['fill', 'color'],
fillRule: ['fill-rule', 'string'],
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ var getFunctionMessage = function(func) {

var createSVG = function(str, attrs) {
if (attrs) {
// Similar to SVGNode.create():
// Similar to SvgElement.create():
var node = document.createElementNS('http://www.w3.org/2000/svg', str);
for (var key in attrs)
node.setAttribute(key, attrs[key]);
Expand Down
2 changes: 1 addition & 1 deletion test/tests/SVGExport.js → test/tests/SvgExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* All rights reserved.
*/

QUnit.module('SVGExport');
QUnit.module('SvgExport');

test('Export SVG line', function() {
var attrs = {
Expand Down
2 changes: 1 addition & 1 deletion test/tests/SVGImport.js → test/tests/SvgImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* All rights reserved.
*/

QUnit.module('SVGImport');
QUnit.module('SvgImport');

test('Import SVG line', function() {
var attrs = {
Expand Down
4 changes: 2 additions & 2 deletions test/tests/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@

/*#*/ include('JSON.js');

/*#*/ include('SVGImport.js');
/*#*/ include('SVGExport.js');
/*#*/ include('SvgImport.js');
/*#*/ include('SvgExport.js');

0 comments on commit af59847

Please sign in to comment.