aboutsummaryrefslogtreecommitdiff
path: root/src/SVG/SVG2zinc/Backend/Tcl.pm.k
blob: 3149ef68d63997bbb6e5c54ca73e18d46a53ddfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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;