SVG Import: Improve handling of sizes in percent.

Closes #1242
This commit is contained in:
Jürg Lehni 2017-03-23 00:14:03 +01:00
parent a43db8427a
commit 261fc02c1d
2 changed files with 26 additions and 23 deletions

View file

@ -163,10 +163,10 @@ PathItem.inject(new function() {
var _path1 = preparePath(path1),
_path2 = preparePath(path2),
crossings = _path1.getCrossings(_path2),
added = {},
paths = [],
subtract = operation === 'subtract',
divide = operation === 'divide',
subtract = operation === 'subtract';
added = {},
paths = [];
function addPath(path) {
// Simple see if the point halfway across the open path is inside

View file

@ -521,23 +521,25 @@ new function() {
* @param {Item} item the item to apply the style and attributes to
*/
function applyAttributes(item, node, isRoot) {
// SVG attributes can be set both as styles and direct node attributes,
// so we need to handle both.
var parent = node.parentNode,
styles = {
node: DomElement.getStyles(node) || {},
// Do not check for inheritance if this is root, since we want
// the default SVG settings to stick. Also detect defs parents,
// of which children need to explicitly inherit their styles.
parent: !isRoot && !/^defs$/i.test(parent.tagName)
&& DomElement.getStyles(parent) || {}
};
Base.each(attributes, function(apply, name) {
var value = getAttribute(node, name, styles);
// 'clip-path' attribute returns a new item, support it here:
item = value !== undefined && apply(item, value, name, node, styles)
|| item;
});
if (node.style) {
// SVG attributes can be set both as styles and direct node
// attributes, so we need to handle both.
var parent = node.parentNode,
styles = {
node: DomElement.getStyles(node) || {},
// Do not check for inheritance if this is root, to make the
// default SVG settings stick. Also detect defs parents, of
// which children need to explicitly inherit their styles.
parent: !isRoot && !/^defs$/i.test(parent.tagName)
&& DomElement.getStyles(parent) || {}
};
Base.each(attributes, function(apply, name) {
var value = getAttribute(node, name, styles);
// 'clip-path' attribute returns a new item, support it here:
item = value !== undefined
&& apply(item, value, name, node, styles) || item;
});
}
return item;
}
@ -571,9 +573,10 @@ new function() {
parent,
next;
if (isRoot && isElement) {
// Set rootSize root element size, fall-back to view size.
rootSize = getSize(node, null, null, true)
|| paper.getView().getSize();
// Set rootSize to view size, as getSize() may refer to it (#1242).
rootSize = paper.getView().getSize();
// Now set rootSize to the root element size, and fall-back to view.
rootSize = getSize(node, null, null, true) || rootSize;
// We need to move the SVG node to the current document, so default
// styles are correctly inherited! For this we create and insert a
// temporary SVG container which is removed again at the end. This