Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've got a script that generates fairly complicated reports using SVGs as templates. The "master" template is an SVG that contains pointers to additional SVGs that provide the content for the report. These SVGs are generated programatically. The point of the master is to layout the content SVGs on the page. To make editing easy, I use a master template that contains colored boxes instead of links to images. Currently I convert the master template manually. I would like to automate this. How can I replace each line in the template:
<rect x="36" y="36" fill="#0000FF" width="392.4" height="43.2"/>
with:
<image overflow="visible" width="392.4" height="43.2" xlink:href="0000FF.svg" transform="matrix(1 0 0 1 36 36)"></image> ?
Additionally, for one particular box, specified by a certain fill color, I would like to read the height so that I can use this to adjust how part of the image generation script functions.
Re: Simple modification to SVG
by kcott (Archbishop) on Sep 04, 2013 at 10:50 UTC
|
SVG is an XML application.
Choose a module that can manipulate XML files and perform the necessary changes.
The module you pick may be dependent on what you're familiar with.
I'd probably choose XML::LibXML because that's what I'm familiar with.
You can search CPAN for modules in the XML:: namespace: there's a lot to choose from (and not all of them applicable to your current requirements).
From the limited information you've provided regarding the replacement, it appears that certain rect element attribute values need to be used (possibly after some manipulation) as image element attribute values.
This looks straightforward, e.g. $href = substr($fill, 1) . '.svg', but come back and ask if you run into difficulties. [To get the best answers, follow the guidelines in "How do I post a question effectively?"]
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
Re: Simple modification to SVG
by choroba (Cardinal) on Sep 04, 2013 at 06:28 UTC
|
As an Anonymous Monk, you cannot edit your previous related questions. You can still link to them, though.
| [reply] [Watch: Dir/Any] |
|