From 230479e038e677650d82a742baf5c43f4a71a41f Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Fri, 22 Feb 2013 15:46:11 +0000 Subject: [PATCH] Fix issue 1053: tspans now get remapped when their text parent are translated git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2460 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/coords.js | 14 +------------- editor/recalculate.js | 17 +++++++++++++++++ test/recalculate_test.html | 9 ++++----- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/editor/coords.js b/editor/coords.js index 85391ee1..8ae98266 100644 --- a/editor/coords.js +++ b/editor/coords.js @@ -93,19 +93,6 @@ svgedit.coords.remapElement = function(selected, changes, m) { t_new = svgedit.math.matrixMultiply(existing.inverse(), m, existing); changes.x = parseFloat(changes.x) + t_new.e; changes.y = parseFloat(changes.y) + t_new.f; - // TODO(codedread): Special handing for tspans: - // - // - // ... - // - // - // - // Note that if the element's x/y coordinates are being - // adjusted, the tspan's x/y coordinates also need to be similarly - // transformed as the coordinate space is not nested: - // - // ... - // } else { // we just absorb all matrices into the element and don't do any remapping var chlist = svgedit.transformlist.getTransformList(selected); @@ -171,6 +158,7 @@ svgedit.coords.remapElement = function(selected, changes, m) { changes.y2 = pt2.y; // deliberately fall through here case 'text': + case 'tspan': case 'use': finishUp(); break; diff --git a/editor/recalculate.js b/editor/recalculate.js index 9a75bc5d..53a44310 100644 --- a/editor/recalculate.js +++ b/editor/recalculate.js @@ -754,6 +754,23 @@ svgedit.recalculate.recalculateDimensions = function(selected) { tlist.appendItem(newRot); } } + // We have special processing for tspans: Tspans are not transformable + // but they can have x,y coordinates (sigh). Thus, if this was a translate, + // on a text element, also translate any tspan children. + if (selected.tagName == 'text') { + var children = selected.childNodes; + var c = children.length; + while (c--) { + var child = children.item(c); + if (child.tagName == 'tspan') { + var tspanChanges = { + x: $(child).attr('x') || 0, + y: $(child).attr('y') || 0 + }; + svgedit.coords.remapElement(child, tspanChanges, m); + } + } + } } // [Rold][M][T][S][-T] became [Rold][M] // we want it to be [Rnew][M][Tr] where Tr is the diff --git a/test/recalculate_test.html b/test/recalculate_test.html index ca0481bf..f6ebc990 100644 --- a/test/recalculate_test.html +++ b/test/recalculate_test.html @@ -117,9 +117,8 @@ tearDown(); }); - test('Test recalculateDimensions() on text w/tspan with simple translate', function() { - expect(3); + expect(5); setUpTextWithTspan(); elem.setAttribute('transform', 'translate(100,50)'); @@ -132,9 +131,9 @@ equal('300', elem.getAttribute('x')); equal('200', elem.getAttribute('y')); -// var tspan = elem.firstElementChild; -// equal('300', tspan.getAttribute('x')); -// equal('200', tspan.getAttribute('y')); + var tspan = elem.firstElementChild; + equal('300', tspan.getAttribute('x')); + equal('200', tspan.getAttribute('y')); tearDown(); });