Page 1 of 1

percentage in SVG-TEXT

Posted: 2016-09-22T15:01:28-07:00
by ogduartev
¿Is this a bug?
ImageMagick does not properly displays TEXTS in SVG files when percentage is used to define position.
Example:
If the file tmp.svg is as shown bellow, 'display tmp.svg' will draw correctly both rectangles, but the text will be placed at (0,0)

===============tmp.svg===========

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg width='500px' height='500px'>
 <rect x='0%' y='0%' width='100%' height='100%' style="fill:rgb(255,255,255);stroke-width:3;stroke:rgb(0,0,0)"/>
 <rect x='10%' y='10%' width='10%' height='10%' style="fill:rgb(255,0,0);stroke-width:3;stroke:rgb(0,0,0)"/>
 <text  x='50%' y='50%' text-anchor='middle'>Some Text</text>
</svg>
=================================

I am using ImageMagick 6.8.9-9 on Ubuntu 16.04

Thanks in advance
Oscar Duarte

Re: percentage in SVG-TEXT

Posted: 2016-09-22T16:31:08-07:00
by snibgo
ogduartev wrote:... but the text will be placed at (0,0)
Are you sure? I think they are at (0.5,0.5) pixels. If you really want a percentage, try much larger ones, eg 1000%.

Re: percentage in SVG-TEXT

Posted: 2016-09-22T16:35:11-07:00
by magick
Try 'display msvg:tmp.svg'. Does that return expected results?

Re: percentage in SVG-TEXT

Posted: 2016-09-23T05:36:18-07:00
by ogduartev
snbigo, you are rigth: trying x=5000% y=5000% puts the text at (50,50) => absolute coordinates, not relative. I mean, ¡it is not a percentage!

magick, when I try 'display msvg:tmp.svg' I get the following message (also trying with sudo):

display: not authorized `/tmp/magick-3751vvQC3HE6NJOI' @ error/constitute.c/ReadImage/412.

Re: percentage in SVG-TEXT

Posted: 2016-09-23T07:30:35-07:00
by snibgo
ogduartev wrote:I mean, ¡it is not a percentage!
Yes it is a percentage of something, but not a percentage of the image width and height.

I find percentages in SVG confusing, so I don't use them. If you have a program or script that creates the SVG, it s simple to do the calculation in the code and create pixel coordinates.

Re: percentage in SVG-TEXT

Posted: 2016-09-23T09:03:13-07:00
by ogduartev
snibgo wrote: Yes it is a percentage of something, but not a percentage of the image width and height.
May be...

So, it is a genuine bug... and I am sure it was not present in previous releases (i am not sure since when it is):

I noticed the bug when I tried to convert an old svg file to eps. This old file was successfully converted two years ago when I had an ubuntu 12.04 (I do not know the ImageMagick release). But know, 'convert' fails...

Re: percentage in SVG-TEXT

Posted: 2016-09-23T09:18:53-07:00
by snibgo
Why do you think it is a bug? It should comply with the SVG specification. What does the specification say "x=10%" should do?

Re: percentage in SVG-TEXT

Posted: 2016-09-24T15:45:02-07:00
by ogduartev
snibgo wrote:Why do you think it is a bug?
I have 3 clues to think that:

1) other programs (gimp, eye of gnome, firefox i.e.) display the file different: they put the text at (250,250) => 50% of the svg container

2) imagemagick display the rects and other objects whose positions and sizes are set by percentages computing the quantities as relatives to the svg container object (see the tmp.svg file)

3) imagemagick was able to position a text positioned with percentages in previous releases as relative values of the svg container object

4) svg specification recognizes percentages as valid values (https://www.w3.org/TR/SVG/types.html#InterfaceSVGLength):
"Note that the non-property <length> definition also allows a percentage unit identifier. The meaning of a percentage length value depends on the attribute for which the percentage length value has been specified. Two common cases are: (a) when a percentage length value represents a percentage of the viewport width or height (refer to the section that discusses units in general), and (b) when a percentage length value represents a percentage of the bounding box width or height on a given object (refer to the section that describes object bounding box units)."

Re: percentage in SVG-TEXT

Posted: 2016-09-24T16:03:30-07:00
by snibgo
SVG wrote:Two common cases are: ...
Yes, that's the part that confuses me. Is text case (a) or (b)? I don't know. If it is (b), what is the bounding box? I don't know.

Re: percentage in SVG-TEXT

Posted: 2016-09-24T16:53:01-07:00
by ogduartev
snibgo wrote:
SVG wrote:Two common cases are: ...
Yes, that's the part that confuses me. Is text case (a) or (b)? I don't know. If it is (b), what is the bounding box? I don't know.
Take a look atbthe example at section 7.10 of
https://www.w3.org/TR/SVG/coords.html#Units

"For percentage values that are defined to be relative to the size of viewport:

For any x-coordinate value or width value expressed as a percentage of the viewport, the value to use is the specified percentage of the actual-width in user units for the nearest containing viewport, where actual-width is the width dimension of the viewport element within the user coordinate system for the viewport element.
For any y-coordinate value or height value expressed as a percentage of the viewport, the value to use is the specified percentage of the actual-height in user units for the nearest containing viewport, where actual-height is the height dimension of the viewport element within the user coordinate system for the viewport element.
For any other length value expressed as a percentage of the viewport, the percentage is calculated as the specified percentage of sqrt((actual-width)**2 + (actual-height)**2))/sqrt(2).
Example Units below illustrates some of the processing rules for different types of units."

Any way, in the tmp.svg file the only "100%" posible is the width/height of the svg element (500px,500px), and it is the way the two rects behave