--- /dev/null
+#!/usr/bin/perl\r
+\r
+###\r
+# SVG2S60 - Cleans Inkscape SVG files for use with svg2svgt in the S60 SDK\r
+# Copyright (C) 2007 Ian Dunbar\r
+# Modified by Brian Smith and Michael Prager\r
+#\r
+# This program is free software; you can redistribute it and/or modify\r
+# it under the terms of the GNU General Public License as published by\r
+# the Free Software Foundation; either version 2 of the License, or\r
+# (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+# GNU General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU General Public License\r
+# along with this program; if not, write to the Free Software\r
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+###\r
+\r
+###\r
+#\r
+# SVG2S60 - Cleans Inkscape SVG files for use with svg2svgt in the S60 SDK\r
+#\r
+# Usage: svg2s60.pl in.svg > out.svg\r
+#\r
+# Description: This script just splits the style tags used by Inkscape, but not\r
+# properly supported by svg2svgt into it's seperate components. This helps to\r
+# solve color mapping issues in svg2svgt for files that have been edited by\r
+# Inkscape.\r
+#\r
+###\r
+\r
+###\r
+# Changelog:\r
+# v1.0 by Ian Dunbar\r
+# - initial release\r
+# v1.1 by Brian Smith\r
+# - update to work with the latest inkscape version 0.47\r
+# v1.2 by Michael Prager\r
+# - fix moveto commands with implicit lineto commands in paths\r
+# - fix gradients that use xlink:href references\r
+###\r
+\r
+my $inputfile = "";\r
+while (<>) {\r
+ $inputfile .= $_;\r
+}\r
+\r
+sub fixPathData {\r
+ my $output = shift;\r
+ # do some cleanup to make regex easier, add spacing between numbers and commands and replace , with space\r
+ $output =~ s/(\d)-/$1 -/g;\r
+ $output =~ s/(\d)([a-df-zA-DF-Z])/$1 $2/g;\r
+ $output =~ s/([a-df-zA-DF-Z])(-?\d)/$1 $2/g;\r
+ $output =~ s/([a-df-zA-DF-Z])([a-df-zA-DF-Z])/$1 $2/g;\r
+ $output =~ s/,/ /g;\r
+ # fix moveto commands that have more than two coordinates. Interpret additionl coordinates as lineto commands as defined in the SVG DTD\r
+ $output =~ s/^m\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s*/M $1 $2 l $3 $4 /g;\r
+ $output =~ s/m\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s*/m $1 $2 l $3 $4 /g;\r
+ $output =~ s/M\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s+([-0-9e\.]+)\s*/M $1 $2 L $3 $4 /g;\r
+ return $output;\r
+}\r
+\r
+sub fixGradient {\r
+ my $output = shift;\r
+ $output =~ s/^#//;\r
+ # dereference linked gradients\r
+ if ($inputfile =~ /<(linearGradient|radialGradient)([^<>]*?)id=\"$output\"([^<>]*?)>(.*?)<\/\1>/i) {\r
+ $output = $4;\r
+ }\r
+ else {\r
+ $output = "";\r
+ }\r
+ return $output;\r
+}\r
+\r
+# remove linebreaks & whitespaces, makes parsing easier\r
+$inputfile =~ s/\n/ /g;\r
+$inputfile =~ s/ +/ /g;\r
+\r
+# remove style attribute used by Inkscape, use normal attributes instead\r
+while($inputfile =~ /\s+style=\"(.*?)\"/g) {\r
+ my $input = $1;\r
+ my $output = "";\r
+ my @styles = split /;/,$input;\r
+ foreach $style (@styles) {\r
+ $style =~ s/(.*):(.*)/$1=\"$2\" /;\r
+ if ($style !~ /^-/) { # don't allow attributes that start with "-"\r
+ $output .= $style;\r
+ }\r
+ }\r
+ $inputfile =~ s/\s+style=\"\Q$input\E\"/ $output/g;\r
+}\r
+\r
+# fix moveto command in paths if implicit lineto commands are used\r
+$inputfile =~ s/<path([^<>]*?)\s+d=\"(.*?)\"/'<path' . $1 . ' d="' . fixPathData($2) . '"'/eg;\r
+\r
+# fix linearGradiants that use references\r
+$inputfile =~ s/<(linearGradient|radialGradient)([^<>]*?)\s*xlink:href="(.*?)"([^<>]*?)\/>/"<$1$2 $4>".fixGradient($3)."<\/$1>"/ieg;\r
+\r
+# restore "human readable" file layout\r
+$inputfile =~ s/<(.*?)>/<$1>\n/g;\r
+$inputfile =~ s/\n +/\n/g;\r
+\r
+print $inputfile;\r