Unit conversion in SVGLength object

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Unit conversion in SVGLength object

vic-17
Hi,

I'm trying to apply a translation to an object using a length in
millimeters instead of pixels. SVGTransforms only accept units in pixels
so I tried to convert them using an SVGLength. However it does not
behave as I expected. Here "svg" is the id of the <svg/> element :

len = document.getElementById("svg").createSVGLength();

len.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM, "30");
  -> len.unitType = 7
  -> len.value = 30
  -> len.valueInSpecifiedUnits = 30
  -> len.valueAsString = 30mm

len.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX);
  -> len.unitType = 5
  -> len.value = 30
  -> len.valueInSpecifiedUnits = 30
  -> len.valueAsString = 30px

So it looks like convertToSpecifiedUnits does not actually convert the
value. Is it a bug, or am I doing something wrong ? Is there another way
to translate by an amount in millimeters ?

This was tested on Firefox 1.5.0.8 and 2.0

Thanks,
vic.
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg
Reply | Threaded
Open this post in threaded view
|

Re: Unit conversion in SVGLength object

Boris Zbarsky
vic wrote:
> So it looks like convertToSpecifiedUnits does not actually convert the
> value. Is it a bug

http://www.w3.org/TR/SVG11/types.html#InterfaceSVGLength says:

convertToSpecifiedUnits
     Preserve the same underlying stored value, but reset the stored
     unit identifier to the given unitType. Object attributes unitType,
     valueAsSpecified and valueAsString might be modified as a result
     of this method. For example, if the original value were "0.5cm"
     and the method was invoked to convert to millimeters, then the
     unitType would be changed to SVG_LENGTHTYPE_MM, valueAsSpecified
     would be changed to the numeric value 5 and valueAsString would be
     changed to "5mm".

So yes, sounds like a bug.  I see this happening on trunk as well.

-Boris
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg
Reply | Threaded
Open this post in threaded view
|

Re: Unit conversion in SVGLength object

Eli Friedman
Bug filed: https://bugzilla.mozilla.org/show_bug.cgi?id=361920.  See the
report for my analysis of the bug.

-Eli

Boris Zbarsky wrote:

> vic wrote:
>> So it looks like convertToSpecifiedUnits does not actually convert the
>> value. Is it a bug
>
> http://www.w3.org/TR/SVG11/types.html#InterfaceSVGLength says:
>
> convertToSpecifiedUnits
>     Preserve the same underlying stored value, but reset the stored
>     unit identifier to the given unitType. Object attributes unitType,
>     valueAsSpecified and valueAsString might be modified as a result
>     of this method. For example, if the original value were "0.5cm"
>     and the method was invoked to convert to millimeters, then the
>     unitType would be changed to SVG_LENGTHTYPE_MM, valueAsSpecified
>     would be changed to the numeric value 5 and valueAsString would be
>     changed to "5mm".
>
> So yes, sounds like a bug.  I see this happening on trunk as well.
>
> -Boris
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg
Reply | Threaded
Open this post in threaded view
|

Re: Unit conversion in SVGLength object

vic-17
Eli Friedman wrote:
> Bug filed: https://bugzilla.mozilla.org/show_bug.cgi?id=361920.  See the
> report for my analysis of the bug.

Thanks, I found the answer to my question in your report,
SVGSVGElement.pixelUnitToMillimeterX ;)

vic
_______________________________________________
dev-tech-svg mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-svg