Largely fixed issue 469 by converting gradients to use objectBoundingBox

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1476 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-03-26 20:30:01 +00:00
parent cbd34c3cfb
commit cb5b6e2d2d
1 changed files with 40 additions and 0 deletions

View File

@ -5880,6 +5880,46 @@ function BatchCommand(text) {
canvas.embedImage(val);
});
// convert gradients with userSpaceOnUse to objectBoundingBox
$(svgcontent).find('linearGradient').each(function() {
var grad = this;
if($(grad).attr('gradientUnits') === 'userSpaceOnUse') {
// TODO: Support more than one element with this ref by duplicating parent grad
// TODO: Support elements with stroke grad
var elems = $(svgcontent).find('[fill=url(#' + grad.id + ')]');
if(!elems.length) return;
// get object's bounding box
var bb = elems[0].getBBox();
// bb.x, bb.y
// bb.width, bb.height
var tot_w = bb.x + bb.width;
var g_coords = $(grad).attr(['x1', 'y1', 'x2', 'y2']);
g_coords.x1 -= bb.x;
g_coords.y1 -= bb.y;
g_coords.x2 -= bb.x;
g_coords.y2 -= bb.y;
var new_x1 = g_coords.x1 / bb.width;
var new_y1 = g_coords.y1 / bb.height;
var new_x2 = g_coords.x2 / bb.width;
var new_y2 = g_coords.y1 / bb.height;
$(grad).attr({
x1: new_x1,
y1: new_y1,
x2: new_x2,
y2: new_y2
});
grad.removeAttribute('gradientUnits');
}
});
// Fix XML for Opera/Win/Non-EN
if(!support.goodDecimals) {
canvas.fixOperaXML(svgcontent, newDoc.documentElement);