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
master
Jeff Schiller 2013-02-22 15:46:11 +00:00
parent 355492050c
commit 230479e038
3 changed files with 22 additions and 18 deletions

View File

@ -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:
// <g transform="translate(-100,0)">
// <text x="100" y="100">
// <tspan x="200" y="100">...</tspan>
// </text>
// </g>
//
// Note that if the <text> 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:
// <text x="0" y="100">
// <tspan x="100" y="100">...</tspan>
// </text>
} 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;

View File

@ -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

View File

@ -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();
});