r695 - packages/libpdf-report-perl/trunk

Gunnar Wolf gwolf@costa.debian.org
Wed, 16 Feb 2005 23:15:41 +0100


Author: gwolf
Date: 2005-02-16 23:15:40 +0100 (Wed, 16 Feb 2005)
New Revision: 695

Modified:
   packages/libpdf-report-perl/trunk/Report.pm
Log:
Extra details in Jordan's patch related to managing images or such embedded objects


Modified: packages/libpdf-report-perl/trunk/Report.pm
===================================================================
--- packages/libpdf-report-perl/trunk/Report.pm	2005-02-16 02:58:36 UTC (rev 694)
+++ packages/libpdf-report-perl/trunk/Report.pm	2005-02-16 22:15:40 UTC (rev 695)
@@ -268,6 +268,8 @@
 	     -indent=>$indent);
 }
 
+=pod
+
 =item PDF::API2 Removes all space between every word in the string you pass 
 and then rejoins each word with one space.  If you want to use a string with 
 more than one space between words for formatting purposes, you can either use 
@@ -565,10 +567,30 @@
 
 =cut
 
+sub iobjbyext {
+  my ( $self, $file ) = @_;
+
+  # stupid hack depending on file extensions
+  my %ext = (gif  => sub { $_[0]->{pdf}->image_gif  ($_[1]) },
+             jpg  => sub { $_[0]->{pdf}->image_jpeg ($_[1]) },
+             jpeg => sub { $_[0]->{pdf}->image_jpeg ($_[1]) },
+             png  => sub { $_[0]->{pdf}->image_png  ($_[1]) },
+             pnm  => sub { $_[0]->{pdf}->image_pnm  ($_[1]) },
+             gd   => sub { $_[0]->{pdf}->image_gd   ($_[1]) },
+             tif  => sub { $_[0]->{pdf}->image_tiff ($_[1]) },
+             tiff => sub { $_[0]->{pdf}->image_tiff ($_[1]) },
+	     );
+ 
+  my $fn = $ext {lc $1} if ($file||'') =~ m|\.(\w+)$| ;
+  # Treat as a .gif if we get no hint
+  $fn ||= sub { $_[0]->{pdf}->image_gif  ($_[1]) };
+  &$fn ($self, $file) ;
+}
+
 sub addImg {
   my ( $self, $file, $x, $y ) = @_;
 
-  my $img = $self->{pdf}->image($file);
+  my $img = $self->iobjbyext($file);
   my $gfx = $self->{page}->gfx;
 
   $gfx->image($img, $x, $y);
@@ -583,7 +605,7 @@
 sub addImgScaled {
   my ( $self, $file, $x, $y, $scale ) = @_;
 
-  my $img = $self->{pdf}->image($file);
+  my $img = $self->iobjbyext($file);
   my $gfx = $self->{page}->gfx;
 
   $gfx->image($img, $x, $y, $scale);