Made import of gradients on stroke work, fixed issue 516

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1487 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-03-29 18:06:51 +00:00
parent effc4200e9
commit 104d4370a1
2 changed files with 45 additions and 29 deletions

View File

@ -192,10 +192,19 @@
}
})();
// Load extensions
var extFunc = function() {
$.each(curConfig.extensions, function() {
$.getScript(curConfig.extPath + this);
});
}
// Load extensions
// Bit of a hack to run extensions in local Opera
if(window.opera && document.location.href.indexOf('http') !== 0) {
setTimeout(extFunc, 1000);
} else {
extFunc();
}
$.svgIcons(curConfig.imgPath + 'svg_edit_icons.svg', {
w:24, h:24,

View File

@ -5881,45 +5881,52 @@ function BatchCommand(text) {
});
// convert gradients with userSpaceOnUse to objectBoundingBox
$(svgcontent).find('linearGradient').each(function() {
$(svgcontent).find('linearGradient, radialGradient').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 + ')]');
var elems = $(svgcontent).find('[fill=url(#' + grad.id + ')],[stroke=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;
if(grad.tagName === 'linearGradient') {
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
x1: (g_coords.x1 - bb.x) / bb.width,
y1: (g_coords.y1 - bb.y) / bb.height,
x2: (g_coords.x2 - bb.x) / bb.width,
y2: (g_coords.y1 - bb.y) / bb.height
});
grad.removeAttribute('gradientUnits');
} else {
// Note: radialGradient elements cannot be easily converted
// because userSpaceOnUse will keep circular gradients, while
// objectBoundingBox will x/y scale the gradient according to
// its bbox.
// For now we'll do nothing, though we should probably have
// the gradient be updated as the element is moved, as
// inkscape/illustrator do.
// var g_coords = $(grad).attr(['cx', 'cy', 'r']);
//
// $(grad).attr({
// cx: (g_coords.cx - bb.x) / bb.width,
// cy: (g_coords.cy - bb.y) / bb.height,
// r: g_coords.r
// });
//
// grad.removeAttribute('gradientUnits');
}
}
});
// Fix XML for Opera/Win/Non-EN
if(!support.goodDecimals) {
canvas.fixOperaXML(svgcontent, newDoc.documentElement);