How to strip out translate() statements from SVG code?

Post about projects that use Inkscape for web design.
Guest

How to strip out translate() statements from SVG code?

Postby Guest » Thu Jan 28, 2010 1:42 pm

I'm currently writing a client for a board game to be played over a network using Javascript and SVG. Inkscape is a great program for designing the sprites for the game, but I'm having trouble copying the raw code into my XML page. Namely, I want to position each object on the page by manipulating transform statements using Javascript, but Inkscape already uses them, and it's gunking up my file. I want to know if there's a way for Inkscape to automatically evaluate the piles of transformations done on each object so the paths' coordinates are in nice, low integers.

This is what I mean. I have this:

Code: Select all

    <path
       transform="translate(-531.14286,-574.79076)"
       id="opponentBg"
       d="m 671.14286,674.79074 30,-49.99998 -30,-50.00002 -140,0 0,100.00002 140,-2e-5 z"
       style="fill:#75507b;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       />


And I want it to become this:

Code: Select all

    <path
       id="opponentBg"
       d="m 140,100 30,-50 -30,-50 -140,0 0,100 140,0 z"
       style="fill:#75507b;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
       />

... without me hand-changing the coordinates of the hundreds of sprites I have so far.

User avatar
tomh
Posts: 218
Joined: Sat Feb 14, 2009 10:14 pm

Re: How to strip out translate() statements from SVG code?

Postby tomh » Thu Jan 28, 2010 11:13 pm

Inkscape Preferences -> Transforms: Store Transformation: Optimised.

Should get rid of the vast majority of the translate() statements, although there may be cases where using a translate() statement is the only way for Inkscape to do something, in which cases you would be out of luck.

Eg.
Groups may have to be ungrouped and then re-grouped to get rid of the transformations.

Hope that helps.

Guest

Re: How to strip out translate() statements from SVG code?

Postby Guest » Fri Jan 29, 2010 3:53 am

Thanks, but that option was already enabled, and it's still storing the transforms for the paths. Weird. I'd also tried creating a new layer and copying everything to that layer, but all that did was get rid of the transform on the layer.

l0b0
Posts: 3
Joined: Thu Jul 29, 2010 10:13 pm

Re: How to strip out translate() statements from SVG code?

Postby l0b0 » Thu Jul 29, 2010 10:25 pm

I'm having the same problem with an image: http://github.com/l0b0/CERN-Central-Library-bookmark/blob/master/recto.svg

I've tried for a while to get rid of all the Inkscape junk - Default style values like text-anchor:start;, the irremovable <marker> definition, redundant attributes like @inkscape:document-units (why isn't @units good enough?), transforms and translates. The file is already much smaller than it used to be, but it's getting difficult to get any further without some serious XSLT.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: How to strip out translate() statements from SVG code?

Postby ~suv » Fri Jul 30, 2010 4:07 am

l0b0 wrote:I've tried for a while to get rid of all the Inkscape junk

Junk? hmmm... Did you look at the different save/export formats of Inkscape? (Plain SVG, Optimized SVG)?
The latter is based on Scour, which can also be used as stand-alone python command line app. The next version of Inkscape will have a GUI for the various options of Scour, based on its current release.

l0b0
Posts: 3
Joined: Thu Jul 29, 2010 10:13 pm

Re: How to strip out translate() statements from SVG code?

Postby l0b0 » Fri Jul 30, 2010 7:37 am


~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: How to strip out translate() statements from SVG code?

Postby ~suv » Fri Jul 30, 2010 12:06 pm

l0b0 wrote:Yep, but Scour messes up paths.

Try the latest version of Scour (outside of Inkscape). Alternatively you could test the Inkscape 0.48pre1 prerelease or a current development snapshot build - both available for win32, osx and linux (Ubuntu PPAs for nightly builds).


Return to “Inkscape & the Web”