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

View File

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