Baz has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have the following SVG -
<g style="fill:#ee3399;"> <path d="M155.9,124.8 A14.4,14.4 0 0 1 173.0,131.5 A18.0,18.0 0 0 1 16 +9.0,145.5 C169.6,149.2 171.9,152.2 175.9,155.5 A12.9,12.9 0 0 1 177.0 +,171.5 A10.0,10.0 0 0 1 163.0,176.3 A8.0,8.0 0 0 1 156.2,164.5 C156.4 +,160.5 154.8,157.8 151.9,155.5 A11.3,11.3 0 0 1 151.9,139.5 A16.5,16. +5 0 0 1 153.1,127.5 z" /> </g> <g style="fill:#FF00FF;"> <path d=" ...
and I wish to scale the values in the above code by a factor of 4. This basically involves dividing all those values above by 4. But for arcs (A) there is an exception - A14.4,14.4 0 0 1 (etc) should be converted to A3.6,3.6 0 0 1, i.e. the 0 0 1 dont get scaled.

This should be the output for converting the above (with values converted to one decimal place) -
<g style="fill:#ee3399;"> <path d="M39.0,31.2 A3.6,3.6 0 0 1 43.3,32.9 A4.5,4.5 0 0 1 42.3,36.4 +C42.4,37.3 43.0,38.1 44.0,38.9 A3.2,3.2 0 0 1 44.3,42.9 A2.5,2.5 0 0 +1 40.8,44.1 A2.0,2.0 0 0 1 39.1,41.1 C39.1,40.2 38.7,39.5 38.0,38.9 A +2.8,2.8 0 0 1 38.0,34.9 A4.1,4.1 0 0 1 38.3,31.9 z" /> </g> <g style="fill:#FF00FF;"> <path d=" ...
I've no idea how to approach this, hope you can help,
Thanks,
Barry.
P.S. If anyone nows how to get IE to cache SVG (outputed from perl with expires set for sometime next year) please let me know. I think this problem applies to all output which IE hands over to a plugin.

Replies are listed 'Best First'.
Re: Scaling the values in a document
by BrowserUk (Patriarch) on Sep 01, 2002 at 02:34 UTC

    From the tutorial at Adobe's site,

    scale(<sx> [<sy>]) will scale the element by factor of <sx> and <sy> f +rom the centerpoint (0,0). If <sy> is not given, it is assumed to be +the same as <sx>. For example, if the value of <sx> is "0.5," the ele +ment will be scaled to 50% of the original width. In the full six-num +ber array, <sx> and <sy> are the first and fourth numbers of the arra +y. To scale using a centerpoint other than (0,0), you must translate the +element so that the centerpoint becomes (0,0), perform the scale, the +n translate the element back to its original location. For example, t +o scale an element by 50% centered on (150,100), you must set the tra +nsform attribute to "translate(150 100) scale(.5) translate(- 150 -10 +0)" (note the reverse order).

    Well It's better than the Abottoire, but Yorkshire!
      that worked a charm, thanks for that ;)
Re: Scaling the values in a document
by theorbtwo (Prior) on Sep 01, 2002 at 01:52 UTC

    I'd tend to say the proper way to do this is not to use perl at all, but rather use SVG's scaling capablities.


    Confession: It does an Immortal Body good.

      yeah - if I knew them :)

        Section 7.4 of the SVG specs show how to create a new coordinate system, presumably on your <g> tag. Specifcly, for this, add a transform="scale(0.5)" on the g tag.


        Confession: It does an Immortal Body good.