aboutsummaryrefslogtreecommitdiff
path: root/src/SVG/SVG2zinc/Backend/Tcl.pm.k
diff options
context:
space:
mode:
Diffstat (limited to 'src/SVG/SVG2zinc/Backend/Tcl.pm.k')
-rw-r--r--src/SVG/SVG2zinc/Backend/Tcl.pm.k96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/SVG/SVG2zinc/Backend/Tcl.pm.k b/src/SVG/SVG2zinc/Backend/Tcl.pm.k
new file mode 100644
index 0000000..3149ef6
--- /dev/null
+++ b/src/SVG/SVG2zinc/Backend/Tcl.pm.k
@@ -0,0 +1,96 @@
+package SVG::SVG2zinc::Backend::Tcl;
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU LGPL Libray General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA,
+# or refer to http://www.gnu.org/copyleft/lgpl.html
+#
+##################################################################
+
+# Backend Class for SVG2zinc
+#
+# Copyright 2003-2004
+# Centre d'Études de la Navigation Aérienne
+#
+# Author: Christophe Mertz <mertz at intuilab dot com>
+#
+# A module for code translation from perl to tcl generation
+#
+# $Id: Tcl.pm.k,v 1.1.1.1 2006-10-20 13:34:31 merlin Exp $
+#############################################################################
+
+
+use vars qw( $VERSION);
+($VERSION) = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
+
+@ISA = qw( Exporter );
+@EXPORT = qw( perl2tcl );
+
+use strict;
+use Carp;
+
+
+sub perl2tcl {
+ my (@lines) = @_;
+ my @res;
+ foreach my $l (@lines) {
+
+ $l =~ s/->(\w*)\((.*)\)/\$w\.zinc $1 $2/g; # ->add(....) => $w.zinc add ...
+
+ $l =~ s/\s*,\s*/ /g; # replacing commas by spaces
+ $l =~ s/\s*=>\s*/ /g; # replacing => by spaces
+
+ $l =~ s/\s*\'([^\s;]+)\'\s*/ $1 /g ; # removing single-quotes around string without spaces
+ $l =~ s/\s*\"([^\s;]+)\"\s*/ $1 /g ; # removing double-quotes around string without spaces
+ $l =~ s/([\"\s])\#/$1\\\#/g ; # prefixing # by a slash
+
+ $l =~ s/\[/\{/g; # replacing [ by }
+ $l =~ s/\]/\}/g; # replacing ] by }
+ $l =~ s/\{\s+/\{/g; # removing spaces after {
+ $l =~ s/\s+\}/\}/g; # removing spaces before }
+
+ $l =~ s/-tags \{(\S+)\}/-tags $1/g; # -tags {toto} ==>> -tags toto
+ $l =~ s/\'/\"/g; # replacing all single quotes by double quotes
+
+ $l = &hack($l);
+
+ $l =~ s/\s+/ /g; # dangerous: removing multiple occurences of blanks
+
+ $l =~ s/^\s+//; # removing blanks at the beginning
+ $l =~ s/\s+$//; # removing trailing blanks
+ $l =~ s/\s*;$//; # removing trailing ;
+ push @res, $l;
+ }
+ return (@res);
+}
+
+
+# this routine is used to do some special code transformation,
+# due to soem discrepancies between tcl/tk and perl/tk
+# the following code is more or less dependant from the generated
+# code by SVG2zinc.pm
+#
+# We assume is code has already been tcl-ised
+sub hack {
+ my ($l) = @_;
+
+ if ($l =~ /^\$w\.zinc fontCreate/) {
+ # this works because I know how fontCreate is used in SVG2zinc
+ $l =~ s/\$w\.zinc fontCreate/font create/;
+ $l =~ s/-weight medium/-weight normal/;
+ }
+
+ return $l;
+}
+
+1;
+