Hello group,
here is a simple flowtext function that uses numbers of
characters instead of pixel width (which shouldn't be too
hard to implement, too). Maybe it's useful.
Willem
nodes.svg:
<?xml version="1.0"?>
<svg onload="replacetext(evt)" >
<script xlink:href="nodes.es" />
<text id="sampletext" y="20">
<tspan x="5" dy="1em">line 1</tspan>
<tspan x="5" dy="1em">line 2</tspan>
<tspan x="5" dy="1em">line 3</tspan>
<tspan x="5" dy="1em">line 4</tspan>
<tspan x="5" dy="1em">line 5</tspan>
<tspan x="5" dy="1em">line 6</tspan>
<tspan x="5" dy="1em">line 7</tspan>
<tspan x="5" dy="1em">line 8</tspan>
<tspan x="5" dy="1em">line 9</tspan>
<tspan x="5" dy="1em">line 10</tspan>
</text>
</svg>
nodes.es:
function replacetext(evt) {
svgns="http://www.w3.org/2000/svg";
nodes = window.svgDocument.getElementById("sampletext").
getElementsByTagNameNS(svgns,
"tspan");
len = nodes.length;
for (i=0; i<len; i++)
nodes.item(i).firstChild.data="node "+i;
var newtext = "This is a text of the flowtext function. It should
have a maximum line width of 25 characters.";
flowtext(nodes, newtext, 25);
}
function max(value1, value2)
{
return value1 > value2 ? value1 : value2;
}
function flowtext(nodes, newtext, textwidth)
{
numnodes = nodes.length;
textlen = newtext.length;
leftindex = 0;
rightindex = textwidth;
for (i=0; i < numnodes; i++)
{
line = newtext.substring(leftindex, rightindex);
lastspaceidx = line.lastIndexOf(" ");
lastdashidx = line.lastIndexOf("-");
lastbreakidx = max(lastspaceidx, lastdashidx);
if (lastbreakidx < textwidth/2)
lastbreakidx = textwidth; // I hate short lines
nodes.item(i).firstChild.data = line.substring(0,
lastbreakidx+1);
leftindex += lastbreakidx+1;
rightindex = leftindex+textwidth;
}
}
PS: I still use different files for svg and script, because
the <![CDATA[...]]> tags have my syntax highlighting confounded.
-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my
membership"
----
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/svg-developers/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/