Wrong Textposition after converting svg

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Alex Dobusch
Posts: 10
Joined: 2011-10-11T07:50:11-07:00
Authentication code: 8675308

Wrong Textposition after converting svg

Post by Alex Dobusch »

Hello

I'm using ImageMagick-6.7.3-7 and Ghostscript 9.0.4.

My svg-file looks like this:

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<svg version="1.1" x="0px" y="0px" width="250px" height="200px" viewBox="0 0 250 200" enable-background="new 0 0 250 200" space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <g id="mch">
    <g id="eingang_passagen">
      <rect x="167.402" y="0.158" fill="none" width="42.522" height="19.843"/>
      <text transform="matrix(1 0 0 1 171.3022 7.4577)" fill="#FF0000" font-size="10">Passage </text>
      <text transform="matrix(1 0 0 1 176.1074 19.4577)" fill="#FF0000" font-size="10">Hall 5</text>
    </g>
    <g id="booth_outlines">
      <polygon fill="#00FFFF" points="124.882,20.112 82.363,20.112 82.363,20 20,20 20,122.047 82.363,122.047 82.363,48.346 124.882,48.346 "/>
    </g>
    <g id="booths">
      <text transform="matrix(1 0 0 1 22.0004 25.6042)" fill="#FF0000" font-size="4">A27</text>
    </g>
  </g>
</svg>
With
convert "test.svg" "test.png"
all text items have the wrong position, outside the image.

Convert creates a temp-file with (just a part with the text from the 'booths'-group)

Code: Select all

affine 1 0 0 1 22.0004 25.6042
fill '#FF0000'
font-size 4
text 167.402,0.158 'A27'
As you can see, the FormatLocaleFile for 'text' uses x and y from the 'rect'-element in the 'eingang_passagen'-group, which has nothing to do with this text item.

After debugging the file 'coders\svg.c' I found at line 2405 following code:

Code: Select all

(void) FormatLocaleFile(svg_info->file,"text %g,%g '%s'\n",
    svg_info->bounds.x,svg_info->bounds.y,text);
Wouldn't it be better to set svg_info->bounds to 0 if there is a 'transform="matrix(a,b,c,d,e,f)"''?

Alex
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Wrong Textposition after converting svg

Post by magick »

We can reproduce the problem you reported. Look for a patch in the Subversion trunk to fix the problem within the next few days. Thanks.
Alex Dobusch
Posts: 10
Joined: 2011-10-11T07:50:11-07:00
Authentication code: 8675308

Re: Wrong Textposition after converting svg

Post by Alex Dobusch »

I've debugged the latest version from the subversion trunk (rev. 6074).
In file 'coders\svg.c' at line 2407 you changed from

Code: Select all

(void) FormatLocaleFile(svg_info->file,"text %g,%g '%s'\n",
svg_info->bounds.x,svg_info->bounds.y,text);
to

Code: Select all

(void) FormatLocaleFile(svg_info->file,"text 0,0 '%s'\n",text);
I think this is wrong, because if a text-item has a x/y property in place of a transformation property, the text will be placed at position 0,0.
My suggestion: replace the new code with the old and insert at line 1092 following code:

Code: Select all

      if (LocaleCompare((const char *) name,"text") == 0)
        {
          (void) FormatLocaleFile(svg_info->file,"push graphic-context\n");
          svg_info->bounds.x = 0;
          svg_info->bounds.y = 0;
          svg_info->bounds.width = 0;
          svg_info->bounds.height = 0;
          break;
        }
Alex
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Wrong Textposition after converting svg

Post by magick »

Look for a patch to the ImageMagick subversion trunk by sometime tomorrow. Thanks.
Alex Dobusch
Posts: 10
Joined: 2011-10-11T07:50:11-07:00
Authentication code: 8675308

Re: Wrong Textposition after converting svg

Post by Alex Dobusch »

With the lastes trunk it works.
Thank you
Alex
Post Reply