Open GoogleCodeExporter opened 8 years ago
For my own needs I created a quick/temporary solution. Basically I look up the
'older
sibling' of the current node and calculate the offset based on the location and
width
of the older sibling. It works for my purposes but should be reviewed and
probably
refactored.
In the 'getAttribute'-function in SVGTextNode.as I replaced:
} else if ( (name == "x" || name == "y") ) {
...
With
} else if ( (name == "x" || name == "y") ) {
if (_getAttribute(name)==null) {
var index:int = svgParent.svgChildren.indexOf(this);
if (index>0) {
var prevSibling:SVGNode = svgParent.svgChildren[index-1];
if (prevSibling is SVGTspanNode) {
if (name == "x") {
this.setAttribute("x",
Number(prevSibling.getAttribute("x"))+Number(prevSibling.topSprite.width)).toStr
ing());
} else if (name == "y") {
this.setAttribute("y",prevSibling.getAttribute("y"));
}
}
}
}
...
Original comment by Matthijs.Mullender
on 12 Jan 2010 at 2:20
Thanks, Matthijs, but unfortunately, that approach doesn't help my example.
For the key line in the example,
<text font-family="Arial" font-size="144" fill="black" x="145" y="254">one
<tspan fill="red">two</tspan> three</text>
There is no (previous) tspan sibling to query for an x attribute + width.
The example is a simple case of the challenge of text layout. Essentially, the
positioning of glyphs in each descendant node of a text element can depend on
all/some/none of the descendants as well as the root text node itself.
For example, if text-anchor="middle" were added to the text element of my
example
<text text-anchor="middle" x="145" y="254">one <tspan fill="red">two</tspan>
three</text>
The widths of all child nodes would be required before the correct positioning
could
be determined.
Complicate it further with nested tspans , x,y lists and <a> elements, and it
quickly
becomes very difficult to manage text layout from the level of each individual
child
node. The layout needs to be managed at the level of the text element node
across
all descendants - a top down approach.
Original comment by k...@svgmaker.com
on 13 Jan 2010 at 8:29
Original issue reported on code.google.com by
k...@svgmaker.com
on 8 Dec 2009 at 3:30Attachments: