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