Page 1 of 1

Problem with dy in text->tspan

Posted: 2019-09-17T09:12:54-07:00
by fedushok
Hello!

This code works fine in browsers and inkscape.

Code: Select all

<svg …>
    <line x1="-60" y1="0" x2="60" y2="0" transform="translate(100,160)" style="…"/>
    <circle r="5" transform="translate(100,160)" style="…"/>
    <text x="100" y="160" dy="-30" style="… text-anchor:middle; …">
        X
        <tspan dy="20" style="…">
            Y
        </tspan>
    </text>
</svg>
It gives the following picture.
tspan.png
tspan.png (2.39 KiB) Viewed 12610 times
But with imagick 3.4.4 (Imagick compiled with ImageMagick version - ImageMagick 6.9.10-43 Q16 x86_64 2019-05-02, Imagick using ImageMagick library version - ImageMagick 6.9.10-64 Q16 x86_64 2019-09-09, ImageMagick release date - 2019-09-09) it gives not correct result.
tspan_.png
tspan_.png (2.06 KiB) Viewed 12610 times
It seems that <tspan> in <text> “knows” nothing about non zero value of “dy” in it’s parent. If “dy” in <text> replace with equvalent tranform=”translate(0,-…)” code will work ok.
Is it a bug? If it is, then in what version of imagemagick it is fixed?

If anybody has version older then in my question, please check this problem.
php script and svg file are attached.
source svg file

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200" version="1.1">
    <line x1="-60" y1="0" x2="60" y2="0" transform="translate(100,160)" style="stroke:#000000"/>
    <circle r="5" transform="translate(100,160)" style="fill:#000000"/>
    <text x="100" y="160" dy="-30" style="font-size:100px; font-family: Times New Roman; text-anchor:middle; fill:#000000;stroke:none"
            >X<tspan dy="20" style="font-size:60px">Y</tspan></text>
</svg>
php script for testing

Code: Select all

<?php
$fileName = 'tspan.svg';
$svg = file_get_contents($fileName);
$image = new Imagick();
$image->readImageBlob($svg);
$image->setImageFormat('png');
$image->setImageType(Imagick::IMGTYPE_GRAYSCALE);
header('Content-type: image/png');
echo $image;
$image->clear();
$image->destroy();
exit;

Re: Problem with dy in text->tspan

Posted: 2019-09-17T09:17:43-07:00
by fmw42
ImageMagick can use one of 3 SVG renderers list from best to worst results: Inkscape, RSVG delegate or MSVG/XML. So what renderer is being used by the ImageMagick called by Imagick? If you install Inkscape on the system that is being used by Imagick, then if ImageMagick can find it, it will be used in preference to the other renderers. Your Imagick/Imagemagick system is likely just using MSVG/XML by default, if neither RSVG nor Inkscape are installed.

convert -list format

will tell you which renderer is used. Look at the end of the line for SVG. If it says XML, then it is MSVG/XML. Otherwise it will say RSVG. If Inkscape is installed, it may still show those. But you should then check the version of inkscape separately.

Bottom line -- install Inkscape.

Re: Problem with dy in text->tspan

Posted: 2019-09-17T09:55:39-07:00
by fedushok
I use ImageMagick on server, not locally. How can I know what renderer is being used by the ImageMagick in this case?

Re: Problem with dy in text->tspan

Posted: 2019-09-17T10:24:41-07:00
by fedushok
It should be noted that I didn't have such problem with previous version (I don't know which version it was). I don't use ImageMagick in sophisticated operations, I use it only to convert svg to png and I'm not experienced in ImageMagick.
I asked hoster your question, but I hope my problem is a bug and it is fixed in older versions. I need to know which version, may be hoster will install it.

Re: Problem with dy in text->tspan

Posted: 2019-09-17T11:05:52-07:00
by fedushok
I got an answer from hoster: MSVG.

Re: Problem with dy in text->tspan

Posted: 2019-09-17T12:07:46-07:00
by fmw42
You can find out by running the following in PHP exec()

exec("convert -list format | grep 'SVG'")