blib/lib/PlotCalendar/Day.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 169 | 199 | 84.9 |
branch | 41 | 64 | 64.0 |
condition | 1 | 3 | 33.3 |
subroutine | 21 | 23 | 91.3 |
pod | 0 | 20 | 0.0 |
total | 232 | 309 | 75.0 |
line | stmt | bran | cond | sub | pod | time | code | |
---|---|---|---|---|---|---|---|---|
1 | package PlotCalendar::Day; | |||||||
2 | ||||||||
3 | # | |||||||
4 | # Version 1.0 - 3/99 - Alan Jackson : ajackson at icct.net | |||||||
5 | # Copyright 1999 may be used and distributed under the | |||||||
6 | # Gnu Copyleft. | |||||||
7 | ||||||||
8 | # Version 1.1 - 6/99 Major code cleanup, and testing really big and | |||||||
9 | # really tiny images. Added documentation. | |||||||
10 | ||||||||
11 | # To do | |||||||
12 | # Add popup for clipped text (or maybe put it in message bar) | |||||||
13 | # Add more intelligence for clip text | |||||||
14 | # Add all the Tk stuff 8-) | |||||||
15 | # | |||||||
16 | # | |||||||
17 | ||||||||
18 | 3 | 3 | 1332 | use strict; | ||||
3 | 5 | |||||||
3 | 113 | |||||||
19 | 3 | 3 | 16 | use vars qw( $VERSION ); | ||||
3 | 6 | |||||||
3 | 118 | |||||||
20 | ||||||||
21 | 3 | 3 | 15 | use Carp; | ||||
3 | 5 | |||||||
3 | 14135 | |||||||
22 | ||||||||
23 | # Note : Day_of_Week returns 1=Mon, 7=Sun | |||||||
24 | ||||||||
25 | $VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ m#(\d+)\.(\d+)#; | |||||||
26 | ||||||||
27 | sub new { | |||||||
28 | 3 | 3 | 0 | 27 | my $proto = shift; | |||
29 | 3 | 33 | 21 | my $class = ref($proto) || $proto; | ||||
30 | 3 | 6 | my $self = {}; | |||||
31 | ||||||||
32 | ||||||||
33 | 3 | 6 | $self->{SIZE} = {}; # hash of dimensions, height and width | |||||
34 | 3 | 5 | $self->{COLOR} = {}; # hash of global colors, | |||||
35 | # foreground, background-main, background-optional | |||||||
36 | # (fg, bgmain) | |||||||
37 | 3 | 7 | $self->{FONT} = {}; # hash of global font sizes, day, main, opt | |||||
38 | 3 | 5 | $self->{STYLE} = {}; # hash of global text styles, day, main, opt (n,b,i,u) | |||||
39 | 3 | 5 | $self->{EXPAND} = 0; # Is height allowed to expand? default = no. | |||||
40 | 3 | 4 | $self->{CLIPTEXT} = 0; # Clip text if too long? default = no. | |||||
41 | 3 | 5 | $self->{DIGIT} = ''; # What day *is* it, anyway? | |||||
42 | 3 | 7 | $self->{DAYNAME} = ''; # What is the day called (like, "Christmas") | |||||
43 | 3 | 6 | $self->{NAMEREF} = ''; # HTML reference for dayname | |||||
44 | 3 | 4 | $self->{HTMLREF} = ''; # HTML reference for whole cell | |||||
45 | 3 | 8 | $self->{TEXT} = []; # array of lines of text | |||||
46 | 3 | 4 | $self->{TEXTCOL} = []; # array of colors for text (optional) | |||||
47 | 3 | 5 | $self->{TEXTSIZE} = []; # array of sizes for text (optional) | |||||
48 | 3 | 6 | $self->{TEXTSTYLE} = []; # array of styles for text (optional) (n,b,i,u) | |||||
49 | # (n)ormal, (b)old, (i)talic, (u)nderline | |||||||
50 | 3 | 8 | $self->{TEXTREF} = []; # array of html references to text | |||||
51 | ||||||||
52 | 3 | 8 | $self->{"FONT_TABLE"}={}; # Table of points to html font sizes | |||||
53 | ||||||||
54 | 3 | 6 | $self->{DIGIT} = shift; | |||||
55 | ||||||||
56 | 3 | 6 | &initialize($self); | |||||
57 | ||||||||
58 | 3 | 7 | bless $self, $class; | |||||
59 | ||||||||
60 | 3 | 8 | return $self; | |||||
61 | ||||||||
62 | } | |||||||
63 | ||||||||
64 | # **************************************************************** | |||||||
65 | sub getascii { | |||||||
66 | 0 | 0 | 0 | 0 | my $self = shift; | |||
67 | ||||||||
68 | 0 | 0 | my $string=''; | |||||
69 | ||||||||
70 | # name | |||||||
71 | 0 | 0 | $string .= "$self->{DAYNAME}\n"; | |||||
72 | ||||||||
73 | # text | |||||||
74 | 0 | 0 | for (my $i=0;$i<=$#{$self->{TEXT}};$i++) { | |||||
0 | 0 | |||||||
75 | 0 | 0 | my $text = $self->{TEXT}[$i]; | |||||
76 | 0 | 0 | $string .= "$text\n"; | |||||
77 | } | |||||||
78 | ||||||||
79 | 0 | 0 | return $string; | |||||
80 | } | |||||||
81 | ||||||||
82 | # **************************************************************** | |||||||
83 | sub gethtml { | |||||||
84 | 3 | 3 | 0 | 9 | my $self = shift; | |||
85 | ||||||||
86 | 3 | 5 | my $string=''; | |||||
87 | ||||||||
88 | # initialize cell | |||||||
89 | ||||||||
90 | 3 | 5 | my ($htmlref,$htmlref2)= ('',''); | |||||
91 | 3 | 50 | 16 | if ($self->{HTMLREF}) {$htmlref = $self->{HTMLREF};$htmlref2='';} | ||||
3 | 4 | |||||||
3 | 6 | |||||||
92 | ||||||||
93 | 3 | 9 | $string = " | {COLOR}{bgmain} ALIGN=LEFT VALIGN=TOP "; | ||||
94 | 3 | 13 | $string .= "HEIGHT=$self->{SIZE}{height} WIDTH=$self->{SIZE}{width}>$htmlref\n"; | |||||
95 | ||||||||
96 | # digit | |||||||
97 | 3 | 6 | my ($style1,$style2)=('',''); | |||||
98 | 3 | 50 | 8 | if ($self->{DIGIT} != 0) { | ||||
99 | 3 | 8 | ($style1,$style2) = htmlstyles($self->{STYLE}{day}); | |||||
100 | 3 | 12 | $string .= "$style1{'FONT_TABLE'}{$self->{FONT}{day}} "; | |||||
101 | 3 | 11 | $string .= "COLOR=$self->{COLOR}{fg} > $self->{DIGIT} $style2\n"; | |||||
102 | } | |||||||
103 | # name | |||||||
104 | 3 | 50 | 11 | if ($self->{FONT}{main} > 0) { | ||||
105 | 3 | 5 | my ($r1,$r2) = ('',''); | |||||
106 | 3 | 100 | 13 | if ($self->{NAMEREF}) {($r1,$r2) = ($self->{NAMEREF},"");} | ||||
2 | 4 | |||||||
107 | 3 | 9 | ($style1,$style2) = htmlstyles($self->{STYLE}{main}); | |||||
108 | 3 | 12 | $string .= "$style1{'FONT_TABLE'}{$self->{FONT}{main}} "; | |||||
109 | 3 | 12 | $string .= "COLOR=$self->{COLOR}{fg} >$r1 $self->{DAYNAME} $r2$style2\n"; | |||||
110 | } | |||||||
111 | ||||||||
112 | # text | |||||||
113 | 3 | 50 | 10 | if ($self->{FONT}{opt} > 0) { | ||||
114 | 3 | 8 | ($style1,$style2) = htmlstyles($self->{STYLE}{opt}); | |||||
115 | 3 | 13 | my $textmax=100; | |||||
116 | 3 | 100 | 8 | if ($self->{CLIPTEXT}) { # pixels/char ~= 6 + fontsize(0,1,2,3) | ||||
117 | 1 | 7 | $textmax = int($self->{SIZE}{width}/(6+$self->{'FONT_TABLE'}{$self->{FONT}{opt}})+.5); | |||||
118 | } | |||||||
119 | 3 | 9 | $string .= "{'FONT_TABLE'}{$self->{FONT}{opt}} "; | |||||
120 | 3 | 6 | $string .= "COLOR=$self->{COLOR}{fg} >\n "; | |||||
121 | 3 | 6 | $string .= "$style1\n "; | |||||
122 | 3 | 4 | for (my $i=0;$i<=$#{$self->{TEXT}};$i++) { | |||||
9 | 26 | |||||||
123 | 6 | 10 | my $text = $self->{TEXT}[$i]; | |||||
124 | 6 | 100 | 14 | if ($self->{CLIPTEXT}) {$text = substr($text,0,$textmax);} | ||||
3 | 7 | |||||||
125 | ||||||||
126 | 6 | 11 | my ($c,$z,$s1,$s2,$r1,$r2,)=('','','','','','',); | |||||
127 | 6 | 50 | 14 | if (defined $self->{TEXTCOL}[$i]) {$c= "COLOR=" . $self->{TEXTCOL}[$i];} | ||||
6 | 12 | |||||||
128 | 6 | 50 | 13 | if (defined $self->{TEXTSIZE}[$i]) {$z= "SIZE=" . $self->{FONT_TABLE}{$self->{TEXTSIZE}[$i]};} | ||||
6 | 26 | |||||||
129 | 6 | 50 | 12 | if (defined $self->{TEXTSTYLE}[$i]) {($s1,$s2)= htmlstyles($self->{TEXTSTYLE}[$i]);} | ||||
6 | 13 | |||||||
130 | 6 | 100 | 19 | if ($self->{TEXTREF}[$i]) {($r1,$r2) = ($self->{TEXTREF}[$i],"");} | ||||
4 | 9 | |||||||
131 | ||||||||
132 | 6 | 50 | 15 | if ($s1) { $string .= " $r1 $style2 $s1 $text $s2$style1 $r2\n";} |
||||
6 | 27 | |||||||
133 | 0 | 0 | else { $string .= " $r1 $text $r2\n";} |
|||||
134 | } | |||||||
135 | 3 | 7 | $string .= "$style2"; | |||||
136 | } | |||||||
137 | ||||||||
138 | # finish up | |||||||
139 | 3 | 4 | $string .= "$htmlref2 | \n";|||||
140 | ||||||||
141 | 3 | 10 | return $string; | |||||
142 | } | |||||||
143 | ||||||||
144 | # **************************************************************** | |||||||
145 | sub gettk { | |||||||
146 | 0 | 0 | 0 | 0 | my $self = shift; | |||
147 | ||||||||
148 | 0 | 0 | return $self->{DAYS}; | |||||
149 | } | |||||||
150 | ||||||||
151 | # **************************************************************** | |||||||
152 | sub htmlstyles { | |||||||
153 | 15 | 15 | 0 | 17 | my $codes = shift; | |||
154 | ||||||||
155 | 15 | 20 | my ($s1,$s2) = ('',''); | |||||
156 | ||||||||
157 | 15 | 29 | foreach my $code (split('',$codes)) { | |||||
158 | 23 | 100 | 52 | if ($code eq 'n') {$s1 .= ' '; $s2 .= ' ';} | ||||
3 | 4 | |||||||
3 | 5 | |||||||
159 | 23 | 100 | 46 | if ($code eq 'b') {$s1 .= ''; $s2 = '' . $s2;} | ||||
10 | 12 | |||||||
10 | 17 | |||||||
160 | 23 | 100 | 42 | if ($code eq 'i') {$s1 .= ''; $s2 = '' . $s2;} | ||||
6 | 9 | |||||||
6 | 9 | |||||||
161 | 23 | 100 | 56 | if ($code eq 'u') {$s1 .= ''; $s2 = '' . $s2;} | ||||
4 | 6 | |||||||
4 | 17 | |||||||
162 | } | |||||||
163 | ||||||||
164 | 15 | 50 | return ($s1,$s2); | |||||
165 | } | |||||||
166 | ||||||||
167 | # **************************************************************** | |||||||
168 | sub dayname { | |||||||
169 | 2 | 2 | 0 | 8 | my $self = shift; | |||
170 | 2 | 50 | 8 | if (@_) { | ||||
171 | 2 | 5 | $self->{DAYNAME} = shift; | |||||
172 | } | |||||||
173 | 0 | 0 | else { return $self->{DAYNAME};} | |||||
174 | } | |||||||
175 | ||||||||
176 | # **************************************************************** | |||||||
177 | sub htmlref { | |||||||
178 | 3 | 3 | 0 | 10 | my $self = shift; | |||
179 | 3 | 50 | 7 | if (@_) { | ||||
180 | 3 | 8 | $self->{HTMLREF} = shift; | |||||
181 | } | |||||||
182 | 0 | 0 | else { return $self->{HTMLREF};} | |||||
183 | } | |||||||
184 | ||||||||
185 | # **************************************************************** | |||||||
186 | sub text { | |||||||
187 | 2 | 2 | 0 | 7 | my $self = shift; | |||
188 | 2 | 50 | 6 | if (@_) { | ||||
189 | 2 | 3 | @{$self->{TEXT}} = @_; | |||||
2 | 8 | |||||||
190 | } | |||||||
191 | 0 | 0 | else { return @{$self->{TEXT}};} | |||||
0 | 0 | |||||||
192 | } | |||||||
193 | ||||||||
194 | # **************************************************************** | |||||||
195 | sub htmlexpand { | |||||||
196 | 3 | 3 | 0 | 10 | my $self = shift; | |||
197 | 3 | 14 | my @ans = qw( no yes ); | |||||
198 | 3 | 50 | 6 | if (@_) { | ||||
199 | 3 | 5 | $self->{EXPAND} = 0; | |||||
200 | 3 | 50 | 15 | if ( $_[0] eq 'yes' ) {$self->{EXPAND} = 1;} | ||||
3 | 8 | |||||||
201 | } | |||||||
202 | 0 | 0 | else { return $ans[$self->{EXPAND}];} | |||||
203 | } | |||||||
204 | ||||||||
205 | # **************************************************************** | |||||||
206 | sub cliptext { | |||||||
207 | 2 | 2 | 0 | 8 | my $self = shift; | |||
208 | 2 | 5 | my @ans = qw( no yes ); | |||||
209 | 2 | 50 | 4 | if (@_) { | ||||
210 | 2 | 3 | $self->{CLIPTEXT} = 0; | |||||
211 | 2 | 100 | 9 | if ( $_[0] eq 'yes' ) {$self->{CLIPTEXT} = 1;} | ||||
1 | 18 | |||||||
212 | } | |||||||
213 | 0 | 0 | else { return $ans[$self->{CLIPTEXT}];} | |||||
214 | } | |||||||
215 | ||||||||
216 | # **************************************************************** | |||||||
217 | sub size { | |||||||
218 | 3 | 3 | 0 | 10 | my $self = shift; | |||
219 | 3 | 50 | 9 | if (@_) { | ||||
220 | 3 | 12 | $self->{SIZE}{height} = shift; | |||||
221 | 3 | 8 | $self->{SIZE}{width} = shift; | |||||
222 | } | |||||||
223 | 0 | 0 | else { return ($self->{SIZE}{height},$self->{SIZE}{width});} | |||||
224 | } | |||||||
225 | ||||||||
226 | # **************************************************************** | |||||||
227 | sub color { | |||||||
228 | 5 | 5 | 0 | 15 | my $self = shift; | |||
229 | 5 | 50 | 12 | if (@_) { | ||||
230 | 5 | 9 | $self->{COLOR}{fg} = shift; | |||||
231 | 5 | 13 | $self->{COLOR}{bgmain} = shift; | |||||
232 | } | |||||||
233 | 0 | 0 | else { return ($self->{COLOR}{fg},$self->{COLOR}{bgmain},);} | |||||
234 | } | |||||||
235 | ||||||||
236 | # **************************************************************** | |||||||
237 | sub font { | |||||||
238 | 3 | 3 | 0 | 9 | my $self = shift; | |||
239 | 3 | 50 | 20 | if (@_) { | ||||
240 | 3 | 6 | $self->{FONT}{day} = shift; | |||||
241 | 3 | 6 | $self->{FONT}{main} = shift; | |||||
242 | 3 | 7 | $self->{FONT}{opt} = shift; | |||||
243 | } | |||||||
244 | 0 | 0 | else { return ($self->{FONT}{day},$self->{FONT}{main},$self->{FONT}{opt},);} | |||||
245 | } | |||||||
246 | ||||||||
247 | # **************************************************************** | |||||||
248 | sub style { | |||||||
249 | 2 | 2 | 0 | 8 | my $self = shift; | |||
250 | 2 | 50 | 6 | if (@_) { | ||||
251 | 2 | 5 | $self->{STYLE}{day} = shift; | |||||
252 | 2 | 3 | $self->{STYLE}{main} = shift; | |||||
253 | 2 | 5 | $self->{STYLE}{opt} = shift; | |||||
254 | } | |||||||
255 | 0 | 0 | else { return ($self->{STYLE}{day},$self->{STYLE}{main},$self->{STYLE}{opt},);} | |||||
256 | } | |||||||
257 | ||||||||
258 | # **************************************************************** | |||||||
259 | sub textcolor { | |||||||
260 | 2 | 2 | 0 | 8 | my $self = shift; | |||
261 | 2 | 50 | 4 | if (@_) { | ||||
262 | 2 | 3 | @{$self->{TEXTCOL}} = @_; | |||||
2 | 8 | |||||||
263 | } | |||||||
264 | 0 | 0 | else { return @{$self->{TEXTCOL}};} | |||||
0 | 0 | |||||||
265 | } | |||||||
266 | ||||||||
267 | # **************************************************************** | |||||||
268 | sub textsize { | |||||||
269 | 2 | 2 | 0 | 8 | my $self = shift; | |||
270 | 2 | 50 | 4 | if (@_) { | ||||
271 | 2 | 3 | @{$self->{TEXTSIZE}} = @_; | |||||
2 | 8 | |||||||
272 | } | |||||||
273 | 0 | 0 | else { return @{$self->{TEXTSIZE}};} | |||||
0 | 0 | |||||||
274 | } | |||||||
275 | ||||||||
276 | # **************************************************************** | |||||||
277 | sub textstyle { | |||||||
278 | 2 | 2 | 0 | 7 | my $self = shift; | |||
279 | 2 | 50 | 5 | if (@_) { | ||||
280 | 2 | 3 | @{$self->{TEXTSTYLE}} = @_; | |||||
2 | 7 | |||||||
281 | } | |||||||
282 | 0 | 0 | else { return @{$self->{TEXTSTYLE}};} | |||||
0 | 0 | |||||||
283 | } | |||||||
284 | ||||||||
285 | # **************************************************************** | |||||||
286 | sub nameref { | |||||||
287 | 2 | 2 | 0 | 5 | my $self = shift; | |||
288 | 2 | 50 | 6 | if (@_) { | ||||
289 | 2 | 5 | $self->{NAMEREF} = shift; | |||||
290 | } | |||||||
291 | 0 | 0 | else { return $self->{NAMEREF};} | |||||
292 | } | |||||||
293 | ||||||||
294 | # **************************************************************** | |||||||
295 | sub textref { | |||||||
296 | 2 | 2 | 0 | 6 | my $self = shift; | |||
297 | 2 | 50 | 5 | if (@_) { | ||||
298 | 2 | 3 | @{$self->{TEXTREF}} = @_; | |||||
2 | 7 | |||||||
299 | } | |||||||
300 | 0 | 0 | else { return @{$self->{TEXTREF}};} | |||||
0 | 0 | |||||||
301 | } | |||||||
302 | ||||||||
303 | # **************************************************************** | |||||||
304 | sub initialize { | |||||||
305 | 3 | 3 | 0 | 4 | my $self = shift; | |||
306 | ||||||||
307 | 3 | 5 | @{$self->{COLORS}} = qw(v w g v w g); | |||||
3 | 10 | |||||||
308 | ||||||||
309 | # default values | |||||||
310 | ||||||||
311 | 3 | 6 | $self->{SIZE}{height} = 100; | |||||
312 | 3 | 6 | $self->{SIZE}{width} = 100; | |||||
313 | 3 | 10 | $self->{COLOR}{fg} = 'BLACK'; | |||||
314 | 3 | 7 | $self->{COLOR}{bgmain} = '#33cc00'; # green | |||||
315 | 3 | 6 | $self->{FONT}{day} = '14'; | |||||
316 | 3 | 5 | $self->{FONT}{main} = '10'; | |||||
317 | 3 | 5 | $self->{FONT}{opt} = '8'; | |||||
318 | 3 | 6 | $self->{STYLE}{day} = 'b'; | |||||
319 | 3 | 6 | $self->{STYLE}{main} = 'b'; | |||||
320 | 3 | 5 | $self->{STYLE}{opt} = 'n'; | |||||
321 | ||||||||
322 | # utility values | |||||||
323 | ||||||||
324 | 3 | 5 | %{$self->{'FONT_TABLE'}}=( | |||||
3 | 30 | |||||||
325 | "3" => "-2", | |||||||
326 | "4" => "-2", | |||||||
327 | "5" => "-1", | |||||||
328 | "6" => "-1", | |||||||
329 | "7" => "+0", | |||||||
330 | "8" => "+0", | |||||||
331 | "9" => "+1", | |||||||
332 | "10" => "+1", | |||||||
333 | "11" => "+2", | |||||||
334 | "12" => "+2", | |||||||
335 | "13" => "+3", | |||||||
336 | "14" => "+3", | |||||||
337 | "15" => "+4", | |||||||
338 | "16" => "+4", | |||||||
339 | ); | |||||||
340 | ||||||||
341 | } | |||||||
342 | ||||||||
343 | 1; | |||||||
344 | __END__ |