line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::FIGlet::Ransom; |
2
|
|
|
|
|
|
|
require 5; |
3
|
4
|
|
|
4
|
|
27
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
175
|
|
4
|
4
|
|
|
4
|
|
23
|
use vars qw/$VERSION @ISA/; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
247
|
|
5
|
4
|
|
|
4
|
|
27
|
use Carp 'croak'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
6331
|
|
6
|
|
|
|
|
|
|
$VERSION = 2.17; |
7
|
|
|
|
|
|
|
@ISA = 'Text::FIGlet::Font'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#Roll our own for 5.005, and remove somewhat heavy List::Util dependency |
10
|
12
|
|
|
12
|
0
|
76
|
sub max{ (sort @_)[-1]; } |
11
|
276
|
|
|
276
|
0
|
476
|
sub sum{ my $cnt; $cnt += $_ foreach @_; return $cnt} |
|
276
|
|
|
|
|
957
|
|
|
276
|
|
|
|
|
703
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new{ |
14
|
4
|
|
|
4
|
1
|
7
|
shift(); |
15
|
4
|
|
|
|
|
25
|
my $self = {-U=>0, -v=>'center', -m=>-1, @_}; |
16
|
4
|
|
|
|
|
10
|
my(@fonts, %fonts); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
4
|
50
|
|
|
|
24
|
if( ref($self->{-f}) eq 'HASH' ){ |
20
|
4
|
50
|
|
|
|
24
|
croak "No default specified" unless defined($self->{-f}->{undef}); |
21
|
4
|
50
|
|
|
|
6
|
croak "Insufficient number of fonts, 2 or more please" unless keys(%{$self->{-f}}) > 1; |
|
4
|
|
|
|
|
22
|
|
22
|
4
|
|
|
|
|
15
|
$self->{_fonts} = [delete($self->{-f}->{undef}), keys %{$self->{-f}}]; |
|
4
|
|
|
|
|
23
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else{ |
25
|
0
|
0
|
|
|
|
0
|
croak "Insufficient number of fonts, 2 or more please" unless scalar(@{$self->{-f}}) > 1; |
|
0
|
|
|
|
|
0
|
|
26
|
0
|
|
|
|
|
0
|
$self->{_fonts} = $self->{-f}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#Load the fonts |
31
|
4
|
|
|
|
|
12
|
my $x =0; |
32
|
4
|
|
|
|
|
8
|
foreach my $font ( @{$self->{_fonts}} ){ |
|
4
|
|
|
|
|
11
|
|
33
|
8
|
|
|
|
|
112
|
push(@fonts, Text::FIGlet::Font->new(%$self, -f=>$font)); |
34
|
8
|
|
|
|
|
71
|
$fonts{$font} = $x++; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#Synthesize a header |
39
|
|
|
|
|
|
|
#Hardblank = DEL |
40
|
4
|
|
|
|
|
21
|
$self->{_header}->[0] = "\x7F"; |
41
|
|
|
|
|
|
|
#Height |
42
|
4
|
|
|
|
|
12
|
$self->{_header}->[1] = max( map {$_->{_header}->[1]} @fonts ); |
|
8
|
|
|
|
|
80
|
|
43
|
|
|
|
|
|
|
#Base height |
44
|
4
|
|
|
|
|
11
|
$self->{_header}->[2] = max( map {$_->{_header}->[2]} @fonts ); |
|
8
|
|
|
|
|
28
|
|
45
|
|
|
|
|
|
|
#Max glyph width |
46
|
4
|
|
|
|
|
11
|
$self->{_header}->[3] = $self->{_maxLen} = max( map {$_->{_maxLen}} @fonts ); |
|
8
|
|
|
|
|
23
|
|
47
|
|
|
|
|
|
|
#Smush = none |
48
|
4
|
|
|
|
|
14
|
$self->{_header}->[4] = 0; |
49
|
|
|
|
|
|
|
#Comment line count, calculated when dumping @_ ... include chr to font mapping? |
50
|
|
|
|
|
|
|
#R2L = false |
51
|
4
|
|
|
|
|
13
|
$self->{_header}->[6] = 0; |
52
|
|
|
|
|
|
|
|
53
|
4
|
50
|
|
|
|
22
|
if( $self->{-v} eq 'base' ){ |
54
|
0
|
|
|
|
|
0
|
my $descender = max( map {$_->{_header}->[1] - $_->{_header}->[2]} @fonts ); |
|
0
|
|
|
|
|
0
|
|
55
|
0
|
|
|
|
|
0
|
$self->{_header}->[1] = $self->{_header}->[2] + $descender; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#Assemble the body |
60
|
4
|
|
|
|
|
17
|
for(my $i=32; $i<127; $i++ ){ |
61
|
380
|
|
|
|
|
431
|
my($c, $R); |
62
|
380
|
50
|
|
|
|
1122
|
if( ref($self->{-f}) eq 'HASH' ){ |
63
|
380
|
|
|
|
|
444
|
while( my($k,$v) = each(%{$self->{-f}}) ){ |
|
656
|
|
|
|
|
2561
|
|
64
|
380
|
100
|
|
|
|
1692
|
if( chr($i) =~ /$v/ ){ |
65
|
104
|
|
|
|
|
225
|
$c = $fonts[$R=$fonts{$k}]->{_font}->[$i]; |
66
|
|
|
|
|
|
|
#Reset counter, may be more trouble than the short-circuit is worth |
67
|
104
|
|
|
|
|
110
|
keys %{$self->{-f}}; |
|
104
|
|
|
|
|
190
|
|
68
|
104
|
|
|
|
|
165
|
last; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
380
|
100
|
|
|
|
1642
|
$c = $fonts[$R=0]->{_font}->[$i] unless $c; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else{ |
74
|
0
|
|
|
|
|
0
|
$R = rand(scalar(@fonts)); |
75
|
0
|
|
|
|
|
0
|
$c = $fonts[$R]->{_font}->[$i]; |
76
|
0
|
|
|
|
|
0
|
$self->{_map}->[$R] .= chr($i); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#Vertical-alignment & padding |
80
|
380
|
100
|
|
|
|
9516
|
if( my $delta = $self->{_header}->[1] - $fonts[$R]->{_header}->[1] ){ |
81
|
|
|
|
|
|
|
#Parens around qw for 5.005 |
82
|
276
|
50
|
|
|
|
706
|
local($self->{-v}) = (qw/top center center bottom/)[rand(4)] |
83
|
|
|
|
|
|
|
if $self->{-v} eq 'random'; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
276
|
50
|
|
|
|
1061
|
my $ws = $self->{-m} == 0 ? $c->[0] : sum(@$c[0,1,2]); |
87
|
276
|
100
|
|
|
|
1004
|
if( $self->{-v} eq 'top' ){ |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
88
|
69
|
|
|
|
|
239
|
push(@$c, (' 'x$ws)x$delta); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif( $self->{-v} eq 'baseline' ){ |
91
|
69
|
|
|
|
|
137
|
my $t = $self->{_header}->[2] - $fonts[$R]->{_header}->[2]; |
92
|
69
|
|
|
|
|
329
|
my $b = $self->{_header}->[1] - $fonts[$R]->{_header}->[1] - $t; |
93
|
69
|
50
|
|
|
|
468
|
splice(@$c, 3, 0, (' 'x$ws)x$t) if $t; |
94
|
69
|
50
|
|
|
|
614
|
push(@$c, (' 'x$ws)x$b) if $b; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
elsif( $self->{-v} eq 'bottom' ){ |
97
|
69
|
|
|
|
|
234
|
splice(@$c, 3, 0, (' 'x$ws)x$delta); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif( $self->{-v} eq 'center' ){ |
100
|
69
|
|
|
|
|
98
|
my $t = int($delta/2); |
101
|
69
|
|
|
|
|
85
|
my $b = $delta - $t; |
102
|
69
|
50
|
|
|
|
231
|
splice(@$c, 3, 0, (' 'x$ws)x$t) if $t; |
103
|
69
|
50
|
|
|
|
199
|
push(@$c, (' 'x$ws)x$b) if $b; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#XXX -m... freeze/thaw? horizontally center w/ padding -height..-1 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#Common hardblank |
111
|
380
|
|
|
|
|
906
|
my $iHard=$fonts[$R]->{_header}->[0]; |
112
|
380
|
|
|
|
|
1558
|
foreach my $j(-$self->{_header}->[1]..-1){ |
113
|
2280
|
|
|
|
|
10151
|
$c->[$j]=~ s/$iHard/$self->{_header}->[0]/g; |
114
|
|
|
|
|
|
|
#$c->[$j].= Text::FIGlet::UTF8len($c->[$j]); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
380
|
|
|
|
|
1704
|
$self->{_font}->[$i] = $c; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
4
|
|
|
|
|
102
|
bless($self); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub freeze{ |
124
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
125
|
0
|
|
|
|
|
|
my $font; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
foreach my $opt ( sort grep {/^-/} keys %{$self} ){ |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $val = $self->{$opt}; |
129
|
0
|
0
|
|
|
|
|
if( ref($val) eq 'ARRAY' ){ |
|
|
0
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$val = '[qw/'. join(' ', @$val) . '/]'; |
131
|
0
|
0
|
|
|
|
|
if( $opt eq '-f' ){ |
132
|
0
|
|
|
|
|
|
for(my $f=0; $f< scalar @{$self->{_map}}; $f++ ){ |
|
0
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$val .= "\n#\tfont$f $self->{_map}->[$f]"; |
134
|
0
|
|
|
|
|
|
$self->{_header}->[5]++; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
elsif( ref($val) eq 'HASH' ){ |
139
|
0
|
|
|
|
|
|
$val = '{undef,'. $self->{_fonts}->[0] .','. join(',',%{$val}) .'}'; |
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
0
|
|
|
|
|
|
$font .= sprintf "#%s => %s\n", $opt, $val; |
142
|
0
|
|
|
|
|
|
$self->{_header}->[5]++; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$font = sprintf("flf2a%s %s %s %s %s %s %s\n", @{$self->{_header}}). $font; |
|
0
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
for(my $i=32; $i<= scalar @{$self->{_font}}; $i++ ){ |
|
0
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my $c = $self->{_font}->[$i]; |
149
|
0
|
|
|
|
|
|
foreach my $j(-$self->{_header}->[1]..-1){ |
150
|
0
|
0
|
|
|
|
|
$font .= $c->[$j] . ($j<-1?"\x1F\n":"\x1F\x1F\n"); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
|
return $font; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
157
|
|
|
|
|
|
|
__END__ |