[Koha-patches] [PATCH] Bugfix: Implimentation of JpegBlob and AltJpeg methods

Chris Nighswonger cnighswonger at foundations.edu
Thu Feb 4 20:47:30 CET 2010


Implimentation of JpegBlob and AltJpeg methods in C4::Creators::PDF
---
 C4/Creators/PDF.pm |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 91 insertions(+), 1 deletions(-)

diff --git a/C4/Creators/PDF.pm b/C4/Creators/PDF.pm
index 1421a2b..7ffb303 100644
--- a/C4/Creators/PDF.pm
+++ b/C4/Creators/PDF.pm
@@ -144,7 +144,97 @@ sub AltJpeg {
 sub Jpeg {
     my $self = shift;
     my ($imageData, $width, $height, $imageFormat) = @_;
-    return prJpeg($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 undef;
+   }
+   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 undef;
+   }
+   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 (BILDFIL, "<$iFile") || errLog("Couldn't open $iFile, $!, aborts");
+          binmode BILDFIL;
+          my $iStream;
+          sysread BILDFIL, $iStream, $iLangd;
+          $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
+                    "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
+                    ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
+                    "/Filter/DCTDecode/ColorSpace/DeviceRGB"
+                    . "/Length $iLangd >>stream\n$iStream\nendstream\nendobj\n";
+          close BILDFIL;
+          $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<</Type/XObject/Subtype/Image/Name/$namnet" .
+                "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
+                ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
+                "/Filter/DCTDecode/ColorSpace/DeviceRGB"
+                . "/Length $iLangd >>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;
 }
 
 sub Js {
-- 
1.6.0.4




More information about the Koha-patches mailing list