Hello.
I need to get the geomtery of a text element. Please cosider the following code:
------------ <svg width="26in" height="16in" viewBox="0 0 26 16" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd" clip-rule="evenodd" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect id="textbbox_2_check" x="5.3733333333333" y="11.31" width="15.773333333333" height="2.2966666666667" style="fill: none; stroke: #000000; stroke-width: 0.01" />
<text id="text_2_check" transform="translate(0,0)" style=" text-anchor:start; font-size: 1; font-family: Arial; fill: #000000; fill-opacity: 1; stroke: none;">Text Line 1</text>
</svg> ------------
As you can see, there is a simple text and a rect. What i need to do is "fit" the text inside that rect. To do this, i use this file (which is a temp file) to query width and height in order to obtain values to apply the correct scale transforms over it. The problem is that it seems texts are not parsed correctly at all. As far as i know, SVG user units should be 90 for 1 inch. So, doing [query-result]/90 gives me the inches value.
Here, the list of query commands performed on both text and rect elements. Below each command, i wrote 3 numbers: [query-result] - [query-result]/90 - inkscape (gui) shown inches value
inkscape -I "text_2_check" -W test.svg 419.81271 - 4.6645856666666666666666666666667 - 5.042
/usr/bin/inkscape -I "text_2_check" -H test.svg 87.39 - 0.971 - 0.730
/usr/bin/inkscape -I "textbbox_2_check" -W test.svg 1420.5 - 15.783333333333333333333333333333 - 15.783
/usr/bin/inkscape -I "textbbox_2_check" -H test.svg 207.6 - 2.3066666666666666666666666666667 - 2.307
As you can see, the "textbbox_2_check" values are correct, and query/gui values are equal. But "text_2_check" values are completely different... Why? Is there a way to get the correct width/height of a text element?
I really need this in order to make the correct "fitting" scaleratio, but i'm completely lost here. Can anyone help? Thanx in advance.
Alex
On Oct 5, 2007, at 7:30 PM, Alexander Bonivento wrote:
The problem is that it seems texts are not parsed correctly at all. As far as i know, SVG user units should be 90 for 1 inch. So, doing [query-result]/90 gives me the inches valu
One warning up front is that SVG user units can be *any* DPI. There is a common defalt many programs use, but they are free to interpret SVG user units as the see fit.
Might be 90 DPI, might be 96, might be 100, might be 72...
And if a program can determine the actual DPI of the monitor in use at the moment, it's recommended to use it.
Jon A. Cruz wrote:
On Oct 5, 2007, at 7:30 PM, Alexander Bonivento wrote:
The problem is that it seems texts are not parsed correctly at all.
As far as i know, SVG user units should be 90 for 1 inch.
So, doing [query-result]/90 gives me the inches valu
One warning up front is that SVG user units can be *any* DPI. There is a common defalt many programs use, but they are free to interpret SVG user units as the see fit.
Might be 90 DPI, might be 96, might be 100, might be 72...
And if a program can determine the actual DPI of the monitor in use at the moment, it's recommended to use it.
Absolutely true, but this does not change the main issue. 90 should be inkscape default, but considering i'm looking for values to create a ratio, the used DPI doesn't really matter. The commands i wrote in my first post was all made with the same tool (inkscape) and on the same file. So, i think i should expect same used DPI, correct?
Infact, values of query/tool about the rect object are correct: my Q is about the text element values, which are not.
On 10/5/07, Alexander Bonivento <redna379@...12...> wrote:
inkscape -I "text_2_check" -W test.svg 419.81271 - 4.6645856666666666666666666666667 - 5.042
I did the same test with your file and see no discrepancy:
416.60156 4.62888888889 4.629
The only explanation I can suggest is that on your system, Inkscape can find some font when run with the GUI and cannot find it when run without GUI, and as a result this text string gets rendered in different fonts in these cases and thus gets different width. It's hard for me to debug this, however, because I cannot reproduce this.
Thank you for your reply. I forgot to mention one very important thing: the commandline version is running on a Linux server, while the GUI version is on a windows machine. I cannot check the GUI on linux (it's a remote server in which i only have shell privileges), so i can only think about differences between window and linux font management system (font are the same in both machines).
Anyhow, i solved in a different way: as the main problem of SVG texts is their variable size, i simply rendered a temp SVG with the text into a PDF file, and then converted it in PNG using imagemagick. This way i was able to get from the PNG the size of text as rendered by inkscape, and this permitted me to create the final file with the correct aspect ratios.
It is good in any case to know you saw no discrepancy, this may be helpful in future, to me.
Again, thank you all for your help!
Alex
bulia byak wrote:
On 10/5/07, Alexander Bonivento <redna379@...12...> wrote:
inkscape -I "text_2_check" -W test.svg 419.81271 - 4.6645856666666666666666666666667 - 5.042
I did the same test with your file and see no discrepancy:
416.60156 4.62888888889 4.629
The only explanation I can suggest is that on your system, Inkscape can find some font when run with the GUI and cannot find it when run without GUI, and as a result this text string gets rendered in different fonts in these cases and thus gets different width. It's hard for me to debug this, however, because I cannot reproduce this.
On 10/7/07, Alexander Bonivento <redna379@...12...> wrote:
Thank you for your reply. I forgot to mention one very important thing: the commandline version is running on a Linux server, while the GUI version is on a windows machine.
Ah, well, then indeed it's most likely caused by a font discrepancy. I tested both on the same Linux machine.
participants (3)
-
Alexander Bonivento
-
bulia byak
-
Jon A. Cruz