From 104d4370a1899a30153304936d3a7a9b7e83c657 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Mon, 29 Mar 2010 18:06:51 +0000 Subject: [PATCH] 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 --- editor/svg-editor.js | 15 ++++++++--- editor/svgcanvas.js | 59 +++++++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 41ddb293..bd71c7c9 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -192,10 +192,19 @@ } })(); + var extFunc = function() { + $.each(curConfig.extensions, function() { + $.getScript(curConfig.extPath + this); + }); + } + // Load extensions - $.each(curConfig.extensions, function() { - $.getScript(curConfig.extPath + this); - }); + // 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, diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 260c341c..edb33019 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -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']); + + $(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 + }); + + 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(['x1', 'y1', 'x2', 'y2']); +// 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'); + } - 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);