Lines 4-10
use strict;
Link Here
|
4 |
use warnings; |
4 |
use warnings; |
5 |
|
5 |
|
6 |
use Text::Wrap qw( wrap ); |
6 |
use Text::Wrap qw( wrap ); |
7 |
use Algorithm::CheckDigits qw( CheckDigits ); |
|
|
8 |
use Text::CSV_XS; |
7 |
use Text::CSV_XS; |
9 |
use Text::Bidi qw( log2vis ); |
8 |
use Text::Bidi qw( log2vis ); |
10 |
|
9 |
|
Lines 14-19
use Koha::Biblios;
Link Here
|
14 |
use Koha::ClassSources; |
13 |
use Koha::ClassSources; |
15 |
use Koha::ClassSortRules; |
14 |
use Koha::ClassSortRules; |
16 |
use Koha::ClassSplitRules; |
15 |
use Koha::ClassSplitRules; |
|
|
16 |
use C4::Barcodes::Drawer; |
17 |
use C4::ClassSplitRoutine::Dewey; |
17 |
use C4::ClassSplitRoutine::Dewey; |
18 |
use C4::ClassSplitRoutine::LCC; |
18 |
use C4::ClassSplitRoutine::LCC; |
19 |
use C4::ClassSplitRoutine::Generic; |
19 |
use C4::ClassSplitRoutine::Generic; |
Lines 353-363
sub create_label {
Link Here
|
353 |
); |
353 |
); |
354 |
} |
354 |
} |
355 |
if ($self->{'printing_type'} =~ /BAR/) { |
355 |
if ($self->{'printing_type'} =~ /BAR/) { |
356 |
barcode( $self, |
356 |
C4::Barcodes::Drawer::draw_barcode( $self, |
357 |
llx => $barcode_llx, |
357 |
llx => $barcode_llx, |
358 |
lly => $barcode_lly, |
358 |
lly => $barcode_lly, |
359 |
width => $barcode_width, |
359 |
width => $barcode_width, |
360 |
y_scale_factor => $barcode_y_scale_factor, |
360 |
y_scale_factor => $barcode_y_scale_factor, |
|
|
361 |
barcode_data => $self->{'barcode'} || _get_label_item($self->{'item_number'}, 1), |
361 |
); |
362 |
); |
362 |
} |
363 |
} |
363 |
return $label_text if $label_text; |
364 |
return $label_text if $label_text; |
Lines 486-591
sub draw_guide_box {
Link Here
|
486 |
return $_[0]->{'guidebox'}; |
487 |
return $_[0]->{'guidebox'}; |
487 |
} |
488 |
} |
488 |
|
489 |
|
489 |
sub barcode { |
|
|
490 |
my $self = shift; |
491 |
my %params = @_; |
492 |
$params{'barcode_data'} = ($self->{'barcode'} || _get_label_item($self->{'item_number'}, 1)) if !$params{'barcode_data'}; |
493 |
$params{'barcode_type'} = $self->{'barcode_type'} if !$params{'barcode_type'}; |
494 |
my $x_scale_factor = 1; |
495 |
my $num_of_bars = length($params{'barcode_data'}); |
496 |
my $tot_bar_length = 0; |
497 |
my $bar_length = 0; |
498 |
my $guard_length = 10; |
499 |
my $hide_text = 'yes'; |
500 |
if ($params{'barcode_type'} =~ m/CODE39/) { |
501 |
$bar_length = '17.5'; |
502 |
$tot_bar_length = ($bar_length * $num_of_bars) + ($guard_length * 2); |
503 |
$x_scale_factor = ($params{'width'} / $tot_bar_length); |
504 |
if ($params{'barcode_type'} eq 'CODE39MOD') { |
505 |
my $c39 = CheckDigits('code_39'); # get modulo43 checksum |
506 |
$params{'barcode_data'} = $c39->complete($params{'barcode_data'}); |
507 |
} |
508 |
elsif ($params{'barcode_type'} eq 'CODE39MOD10') { |
509 |
my $c39_10 = CheckDigits('siret'); # get modulo43 checksum |
510 |
$params{'barcode_data'} = $c39_10->complete($params{'barcode_data'}); |
511 |
$hide_text = ''; |
512 |
} |
513 |
eval { |
514 |
PDF::Reuse::Barcode::Code39( |
515 |
x => $params{'llx'}, |
516 |
y => $params{'lly'}, |
517 |
value => "*$params{barcode_data}*", |
518 |
xSize => $x_scale_factor, |
519 |
ySize => $params{'y_scale_factor'}, |
520 |
hide_asterisk => 1, |
521 |
text => $hide_text, |
522 |
mode => 'graphic', |
523 |
); |
524 |
}; |
525 |
if ($@) { |
526 |
warn sprintf('Barcode generation failed for item %s with this error: %s', $self->{'item_number'}, $@); |
527 |
} |
528 |
} |
529 |
elsif ($params{'barcode_type'} eq 'COOP2OF5') { |
530 |
$bar_length = '9.43333333333333'; |
531 |
$tot_bar_length = ($bar_length * $num_of_bars) + ($guard_length * 2); |
532 |
$x_scale_factor = ($params{'width'} / $tot_bar_length) * 0.9; |
533 |
eval { |
534 |
PDF::Reuse::Barcode::COOP2of5( |
535 |
x => $params{'llx'}, |
536 |
y => $params{'lly'}, |
537 |
value => $params{barcode_data}, |
538 |
xSize => $x_scale_factor, |
539 |
ySize => $params{'y_scale_factor'}, |
540 |
mode => 'graphic', |
541 |
); |
542 |
}; |
543 |
if ($@) { |
544 |
warn sprintf('Barcode generation failed for item %s with this error: %s', $self->{'item_number'}, $@); |
545 |
} |
546 |
} |
547 |
elsif ( $params{'barcode_type'} eq 'INDUSTRIAL2OF5' ) { |
548 |
$bar_length = '13.1333333333333'; |
549 |
$tot_bar_length = ($bar_length * $num_of_bars) + ($guard_length * 2); |
550 |
$x_scale_factor = ($params{'width'} / $tot_bar_length) * 0.9; |
551 |
eval { |
552 |
PDF::Reuse::Barcode::Industrial2of5( |
553 |
x => $params{'llx'}, |
554 |
y => $params{'lly'}, |
555 |
value => $params{barcode_data}, |
556 |
xSize => $x_scale_factor, |
557 |
ySize => $params{'y_scale_factor'}, |
558 |
mode => 'graphic', |
559 |
); |
560 |
}; |
561 |
if ($@) { |
562 |
warn sprintf('Barcode generation failed for item %s with this error: %s', $self->{'item_number'}, $@); |
563 |
} |
564 |
} |
565 |
elsif ($params{'barcode_type'} eq 'EAN13') { |
566 |
$bar_length = 4; # FIXME |
567 |
$num_of_bars = 13; |
568 |
$tot_bar_length = ($bar_length * $num_of_bars) + ($guard_length * 2); |
569 |
$x_scale_factor = ($params{'width'} / $tot_bar_length) * 0.9; |
570 |
eval { |
571 |
PDF::Reuse::Barcode::EAN13( |
572 |
x => $params{'llx'}, |
573 |
y => $params{'lly'}, |
574 |
value => sprintf('%013d',$params{barcode_data}), |
575 |
# xSize => $x_scale_factor, |
576 |
# ySize => $params{'y_scale_factor'}, |
577 |
mode => 'graphic', |
578 |
); |
579 |
}; |
580 |
if ($@) { |
581 |
warn sprintf('Barcode generation failed for item %s with this error: %s', $self->{'item_number'}, $@); |
582 |
} |
583 |
} |
584 |
else { |
585 |
warn "unknown barcode_type: $params{barcode_type}"; |
586 |
} |
587 |
} |
588 |
|
589 |
sub csv_data { |
490 |
sub csv_data { |
590 |
my $self = shift; |
491 |
my $self = shift; |
591 |
my $label_fields = _get_text_fields($self->{'format_string'}); |
492 |
my $label_fields = _get_text_fields($self->{'format_string'}); |
Lines 776-804
R = Right
Link Here
|
776 |
justify => $text_justification, |
677 |
justify => $text_justification, |
777 |
);> |
678 |
);> |
778 |
|
679 |
|
779 |
=head2 barcode() |
|
|
780 |
|
781 |
Invoking the I<barcode> method generates a barcode for the label object and inserts it into the current pdf stream. This method accepts the following parameters as key => value |
782 |
pairs (C<barcode_data> is optional and omitting it will cause the barcode from the current item to be used. C<barcode_type> is also optional. Omission results in the barcode |
783 |
type of the current template being used.): |
784 |
|
785 |
C<llx> The lower-left x coordinate for the barcode block (The point of origin for all PDF's is the lower left of the page per ISO 32000-1) |
786 |
C<lly> The lower-left y coordinate for the barcode block |
787 |
C<width> The width of the barcode block |
788 |
C<y_scale_factor> The scale factor to be applied to the y axis of the barcode block |
789 |
C<barcode_data> The data to be encoded in the barcode |
790 |
C<barcode_type> The barcode type (See the C<new()> method for supported barcode types) |
791 |
|
792 |
example: |
793 |
C<$label->barcode( |
794 |
llx => $barcode_llx, |
795 |
lly => $barcode_lly, |
796 |
width => $barcode_width, |
797 |
y_scale_factor => $barcode_y_scale_factor, |
798 |
barcode_data => $barcode, |
799 |
barcode_type => $barcodetype, |
800 |
);> |
801 |
|
802 |
=head2 csv_data() |
680 |
=head2 csv_data() |
803 |
|
681 |
|
804 |
Invoking the I<csv_data> method returns an arrayref of an array containing the label data suitable for passing to Text::CSV_XS->combine() to produce csv output. |
682 |
Invoking the I<csv_data> method returns an arrayref of an array containing the label data suitable for passing to Text::CSV_XS->combine() to produce csv output. |