X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FCreators%2FPDF.pm;h=e90b0bd3d7db3942af400804c347cd705eef20e0;hb=9d6d641d1f8b77271800f43bc027b651f9aea52b;hp=871e32bd87a78a92f19e734cc62d9fe49900cc96;hpb=1fd99527bd947a6d2d86822fb9fd964fc35cc582;p=srvgit diff --git a/C4/Creators/PDF.pm b/C4/Creators/PDF.pm index 871e32bd87..e90b0bd3d7 100644 --- a/C4/Creators/PDF.pm +++ b/C4/Creators/PDF.pm @@ -4,28 +4,57 @@ package C4::Creators::PDF; # # 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; -use PDF::Reuse; +use PDF::Reuse qw( + prAdd + prAltJpeg + prBookmark + prCompress + prDoc + prDocDir + prDocForm + prEnd + prExtract + prField + prFile + prFont + prFontSize + prForm + prGetLogBuffer + prGraphState + prImage + prInit + prInitVars + prJpeg + prJs + prLink + prLog + prLogDir + prMbox + prPage + prSinglePage + prStrWidth + prText + prTTFont +); use PDF::Reuse::Barcode; use File::Temp; +use List::Util qw( first ); -BEGIN { - use version; our $VERSION = qv('3.07.00.049'); -} sub _InitVars { my $self = shift; @@ -55,8 +84,7 @@ sub new { sub End { my $self = shift; - # if the pdf stream is utf8, explicitly set it to utf8; this avoids at lease some wide character errors -chris_n - utf8::encode($PDF::Reuse::stream) if utf8::is_utf8($PDF::Reuse::stream); + prEnd(); # slurp temporary filename and print it out for plack to pick up @@ -112,6 +140,17 @@ sub Field { sub Font { my $self = shift; my $fontName = shift; + + my $ttf = C4::Context->config('ttf'); + + if ( $ttf ) { + my $ttf_path = first { $_->{type} eq $fontName } @{ $ttf->{font} }; + if ( -e $ttf_path->{content} ) { + return prTTFont($ttf_path->{content}); + } else { + warn "ERROR in koha-conf.xml -- missing /path/to/font.ttf"; + } + } return prFont($fontName); } @@ -159,97 +198,7 @@ sub AltJpeg { sub Jpeg { my $self = shift; my ($imageData, $width, $height, $imageFormat) = @_; - return prJpegBlob($imageData, $width, $height, $imageFormat); -} - -# FIXME: This magick foo is an absolute hack until the maintainer of PDF::Reuse releases the next version which will include these features - -sub prAltJpeg -{ my ($iData, $iWidth, $iHeight, $iFormat,$aiData, $aiWidth, $aiHeight, $aiFormat) = @_; - my ($namnet, $utrad); - if (! $PDF::Reuse::pos) # If no output is active, it is no use to continue - { return; - } - prJpegBlob($aiData, $aiWidth, $aiHeight, $aiFormat); - my $altObjNr = $PDF::Reuse::objNr; - $PDF::Reuse::imageNr++; - $namnet = 'Ig' . $PDF::Reuse::imageNr; - $PDF::Reuse::objNr++; - $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos; - $utrad = "$PDF::Reuse::objNr 0 obj\n" . - "[ << /Image $altObjNr 0 R\n" . - "/DefaultForPrinting true\n" . - ">>\n" . - "]\n" . - "endobj\n"; - $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad; - if ($PDF::Reuse::runfil) - { $PDF::Reuse::log .= "Jpeg~AltImage\n"; - } - $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr; - $namnet = prJpegBlob($iData, $iWidth, $iHeight, $iFormat, $PDF::Reuse::objNr); - if (! $PDF::Reuse::pos) - { errLog("No output file, you have to call prFile first"); - } - return $namnet; -} - -sub prJpegBlob -{ my ($iData, $iWidth, $iHeight, $iFormat, $altArrayObjNr) = @_; - my ($iLangd, $namnet, $utrad); - if (! $PDF::Reuse::pos) # If no output is active, it is no use to continue - { return; - } - my $checkidOld = $PDF::Reuse::checkId; - if (!$iFormat) - { my ($iFile, $checkId) = findGet($iData, $checkidOld); - if ($iFile) - { $iLangd = (stat($iFile))[7]; - $PDF::Reuse::imageNr++; - $namnet = 'Ig' . $PDF::Reuse::imageNr; - $PDF::Reuse::objNr++; - $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos; - open (my $fh, '<', "$iFile") || errLog("Couldn't open $iFile, $!, aborts"); - binmode $fh; - my $iStream; - sysread $fh, $iStream, $iLangd; - $utrad = "$PDF::Reuse::objNr 0 obj\n<>stream\n$iStream\nendstream\nendobj\n"; - close $fh; - $PDF::Reuse::pos += syswrite $PDF::Reuse::UTFIL, $utrad; - if ($PDF::Reuse::runfil) - { $PDF::Reuse::log .= "Cid~$PDF::Reuse::checkId\n"; - $PDF::Reuse::log .= "Jpeg~$iFile~$iWidth~$iHeight\n"; - } - $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr; - } - undef $checkId; - } - elsif ($iFormat == 1) - { my $iBlob = $iData; - $iLangd = length($iBlob); - $PDF::Reuse::imageNr++; - $namnet = 'Ig' . $PDF::Reuse::imageNr; - $PDF::Reuse::objNr++; - $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos; - $utrad = "$PDF::Reuse::objNr 0 obj\n<>stream\n$iBlob\nendstream\nendobj\n"; - $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad; - if ($PDF::Reuse::runfil) - { $PDF::Reuse::log .= "Jpeg~Blob~$iWidth~$iHeight\n"; - } - $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr; - } - if (! $PDF::Reuse::pos) - { errLog("No output file, you have to call prFile first"); - } - return $namnet; + return prJpeg($imageData, $width, $height, $imageFormat); } sub Js { @@ -297,6 +246,10 @@ sub SinglePage { sub StrWidth { my $self = shift; my ($string, $font, $fontSize) = @_; + + # replace font code with correct internal font + $font = C4::Creators::PDF->Font($font); + return prStrWidth($string, $font, $fontSize); } @@ -390,7 +343,7 @@ __END__ =head1 NAME -C4::Creators::PDF - A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a psuedo-object. For usage see +C4::Creators::PDF - A class wrapper for PDF::Reuse and PDF::Reuse::Barcode to allow usage as a pseudo-object. For usage see PDF::Reuse documentation and C4::Creators::PDF code. =cut