diff options
author | Rodney Dawes <dobey@gnome.org> | 2008-09-04 22:35:41 -0400 |
---|---|---|
committer | Rodney Dawes <dobey@gnome.org> | 2008-09-04 22:35:41 -0400 |
commit | f619c6f6158c7059e85ca520ceab36894571eb2b (patch) | |
tree | 5d7f31d8fb46ba9af0286e6d96a98877b2920b7b | |
parent | 9d4753968af73fa5f223f111da5b4365f9a87bc2 (diff) |
2008-09-04 Rodney Dawes <dobey.pwns@gmail.com>
* render-bitmaps.pl:
Add a PERL version of the bitmap rendering script
* svg/test-sheet.svg:
Clean up the file and remove unneeded invisible objects
-rwxr-xr-x | render-bitmaps.pl | 101 | ||||
-rw-r--r-- | svg/test-sheet.svg | 120 |
2 files changed, 110 insertions, 111 deletions
diff --git a/render-bitmaps.pl b/render-bitmaps.pl new file mode 100755 index 0000000..cb6b1a9 --- /dev/null +++ b/render-bitmaps.pl @@ -0,0 +1,101 @@ +#!/usr/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*- +############################################################################# +## Copyright (C) 2008 Rodney Dawes +## +## Authors: Rodney Dawes <dobey@gnome.org> +## + +use strict; +use XML::Simple; +use Getopt::Long; + +my $inkscape = "inkscape"; +my $sizeonly; +my $outdir; +my $dirall; + +############################################################################ +my @default_getopt_config = ("permute", "pass_through", "bundling", + "no_auto_abbrev", "no_ignore_case"); + +Getopt::Long::Configure (@default_getopt_config); +GetOptions ("size|s=s" => \$sizeonly, + "inkscape|i=s" => \$inkscape, + "output-dir|o=s" => \$outdir, + "directory|d=s" => \$dirall); + +############################################################################ + +use Data::Dumper; + +sub render_icons { + my $filename = shift; + + my $mapping = XML::Simple::XMLin ($filename, + keyattr => [ qw() ], + forcearray => [ qw(g rect text) ]); + + foreach my $icon (@{$mapping->{g}}) { + my $name; + my $context; + + foreach my $plate (@{$icon->{g}}) { + if (defined $plate->{'inkscape:label'} && + $plate->{'inkscape:label'} =~ m/plate(.*)/) { + + foreach my $text (@{$plate->{text}}) { + if (defined $text->{'inkscape:label'} && + $text->{'inkscape:label'} eq "icon-name") { + $name = $text->{tspan}->{content}; + } elsif (defined $text->{'inkscape:label'} && + $text->{'inkscape:label'} eq "context") { + $context = $text->{tspan}->{content}; + } + } + foreach my $box (@{$plate->{rect}}) { + if (defined $box->{'inkscape:label'}) { + my $size = $box->{'inkscape:label'}; + my $dir = "$size/$context"; + + next if (defined $sizeonly && $size ne $sizeonly); + + if (! -d $dir) { + system ("mkdir -p $dir"); + } + my $cmd = "$inkscape -i $box->{id} -e $dir/$name.png $filename > /dev/null"; + system ($cmd); + } + } + } + } + } +} + +sub usage { + print "Usage: render-bitmaps.pl [OPTIONS] <SVGFILE> + + -d, --directory=<dir> Render all SVGs in <dir> + -i, --inkscape=<path> Path to inkscape binary to use + -o, --output=<dirname> Directory to output PNGs to + -s, --size=<size> Size to render from <SVGFILE> + +"; + + exit 1; +} + +if (defined $ARGV[0]) { + render_icons ($ARGV[0]); +} elsif (defined $dirall) { + opendir (DIR, $dirall) || die ("ERROR: Failed to open directory: $dirall"); + my @filelist = readdir (DIR); + closedir (DIR); + + foreach my $file (@filelist) { + next if ($file eq "." || $file eq ".."); + render_icons ("$dirall/$file"); + } +} else { + usage (); +} diff --git a/svg/test-sheet.svg b/svg/test-sheet.svg index e6da254..7c0d2c5 100644 --- a/svg/test-sheet.svg +++ b/svg/test-sheet.svg @@ -16,7 +16,7 @@ height="600" id="svg11300" sodipodi:version="0.32" - inkscape:version="0.46+devel" + inkscape:version="0.46" sodipodi:docname="test-sheet.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" version="1.0" @@ -1120,9 +1120,9 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="1" - inkscape:cx="347.02658" - inkscape:cy="305.20708" - inkscape:current-layer="layer6" + inkscape:cx="223.02658" + inkscape:cy="286.20708" + inkscape:current-layer="layer3" showgrid="false" inkscape:grid-bbox="true" inkscape:document-units="px" @@ -1219,108 +1219,6 @@ inkscape:label="artwork:audio-x-generic" inkscape:groupmode="layer" style="display:inline"> - <rect - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - id="256x256" - width="256" - height="256" - x="26.5" - y="32.823101" - inkscape:label="256x256" /> - <rect - y="32.823101" - x="-35.5" - height="48" - width="48" - id="48x48" - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - inkscape:label="48x48" /> - <rect - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - id="24x24" - width="24" - height="24" - x="-120.5" - y="32.823101" - inkscape:label="24x24" /> - <rect - y="32.823101" - x="-152.5" - height="16" - width="16" - id="16x16" - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - inkscape:label="16x16" /> - <text - xml:space="preserve" - style="font-size:56.11526489px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;fill:#2e3436;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate;font-family:Myriad" - x="-136.6134" - y="-51.053188" - id="text4713" - sodipodi:linespacing="125%"><tspan - sodipodi:role="line" - id="tspan4715" - x="-136.6134" - y="-51.053188">folder</tspan></text> - <rect - inkscape:label="32x32" - y="32.823101" - x="-84.5" - height="32" - width="32" - id="32x32" - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" /> - <rect - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - id="rect6083" - width="256" - height="256" - x="-255.29855" - y="117.96112" - inkscape:label="256x256" /> - <rect - y="117.96112" - x="-317.29855" - height="48" - width="48" - id="rect6085" - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - inkscape:label="48x48" /> - <rect - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - id="rect6087" - width="24" - height="24" - x="-402.29855" - y="117.96112" - inkscape:label="24x24" /> - <rect - y="117.96112" - x="-434.29855" - height="16" - width="16" - id="rect6089" - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" - inkscape:label="16x16" /> - <text - xml:space="preserve" - style="font-size:56.11526489px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;fill:#2e3436;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate;font-family:Myriad" - x="-418.41196" - y="34.084831" - id="text6091" - sodipodi:linespacing="125%"><tspan - sodipodi:role="line" - id="tspan6093" - x="-418.41196" - y="34.084831">audio-x-generic</tspan></text> - <rect - inkscape:label="32x32" - y="117.96112" - x="-366.29855" - height="32" - width="32" - id="rect6095" - style="fill:#eeeeec;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:5;marker:none;marker-start:none;marker-mid:none;marker-end:none;visibility:visible;display:none;overflow:visible;enable-background:accumulate" /> <g inkscape:groupmode="layer" id="layer6" @@ -1373,7 +1271,7 @@ height="256" x="20" y="29.99999" - inkscape:label="this is unneeded even" /> + inkscape:label="256x256" /> <text xml:space="preserve" style="font-size:18.30070686px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;enable-background:new;font-family:Bitstream Vera Sans" @@ -2017,10 +1915,10 @@ height="256" x="20" y="330" - inkscape:label="this is unneeded even" /> + inkscape:label="256x256" /> <text xml:space="preserve" - style="font-size:18.30070686px;font-style:normal;font-weight:bold;fill:#000000;fill-opacity:1;stroke:none;display:inline;enable-background:new;font-family:Droid Sans;-inkscape-font-specification:Droid Sans Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + style="font-size:18.30070686px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;display:inline;enable-background:new;font-family:Droid Sans;-inkscape-font-specification:Droid Sans Bold" x="191.97075" y="321.51361" id="text3029" @@ -2133,9 +2031,9 @@ transform="translate(700,0)"><flowRegion id="flowRegion2744"><rect id="rect2746" - width="343" + width="322" height="607" - x="-359" + x="-295" y="-5" /></flowRegion><flowPara id="flowPara2748" style="font-size:40px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;font-family:Droid Sans;-inkscape-font-specification:Droid Sans Bold" /></flowRoot> <text |