Inkscape.org
Beyond the Basics Font size as given in the SVG file
  1. #1
    Riccardo Riccardo @fintatarta

    Dear all,

    I need to find (even a very rough approximation) the area taken by a short text (not more than one line) on the exported PNG image. I need this because I want to use (in an application of mine that will be used only internally) that area as a "sensitive area" that can respond to clicks.  Because of this, even a very rough approximation would suffice.

    My idea was to approximate the average character size as a square, therefore the area would have the font size as height and the font size times the number of characters as width.  Yes, very crude, but it could be enough for my purposes, I need to try. 

    I can easily find the text nodes of interest.  However, if I look inside the SVG file (see attachment) I see that

    1. The font size is given in pixel, while the document units are mm.  This sounds strange to me since the conversion mm <-> pixels depends on the resolution. I would had expected that point was used instead
    2. Even the size in pixel is totally off. If you open with a text editor the attached file you can see that font-size is 7.055px, while the UI says that font-size is 26.666px (see attached picture)
    3. Funny enough, if you divide font-size by stroke-width you get approximately the true size (still in pixel), but I guess that this is just a random thing.

    I understand that the true font-size can be changed by any transform applied to the node or its ancestors, but a visual inspection (and Ctrl-F transf, too) did not find anything.

    I guess there is a scale factor hidden somewhere, but I cannot imagine where.

    I am using Inkscape 1.1.2 (0a00cf5339, 2022-02-04) on Ubuntu 22.04.5 LTS

    Linux rpr-LIFEBOOK-A357 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

     

    Screenshot From 2024 10 02 13 45 16
    010 001 A
  2. #2
    Tyler Durden Tyler Durden @TylerDurden

    I'd try using a template for screen that has px as the unit and a scale of 1. This should have no hidden transforms.

    I'd also consider updating to Inkscape version 1.3.2.

     

  3. #3
    Riccardo Riccardo @fintatarta

    I tried both suggestions, but with no result.  The svg file still has a rescaled font size.  Here it is an excerpt

    style="font-size:6.35px;line-height:1.25;font-family:'Latin Modern Roman';-inkscape-font-specification:'Latin Modern Roman, ';font-variant-ligatures:none;stroke-width:0.264583"

    Note that the real font size is 24px, as shown the screenshot. 

    Meanwhile I tried to find more information and did some experiments changing this and that and it would seem that the scale factor is the scale used to match the viewport to the svg dimensions specified in attributes width and height (when expressed in pixels).  A bit like the font size was expressed in the viewport reference.  Hmmm... It would almost make sense.  Am I right?

    Screenshot
    Hh
  4. #4
    Tyler Durden Tyler Durden @TylerDurden
    *

    The svg document shared above has a scale of 3.779528. Most Inkscape templates have px as the units and scale of 1, as described earlier.

    Please try with the attached svg. 

     

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Font size as given in the SVG file