]>
code.delx.au - comingnext/blob - logo/svg2s60.pl
4 # SVG2S60 - Cleans Inkscape SVG files for use with svg2svgt in the S60 SDK
5 # Copyright (C) 2007 Ian Dunbar
6 # Modified by Brian Smith and Michael Prager
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # SVG2S60 - Cleans Inkscape SVG files for use with svg2svgt in the S60 SDK
27 # Usage: svg2s60.pl in.svg > out.svg
29 # Description: This script just splits the style tags used by Inkscape, but not
30 # properly supported by svg2svgt into it's seperate components. This helps to
31 # solve color mapping issues in svg2svgt for files that have been edited by
41 # - update to work with the latest inkscape version 0.47
42 # v1.2 by Michael Prager
43 # - fix moveto commands with implicit lineto commands in paths
44 # - fix gradients that use xlink:href references
54 # do some cleanup to make regex easier, add spacing between numbers and commands and replace , with space
55 $output =~ s/(\d)-/$1 -/g;
56 $output =~ s/(\d)([a-df-zA-DF-Z])/$1 $2/g;
57 $output =~ s/([a-df-zA-DF-Z])(-?\d)/$1 $2/g;
58 $output =~ s/([a-df-zA-DF-Z])([a-df-zA-DF-Z])/$1 $2/g;
60 # fix moveto commands that have more than two coordinates. Interpret additionl coordinates as lineto commands as defined in the SVG DTD
61 $output =~ s/^m\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s*/M $1 $2 l $3 $4 /g;
62 $output =~ s/m\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s*/m $1 $2 l $3 $4 /g;
63 $output =~ s/M\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s*/M $1 $2 L $3 $4 /g;
70 # dereference linked gradients
71 if ($inputfile =~ /<(linearGradient|radialGradient)([^<>]*?)id=\"$output\"([^<>]*?)>(.*?)<\/\
1>/i
) {
80 # remove linebreaks & whitespaces, makes parsing easier
81 $inputfile =~ s/\n/ /g;
82 $inputfile =~ s/ +/ /g;
84 # remove style attribute used by Inkscape, use normal attributes instead
85 while($inputfile =~ /\s+style=\"(.*?)\"/g) {
88 my @styles = split /;/,$input;
89 foreach $style (@styles) {
90 $style =~ s/(.*):(.*)/$1=\"$2\" /;
91 if ($style !~ /^-/) { # don't allow attributes that start with "-"
95 $inputfile =~ s/\s+style=\"\Q$input\E\"/ $output/g;
98 # fix moveto command in paths if implicit lineto commands are used
99 $inputfile =~ s/<path([^<>]*?)\s+d=\"(.*?)\"/'<path' . $1 . ' d="' . fixPathData($2) . '"'/eg;
101 # fix linearGradiants that use references
102 $inputfile =~ s/<(linearGradient|radialGradient)([^<>]*?)\s*xlink:href="(.*?)"([^<>]*?)\/>/"<$1$2 $4>".fixGradient
($3)."<\/$1>"/ieg
;
104 # restore "human readable" file layout
105 $inputfile =~ s/<(.*?)>/<$1>\n/g;
106 $inputfile =~ s/\n +/\n/g;