/
Report.pm
1200 lines (888 loc) · 30 KB
/
Report.pm
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#---------------------------------------------------------------------
package PostScript::Report;
#
# Copyright 2009 Christopher J. Madsen
#
# Author: Christopher J. Madsen <perl@cjmweb.net>
# Created: October 12, 2009
#
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
# GNU General Public License or the Artistic License for more details.
#
# ABSTRACT: Produce formatted reports in PostScript
#---------------------------------------------------------------------
our $VERSION = '0.12';
# This file is part of {{$dist}} {{$dist_version}} ({{$date}})
use 5.008;
use Moose 0.90; # Moose::Meta::Attribute::Native
use MooseX::Types::Moose qw(ArrayRef Bool CodeRef HashRef Int Num Str);
use PostScript::Report::Types ':all';
use PostScript::File 2.20 'pstr'; # Use function library
use PostScript::Report::Font ();
use List::Util 'min';
use Scalar::Util 'reftype';
use namespace::autoclean;
#---------------------------------------------------------------------
=method build
$rpt = PostScript::Report->build(\%description)
This is the usual method for constructing a PostScript::Report. It
passes the C<%description> to L<PostScript::Report::Builder>.
If C<%description> does not define C<report_class>, then it is set to
the class on which you called C<build>. (This matters only if you
have subclassed PostScript::Report.)
=cut
sub build
{
my ($class, $descHash) = @_;
confess "build is a class method" if ref $class;
require PostScript::Report::Builder;
my $builder = PostScript::Report::Builder->new($descHash);
$builder->report_class($class) unless $descHash->{report_class};
$builder->build($descHash);
} # end build
#---------------------------------------------------------------------
=for Pod::Loom-sort_attr
report_header
page_header
detail
page_footer
report_footer
=attr-sec report_header
This is printed at the top of the first page.
=attr-sec page_header
This is printed at the top of every page (and below the
C<report_header> on the first page).
=attr-sec detail
This is printed once for each row of C<@rows>. See L</"run">.
=attr-sec page_footer
This is printed at the end of every page (and above the
C<report_footer> on the last page). Also see L</"first_footer">
and L</"footer_align">.
=attr-sec report_footer
This is printed at the end of the last page.
Also see L</"first_footer"> and L</"footer_align">.
=cut
has report_header => (
is => 'rw',
isa => Component,
);
has page_header => (
is => 'rw',
isa => Component,
);
has detail => (
is => 'rw',
isa => Component,
);
has page_footer => (
is => 'rw',
isa => Component,
);
has report_footer => (
is => 'rw',
isa => Component,
);
=attr-fmt detail_background
This is a code reference that is called before the detail section is
drawn. It receives two parameters: the row number and the row number
on this page (both 0-based). It returns the background color for the
detail section, or C<undef> (which means to use the same color as last
time).
=cut
has detail_background => (
is => 'ro',
isa => CodeRef,
);
=attr-fmt first_footer
This may be either C<page> or C<report>, and controls the order of the
footers on the last page. The default is C<page>, which puts the page
footer above the report footer.
=cut
has first_footer => (
is => 'ro',
isa => SectionType,
default => 'page',
);
=attr-fmt footer_align
This may be either C<top>, C<bottom>, or C<split>. If it's C<bottom>
(the default), the footers are placed at the very bottom of the page,
touching the bottom margin. If it's C<top>, then the footers are
placed immediately after the last detail row. If it's C<split>, then
the first footer is placed using C<top>, and the second footer is
placed using C<bottom>. (Do not use C<split> unless you have defined
both footers.)
=cut
has footer_align => (
is => 'ro',
isa => FooterPos,
default => 'bottom',
);
sub _sections { qw(report_header page_header detail page_footer report_footer) }
sub _init
{
my ($self) = @_;
$self->_set_ps( my $ps = $self->_build_ps );
foreach my $sectionName ($self->_sections) {
my $section = $self->$sectionName or next;
$section->init($self, $self);
$section->_set_height($self->row_height) unless $section->has_height;
} # end foreach $sectionName
$ps->use_functions(qw(drawBox));
$self->ps_functions->{+__PACKAGE__} = <<'END PS';
%---------------------------------------------------------------------
% Draw border styles: Left Top Right Bottom Linewidth dbX
/db0 { 5 { pop } repeat } bind def
/db1 { gsave setlinewidth drawBox grestore } bind def
% Easy access to the corners of a box:
% 3 3 1 1
% L T R B
/boxLT { 3 index 3 index } bind def
/boxRT { 1 index 3 index } bind def
/boxLB { 3 index 1 index } bind def
/boxRB { 2 copy } bind def
% Start drawing a border: L T R B LW bdrB
/bdrB { gsave setlinewidth } bind def
% Finish drawing a border: L T R B X Y bdrE
/bdrE {
lineto stroke % Finish the line and stroke it
pop pop pop pop % Remove L T R B
grestore
} bind def
/dbT { bdrB boxLT moveto boxRT bdrE } bind def
/dbB { bdrB boxLB moveto boxRB bdrE } bind def
/dbL { bdrB boxLT moveto boxLB bdrE } bind def
/dbR { bdrB boxRT moveto boxRB bdrE } bind def
/dbTB { 5 copy dbT dbB } bind def
/dbLR { 5 copy dbL dbR } bind def
/dbTL { bdrB boxRT moveto boxLT lineto boxLB bdrE } bind def
/dbTR { bdrB boxLT moveto boxRT lineto boxRB bdrE } bind def
/dbBL { bdrB boxRB moveto boxLB lineto boxLT bdrE } bind def
/dbBR { bdrB boxLB moveto boxRB lineto boxRT bdrE } bind def
/dbTLR { bdrB boxLB moveto boxLT lineto boxRT lineto boxRB bdrE } bind def
/dbBLR { bdrB boxLT moveto boxLB lineto boxRB lineto boxRT bdrE } bind def
/dbTBL { bdrB boxRT moveto boxLT lineto boxLB lineto boxRB bdrE } bind def
/dbTBR { bdrB boxLT moveto boxRT lineto boxRB lineto boxLB bdrE } bind def
END PS
} # end _init
#---------------------------------------------------------------------
# NOTE: width and height are now handled by the ps attribute:
=method width
$width = $rpt->width;
This returns the width of the report (the paper width minus the margins).
=method height
$height = $rpt->height;
This returns the height of the report (the paper height minus the margins).
=attr-in row_height
This is the default height of a row on the report (default 15).
=cut
has row_height => (
is => 'ro',
isa => Int,
default => 15,
);
=attr-in align
This is the default text alignment. It may be C<left>, C<center>, or
C<right> (default C<left>).
=cut
has align => (
is => 'ro',
isa => HAlign,
default => 'left',
);
=attr-in border
This is the default border style. It may be 1 for a solid border (the
default), or 0 for no border. In addition, you may specify any
combination of the letters T, B, L, and R (meaning top, bottom, left,
and right) to have a border only on the specified side(s).
The thickness of the border is controlled by L</line_width>.
(Note: The string you give will be converted into the canonical
representation, which has the letters upper case and in the order
TBLR.)
=cut
has border => (
is => 'ro',
isa => BorderStyle,
coerce => 1,
default => 1,
);
=attr-in font
This is the default font. It defaults to Helvetica 9.
=cut
has font => (
is => 'rw',
isa => FontObj,
lazy => 1,
default => sub { shift->get_font(Helvetica => 9) },
init_arg => undef,
);
my $coerce_font = sub {
my $orig = shift;
my $self = shift;
# If they pass a font name & size, create a font object:
@_ = $self->get_font(@_) if @_ == 2;
return $self->$orig(@_);
};
around font => $coerce_font;
=attr-in line_width
This is the default line width (0.5 by default).
It's used mainly for component borders.
A line width of 0 means "as thin as possible".
=cut
has line_width => (
is => 'ro',
isa => Num,
default => 0.5,
);
=attr-in padding_bottom
This indicates the distance between the bottom of a component and the
baseline of the text inside it (4 by default). If this is too small,
then the descenders (on letters like "p" and "y") will be cut off.
(The exact minimum necessary depends on the selected font and size.)
=cut
has padding_bottom => (
is => 'ro',
isa => Num,
default => 4,
);
=attr-in padding_side
This indicates the space between the side of a component and the text
inside it (3 by default).
=cut
has padding_side => (
is => 'ro',
isa => Num,
default => 3,
);
=attr-o extra_styles
This is a hash of additional attributes that can be inherited by child
Components. You wouldn't normally set this directly, because
L<PostScript::Report::Builder> will automatically move any unknown
attributes into this hash.
=cut
has extra_styles => (
is => 'ro',
isa => HashRef,
);
=method get_style
$rpt->get_style($attribute)
Child Components call this method to get the inherited value of any
non-standard style attribute.
=cut
sub get_style
{
my ($self, $attribute) = @_;
# See if we have the attribute:
my $styles = $self->extra_styles or return undef;
return $styles->{$attribute};
} # end get_style
#---------------------------------------------------------------------
=attr-o ps
This is the L<PostScript::File> object containing the report. It's
constructed by the L</run> method, and can be freed by calling the
L</clear> method.
=method clear
$rpt->clear()
This releases the PostScript::File object created by running the
report. You never need to call this method, but it will free up
memory if you want to save the report object and run the report again
later.
=method output
$rpt->output($filename [, $dir]) # save to file
$rpt->output() # return as string
This method takes the same parameters as L<PostScript::File/output>.
You can pass a filename (and optional directory name) to store the
report in a file. (No extension will be added to C<$filename>, so it
should normally end in ".ps".)
If you don't pass a filename, then the PostScript code is returned as
a string.
If you want to reuse the report object, you can call C<clear>
afterwards to free up memory.
=cut
has ps => (
is => 'ro',
isa => 'PostScript::File',
writer => '_set_ps',
clearer => 'clear',
handles => {
output => 'output',
width => 'get_printable_width',
height => 'get_printable_height',
},
init_arg=> undef,
);
*get__PostScript_File = \&ps; # Alias for PostScript::Convert
=for Pod::Coverage
get__PostScript_File
=attr-o ps_functions
This is a hashref of PostScript code blocks that should be added to
the L<PostScript::File> object. The key should begin with the package
inserting the code. If a package adds more than one such block, the
package name should be followed by a hyphen and the block name.
Blocks are added in ASCIIbetical order. A component's C<init> method
may add an entry here.
=cut
has ps_functions => (
is => 'ro',
isa => HashRef[Str],
default => sub { {} },
init_arg => undef,
);
=attr-fmt ps_parameters
This is a hashref of additional parameters to pass to
PostScript::File's constructor. These values will override the
parameters that PostScript::Report generates itself (but you should
reserve this for things that can't be controlled through
other PostScript::Report attributes).
=cut
has ps_parameters => (
is => 'ro',
isa => HashRef,
default => sub { {} },
);
=attr-fmt paper_size
This the paper size (default C<Letter>). See L<PostScript::File/paper>.
=cut
has paper_size => (
is => 'ro',
isa => Str,
default => 'Letter',
);
=attr-fmt top_margin
This is the top margin (default 72, or one inch).
=attr-fmt bottom_margin
This is the bottom margin (default 72, or one inch).
=attr-fmt left_margin
This is the left margin (default 72, or one inch).
=attr-fmt right_margin
This is the right margin (default 72, or one inch).
=cut
has top_margin => (
is => 'ro',
isa => Int,
default => 72,
);
has bottom_margin => (
is => 'ro',
isa => Int,
default => 72,
);
has left_margin => (
is => 'ro',
isa => Int,
default => 72,
);
has right_margin => (
is => 'ro',
isa => Int,
default => 72,
);
=attr-fmt title
This is the report's title, which is used only to set the
corresponding PostScript comment in the document.
The default is C<Report>.
=cut
has title => (
is => 'ro',
isa => Str,
default => 'Report',
);
=attr-fmt landscape
If set to a true value, the report will be printed in landscape mode.
The default is false.
=cut
has landscape => (
is => 'ro',
isa => Bool,
default => 0,
);
sub _build_ps
{
my ($self) = @_;
PostScript::File->new(
paper => $self->paper_size,
top => $self->top_margin,
bottom => $self->bottom_margin,
left => $self->left_margin,
right => $self->right_margin,
title => pstr($self->title),
order => 'Ascend',
reencode => 'cp1252',
file_ext => '',
font_suffix => '-iso',
landscape => $self->landscape,
newpage => 0,
%{ $self->ps_parameters },
);
} # end _build_ps
#---------------------------------------------------------------------
has _data => (
is => 'rw',
isa => HashRef,
clearer => '_clear_data',
init_arg => undef,
);
has _rows => (
is => 'rw',
isa => ArrayRef[ArrayRef],
clearer => '_clear_rows',
init_arg => undef,
);
has _current_row => (
is => 'rw',
isa => Int,
init_arg => undef,
);
=method get_value
$field_content = $rpt->get_value($value_source)
When a Component needs to fetch the content it should display, it
calls C<get_value> with its RptValue. This can be one of three
things:
=over
=item a non-negative integer
A 0-based column in the current row (normally used only in the
C<detail> section). A warning will be issued if the current row does
not have that many columns.
=item a string
An entry in the C<%data> passed to L</run>. A warning will be issued
if the key does not exist in C<%data>.
=item an object
This returns C<< $value_source->get_value($rpt) >>.
=back
If the result would be C<undef>, the empty string is returned instead.
(No warning is issued for this.)
=cut
sub get_value
{
my ($self, $value) = @_;
my $result = do {
if (ref $value) {
$value->get_value($self);
} elsif ($value =~ /^\d+$/) {
my $row = $self->_rows->[ $self->_current_row ];
warn sprintf("Row %d has no column %d (only 0 through %d)\n",
$self->_current_row, $value, $#$row)
unless not $row or $value <= $#$row;
$row->[$value];
} else {
my $dataHash = $self->_data;
warn "$value is not a key in this report's \%data\n"
unless exists $dataHash->{$value};
$dataHash->{$value};
}
};
defined($result) ? $result : '';
} # end get_value
#---------------------------------------------------------------------
has _fonts => (
is => 'ro',
isa => HashRef[FontObj],
default => sub { {} },
init_arg => undef,
);
=method get_font
$font_object = $rpt->get_font($font_name, $font_size)
Because a report needs to know what fonts will be used in it, you must
use this method to construct L<PostScript::Report::Font> objects. If
the specified font has already been used in this report, the same
C<$font_object> will be returned. (Normally, fonts are constructed by
L<PostScript::Report::Builder>.)
=cut
sub get_font
{
my ($self, $name, $size) = @_;
unless ($name =~ s/^=//) {
$name .= '-iso' unless $name eq 'Symbol';
}
my $fontname = "$name-$size";
$self->_fonts->{$fontname} ||= PostScript::Report::Font->new(
document => $self,
font => $name,
size => $size,
id => $self->_next_font_id,
);
} # end get_font
has _font_id_counter => (
is => 'rw',
isa => Str,
init_arg => undef,
default => 'A',
);
sub _next_font_id
{
my ($self) = @_;
my $id = $self->_font_id_counter;
my $fontID = "fn$id";
$self->_font_id_counter(++$id);
$fontID;
} # end _next_font_id
#---------------------------------------------------------------------
=attr-o page_count
This contains the number of pages in the report. It's only valid
after L</run> has been called.
=cut
has page_count => (
is => 'ro',
isa => Int,
writer => '_set_page_count',
init_arg => undef,
);
=attr-o page_number
This contains the number of the page currently being generated. It's
only valid while the L</run> method is processing.
=cut
has page_number => (
is => 'ro',
isa => Int,
writer => '_set_page_number',
init_arg => undef,
);
sub _calculate_page_count
{
my ($self) = @_;
my $pageHeight = $self->height;
my $rowCount = @{ $self->_rows };
# Collect height of each section:
my %height;
foreach my $sectionName ($self->_sections) {
if (my $section = $self->$sectionName) {
$height{$sectionName} = $section->height;
} else {
$height{$sectionName} = 0;
}
} # end foreach $sectionName
# Perform sanity checks:
if ($height{report_header} + $height{page_header} + $height{detail}
+ $height{page_footer} > $pageHeight) {
die "Can't fit report header, page header, page footer, and a detail line on a single page";
}
if ($height{page_header} + $height{detail} + $height{page_footer}
+ $height{report_footer} > $pageHeight) {
die "Can't fit page header, page footer, report footer, and a detail line on a single page";
}
# Calculate how many lines we can fit on each page:
my $available = $pageHeight - $height{page_header} - $height{page_footer};
my $detail = $height{detail};
my $pageCount = 1;
my $rowsThisPage = 0;
if ($detail) {
my $rowsPerPage = int($available / $detail);
$rowsThisPage = min($rowCount,
int(($available - $height{report_header}) / $detail));
while ($rowCount > $rowsThisPage) {
++$pageCount;
$rowCount -= $rowsThisPage;
$rowsThisPage = min($rowCount, $rowsPerPage);
} # end while $rowCount > $rowsThisPage
} # end if detail section
# If the report_footer won't fit on the last page, add another page:
++$pageCount
if $height{report_footer} > $available - $rowsThisPage * $detail -
($pageCount == 1 ? $height{report_header} : 0);
$self->_set_page_count($pageCount);
} # end _calculate_page_count
#---------------------------------------------------------------------
=method run
$rpt->run(\%data, \@rows)
This method runs the report on the specified data. C<%data> is a hash
containing values for the report. C<@rows> is an array of arrayrefs
of strings. The L</detail> section is printed once for each arrayref.
After running the report, you should call L</output> to store the
results. C<run> returns C<$rpt>, so you can chain the method calls:
$rpt->run(\%data, \@rows)->output($filename);
If you omit either C<%data> or C<@rows> (or pass C<undef>), an empty
hash or array will be substituted.
=cut
sub run
{
my ($self, $data, $rows) = @_;
# Handle $rpt->run(\@rows):
if (not defined $rows and (reftype($data)||'') eq 'ARRAY') {
$rows = $data;
$data = {};
} # end if only one parameter, and it's an arrayref
$self->_data($data ||= {});
$self->_rows($rows ||= []);
$self->_current_row(0);
$self->_init;
$self->_calculate_page_count;
my $ps = $self->ps;
my ($x, $yBot, $yTop) = ($ps->get_bounding_box)[0,1,3];
my $report_header = $self->report_header;
my $report_footer = $self->report_footer;
my $page_header = $self->page_header;
my $page_footer = $self->page_footer;
my $detail = $self->detail;
my $footer2bottom = (($self->footer_align eq 'bottom') or
($self->footer_align eq 'split' and
$self->first_footer eq 'report'));
my $minY = $yBot;
$minY += $detail->height if $detail;
$minY += $page_footer->height if $page_footer;
my $y;
for my $page (1 .. $self->page_count) {
$self->_set_page_number($page);
$ps->newpage($page);
$y = $yTop;
if ($report_header) {
$report_header->draw($x, $y, $self);
$y -= $report_header->height;
undef $report_header; # Only on first page
} # end if $report_header
if ($page_header) {
$page_header->draw($x, $y, $self);
$y -= $page_header->height;
} # end if $page_header
if ($detail) {
my $rowOnPage = 0;
while ($y >= $minY) {
$self->_stripe_detail($rowOnPage++);
$detail->draw($x, $y, $self);
$y -= $detail->height;
if ($self->_current_row( $self->_current_row + 1 ) > $#$rows) {
undef $detail; # There might be another page for the footer
last;
} # end if this was the last row
} # end while room for another row
} # end if $detail
# Draw the footer(s):
if ($report_footer and $page == $self->page_count) {
# This is the last page, and we have a report_footer:
my @footers = ($self->first_footer eq 'page'
? ($page_footer, $report_footer)
: ($report_footer, $page_footer));
# Get only defined footers:
@footers = grep { defined $_ } @footers;
# Position and draw the first footer:
if ($self->footer_align eq 'bottom') {
$y = $yBot;
$y += $_->height for @footers;
} # end if footer_align is bottom
$footers[0]->draw($x, $y, $self);
# Draw the second footer, if it exists:
if ($footers[1]) {
if ($self->footer_align eq 'split') {
$y = $yBot + $footers[1]->height;
} else {
$y -= $footers[0]->height;
}
$footers[1]->draw($x, $y, $self);
} # end if we have a second footer
} elsif ($page_footer) {
# This page has only a page_footer:
$y = $yBot + $page_footer->height if $footer2bottom;
$page_footer->draw($x, $y, $self);
} # end elsif $page_footer
} # end for each $page
$self->_clear_data;
$self->_clear_rows;
$self->_generate_font_list;
$self->_attach_ps_resources;
$self; # Allow for method chaining
} # end run
#---------------------------------------------------------------------
sub _stripe_detail
{
my ($self, $rowOnPage) = @_;
my $code = $self->detail_background or return;
my $color = $code->($self->_current_row, $rowOnPage);
$self->detail->_set_background($color) if defined $color;
} # end _stripe_detail
#---------------------------------------------------------------------
sub _generate_font_list
{
my ($self) = @_;
my %font;
my $ps = $self->ps;
foreach my $font (values %{ $self->_fonts }) {
my $name = $font->font;
$font{$font->id} = sprintf("/%s /%s findfont %s scalefont def\n",
$font->id, $name, $font->size);
$name =~ s/-iso$//;
$ps->need_resource(font => $name);
} # end foreach $font
$ps->add_setup(join('',
"% begin report fonts\n", (sort values %font), "% end report fonts\n"
));
} # end _generate_font_list
#---------------------------------------------------------------------
sub _attach_ps_resources
{
my ($self) = @_;
my $ps = $self->ps;
my $funcs = $self->ps_functions;
foreach my $key (sort keys %$funcs) {
# Try to determine the version of this procset:
my $version;
$version = eval { $1->VERSION } if $key =~ /^([\w:]+)/;
(my $name = $key) =~ s/:/_/g;
$ps->add_procset($name, $funcs->{$key}, $version);
} # end foreach $key
%$funcs = (); # Clear out ps_functions
} # end _attach_ps_resources
#=====================================================================
# Debugging support:
=method-dbg dump
$rpt->dump;
This method (for debugging purposes only) prints a representation of
the report to the currently selected filehandle. (Inherited values
are not shown.) Note that layout calculations are not done until the
report is run, so you will normally see additional C<height> and
C<width> values after calling L</run>.
=cut
sub dump
{