kimoa / svg-edit

Automatically exported from code.google.com/p/svg-edit
MIT License
3 stars 0 forks source link

Moving absolutely positioned tspans incorrectly #797

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Paste in the following SVG document:

<svg width="400" height="300" xmlns="http://www.w3.org/2000/svg">
 <g>
  <title>Layer 1</title>
  <text fill="#000000" font-family="Bitstream Vera Sans" x="200" y="200" font-style="normal" font-size="40px" xml:space="preserve" font-weight="normal" id="text3642">
   <tspan font-family="Arial" x="200" y="200" font-style="normal" font-weight="normal" id="tspan3644">Browser</tspan>
  </text>
 </g>
</svg>

2. Drag the text around

What is the expected output? What do you see instead?

The text should move where the user dragged, but it snaps back to its original 
location, though the selection box stays where you dropped it.  

The reason is because we do not properly transform <tspan> elements that are 
absolutely positioned (the x,y on the <text> and the <tspan> are identical).

Unfortunately, this type of code is commonly produced by Inkscape.

Original issue reported on code.google.com by codedr...@gmail.com on 17 Mar 2011 at 6:17

GoogleCodeExporter commented 9 years ago

Original comment by codedr...@gmail.com on 17 Mar 2011 at 6:17

GoogleCodeExporter commented 9 years ago

Original comment by codedr...@gmail.com on 17 Mar 2011 at 6:20

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This patch solves the dragging issue, but since svg edit doesn't support tspans 
or multiline text, if you edit the text it will remove them (flattening 
multiline text).

Original comment by duopi...@gmail.com on 23 Mar 2012 at 11:25

Attachments:

GoogleCodeExporter commented 9 years ago
Hmmm just tested a bit more and it breaks undo. Any pointers appreciated.

You also can't change the font because it's overridden by the tspan, but this 
is a different bug.

Original comment by duopi...@gmail.com on 23 Mar 2012 at 11:42

GoogleCodeExporter commented 9 years ago
If undo is your main issue you can always manipulate the undo buffer manually. 
Check out history.js. You can get the buffer with svgCanvas.undoMgr object.

Original comment by asyazwan on 23 Mar 2012 at 11:59

GoogleCodeExporter commented 9 years ago
This patch may not work if x or y are not defined (for instance, if editor did 
use dy or dx or if tspan are just set up without x/y attributes)

I propose the following modification :

var tspan = selected.querySelectorAll('tspan');
var i = tspan.length
while(i--) {
  var selX = convertToNum("x", selected.getAttribute('x'));
  var tx = convertToNum("x", tspan[i].getAttribute('x'));
  var selY = convertToNum("y", selected.getAttribute('y'));
  var ty = convertToNum("y", tspan[i].getAttribute('y'));
  var offset = new Object();
  if (!isNaN(selX) && !isNaN(tx) && selX!=0 && tx!=0 && changes.x)
    offset.x = changes.x - (selX - tx);
  if (!isNaN(selY) && !isNaN(ty) && selY!=0 && ty!=0 && changes.y)
    offset.y = changes.y - (selY - ty);
  if (offset.x || offset.y)
    assignAttributes(tspan[i], offset, 1000, true);
}

Original comment by pierre.s...@gmail.com on 23 Mar 2012 at 5:07

GoogleCodeExporter commented 9 years ago

Original comment by asyazwan on 4 Dec 2012 at 6:19

GoogleCodeExporter commented 9 years ago

Original comment by asyazwan on 4 Dec 2012 at 6:25

GoogleCodeExporter commented 9 years ago

Original comment by bret...@gmail.com on 7 Apr 2014 at 3:38

GoogleCodeExporter commented 9 years ago

Original comment by bret...@gmail.com on 7 Apr 2014 at 3:45