[poppler] 5 commits - CMakeLists.txt config.h.cmake configure.ac m4/libpng.m4 utils/CMakeLists.txt utils/HtmlOutputDev.cc utils/HtmlOutputDev.h utils/Makefile.am

Albert Astals Cid aacid at kemper.freedesktop.org
Mon Jan 5 16:41:04 PST 2009


 CMakeLists.txt         |    6 ++
 config.h.cmake         |    3 +
 configure.ac           |   14 ++++
 m4/libpng.m4           |   99 ++++++++++++++++++++++++++++++++++
 utils/CMakeLists.txt   |    4 +
 utils/HtmlOutputDev.cc |  141 +++++++++++++++++++++++++++++++++++++++++++++----
 utils/HtmlOutputDev.h  |    3 -
 utils/Makefile.am      |    4 +
 8 files changed, 262 insertions(+), 12 deletions(-)

New commits:
commit af74fef03bfbd79334da5612c63c7793952542f9
Author: Warren Toomey <poppler at tuhs.org>
Date:   Tue Jan 6 01:36:31 2009 +0100

    Add forgotten file to let the autotools based system build

diff --git a/m4/libpng.m4 b/m4/libpng.m4
new file mode 100644
index 0000000..2633c13
--- /dev/null
+++ b/m4/libpng.m4
@@ -0,0 +1,99 @@
+dnl Based on Xpdf configure.in and evince configure.ac
+dnl Based on kde acinclude.m4.in, LGPL Licensed
+
+AC_DEFUN([AC_FIND_FILE],
+[
+$3=NO
+for i in $2;
+do
+  for j in $1;
+  do
+    echo "configure: __oline__: $i/$j" >&AC_FD_CC
+    if test -r "$i/$j"; then
+      echo "taking that" >&AC_FD_CC
+      $3=$i
+      break 2
+    fi
+  done
+done
+])
+
+AC_DEFUN([FIND_PNG_HELPER],
+[
+AC_MSG_CHECKING([for libpng])
+AC_CACHE_VAL(ac_cv_lib_png,
+[
+ac_save_LIBS="$LIBS"
+LIBS="$all_libraries $USER_LDFLAGS -lpng -lm"
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS $all_includes $USER_INCLUDES"
+AC_TRY_LINK(
+[
+#ifdef __cplusplus
+extern "C" {
+#endif
+void png_access_version_number();
+#ifdef __cplusplus
+}
+#endif
+],
+[png_access_version_number();],
+            eval "ac_cv_lib_png=-lpng",
+            eval "ac_cv_lib_png=no")
+LIBS="$ac_save_LIBS"
+CFLAGS="$ac_save_CFLAGS"
+])
+
+if eval "test ! \"`echo $ac_cv_lib_png`\" = no"; then
+  enable_libpng=yes
+  LIBPNG_LIBS="$ac_cv_lib_png"
+  AC_MSG_RESULT($ac_cv_lib_png)
+else
+  AC_MSG_RESULT(no)
+  $1
+fi
+])
+
+
+AC_DEFUN([POPPLER_FIND_PNG],
+[
+dnl first look for libraries
+FIND_PNG_HELPER(
+   FIND_PNG_HELPER(normal, [],
+    [
+       LIBPNG_LIBS=
+    ]
+   )
+)
+
+dnl then search the headers (can't use simply AC_TRY_xxx, as png.h
+dnl requires system dependent includes loaded before it)
+png_incdirs="`eval echo $includedir` /usr/include /usr/local/include "
+AC_FIND_FILE(png.h, $png_incdirs, png_incdir)
+test "x$png_incdir" = xNO && png_incdir=
+
+dnl if headers _and_ libraries are missing, this is no error, and we
+dnl continue with a warning (the user will get no png support)
+dnl if only one is missing, it means a configuration error, but we still
+dnl only warn
+if test -n "$png_incdir" && test -n "$LIBPNG_LIBS" ; then
+  AC_DEFINE_UNQUOTED(ENABLE_LIBPNG, 1, [Define if you have libpng])
+else
+  if test -n "$png_incdir" || test -n "$LIBPNG_LIBS" ; then
+    AC_MSG_WARN([
+There is an installation error in png support. You seem to have only one of
+either the headers _or_ the libraries installed. You may need to either provide
+correct --with-extra-... options, or the development package of libpng. You
+can get a source package of libpng from http://www.libpng.org/pub/png/libpng.html
+Disabling PNG support.
+])
+  else
+    AC_MSG_WARN([libpng not found. disable PNG support.])
+  fi
+  png_incdir=
+  enable_libpng=no
+  LIBPNG_LIBS=
+fi
+
+AC_SUBST(LIBPNG_LIBS)
+])
commit ae588500f62bab5666174ff3b1564c414c5a76c5
Author: Albert Astals Cid <aacid at kde.org>
Date:   Tue Jan 6 01:35:38 2009 +0100

    Fix the cmake buildsystem

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45c77fe..c088bd3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,6 +40,7 @@ macro_bool_to_01(ENABLE_SPLASH HAVE_SPLASH)
 find_package(Freetype REQUIRED)
 find_package(Fontconfig REQUIRED)
 macro_optional_find_package(JPEG)
+macro_optional_find_package(PNG)
 if(JPEG_FOUND)
   set(ENABLE_LIBJPEG ${JPEG_FOUND})
 endif(JPEG_FOUND)
@@ -89,6 +90,10 @@ if(JPEG_FOUND)
   include_directories(${JPEG_INCLUDE_DIR})
   set(ENABLE_LIBJPEG ON)
 endif(JPEG_FOUND)
+if(PNG_FOUND)
+  include_directories(${PNG_INCLUDE_DIR})
+  set(ENABLE_LIBPNG ON)
+endif(PNG_FOUND)
 if(ENABLE_ABIWORD)
   include_directories(${LIBXML2_INCLUDE_DIR})
   add_definitions(${LIBXML2_DEFINITIONS})
@@ -426,6 +431,7 @@ show_end_message("qt4 wrapper" QT4_FOUND)
 show_end_message("glib wrapper" GLIB_FOUND)
 # message("  use gtk-doc:        $enable_gtk_doc") # TODO
 show_end_message("use libjpeg" ENABLE_LIBJPEG)
+show_end_message("use libpng" ENABLE_LIBPNG)
 show_end_message("use zlib" ENABLE_ZLIB)
 show_end_message("use libopenjpeg" LIBOPENJPEG_FOUND)
 show_end_message("command line utils" ENABLE_UTILS)
diff --git a/config.h.cmake b/config.h.cmake
index 1d34b54..b64185c 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -6,6 +6,9 @@
 /* Use zlib instead of builtin zlib decoder. */
 #cmakedefine ENABLE_ZLIB 1
 
+/* Use libpng to export images in pdftohtml. */
+#cmakedefine ENABLE_LIBPNG 1
+
 /* Use cairo for rendering. */
 #cmakedefine HAVE_CAIRO 1
 
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index f5d4911..233fdcb 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -69,7 +69,11 @@ set(pdftohtml_SOURCES ${common_srcs}
   HtmlOutputDev.cc
 )
 add_executable(pdftohtml ${pdftohtml_SOURCES})
+if (ENABLE_LIBPNG)
+target_link_libraries(pdftohtml ${common_libs} ${PNG_LIBRARIES})
+else (ENABLE_LIBPNG)
 target_link_libraries(pdftohtml ${common_libs})
+endif (ENABLE_LIBPNG)
 install(TARGETS pdftohtml DESTINATION bin)
 
 if (ENABLE_ABIWORD)
commit 940d060a14712c09da427e2fac4ec579f7291b0f
Author: Albert Astals Cid <aacid at kde.org>
Date:   Tue Jan 6 01:27:06 2009 +0100

    do not leak fName if fopen fails

diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 19dcf7e..bda3846 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -1204,6 +1204,7 @@ void HtmlOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
     ++imgNum;
     if (!(f1 = fopen(fName->getCString(), "wb"))) {
       error(-1, "Couldn't open image file '%s'", fName->getCString());
+      delete fName;
       return;
     }
 
@@ -1292,6 +1293,7 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     
     if (!(f1 = fopen(fName->getCString(), "wb"))) {
       error(-1, "Couldn't open image file '%s'", fName->getCString());
+      delete fName;
       return;
     }
 
@@ -1332,6 +1334,7 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     // Open the image file
     if (!(f1 = fopen(fName->getCString(), "wb"))) {
       error(-1, "Couldn't open image file '%s'", fName->getCString());
+      delete fName;
       return;
     }
 
commit 7be9198adb940ad7c5fffc6db0158cf7042e1b8f
Author: Albert Astals Cid <aacid at kde.org>
Date:   Tue Jan 6 01:24:15 2009 +0100

    Do not leak pgNum and imgnum if fopen fails

diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 2b10628..19dcf7e 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -17,7 +17,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2005-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2009 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2008 Kjartan Maraas <kmaraas at gnome.org>
 // Copyright (C) 2008 Boris Toloknov <tlknv at yandex.ru>
 // Copyright (C) 2008 Haruyuki Kawabe <Haruyuki.Kawabe at unisys.co.jp>
@@ -1198,6 +1198,9 @@ void HtmlOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
     GooString *imgnum=GooString::fromInt(imgNum);
     // open the image file
     fName->append(pgNum)->append("_")->append(imgnum)->append(".jpg");
+    delete pgNum;
+    delete imgnum;
+
     ++imgNum;
     if (!(f1 = fopen(fName->getCString(), "wb"))) {
       error(-1, "Couldn't open image file '%s'", fName->getCString());
@@ -1214,8 +1217,6 @@ void HtmlOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
 
     fclose(f1);
    
-  if (pgNum) delete pgNum;
-  if (imgnum) delete imgnum;
   if (fName) imgList->append(fName);
   }
   else {
@@ -1284,6 +1285,9 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     
     // open the image file
     fName->append(pgNum)->append("_")->append(imgnum)->append(".jpg");
+    delete pgNum;
+    delete imgnum;
+
     ++imgNum;
     
     if (!(f1 = fopen(fName->getCString(), "wb"))) {
@@ -1302,8 +1306,6 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     fclose(f1);
   
     if (fName) imgList->append(fName);
-    delete pgNum;
-    delete imgnum;
   }
   else {
 #ifdef ENABLE_LIBPNG
@@ -1324,6 +1326,8 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     GooString *pgNum= GooString::fromInt(pageNum);
     GooString *imgnum= GooString::fromInt(imgNum);  
     fName->append(pgNum)->append("_")->append(imgnum)->append(".png");
+    delete pgNum;
+    delete imgnum;
 
     // Open the image file
     if (!(f1 = fopen(fName->getCString(), "wb"))) {
@@ -1407,8 +1411,6 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     free(row);
     imgList->append(fName);
     ++imgNum;
-    delete pgNum;
-    delete imgnum;
     delete imgStr;
 #else
     OutputDev::drawImage(state, ref, str, width, height, colorMap,
commit dfba6c022b150553cb2b18b027e661b3b4625ce7
Author: Warren Toomey <poppler at tuhs.org>
Date:   Tue Jan 6 01:16:31 2009 +0100

    Make pdftohtml output png images when the image stream is not a jpeg

diff --git a/configure.ac b/configure.ac
index 96ebe8d..010b77e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -180,6 +180,19 @@ AM_CONDITIONAL(BUILD_LIBJPEG, test x$enable_libjpeg = xyes)
 AH_TEMPLATE([ENABLE_LIBJPEG],
             [Use libjpeg instead of builtin jpeg decoder.])
 
+dnl Test for libpng
+AC_ARG_ENABLE(libpng,
+	      AC_HELP_STRING([--disable-libpng],
+	                     [Don't build against libpng.]),
+              enable_libpng=$enableval,
+              enable_libpng="try")
+if test x$enable_libpng != xno; then
+  POPPLER_FIND_PNG
+fi
+
+AM_CONDITIONAL(BUILD_LIBPNG, test x$enable_libpng = xyes)
+AH_TEMPLATE([ENABLE_LIBPNG],
+            [Build against libpng.])
 
 dnl Check for freetype headers
 FREETYPE_LIBS=
@@ -493,6 +506,7 @@ echo "  glib wrapper:       $enable_poppler_glib"
 echo "    use GDK:          $enable_gdk"
 echo "  use gtk-doc:        $enable_gtk_doc"
 echo "  use libjpeg:        $enable_libjpeg"
+echo "  use libpng:         $enable_libpng"
 echo "  use zlib:           $enable_zlib"
 echo "  use libopenjpeg:    $enable_libopenjpeg"
 echo "  command line utils: $enable_utils"
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 86bc2ef..2b10628 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -22,6 +22,7 @@
 // Copyright (C) 2008 Boris Toloknov <tlknv at yandex.ru>
 // Copyright (C) 2008 Haruyuki Kawabe <Haruyuki.Kawabe at unisys.co.jp>
 // Copyright (C) 2008 Tomas Are Haavet <tomasare at gmail.com>
+// Copyright (C) 2009 Warren Toomey <wkt at tuhs.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -49,12 +50,16 @@
 #ifdef ENABLE_LIBJPEG
 #include "DCTStream.h"
 #endif
+#ifdef ENABLE_LIBPNG
+#include "png.h"
+#endif
 #include "GlobalParams.h"
 #include "HtmlOutputDev.h"
 #include "HtmlFonts.h"
 
 int HtmlPage::pgNum=0;
 int HtmlOutputDev::imgNum=1;
+GooList *HtmlOutputDev::imgList=new GooList();
 
 extern double scale;
 extern GBool complexMode;
@@ -759,11 +764,14 @@ void HtmlPage::dump(FILE *f, int pageNum)
   else
   {
     fprintf(f,"<A name=%d></a>",pageNum);
-    GooString* fName=basename(DocName); 
-    for (int i=1;i<HtmlOutputDev::imgNum;i++)
-      fprintf(f,"<IMG src=\"%s-%d_%d.jpg\"><br>\n",fName->getCString(),pageNum,i);
+    // Loop over the list of image names on this page
+    int listlen=HtmlOutputDev::imgList->getLength();
+    for (int i = 0; i < listlen; i++) {
+      GooString *fName= (GooString *)HtmlOutputDev::imgList->del(0);
+      fprintf(f,"<IMG src=\"%s\"><br>\n",fName->getCString());
+      delete fName;
+    }
     HtmlOutputDev::imgNum=1;
-    delete fName;
 
     GooString* str;
     for(HtmlString *tmp=yxStrings;tmp;tmp=tmp->yxNext){
@@ -1208,7 +1216,7 @@ void HtmlOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
    
   if (pgNum) delete pgNum;
   if (imgnum) delete imgnum;
-  if (fName) delete fName;
+  if (fName) imgList->append(fName);
   }
   else {
     OutputDev::drawImageMask(state, ref, str, width, height, invert, inlineImg);
@@ -1293,13 +1301,119 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     
     fclose(f1);
   
-    delete fName;
+    if (fName) imgList->append(fName);
     delete pgNum;
     delete imgnum;
   }
   else {
+#ifdef ENABLE_LIBPNG
+    // Dump the image as a PNG file. Much of the PNG code
+    // comes from an example by Guillaume Cottenceau.
+    Guchar *p;
+    GfxRGB rgb;
+    png_structp png_ptr;
+    png_infop info_ptr;
+    png_byte color_type= PNG_COLOR_TYPE_RGB;
+    png_byte bit_depth= 8;
+    png_byte *row = (png_byte *) malloc(3 * width);   // 3 bytes/pixel: RGB
+    png_bytep *row_pointer= &row;
+
+    // Create the image filename
+    GooString *fName=new GooString(Docname);
+    fName->append("-");
+    GooString *pgNum= GooString::fromInt(pageNum);
+    GooString *imgnum= GooString::fromInt(imgNum);  
+    fName->append(pgNum)->append("_")->append(imgnum)->append(".png");
+
+    // Open the image file
+    if (!(f1 = fopen(fName->getCString(), "wb"))) {
+      error(-1, "Couldn't open image file '%s'", fName->getCString());
+      return;
+    }
+
+    // Initialize the PNG stuff
+    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+    if (!png_ptr) {
+      error(-1, "png_create_write_struct failed");
+      return;
+    }
+
+    info_ptr = png_create_info_struct(png_ptr);
+    if (!info_ptr) {
+      error(-1, "png_create_info_struct failed");
+      return;
+    }
+    if (setjmp(png_jmpbuf(png_ptr))) {
+      error(-1, "error during init_io");
+      return;
+    }
+
+    // Write the PNG header
+    png_init_io(png_ptr, f1);
+    if (setjmp(png_jmpbuf(png_ptr))) {
+      error(-1, "error during writing png header");
+      return;
+    }
+
+    // Set up the type of PNG image and the compression level
+    png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
+
+    png_set_IHDR(png_ptr, info_ptr, width, height,
+                     bit_depth, color_type, PNG_INTERLACE_NONE,
+                     PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
+    // Write the image info bytes
+    png_write_info(png_ptr, info_ptr);
+    if (setjmp(png_jmpbuf(png_ptr))) {
+      error(-1, "error during writing png info bytes");
+      return;
+    }
+
+    // Initialize the image stream
+    ImageStream *imgStr = new ImageStream(str, width,
+                        colorMap->getNumPixelComps(), colorMap->getBits());
+    imgStr->reset();
+
+    // For each line...
+    for (int y = 0; y < height; y++) {
+
+      // Convert into a PNG row
+      p = imgStr->getLine();
+      for (int x = 0; x < width; x++) {
+        colorMap->getRGB(p, &rgb);
+	// Write the RGB pixels into the row
+	row[3*x]= colToByte(rgb.r);
+	row[3*x+1]= colToByte(rgb.g);
+	row[3*x+2]= colToByte(rgb.b);
+         p += colorMap->getNumPixelComps();
+      }
+
+      // Write the row to the file
+      png_write_rows(png_ptr, row_pointer, 1);
+      if (setjmp(png_jmpbuf(png_ptr))) {
+        error(-1, "error during png row write");
+        return;
+      }
+    }
+
+    // Finish off the PNG file
+    png_write_end(png_ptr, info_ptr);
+    if (setjmp(png_jmpbuf(png_ptr))) {
+      error(-1, "error during png end of write");
+      return;
+    }
+
+    fclose(f1);
+    free(row);
+    imgList->append(fName);
+    ++imgNum;
+    delete pgNum;
+    delete imgnum;
+    delete imgStr;
+#else
     OutputDev::drawImage(state, ref, str, width, height, colorMap,
 			 maskColors, inlineImg);
+#endif
   }
 }
 
diff --git a/utils/HtmlOutputDev.h b/utils/HtmlOutputDev.h
index e42146b..a048a72 100644
--- a/utils/HtmlOutputDev.h
+++ b/utils/HtmlOutputDev.h
@@ -15,7 +15,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2006-2007 Albert Astals Cid <aacid at kde.org>
-// Copyright (C) 2008 Warren Toomey <wkt at tuhs.org>
+// Copyright (C) 2008-2009 Warren Toomey <wkt at tuhs.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -316,6 +316,7 @@ private:
   int maxPageWidth;
   int maxPageHeight;
   static int imgNum;
+  static GooList *imgList;
   GooString *Docname;
   GooString *docTitle;
   GooList *glMetaVars;
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 19e8a20..6042273 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -33,6 +33,10 @@ LDADD =						\
 	$(UTILS_LIBS)				\
 	$(FONTCONFIG_LIBS)
 
+if BUILD_LIBPNG
+pdftohtml_LDADD = $(LDADD) $(LIBPNG_LIBS)
+endif
+
 AM_LDFLAGS = @auto_import_flags@
 
 bin_PROGRAMS =					\


More information about the poppler mailing list