line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormatNroff::Table::Nroff; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
159
|
use 5.004; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
247
|
|
4
|
7
|
|
|
7
|
|
28
|
use strict; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
204
|
|
5
|
7
|
|
|
7
|
|
44
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
278
|
|
6
|
7
|
|
|
7
|
|
27
|
use parent 'HTML::FormatNroff::Table'; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
3202
|
use HTML::FormatNroff::Table::Row::Nroff; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
216
|
|
9
|
7
|
|
|
7
|
|
37
|
use Carp; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
5073
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub rnd { |
12
|
0
|
|
|
0
|
0
|
0
|
my ($num) = @_; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
0
|
my $result = int $num; |
15
|
0
|
|
|
|
|
0
|
my $frac = $num - $result; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
0
|
print STDERR "frac $frac\n"; |
18
|
0
|
0
|
|
|
|
0
|
if ( $frac > .5 ) { |
19
|
0
|
|
|
|
|
0
|
$result++; |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
0
|
return $result; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $_width_used = 0; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub calculate_width { |
27
|
5
|
|
|
5
|
1
|
9
|
my ( $self, $total, $num ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
10
|
my $page_width = $self->{'page_width'}; |
30
|
5
|
50
|
|
|
|
17
|
unless ($page_width) { $page_width = 6; } |
|
0
|
|
|
|
|
0
|
|
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
8
|
my $width = $page_width; |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
|
|
17
|
my $table_width = $self->{'width'}; |
35
|
5
|
50
|
|
|
|
11
|
if ($table_width) { |
36
|
0
|
|
|
|
|
0
|
$table_width =~ s/([0-9]*)%/$1/; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
$width = $page_width * $table_width / 100; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
18
|
my $start = $num * $width / $total; |
42
|
|
|
|
|
|
|
|
43
|
5
|
50
|
|
|
|
20
|
if ( $start < 1 ) { |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# try to make this column as big as the biggest string |
46
|
0
|
|
|
|
|
0
|
$start = int $num / 12; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
5
|
50
|
|
|
|
22
|
if ( ( $_width_used + $start ) <= $width ) { |
50
|
5
|
|
|
|
|
6
|
$_width_used += $start; |
51
|
5
|
|
|
|
|
78
|
return $start; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
return $width - $_width_used; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub attributes { |
58
|
6
|
|
|
6
|
1
|
8
|
my ($self) = @_; |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
|
|
8
|
my @attributes; |
61
|
|
|
|
|
|
|
|
62
|
6
|
|
|
|
|
17
|
my $tab_attr = 'tab(' . $self->{'tab'} . ')'; |
63
|
6
|
|
|
|
|
10
|
push( @attributes, $tab_attr ); |
64
|
|
|
|
|
|
|
|
65
|
6
|
50
|
33
|
|
|
30
|
unless ( $self->{'width'} and $self->{'width'} ne '100%' ) { |
66
|
6
|
|
|
|
|
10
|
push( @attributes, 'expand' ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
6
|
50
|
|
|
|
36
|
if ( $self->{'align'} eq 'center' ) { |
70
|
0
|
|
|
|
|
0
|
push( @attributes, $self->{'align'} ); |
71
|
|
|
|
|
|
|
} |
72
|
6
|
|
|
|
|
24
|
return (@attributes); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub output { |
76
|
3
|
|
|
3
|
1
|
14
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# if the table is empty, forget it. |
79
|
3
|
50
|
|
|
|
13
|
unless ( defined $self->{"current_row"} ) { |
80
|
0
|
|
|
|
|
0
|
$self->{'formatter'}->out("\n.sp\n"); |
81
|
0
|
|
|
|
|
0
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# start the table |
85
|
3
|
|
|
|
|
18
|
$self->{'formatter'}->out("\n.in 0\n.sp\n.TS\n"); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# put out attributes, if any |
88
|
3
|
|
|
|
|
16
|
my $attribute; |
89
|
3
|
|
|
|
|
14
|
my @atts = $self->attributes(); |
90
|
3
|
|
|
|
|
5
|
my $cnt = @atts; |
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
|
|
10
|
foreach $attribute ( $self->attributes() ) { |
93
|
6
|
|
|
|
|
24
|
$self->{'formatter'}->out("$attribute"); |
94
|
6
|
100
|
|
|
|
40
|
if ( $cnt > 1 ) { |
95
|
3
|
|
|
|
|
13
|
$self->{'formatter'}->out(", "); |
96
|
|
|
|
|
|
|
} |
97
|
6
|
|
|
|
|
27
|
$cnt--; |
98
|
|
|
|
|
|
|
} |
99
|
3
|
|
|
|
|
17
|
$self->{'formatter'}->out(";\n"); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# put out data |
102
|
3
|
|
|
|
|
18
|
my @row_widths; |
103
|
3
|
|
|
|
|
28
|
$self->row_iterator( 'widths', \@row_widths ); |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
4
|
my $arrayref; |
106
|
|
|
|
|
|
|
my @maxvals; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# my @sum; |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
7
|
foreach $arrayref (@row_widths) { |
111
|
7
|
|
|
|
|
8
|
my $i; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# print STDERR "ROW\n"; |
114
|
|
|
|
|
|
|
|
115
|
7
|
|
|
|
|
8
|
for $i ( 0 .. $#{$arrayref} ) { |
|
7
|
|
|
|
|
20
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# print STDERR "$i -> ", $$arrayref[$i], " max is ", |
118
|
|
|
|
|
|
|
# $maxvals[$i], "\n"; |
119
|
|
|
|
|
|
|
|
120
|
13
|
100
|
66
|
|
|
55
|
unless (( defined $maxvals[$i] ) |
121
|
|
|
|
|
|
|
and ( $maxvals[$i] > $$arrayref[$i] ) ) { |
122
|
5
|
|
|
|
|
15
|
$maxvals[$i] = $$arrayref[$i]; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# $sum[$i] += $$arrayref[$i]; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
3
|
|
|
|
|
7
|
my $total = 0; |
130
|
3
|
|
|
|
|
13
|
map { $total += $_; } @maxvals; |
|
5
|
|
|
|
|
11
|
|
131
|
|
|
|
|
|
|
|
132
|
3
|
|
|
|
|
5
|
$_width_used = 0; |
133
|
5
|
|
|
|
|
20
|
my @widths = |
134
|
3
|
|
|
|
|
7
|
map { sprintf( "%.2f", $self->calculate_width( $total, $_ ) ); } |
135
|
|
|
|
|
|
|
@maxvals; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# put out format |
138
|
3
|
|
|
|
|
14
|
$self->row_iterator( 'output_format', $self->{'formatter'}, @widths ); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# put out data |
141
|
3
|
|
|
|
|
23
|
$self->row_iterator( 'output', $self->{'formatter'}, $self->{'tab'} ); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# end the table |
144
|
3
|
|
|
|
|
21
|
$self->{'formatter'}->out(".TE\n"); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub add_row { |
148
|
7
|
|
|
7
|
1
|
12
|
my ( $self, %attr ) = @_; |
149
|
|
|
|
|
|
|
|
150
|
7
|
100
|
|
|
|
22
|
if ( defined( $self->{"current_row"} ) ) { |
151
|
4
|
|
|
|
|
17
|
push( @{ $self->{'previous_rows'} }, $self->{"current_row"} ); |
|
4
|
|
|
|
|
10
|
|
152
|
|
|
|
|
|
|
} |
153
|
7
|
|
|
|
|
62
|
$self->{"current_row"} = HTML::FormatNroff::Table::Row::Nroff->new(%attr); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub row_iterator { |
157
|
9
|
|
|
9
|
1
|
26
|
my ( $self, $method, @args ) = @_; |
158
|
|
|
|
|
|
|
|
159
|
9
|
|
|
|
|
12
|
my $row; |
160
|
9
|
|
|
|
|
9
|
foreach $row ( @{ $self->{'previous_rows'} } ) { |
|
9
|
|
|
|
|
24
|
|
161
|
12
|
|
|
|
|
76
|
$row->$method( 0, @args ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
9
|
50
|
|
|
|
47
|
if ( defined $self->{"current_row"} ) { |
165
|
9
|
|
|
|
|
46
|
$self->{"current_row"}->$method( 1, @args ); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
__END__ |