Loading ...
Sorry, an error occurred while loading the content.

Re: How to convert svg rect to path

Expand Messages
  • fisad@rocketmail.com
    Thanks for the help has been very useful
    Message 1 of 5 , Oct 23, 2010
    • 0 Attachment
      Thanks for the help has been very useful


      --- In svg-developers@yahoogroups.com, John Delacour <JD@...> wrote:
      >
      > At 11:46 +0000 20/10/10, fisad@... wrote:
      >
      > >Anybody can help me with svg rect convertion to svg path? I need
      > >know the steps to convert rect parameters to path commands.
      > >
      > >Example, I have:
      > >
      > >rect:
      > >height 2.8569181
      > >width 90.898613
      > >x 20.280216
      > >y 838.27399
      > >rx 0.9670065
      > >ry 1.2499017
      > >
      > >Inkscape make this:
      > >
      > >m 21.247223,838.27399 88.964597,0 c 0.53572,0 0.96701,0.55745
      > >0.96701,1.2499 l 0,0.35711 c 0,0.69245 -0.43129,1.2499
      > >-0.96701,1.2499 l -88.964597,0 c -0.535722,0 -0.967007,-0.55745
      > >-0.967007,-1.2499 l 0,-0.35711 c 0,-0.69245 0.431285,-1.2499
      > >0.967007,-1.2499 z
      > >
      > >My problem is with c command control points.
      >
      > You are dealing here not with curves but elliptical arcs, so the
      > maths is extremely simple. Here's a perl script that does the job
      > and should be self-explanatory. Where you actually start the path is
      > up to you.
      >
      >
      > #!/usr/bin/perl
      > use strict;
      > # Rectangle
      > my $height = 2.8569181;
      > my $width = 90.898613;
      > my $x = 20.280216;
      > my $y = 838.27399;
      > my $rx = 0.9670065;
      > my $ry = 1.2499017;
      > # My dims
      > my $mx = $x;
      > my $my = $y + $ry;
      > my $v = $height - 2 * $ry;
      > my $h = $width - 2 * $rx;
      > # Print path
      > print "<path d=\"" .
      > "m $mx $my " .
      > "v $v " .
      > "a $rx $ry 0 0 0 $rx $ry " .
      > "h $h " .
      > "a $rx $ry 0 0 0 $rx -$ry " .
      > "v -$v " .
      > "a $rx $ry 0 0 0 -$rx -$ry " .
      > "h -$h " .
      > "a $rx $ry 0 0 0 -$rx $ry" .
      > "\" />";
      >
      > RESULT:
      > <path d="m 20.280216 839.5238917 v 0.3571147 a 0.9670065 1.2499017 0
      > 0 0 0.9670065 1.2499017 h 88.9646 a 0.9670065 1.2499017 0 0 0
      > 0.9670065 -1.2499017 v -0.3571147 a 0.9670065 1.2499017 0 0 0
      > -0.9670065 -1.2499017 h -88.9646 a 0.9670065 1.2499017 0 0 0
      > -0.9670065 1.2499017" />
      >
      > JD
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.