Properly handle generated IDs in SVG export.

Closes #1138
This commit is contained in:
Jürg Lehni 2016-11-20 20:53:41 -05:00
parent 8946f44ed9
commit 3c43a78c53
3 changed files with 26 additions and 7 deletions

View file

@ -326,8 +326,8 @@ new function() {
definitions = { ids: {}, svgs: {} };
// Use #__id for items that don't have internal #_id properties (Color),
// and give them ids from their own private id pool named 'svg'.
var id = item._id || item.__id || (item.__id = UID.get('svg'));
return item && definitions.svgs[type + '-' + id];
return item && definitions.svgs[type + '-'
+ (item._id || item.__id || (item.__id = UID.get('svg')))];
}
function setDefinition(item, node, type) {

View file

@ -217,11 +217,9 @@ var comparePixels = function(actual, expected, message, options) {
var tolerance = (options.tolerance || 1e-4) * 100,
fixed = tolerance < 1 ? ((1 / tolerance) + '').length - 1 : 0,
identical = result ? 100 - result.misMatchPercentage : 0,
reached = identical.toFixed(fixed),
hundred = (100).toFixed(fixed),
ok = reached == hundred,
text = reached + '% identical';
QUnit.push(ok, text, hundred + '% identical', message);
ok = Math.abs(100 - identical) <= tolerance,
text = identical.toFixed(fixed) + '% identical';
QUnit.push(ok, text, (100).toFixed(fixed) + '% identical', message);
if (!ok && result && !isNode) {
// Get the right entry for this unit test and assertion, and
// replace the results with images

View file

@ -191,4 +191,25 @@ if (!isNode) {
tolerance: 1e-2
});
});
test('Export SVG with clipping defs', function(assert) {
var group = new Group({
children: [
new Path.Circle({
center: [150, 150],
radius: 50
}),
new Path.Rectangle({
point: [100, 100],
size: [100, 100],
fillColor: 'green'
})
],
clipped: true
});
var svg = project.exportSVG({ bounds: 'content', asString: true });
compareSVG(assert.async(), svg, project.activeLayer, null, {
tolerance: 1e-2
});
});
}