Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-6170 do not try to create missing clippath #6210

Merged
merged 3 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/elements_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ fabric.ElementsParser = function(elements, callback, options, reviver, parsingOp
clipPath.setPositionByOrigin({ x: options.translateX, y: options.translateY }, 'center', 'center');
obj.clipPath = clipPath;
}
else {
// if clip-path does not resolve to any element, delete the property.
delete obj.clipPath;
}
};

proto.checkIfDone = function() {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,20 @@
});
});

QUnit.test('parseSVGFromString with missing clippath', function(assert) {
var done = assert.async();
var string = '<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
'<g clip-path="url(#i)">' +
'<path d="m59.09 7.55c-5.22 1.85-5.74-1.42-5.74-1.42-2.83 1.41-0.97 4.45-0.97 4.45s-2.87-0.21-4.1 2.27c-1.29 2.6-0.15 4.59-0.15 4.59s-2.76 1.75-1.68 4.95c0.72 2.12 2.87 2.97 2.87 2.97-0.26 4.57 1.18 6.79 1.18 6.79s1.79-7.85 1.62-9.05c0 0 3.3-0.66 7.05-2.8 2.53-1.45 4.26-3.15 7.11-3.79 4.33-0.98 5.3 2.16 5.3 2.16s4.01-0.77 5.22 4.8c0.5 2.29 0.71 6.12 0.98 8.45-0.02-0.2 1.49-2.72 1.75-5.28 0.1-0.95 1.54-3.26 1.97-4.99 0.94-3.75-0.29-6.7-0.88-7.58-1.07-1.61-3.61-3.83-5.52-3.51 0.1-2.04-1.51-3.94-3.45-4.59-5.29-1.8-11 1.02-12.56 1.58z" fill="none" stroke="#402720" stroke-miterlimit="10" stroke-width="2"/>' +
'</g>' +
'</svg>';

fabric.loadSVGFromString(string, function(objects) {
assert.equal(objects[0].clipPath, undefined);
done();
});
});

QUnit.test('parseSVGFromString with empty <style/>', function(assert) {
var done = assert.async();
var string = '<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
Expand Down
24 changes: 24 additions & 0 deletions test/visual/assets/svg_missing_clippath.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/visual/golden/svg_missing_clippath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion test/visual/svg_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
'notoemoji-person',
// 'clippath-8',
'emoji-b',
'gold-logo'
'gold-logo',
'svg_missing_clippath'
].map(createTestFromSVG);

tests.forEach(visualTestLoop(QUnit));
Expand Down