From 7b1a3d1ae89ef8f665aeda9ec16e68f44bbb9891 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Mon, 8 Feb 2010 11:01:55 -0500 Subject: [PATCH] Bugfix: Fixing issues with the patron card pdf rendering code 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. Signed-off-by: Galen Charlton --- 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 b0061aec52..09e8d9c362 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 595dfd1b5c..7bf957ff60 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 830334dc6f..2a26c6e18c 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; -- 2.39.2