Short form:
From within inkscape, how does one calculate the width of a string given its text, font, and font size? This will not be drawn immediately and sizes will not (normally) be integers. These strings are, at the point this is being calculated, not yet part of any part of the drawing.
Long form:
I have been trying to figure out how to get from a set of ~adjacent input text strings from an EMF file to an editable SVG format. That is to address this problem:
http://saf.bio.caltech.edu/PPT_G_P_I/#I2P_formatted_strings
In the PowerPoint -> EMF -> Inkscape direction. Experimentation has shown that so long as all <tspans> have absolute x,y coordinates the text editing is broken. For instance, press "enter" and that tspan folds back on itself. Text editing works OK though for an SVG like
<tspan x="100" y="100" sodipodi:role="line"> (many tspans with only dx,dy offsets) </tspan> <tspan x="100" y="200" sodipodi:role="line"> (many tspans with only dx,dy offsets) </tspan>
Now the problem is that in order to convert from (x,y,text) format, which is what comes out of the EMF, like:
{100,100,"line of text") (150,105,"superscript") (160,100"" more text on the same line")
to (dx,dy,text) format one needs to know exactly how long each string is in the specified font/character size. With that one extra piece of information it is trivial to convert to:
(0,0,"line of text") (22.5,5,"superscript") (0,-5,"more text on the same line")
which can then be used to make editable SVG. In many cases, if adjacent strings really were originally part of a line of text, then dx is 0, but it need not be, and there is no way to know without calculating the string widths.
Specifically, we know:
1. every character in the string 2. the font name 3. the font size 4. where the string starts (x1,y1) 5. where the next string starts (x2,y2)
and from that we need
6 xfinal = where the string stops
to calculate
dx = x2-xfinal
Thanks,
David Mathog mathog@...1176... Manager, Sequence Analysis Facility, Biology Division, Caltech