[Koha-patches] [PATCH] Bugfix: Fixing issues with the patron card pdf rendering code
Chris Nighswonger
cnighswonger at foundations.edu
Mon Feb 8 17:01:55 CET 2010
This patch fixes two bugs:
1. Correcting the text alignment alogrithms for center and right alignment
2. Changes a reference to layout to a copy of the layout to avoid performing
operations on the layout.
---
C4/Patroncards/Lib.pm | 4 ++--
C4/Patroncards/Patroncard.pm | 2 +-
patroncards/create-pdf.pl | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/C4/Patroncards/Lib.pm b/C4/Patroncards/Lib.pm
index b0061ae..09e8d9c 100644
--- a/C4/Patroncards/Lib.pm
+++ b/C4/Patroncards/Lib.pm
@@ -58,12 +58,12 @@ sub text_alignment {
return $origin_llx, $Tw;
}
elsif ($alignment eq 'C') {
- my $center_margin = ($text_box_width / 2) + $text_llx;
+ my $center_margin = ($text_box_width / 2) + ($origin_llx - $text_llx);
$Tx = $center_margin - ($string_width / 2);
return $Tx, $Tw;
}
elsif ($alignment eq 'R') {
- $Tx = ($text_box_width - $string_width) + ($text_llx / 2);
+ $Tx = ($text_box_width - $string_width) + (($origin_llx - $text_llx) / 2);
return $Tx, $Tw;
}
elsif ($alignment eq 'L') {
diff --git a/C4/Patroncards/Patroncard.pm b/C4/Patroncards/Patroncard.pm
index 595dfd1..7bf957f 100644
--- a/C4/Patroncards/Patroncard.pm
+++ b/C4/Patroncards/Patroncard.pm
@@ -83,7 +83,7 @@ sub draw_text {
my ($self, $pdf, %params) = @_;
warn sprintf('No pdf object passed in.') and return -1 if !$pdf;
my @card_text = ();
- my $text = $self->{'layout'}->{'text'};
+ my $text = [@{$self->{'layout'}->{'text'}}]; # make a copy of the arrayref *not* simply a pointer
return unless (ref($text) eq 'ARRAY'); # just in case there is not text
while (scalar @$text) {
my $line = shift @$text;
diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl
index 830334d..2a26c6e 100755
--- a/patroncards/create-pdf.pl
+++ b/patroncards/create-pdf.pl
@@ -65,7 +65,7 @@ my $lower_left_y = 0;
my $upper_right_x = $template->get_attr('page_width');
my $upper_right_y = $template->get_attr('page_height');
-$pdf->Compress(1);
+$pdf->Compress(1); # comment this out to debug pdf files, but be sure to uncomment it in production or you may be very sorry...
$pdf->Mbox($lower_left_x, $lower_left_y, $upper_right_x, $upper_right_y);
my ($llx, $lly) = 0,0;
--
1.6.0.4
More information about the Koha-patches
mailing list