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 <matt.blenkinsop@ptfs-europe.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> (cherry picked from commit1164402b49
) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> (cherry picked from commitfb988b42c4
) Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
parent
a8e7f07a8a
commit
88f1dabcf0
1 changed files with 53 additions and 29 deletions
|
@ -92,13 +92,18 @@ sub new {
|
|||
|
||||
sub draw_barcode {
|
||||
my ( $self, $pdf ) = @_;
|
||||
|
||||
# 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'};
|
||||
|
||||
_draw_barcode( $self,
|
||||
llx => $self->{'llx'} + $self->{'layout'}->{'barcode'}->[0]->{'llx'} * $self->{'unitvalue'},
|
||||
lly => $self->{'lly'} + $self->{'layout'}->{'barcode'}->[0]->{'lly'} * $self->{'unitvalue'},
|
||||
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 => $llx + $llx_layout * $self->{'unitvalue'},
|
||||
lly => $lly + $lly_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 +247,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->{'lly'} || 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
|
||||
|
@ -258,32 +268,46 @@ sub draw_text {
|
|||
# my $units_per_em = $m->get_units_per_em();
|
||||
# my $font_units_width = $m->string_width($line);
|
||||
# my $string_width = ($font_units_width * $text_attribs->{'font_size'}) / $units_per_em;
|
||||
## Please see file perltidy.ERR
|
||||
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) {
|
||||
|
||||
# $line =~ m/^.*(\s\b.*\b\s*|\s&|\<\b.*\b\>)$/; # original regexp... can be removed after dev stage is over
|
||||
$line =~ m/^.*(\s.*\s*|\s&|\<.*\>)$/;
|
||||
$trim = $1 . $trim;
|
||||
|
||||
#Sanitize the input into this regular expression so regex metacharacters are escaped as literal values (https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22429)
|
||||
$line =~ s/\Q$1\E$//;
|
||||
$string_width = C4::Creators::PDF->StrWidth($line, $text_attribs->{'font'}, $text_attribs->{'font_size'});
|
||||
$string_width =
|
||||
C4::Creators::PDF->StrWidth( $line, $text_attribs->{'font'}, $text_attribs->{'font_size'} );
|
||||
|
||||
# $font_units_width = $m->string_width($line);
|
||||
# $string_width = ($font_units_width * $text_attribs->{'font_size'}) / $units_per_em;
|
||||
if ( ( $string_width + $text_attribs->{'llx'} ) < $self->{'width'} ) {
|
||||
($Tx, $Tw) = text_alignment($origin_llx, $self->{'width'}, $text_attribs->{'llx'}, $string_width, $line, $text_attribs->{'text_alignment'});
|
||||
( $Tx, $Tw ) = text_alignment(
|
||||
$origin_llx, $self->{'width'}, $text_attribs->{'llx'}, $string_width, $line,
|
||||
$text_attribs->{'text_alignment'}
|
||||
);
|
||||
push @lines, { line => $line, Tx => $Tx, Ty => $Ty, Tw => $Tw };
|
||||
$line = undef;
|
||||
last WRAP_LINES if $trim eq '';
|
||||
$Ty -= leading( $text_attribs->{'font_size'} );
|
||||
$line = $trim;
|
||||
$trim = '';
|
||||
$string_width = C4::Creators::PDF->StrWidth($line, $text_attribs->{'font'}, $text_attribs->{'font_size'});
|
||||
$string_width =
|
||||
C4::Creators::PDF->StrWidth( $line, $text_attribs->{'font'}, $text_attribs->{'font_size'} );
|
||||
|
||||
#$font_units_width = $m->string_width($line);
|
||||
#$string_width = ($font_units_width * $text_attribs->{'font_size'}) / $units_per_em;
|
||||
if ( $string_width + ( $text_attribs->{'llx'} * $self->{'unitvalue'} ) < $self->{'width'} ) {
|
||||
($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'},
|
||||
$text_attribs->{'llx'} * $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};
|
||||
last WRAP_LINES;
|
||||
|
@ -298,7 +322,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};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue