|
Lines 24-30
use autouse 'Data::Dumper' => qw(Dumper);
Link Here
|
| 24 |
use Text::Wrap qw(wrap); |
24 |
use Text::Wrap qw(wrap); |
| 25 |
#use Font::TTFMetrics; |
25 |
#use Font::TTFMetrics; |
| 26 |
|
26 |
|
| 27 |
use C4::Creators::Lib qw(get_font_types); |
27 |
use C4::Creators::Lib qw(get_font_types get_unit_values); |
| 28 |
use C4::Creators::PDF qw(StrWidth); |
28 |
use C4::Creators::PDF qw(StrWidth); |
| 29 |
use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_attributes); |
29 |
use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_attributes); |
| 30 |
|
30 |
|
|
Lines 32-37
use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_
Link Here
|
| 32 |
sub new { |
32 |
sub new { |
| 33 |
my ($invocant, %params) = @_; |
33 |
my ($invocant, %params) = @_; |
| 34 |
my $type = ref($invocant) || $invocant; |
34 |
my $type = ref($invocant) || $invocant; |
|
|
35 |
|
| 36 |
my $units = get_unit_values(); |
| 37 |
my $unitvalue = 1; |
| 38 |
my $unitdesc = ''; |
| 39 |
foreach my $un (@$units){ |
| 40 |
if ($un->{'type'} eq $params{'layout'}->{'units'}) { |
| 41 |
$unitvalue = $un->{'value'}; |
| 42 |
$unitdesc = $un->{'desc'}; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 35 |
my $self = { |
46 |
my $self = { |
| 36 |
batch_id => $params{'batch_id'}, |
47 |
batch_id => $params{'batch_id'}, |
| 37 |
#card_number => $params{'card_number'}, |
48 |
#card_number => $params{'card_number'}, |
|
Lines 41-46
sub new {
Link Here
|
| 41 |
height => $params{'height'}, |
52 |
height => $params{'height'}, |
| 42 |
width => $params{'width'}, |
53 |
width => $params{'width'}, |
| 43 |
layout => $params{'layout'}, |
54 |
layout => $params{'layout'}, |
|
|
55 |
unitvalue => $unitvalue, |
| 56 |
unitdesc => $unitdesc, |
| 44 |
text_wrap_cols => $params{'text_wrap_cols'}, |
57 |
text_wrap_cols => $params{'text_wrap_cols'}, |
| 45 |
barcode_height_scale => $params{'layout'}->{'barcode'}[0]->{'height_scale'} || 0.01, |
58 |
barcode_height_scale => $params{'layout'}->{'barcode'}[0]->{'height_scale'} || 0.01, |
| 46 |
barcode_width_scale => $params{'layout'}->{'barcode'}[0]->{'width_scale'} || 0.8, |
59 |
barcode_width_scale => $params{'layout'}->{'barcode'}[0]->{'width_scale'} || 0.8, |
|
Lines 69-74
sub draw_barcode {
Link Here
|
| 69 |
sub draw_guide_box { |
82 |
sub draw_guide_box { |
| 70 |
my ($self, $pdf) = @_; |
83 |
my ($self, $pdf) = @_; |
| 71 |
warn sprintf('No pdf object passed in.') and return -1 if !$pdf; |
84 |
warn sprintf('No pdf object passed in.') and return -1 if !$pdf; |
|
|
85 |
|
| 72 |
my $obj_stream = "q\n"; # save the graphic state |
86 |
my $obj_stream = "q\n"; # save the graphic state |
| 73 |
$obj_stream .= "0.5 w\n"; # border line width |
87 |
$obj_stream .= "0.5 w\n"; # border line width |
| 74 |
$obj_stream .= "1.0 0.0 0.0 RG\n"; # border color red |
88 |
$obj_stream .= "1.0 0.0 0.0 RG\n"; # border color red |
|
Lines 79-84
sub draw_guide_box {
Link Here
|
| 79 |
$pdf->Add($obj_stream); |
93 |
$pdf->Add($obj_stream); |
| 80 |
} |
94 |
} |
| 81 |
|
95 |
|
|
|
96 |
sub draw_guide_grid { |
| 97 |
my ($self, $pdf) = @_; |
| 98 |
warn sprintf('No pdf object passed in.') and return -1 if !$pdf; |
| 99 |
|
| 100 |
# Set up the grid in user defined units. |
| 101 |
# Each 5th and 10th line get separate values |
| 102 |
|
| 103 |
my $obj_stream = "q\n"; # save the graphic state |
| 104 |
my $x = $self->{'llx'}; |
| 105 |
my $y = $self->{'lly'}; |
| 106 |
|
| 107 |
my $cnt = 0; |
| 108 |
for ( $x = $self->{'llx'}/$self->{'unitvalue'}; $x <= ($self->{'llx'} + $self->{'width'})/$self->{'unitvalue'}; $x++) { |
| 109 |
my $xx = $x*$self->{'unitvalue'}; |
| 110 |
my $yy = $y + $self->{'height'}; |
| 111 |
if ( ($cnt % 10) && ! ($cnt % 5) ) { |
| 112 |
$obj_stream .= "0.0 1.0 0.0 RG\n"; |
| 113 |
$obj_stream .= "0 w\n"; |
| 114 |
} elsif ( $cnt % 5 ) { |
| 115 |
$obj_stream .= "0.0 1.0 1.0 RG\n"; |
| 116 |
$obj_stream .= "0 w\n"; |
| 117 |
} else { |
| 118 |
$obj_stream .= "0.0 0.0 1.0 RG\n"; |
| 119 |
$obj_stream .= "0 w\n"; |
| 120 |
} |
| 121 |
$cnt ++; |
| 122 |
|
| 123 |
$obj_stream .= "$xx $y m\n"; |
| 124 |
$obj_stream .= "$xx $yy l\n"; |
| 125 |
|
| 126 |
$obj_stream .= "s\n"; |
| 127 |
} |
| 128 |
|
| 129 |
$x = $self->{'llx'}; |
| 130 |
$y = $self->{'lly'}; |
| 131 |
$cnt = 0; |
| 132 |
for ( $y = $self->{'lly'}/$self->{'unitvalue'}; $y <= ($self->{'lly'} + $self->{'height'})/$self->{'unitvalue'}; $y++) { |
| 133 |
|
| 134 |
my $xx = $x + $self->{'width'}; |
| 135 |
my $yy = $y*$self->{'unitvalue'}; |
| 136 |
|
| 137 |
if ( ($cnt % 10) && ! ($cnt % 5) ) { |
| 138 |
$obj_stream .= "0.0 1.0 0.0 RG\n"; |
| 139 |
$obj_stream .= "0 w\n"; |
| 140 |
} elsif ( $cnt % 5 ) { |
| 141 |
$obj_stream .= "0.0 1.0 1.0 RG\n"; |
| 142 |
$obj_stream .= "0 w\n"; |
| 143 |
} else { |
| 144 |
$obj_stream .= "0.0 0.0 1.0 RG\n"; |
| 145 |
$obj_stream .= "0 w\n"; |
| 146 |
} |
| 147 |
$cnt ++; |
| 148 |
|
| 149 |
$obj_stream .= "$x $yy m\n"; |
| 150 |
$obj_stream .= "$xx $yy l\n"; |
| 151 |
$obj_stream .= "s\n"; |
| 152 |
} |
| 153 |
|
| 154 |
$obj_stream .= "Q\n"; # restore the graphic state |
| 155 |
$pdf->Add($obj_stream); |
| 156 |
|
| 157 |
# Add info about units |
| 158 |
my $strbottom = "0/0 $self->{'unitdesc'}"; |
| 159 |
my $strtop = sprintf('%.2f', $self->{'width'}/$self->{'unitvalue'}) .'/'. sprintf('%.2f', $self->{'height'}/$self->{'unitvalue'}); |
| 160 |
my $font_size = 6; |
| 161 |
$pdf->Font( 'Courier' ); |
| 162 |
$pdf->FontSize( $font_size ); |
| 163 |
my $strtop_len = $pdf->StrWidth($strtop) * 1.5; |
| 164 |
$pdf->Text( $self->{'llx'} + 2, $self->{'lly'} + 2, $strbottom ); |
| 165 |
$pdf->Text( $self->{'llx'} + $self->{'width'} - $strtop_len , $self->{'lly'} + $self->{'height'} - $font_size , $strtop ); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 82 |
sub draw_text { |
169 |
sub draw_text { |
| 83 |
my ($self, $pdf, %params) = @_; |
170 |
my ($self, $pdf, %params) = @_; |
| 84 |
warn sprintf('No pdf object passed in.') and return -1 if !$pdf; |
171 |
warn sprintf('No pdf object passed in.') and return -1 if !$pdf; |