View | Details | Raw Unified | Return to bug 13407
Collapse All | Expand All

(-)a/C4/Creators/PDF.pm (-92 / +1 lines)
Lines 170-266 sub AltJpeg { Link Here
170
sub Jpeg {
170
sub Jpeg {
171
    my $self = shift;
171
    my $self = shift;
172
    my ($imageData, $width, $height, $imageFormat) = @_;
172
    my ($imageData, $width, $height, $imageFormat) = @_;
173
    return prJpegBlob($imageData, $width, $height, $imageFormat);
173
    return prJpeg($imageData, $width, $height, $imageFormat);
174
}
175
176
# FIXME: This magick foo is an absolute hack until the maintainer of PDF::Reuse releases the next version which will include these features
177
178
sub prAltJpeg
179
{  my ($iData, $iWidth, $iHeight, $iFormat,$aiData, $aiWidth, $aiHeight, $aiFormat) = @_;
180
   my ($namnet, $utrad);
181
   if (! $PDF::Reuse::pos)                    # If no output is active, it is no use to continue
182
   {   return;
183
   }
184
   prJpegBlob($aiData, $aiWidth, $aiHeight, $aiFormat);
185
   my $altObjNr = $PDF::Reuse::objNr;
186
   $PDF::Reuse::imageNr++;
187
   $namnet = 'Ig' . $PDF::Reuse::imageNr;
188
   $PDF::Reuse::objNr++;
189
   $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
190
   $utrad = "$PDF::Reuse::objNr 0 obj\n" .
191
            "[ << /Image $altObjNr 0 R\n" .
192
            "/DefaultForPrinting true\n" .
193
            ">>\n" .
194
            "]\n" .
195
            "endobj\n";
196
   $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad;
197
   if ($PDF::Reuse::runfil)
198
   {  $PDF::Reuse::log .= "Jpeg~AltImage\n";
199
   }
200
   $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
201
   $namnet = prJpegBlob($iData, $iWidth, $iHeight, $iFormat, $PDF::Reuse::objNr);
202
   if (! $PDF::Reuse::pos)
203
   {  errLog("No output file, you have to call prFile first");
204
   }
205
   return $namnet;
206
}
207
208
sub prJpegBlob
209
{  my ($iData, $iWidth, $iHeight, $iFormat, $altArrayObjNr) = @_;
210
   my ($iLangd, $namnet, $utrad);
211
   if (! $PDF::Reuse::pos)                    # If no output is active, it is no use to continue
212
   {   return;
213
   }
214
   my $checkidOld = $PDF::Reuse::checkId;
215
   if (!$iFormat)
216
   {   my ($iFile, $checkId) = findGet($iData, $checkidOld);
217
       if ($iFile)
218
       {  $iLangd = (stat($iFile))[7];
219
          $PDF::Reuse::imageNr++;
220
          $namnet = 'Ig' . $PDF::Reuse::imageNr;
221
          $PDF::Reuse::objNr++;
222
          $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
223
          open (my $fh, '<', "$iFile") || errLog("Couldn't open $iFile, $!, aborts");
224
          binmode $fh;
225
          my $iStream;
226
          sysread $fh, $iStream, $iLangd;
227
          $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
228
                    "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
229
                    ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
230
                    "/Filter/DCTDecode/ColorSpace/DeviceRGB"
231
                    . "/Length $iLangd >>stream\n$iStream\nendstream\nendobj\n";
232
          close $fh;
233
          $PDF::Reuse::pos += syswrite $PDF::Reuse::UTFIL, $utrad;
234
          if ($PDF::Reuse::runfil)
235
          {  $PDF::Reuse::log .= "Cid~$PDF::Reuse::checkId\n";
236
             $PDF::Reuse::log .= "Jpeg~$iFile~$iWidth~$iHeight\n";
237
          }
238
          $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
239
       }
240
       undef $checkId;
241
   }
242
   elsif ($iFormat == 1)
243
   {  my $iBlob = $iData;
244
      $iLangd = length($iBlob);
245
      $PDF::Reuse::imageNr++;
246
      $namnet = 'Ig' . $PDF::Reuse::imageNr;
247
      $PDF::Reuse::objNr++;
248
      $PDF::Reuse::objekt[$PDF::Reuse::objNr] = $PDF::Reuse::pos;
249
      $utrad = "$PDF::Reuse::objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
250
                "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
251
                ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
252
                "/Filter/DCTDecode/ColorSpace/DeviceRGB"
253
                . "/Length $iLangd >>stream\n$iBlob\nendstream\nendobj\n";
254
      $PDF::Reuse::pos += syswrite *PDF::Reuse::UTFIL, $utrad;
255
      if ($PDF::Reuse::runfil)
256
      {  $PDF::Reuse::log .= "Jpeg~Blob~$iWidth~$iHeight\n";
257
      }
258
      $PDF::Reuse::objRef{$namnet} = $PDF::Reuse::objNr;
259
   }
260
   if (! $PDF::Reuse::pos)
261
   {  errLog("No output file, you have to call prFile first");
262
   }
263
   return $namnet;
264
}
174
}
265
175
266
sub Js {
176
sub Js {
267
- 

Return to bug 13407