Fixed issue 717: Bounding box not surrounding entire image library image
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1988 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
292391150f
commit
ca671f90d2
|
@ -96,6 +96,24 @@ var supportsPathBBox_ = (function() {
|
||||||
return (bbox.height > 4 && bbox.height < 5);
|
return (bbox.height > 4 && bbox.height < 5);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Support for correct bbox sizing on groups with horizontal/vertical lines
|
||||||
|
var supportsHVLineContainerBBox_ = (function() {
|
||||||
|
var svgcontent = document.createElementNS(svgns, 'svg');
|
||||||
|
document.documentElement.appendChild(svgcontent);
|
||||||
|
var path = document.createElementNS(svgns, 'path');
|
||||||
|
path.setAttribute('d','M0,0 10,0');
|
||||||
|
var path2 = document.createElementNS(svgns, 'path');
|
||||||
|
path2.setAttribute('d','M5,0 15,0');
|
||||||
|
var g = document.createElementNS(svgns, 'g');
|
||||||
|
g.appendChild(path);
|
||||||
|
g.appendChild(path2);
|
||||||
|
svgcontent.appendChild(g);
|
||||||
|
var bbox = g.getBBox();
|
||||||
|
document.documentElement.removeChild(svgcontent);
|
||||||
|
// Webkit gives 0, FF gives 10, Opera (correctly) gives 15
|
||||||
|
return (bbox.width == 15);
|
||||||
|
})();
|
||||||
|
|
||||||
var supportsEditableText_ = (function() {
|
var supportsEditableText_ = (function() {
|
||||||
// TODO: Find better way to check support for this
|
// TODO: Find better way to check support for this
|
||||||
return isOpera_;
|
return isOpera_;
|
||||||
|
@ -141,6 +159,7 @@ svgedit.browser.supportsXpath = function() { return supportsXpath_; }
|
||||||
svgedit.browser.supportsPathReplaceItem = function() { return supportsPathReplaceItem_; }
|
svgedit.browser.supportsPathReplaceItem = function() { return supportsPathReplaceItem_; }
|
||||||
svgedit.browser.supportsPathInsertItemBefore = function() { return supportsPathInsertItemBefore_; }
|
svgedit.browser.supportsPathInsertItemBefore = function() { return supportsPathInsertItemBefore_; }
|
||||||
svgedit.browser.supportsPathBBox = function() { return supportsPathBBox_; }
|
svgedit.browser.supportsPathBBox = function() { return supportsPathBBox_; }
|
||||||
|
svgedit.browser.supportsHVLineContainerBBox = function() { return supportsHVLineContainerBBox_; }
|
||||||
svgedit.browser.supportsTextCharPos = function() { return supportsTextCharPos_; }
|
svgedit.browser.supportsTextCharPos = function() { return supportsTextCharPos_; }
|
||||||
svgedit.browser.supportsEditableText = function() { return supportsEditableText_; }
|
svgedit.browser.supportsEditableText = function() { return supportsEditableText_; }
|
||||||
svgedit.browser.supportsGoodDecimals = function() { return supportsGoodDecimals_; }
|
svgedit.browser.supportsGoodDecimals = function() { return supportsGoodDecimals_; }
|
||||||
|
|
|
@ -409,6 +409,52 @@ svgedit.utilities.getPathBBox = function(path) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function: groupBBFix
|
||||||
|
// Get the given/selected element's bounding box object, checking for
|
||||||
|
// horizontal/vertical lines (see issue 717)
|
||||||
|
// Note that performance is currently terrible, so some way to improve would
|
||||||
|
// be great.
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
// selected - Container or <use> DOM element
|
||||||
|
function groupBBFix(selected) {
|
||||||
|
if(svgedit.browser.supportsHVLineContainerBBox()) {
|
||||||
|
try { return selected.getBBox();} catch(e){}
|
||||||
|
}
|
||||||
|
var ref = $.data(selected, 'ref');
|
||||||
|
var matched = null;
|
||||||
|
|
||||||
|
if(ref) {
|
||||||
|
var copy = $(ref).children().clone().attr('visibility', 'hidden');
|
||||||
|
$(svgroot_).append(copy);
|
||||||
|
matched = copy.filter('line, path');
|
||||||
|
} else {
|
||||||
|
matched = $(selected).find('line, path');
|
||||||
|
}
|
||||||
|
|
||||||
|
var issue = false;
|
||||||
|
if(matched.length) {
|
||||||
|
matched.each(function() {
|
||||||
|
var bb = this.getBBox();
|
||||||
|
if(!bb.width || !bb.height) {
|
||||||
|
issue = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(issue) {
|
||||||
|
var elems = ref ? copy : $(selected).children();
|
||||||
|
ret = getStrokedBBox(elems);
|
||||||
|
} else {
|
||||||
|
ret = selected.getBBox();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = selected.getBBox();
|
||||||
|
}
|
||||||
|
if(ref) {
|
||||||
|
copy.remove();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Function: svgedit.utilities.getBBox
|
// Function: svgedit.utilities.getBBox
|
||||||
// Get the given/selected element's bounding box object, convert it to be more
|
// Get the given/selected element's bounding box object, convert it to be more
|
||||||
// usable when necessary
|
// usable when necessary
|
||||||
|
@ -440,28 +486,16 @@ svgedit.utilities.getBBox = function(elem) {
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'a':
|
case 'a':
|
||||||
var matched = $(selected).find('line, path');
|
ret = groupBBFix(selected);
|
||||||
var issue = false;
|
|
||||||
if(matched.length) {
|
|
||||||
matched.each(function() {
|
|
||||||
var bb = this.getBBox();
|
|
||||||
if(!bb.width || !bb.height) {
|
|
||||||
issue = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(issue) {
|
|
||||||
ret = getStrokedBBox($(selected).children());
|
|
||||||
} else {
|
|
||||||
ret = selected.getBBox();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ret = selected.getBBox();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
if(elname === 'use') {
|
||||||
|
ret = groupBBFix(selected, true);
|
||||||
|
}
|
||||||
|
|
||||||
if(elname === 'use' && !svgedit.browser.isWebkit() || elname === 'foreignObject') {
|
if((elname === 'use' && !svgedit.browser.isWebkit()) || elname === 'foreignObject') {
|
||||||
ret = selected.getBBox();
|
if(!ret) ret = selected.getBBox();
|
||||||
var bb = {};
|
var bb = {};
|
||||||
bb.width = ret.width;
|
bb.width = ret.width;
|
||||||
bb.height = ret.height;
|
bb.height = ret.height;
|
||||||
|
|
Loading…
Reference in New Issue