From 2f6aa19761e7e03f102c3445e5ee2356d5a0d7d8 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Mon, 14 Aug 2023 21:11:52 +0000 Subject: [PATCH] Bug 34532: Silence warns in Patroncard.pm To test: 1. Go to patron card creator and make a patron card batch, card layout, and card template. 2. In the card layout leave some values blank for Lower left X coordinate and Lower left Y coordinate. 3. Now go create a card batch while tailing the plack-intranet-error log/ 4. Notice in the logs: [2023/08/14 20:50:54] [WARN] Argument "" isn't numeric in multiplication (*) at /kohadevbox/koha/C4/Patroncards/Patroncard.pm line 109. [2023/08/14 20:50:54] [WARN] Argument "" isn't numeric in multiplication (*) at /kohadevbox/koha/C4/Patroncards/Patroncard.pm line 248. [2023/08/14 20:50:54] [WARN] Argument "" isn't numeric in multiplication (*) at /kohadevbox/koha/C4/Patroncards/Patroncard.pm line 249. 5. Apply patch, restart_all 6. Try again and notice the WARNS should be gone from the logs now. 7. Make sure you can still create patron cards and the PDF's the generate look right. Signed-off-by: Matt Blenkinsop --- C4/Patroncards/Patroncard.pm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/C4/Patroncards/Patroncard.pm b/C4/Patroncards/Patroncard.pm index 9a8901ae0e..7a1aacb2d3 100644 --- a/C4/Patroncards/Patroncard.pm +++ b/C4/Patroncards/Patroncard.pm @@ -95,10 +95,13 @@ sub draw_barcode { # Default values for barcode scaling are set in constructor to work with pre-existing installations my $barcode_height_scale = $self->{'barcode_height_scale'}; my $barcode_width_scale = $self->{'barcode_width_scale'}; - + my $llx = $self->{'llx'} || 0; + my $llx_layout = $self->{'layout'}->{'barcode'}->[0]->{'llx'} || 0; + my $lly = $self->{'lly'} || 0; + my $lly_layout = $self->{'layout'}->{'barcode'}->[0]->{'lly'} || 0; _draw_barcode( $self, - llx => $self->{'llx'} + $self->{'layout'}->{'barcode'}->[0]->{'llx'} * $self->{'unitvalue'}, - lly => $self->{'lly'} + $self->{'layout'}->{'barcode'}->[0]->{'lly'} * $self->{'unitvalue'}, + llx => $llx + $llx_layout * $self->{'unitvalue'}, + lly => $llx + $llx_layout * $self->{'unitvalue'}, width => $self->{'width'} * $barcode_width_scale, y_scale_factor => $self->{'height'} * $barcode_height_scale, barcode_type => $self->{'layout'}->{'barcode'}->[0]->{'type'}, @@ -242,8 +245,13 @@ sub draw_text { $line = join(' ',@orig_line); } my $text_attribs = shift @$text; - my $origin_llx = $self->{'llx'} + $text_attribs->{'llx'} * $self->{'unitvalue'}; - my $origin_lly = $self->{'lly'} + $text_attribs->{'lly'} * $self->{'unitvalue'}; + my $llx = $self->{'llx'} || 0; + my $llx_text_attr = $text_attribs->{'llx'} || 0; + my $lly = $self->{'llx'} || 0; + my $lly_text_attr = $text_attribs->{'lly'} || 0; + + my $origin_llx = $llx + $llx_text_attr * $self->{'unitvalue'}; + my $origin_lly = $lly + $lly_text_attr * $self->{'unitvalue'}; my $Tx = 0; # final text llx my $Ty = $origin_lly; # final text lly my $Tw = 0; # final text word spacing. See http://www.adobe.com/devnet/pdf/pdf_reference.html ISO 32000-1 @@ -259,7 +267,7 @@ sub draw_text { # my $font_units_width = $m->string_width($line); # my $string_width = ($font_units_width * $text_attribs->{'font_size'}) / $units_per_em; my $string_width = C4::Creators::PDF->StrWidth($line, $text_attribs->{'font'}, $text_attribs->{'font_size'}); - if (($string_width + $text_attribs->{'llx'}) > $self->{'width'}) { + if (($string_width + $llx_text_attr) > $self->{'width'}) { my $cur_line = ""; WRAP_LINES: while (1) { @@ -298,7 +306,7 @@ sub draw_text { } } else { - ($Tx, $Tw) = text_alignment($origin_llx, $self->{'width'}, $text_attribs->{'llx'} * $self->{'unitvalue'}, $string_width, $line, $text_attribs->{'text_alignment'}); + ($Tx, $Tw) = text_alignment($origin_llx, $self->{'width'}, $lly_text_attr * $self->{'unitvalue'}, $string_width, $line, $text_attribs->{'text_alignment'}); $line =~ s/^\s+//g; # strip naughty leading spaces push @lines, {line=> $line, Tx => $Tx, Ty => $Ty, Tw => $Tw}; } -- 2.37.1 (Apple Git-137.1)