X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FPatroncards%2FPatroncard.pm;h=f6a18127c631ed50bf20225814f3a73d13f66b29;hb=c9234cb92ddd9ec1ec19e399c185e1ba9b11a9d9;hp=7bf957ff605b8724ed21670dc027c067cfc4917c;hpb=7b1a3d1ae89ef8f665aeda9ec16e68f44bbb9891;p=koha.git diff --git a/C4/Patroncards/Patroncard.pm b/C4/Patroncards/Patroncard.pm index 7bf957ff60..f6a18127c6 100644 --- a/C4/Patroncards/Patroncard.pm +++ b/C4/Patroncards/Patroncard.pm @@ -4,18 +4,18 @@ package C4::Patroncards::Patroncard; # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; @@ -24,12 +24,12 @@ use autouse 'Data::Dumper' => qw(Dumper); use Text::Wrap qw(wrap); #use Font::TTFMetrics; -use C4::Creators::Lib 1.000000 qw(get_font_types); -use C4::Creators::PDF 1.000000 qw(StrWidth); -use C4::Patroncards::Lib 1.000000 qw(unpack_UTF8 text_alignment leading box get_borrower_attributes); +use C4::Creators::Lib qw(get_font_types); +use C4::Creators::PDF qw(StrWidth); +use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_attributes); BEGIN { - use version; our $VERSION = qv('1.0.0_1'); + use version; our $VERSION = qv('3.07.00.049'); } sub new { @@ -45,6 +45,8 @@ sub new { width => $params{'width'}, layout => $params{'layout'}, text_wrap_cols => $params{'text_wrap_cols'}, + barcode_height_scale => $params{'layout'}->{'barcode'}[0]->{'height_scale'} || 0.01, + barcode_width_scale => $params{'layout'}->{'barcode'}[0]->{'width_scale'} || 0.8, }; bless ($self, $type); return $self; @@ -52,14 +54,15 @@ sub new { sub draw_barcode { my ($self, $pdf) = @_; -#FIXME: We do some scaling foo on the barcode here which probably should be done by the one invoking draw_barcode - my $barcode_width = 0.8 * $self->{'width'}; # this scales the barcode width to 80% of the label width - my $barcode_y_scale_factor = 0.01 * $self->{'height'}; # this scales the barcode height to 1% of the label height + # 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'}, lly => $self->{'lly'} + $self->{'layout'}->{'barcode'}->[0]->{'lly'}, - width => $barcode_width, - y_scale_factor => $barcode_y_scale_factor, + width => $self->{'width'} * $barcode_width_scale, + y_scale_factor => $self->{'height'} * $barcode_height_scale, barcode_type => $self->{'layout'}->{'barcode'}->[0]->{'type'}, barcode_data => $self->{'layout'}->{'barcode'}->[0]->{'data'}, text => $self->{'layout'}->{'barcode'}->[0]->{'text_print'}, @@ -83,8 +86,8 @@ sub draw_text { my ($self, $pdf, %params) = @_; warn sprintf('No pdf object passed in.') and return -1 if !$pdf; my @card_text = (); + return unless (ref($self->{'layout'}->{'text'}) eq 'ARRAY'); # just in case there is not 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; my $parse_line = $line; @@ -127,7 +130,7 @@ sub draw_text { 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&|\<.*\>)$/; - warn sprintf('Line wrap failed. DEBUG INFO: Data: \'%s\'\n Method: C4::Patroncards->draw_text Additional Information: Line wrap regexp failed. (Please file in this information in a bug report at http://bugs.koha.org', $line) and last WRAP_LINES if !$1; + warn sprintf('Line wrap failed. DEBUG INFO: Data: \'%s\'\n Method: C4::Patroncards->draw_text Additional Information: Line wrap regexp failed. (Please file in this information in a bug report at http://bugs.koha-community.org', $line) and last WRAP_LINES if !$1; $trim = $1 . $trim; $line =~ s/$1//; $string_width = C4::Creators::PDF->StrWidth($line, $text_attribs->{'font'}, $text_attribs->{'font_size'}); @@ -173,13 +176,10 @@ sub draw_text { } box ($origin_llx, $box_lly, $self->{'width'} - $text_attribs->{'llx'}, $box_height, $pdf); } -# my $font_resource = $pdf->TTFont("/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman_Bold.ttf"); -# $pdf->FontSize($text_attribs->{'font_size'}); - my $font_resource = $pdf->Font($text_attribs->{'font'}); + $pdf->Font($text_attribs->{'font'}); + $pdf->FontSize($text_attribs->{'font_size'}); foreach my $line (@lines) { -# $pdf->Text($line->{'Tx'}, $line->{'Ty'}, $line->{'line'}); - my $text_line = "BT /$font_resource $text_attribs->{'font_size'} Tf $line->{'Tx'} $line->{'Ty'} Td $line->{'Tw'} Tw ($line->{'line'}) Tj ET"; - $pdf->Add($text_line); + $pdf->Text($line->{'Tx'}, $line->{'Ty'}, $line->{'line'}); } } } @@ -197,6 +197,7 @@ sub draw_image { my $intName = $pdf->AltJpeg($images->{$image}->{'data'},$images->{$image}->{'Sx'}, $images->{$image}->{'Sy'}, 1, $images->{$image}->{'alt'}->{'data'},$images->{$image}->{'alt'}->{'Sx'}, $images->{$image}->{'alt'}->{'Sy'}, 1); my $obj_stream = "q\n"; $obj_stream .= "$images->{$image}->{'Sx'} $images->{$image}->{'Ox'} $images->{$image}->{'Oy'} $images->{$image}->{'Sy'} $Tx $Ty cm\n"; # see http://www.adobe.com/devnet/pdf/pdf_reference.html sec 8.3.3 of ISO 32000-1 + $obj_stream .= "$images->{$image}->{'scale'} 0 0 $images->{$image}->{'scale'} 0 0 cm\n"; #scale to 20% $obj_stream .= "/$intName Do\n"; $obj_stream .= "Q\n"; $pdf->Add($obj_stream);