0

I have some graphics done in my favourite Inkscape and I need it to be Tiny SVG compliant in order to be able to drive it later pragmatically by QtSVG.

Collecting tiny bits and pieces from many different sources, I came with a following procedure:

  1. Save as..
  2. Choosing "Optimized SVG"
  3. In the optimization dialog I checked (translated to EN):
    • Options
      • [x] Shorten color values
      • [x] Convert CSS properties to XML
      • [x] Collapse groups
      • [x] Create groups for similar attributes
      • [ ] Keep editor data
      • [ ] Keep unreferenced definitions
      • [x] Work around renderer bugs
    • SVG output
      • [ ] Remove XML declaration
      • [x] Remove metadata <<< Note: Important <<<
      • [ ] Remove comments
      • [x] Embed raster images
      • [ ] Enable viewboxing
      • [x] Format output with line-breaks and indentation
      • [ ] Strip the "xml:space" attribute from the root SVG element
    • ID
      • [ ] Remove unused IDs
      • [ ] Shorten IDs
      • [x] Preserve manually created IDs not ending with digits

Now it works, if the graphics does not contain a text. However I need the graphics to contain text, basically AFAIK meaning it must contain <text> elements.

My Inkscape is 1.0.1 running on OpenSuSE Leap 15.3 Linux system with "Optimized SVG" extension for Scour of version 0.31+. System tells me I have python3-scour 0.37-1.45.

The default format of the output for a text field from Inkscape is:

<text id="T1m" transform="translate(-4.4781 -24.9064)"
 fill="#000000" font-family="sans-serif" font-size="10.5833px"
 letter-spacing="0px" word-spacing="0px">
   <tspan x="46.580078" y="138.18859">
      <tspan>T</tspan>
      <tspan baseline-shift="sub" font-size="65%">1m</tspan> 
      <tspan>=15°C</tspan>
   </tspan>
</text>

That gives me errors like:

qt.svg: <input>:207:212: Could not add child element to parent element because the types are incorrect.
qt.svg: <input>:207:273: Could not add child element to parent element because the types are incorrect.
qt.svg: <input>:207:298: Could not add child element to parent element because the types are incorrect. 

...and the program subsequently crashes.

If I manually edit it removing <tspan> elements:

  <text id="T1m" transform="translate(-4.4781 -24.9064)" fill="#000000" font-family="sans-serif" font-size="10.5833px" letter-spacing="0px" word-spacing="0px">T1m=15°C</text>

...then I get no errors, but also no text in the graphics.

Could anyone advise how to get a compliant Tiny SVG from Inkscape? I.e. a change to the output dialogue, a CLI conversion tool or even a text-editor changes that make the text elements to work...

3
  • Hi. Welcome to GDSE. I don't see how this is a graphic design question TBH. Changes to the way Inkscape exports SVGs is not something a graphic designer can really help you with. If you think there is a bug then better to contact the developers. Sorry about that.
    – Billy Kerr
    May 29 at 18:42
  • If you don't need actual editable text, you could convert text to outlines using Path > Object to Path, but I've no idea if this will work for you.
    – Billy Kerr
    May 29 at 18:45
  • No I don't really think there's a bug in Inkscape, I think it's about to know what to set. I assume there are people dealing with SVG and particularly Tiny SVG, who are accustomed to the peculiarities of such export or conversion :-). And unfortunately, I do need to dynamically modify the text... May 29 at 18:57

1 Answer 1

0

Since there was no answer, the only way I could resolve it is to manually edit the SVG file using the Tiny SVG documentation.

So I turned the line with text property mentioned in the question into following one:

<text id="T1m" fill="#000000" font-family="sans-serif" font-size="10px" letter-spacing="0px" word-spacing="0px" x="50" y="150">T1m=15°C</text>

Particularly the subscript and some tspan nesting and/or attributes seem to create issues. I needed to recalculate position coordinates too.

I'll see if I improve and automate this in future. Will expand this answer in such case.

1
  • TSPAN elements will be added to text in Inkscape automatically, but you can remove them in the XML editor right inside Inkscape. See example here
    – Billy Kerr
    Jun 3 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.