Bugfix: Fixing issues with the patron card pdf rendering code
authorChris Nighswonger <cnighswonger@foundations.edu>
Mon, 8 Feb 2010 16:01:55 +0000 (11:01 -0500)
committerGalen Charlton <gmcharlt@gmail.com>
Mon, 8 Feb 2010 16:25:49 +0000 (11:25 -0500)
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 <gmcharlt@gmail.com>
C4/Patroncards/Lib.pm
C4/Patroncards/Patroncard.pm
patroncards/create-pdf.pl

index b0061ae..09e8d9c 100644 (file)
@@ -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') {
index 595dfd1..7bf957f 100644 (file)
@@ -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;
index 830334d..2a26c6e 100755 (executable)
@@ -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;