aboutsummaryrefslogtreecommitdiff
path: root/Perl/t/text.t
blob: b8893dbe020131beab6a1d8fdf3234e0c12fbaa9 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/perl -w

#
# $Id: text.t,v 1.6 2004-05-07 13:53:00 mertz Exp $
# Author: Christophe Mertz
#

# testing text item

# this script can be used with an optionnal argument, an integer giving
# the delay in seconds during which the graphic updates will be displayed
# this is usefull for visual inspection!

my $mw;
BEGIN {
    if (!eval q{
#        use Test::More qw(no_plan);
        use Test::More tests => 69;
        1;
    }) {
        print "# tests only work properly with installed Test::More module\n";
        print "1..1\n";
        print "ok 1\n";
        exit;
    }
    if (!eval q{
	use Tk::Zinc;
 	1;
    }) {
        print "unable to load Tk::Zinc";
        print "1..1\n";
        print "ok 1\n";
        exit;
    }
    if (!eval q{
 	$mw = MainWindow->new();
 	1;
    }) {
        print "# tests only work properly when it is possible to create a mainwindow in your env\n";
        print "1..1\n";
        print "ok 1\n";
        exit;
    }
}

use strict;

my $zinc = $mw->Zinc(-render => 1,
		     -width => 400, -height => 1200)->pack;

like  ($zinc, qr/^Tk::Zinc=HASH/ , "zinc has been created");


my $g1 = $zinc->add('group',1, -tags => "gr1");


my $TEXT = "";

my @families = $mw->fontFamilies;
#print "families=@families\n";

my $family="";
if ( grep /^verdana$/i , @families) {
    $family = "verdana";
#    $family = "helvetica";
} elsif ( grep /^helvetica$/i , @families) {
    $family = "helvetica";
} elsif  ( grep /^arial$/i , @families) {
    $family = "arial";
}
#print "family=$family\n";

my $topLevel = $mw->Toplevel();
$topLevel->title("testing all ascii glyphs of $family");

my $zinc0 = $topLevel->Zinc(-render => 1,
			    -width => 300, 
			    -height => 400,)->pack;
like  ($zinc, qr/^Tk::Zinc=HASH/ , "zinc0 has been created");

$zinc0->fontCreate("fonta", -family => $family, -size => -20, -weight => 'normal');


foreach my $row (2..15) {
    my $string = "";
    foreach my $col (0..15) {
	$string .= chr($row*16+$col);
    }
    $zinc0->add('text', 1, -position => [10,$row*20-40], 
		-text => $string, -font => 'fonta');
    $zinc0->update;
    &pass("adding text item n°$row with a $family font of size 20 and normal weight");
}


### creating text items with many different fonts:

my $size = 8;
my $y = 10 ;

$zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal');


### creating text items with many different fonts:
$zinc->add('text', $g1, -position => [10,$y],  -tags => ["txt$size"], -font => "font$size",
	   -text => "$size pixels $family");
$zinc->remove('txt8');
$zinc->fontDelete("font$size");
$zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal');
$zinc->add('text', $g1, -position => [10,$y],  -tags => ["txt$size"], -font => "font$size",
	   -text => "$size pixels $family");





foreach my $size (9..60) {
    $zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal');
    $zinc->add('text', $g1, -position => [10,$y],  -tags => ["txt$size"], -font => "font$size",
	       -text => "$size pixels $family");
    $zinc->update;

    # deleting both the font and the text item and recreating it 10 times
    foreach my $count (1..10) {
	$zinc->fontDelete("font$size");
	$zinc->remove('txt8');
	$zinc->fontCreate("font$size", -family => $family, -size => -$size, -weight => 'normal');
	$zinc->add('text', $g1, -position => [10,$y],  -tags => ["txt$size"], -font => "font$size",
		   -text => "$size pixels $family");
	$zinc->update;
    }
    &pass("creating and deleting 10 times a text item with a $family font of size $size");
    $y += $size;
}


&wait;

## we should certainly test much much other things!



sub wait {
    $zinc->update;
    ok (1, $_[0]);

    my $delay = $ARGV[0];
    if (defined $delay) {
	$zinc->update;
	if ($delay =~ /^\d+$/) {
	    sleep $delay;
	} else {
	    sleep 1;
	}
    }
    
}



diag("############## end of text test");