Sharp: SVG Text dy and dx is not handled correctly

Created on 13 Aug 2019  路  6Comments  路  Source: lovell/sharp

We have discovered that when trying to do multiline text in SVG the dy and dx attributes are not treaded correctly.
Sample svg:

<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"  viewBox="0 0 178 178" version="1.1">
<style type="text/css">
    svg {
        font-family: Times;
        font-size: 44px;
    }
  </style>
  <text  x="0" y="0">
  <tspan x="0" dy="1.2em">Tata</tspan>
  <tspan x="0" dy="1.2em">Toto tu</tspan>
  <tspan x="0" dy="1.2em">ppo</tspan>
  </text>
</svg>

Expected output:
text

Acutal output:
text

If I change the dy's of the svg to

  <text  x="0" y="0">
  <tspan x="0" dy="1.2em">Tata</tspan>
  <tspan x="0" dy="2.4em">Toto tu</tspan>
  <tspan x="0" dy="3.6em">ppo</tspan>
  </text>

It produces the "correct" output.

I believe that it could be related to rsvg and it might be fixed in 2.45.7

  • Fix #481: Don't ignore the first x/y/dx/dy in text/tspan elements if
    there is more than one position specified.

But I have not been able to verify this because I'm having troubles with figuring out how to build sharp with a newer version of rsvg.

bug ready-to-ship

All 6 comments

Using the rsvg-convert command line tool, librsvg version 2.44.10 works but version 2.45.5 (as used by the latest sharp) does not. The latest librsvg master branch (version 2.45.91) also fails.

This means it is very likely to be a recent regression in librsvg, possibly as a result of the move from C to Rust. Please can you report this upstream.

Which version of sharp uses 2.44.10?

For Linux, the libvips v8.7.0 tarball as used by sharp v0.21.x provides librsvg v2.43.4.

$ npm i [email protected]
$ node -e "console.log(require('sharp').versions.svg)"
2.43.4

From upstream: This is fixed now on master, and the fix will appear in 2.45.91
https://gitlab.gnome.org/GNOME/librsvg/issues/494#note_579774

v0.24.0 is now available with a prebuilt librsvg with the upstream fix. Thanks for reporting this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natural-law picture natural-law  路  3Comments

zhump picture zhump  路  3Comments

OleVik picture OleVik  路  3Comments

Andresmag picture Andresmag  路  3Comments

zilions picture zilions  路  3Comments