Debian Codegraph @

examples/canvas_ps

raw
1 #!/usr/local/bin/perl -w
2
3 use Tk;
4
5 %Tk::FontMap = ();
6
7 sub Tk::Font
8 {
9 my ($w,%args) = @_;
10 $args{'family'} = 'times' unless (exists $args{'family'});
11 $args{'weight'} = 'medium' unless (exists $args{'weight'});
12 $args{'slant'} = 'r' unless (exists $args{'slant'});
13 $args{'size'} = 140 unless (exists $args{'size'});
14 $args{'spacing'} = '*' unless (exists $args{'spacing'});
15 $args{'foundry'} = '*' unless (exists $args{'foundry'});
16 $args{'slant'} = substr($args{'slant'},0,1);
17 my $name = "-$args{'foundry'}-$args{'family'}-$args{'weight'}-$args{'slant'}-*-*-*-$args{'size'}-*-*-$args{'spacing'}-*-iso8859-1";
18 unless (exists $Tk::FontMap{$name})
19 {
20 my $fam = "\u\L$args{'family'}";
21 my $w = "\u\L$args{'weight'}";
22 my $sz = $args{'size'}/10;
23 my $sl = "\L$args{'slant'}";
24 my $an = "";
25 $w .= "Italic" if ($sl eq 'i');
26 $w .= "Oblique" if ($sl eq 'o');
27 $Tk::FontMap{$name} = [ "$fam-$w", $sz ];
28 print "$fam-$w","\n";
29 }
30 return $name;
31 }
32
33 %colormap = ();
34
35 sub plot
36 {
37 my ($c) = @_;
38 my $ps = $c->postscript('-x' => 0, '-y' => 0, -width => $c->Width, -height => $c->Height,
39 -fontmap => \%Tk::FontMap, -colormap => \%colormap);
40 open(PS,">$0.ps") || die "Cannot open $0.ps:$!";
41 print PS $ps,"\n";
42 close(PS);
43 }
44
45 $top = MainWindow->new();
46 $c = $top->Canvas();
47 $c->pack(-expand => 1, -fill => 'both');
48 $b = $top->Button(-text => 'Quit', -command => [ 'destroy', $top ]);
49 $b->pack;
50 $b = $top->Button(-text => 'Plot', -command => [ \&plot, $c ]);
51 $b->pack;
52
53 $f1 = $c->Font(family => 'courier', weight => 'bold', size => 120);
54
55 $c->create('text', 20, 20, -font => $f1, -anchor => 'nw', -fill => 'red',
56 -justify => 'left',
57 -text => 'This is a piece of "courier" Text');
58
59 $colormap{'red'} = '0.2 setgray';
60
61 $f2 = $c->Font(family => 'times', slant => 'italic', weight => 'bold', size => 140);
62
63 $c->create('text', 20, 80, -font => $f2, -anchor => 'nw', -fill => 'green',
64 -justify => 'left',
65 -text => 'This is a piece of "times" Text');
66
67 $c->create('text', 20, 120,
68 -font => $c->Font(family => 'times', weight => 'bold', size => 240),
69 -anchor => 'nw',
70 -justify => 'left',
71 -text => 'This is a piece of "times" Text');
72
73 $colormap{'green'} = '0.5 setgray';
74
75 MainLoop;