Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Simple modification to SVG

by Anonymous Monk
on Sep 04, 2013 at 05:57 UTC ( #1052218=perlquestion: print w/ replies, xml ) Need Help??
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.

Comment on Simple modification to SVG
Re: Simple modification to SVG
by choroba (Abbot) 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.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Simple modification to SVG
by kcott (Abbot) 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?"]

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1052218]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-08-28 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (257 votes), past polls