[poppler] Branch 'cpp-frontend' - 8 commits - CMakeLists.txt cmake/modules config.h.cmake configure.ac cpp/CMakeLists.txt cpp/Makefile.am cpp/poppler-global.cpp cpp/poppler-private.cpp cpp/tests m4/iconv.m4 Makefile.am

Pino Toscano pino at kemper.freedesktop.org
Wed Dec 30 15:21:12 PST 2009


 CMakeLists.txt                |    6 +
 Makefile.am                   |    1 
 cmake/modules/FindIconv.cmake |   57 +++++++++++++
 config.h.cmake                |    6 +
 configure.ac                  |    6 +
 cpp/CMakeLists.txt            |    2 
 cpp/Makefile.am               |    5 -
 cpp/poppler-global.cpp        |   92 ++++++++++++++-------
 cpp/poppler-private.cpp       |   44 +++++++++-
 cpp/tests/poppler-dump.cpp    |   54 ++++++++++++
 m4/iconv.m4                   |  180 ++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 417 insertions(+), 36 deletions(-)

New commits:
commit f3862f7d987aae52a1fd2bb0af27d1cd803a5b84
Author: Pino Toscano <pino at kde.org>
Date:   Thu Dec 31 00:20:11 2009 +0100

    [cpp/tests] poppler-dump: show a string for the font type

diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index ef96ca7..745d038 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -132,6 +132,27 @@ static std::string out_page_orientation(poppler::page::orientation_enum o)
     return "<unknown orientation>";
 }
 
+static std::string out_font_info_type(poppler::font_info::type_enum t)
+{
+#define OUT_FONT_TYPE(thetype) case poppler::font_info::thetype: return #thetype
+    switch (t) {
+    OUT_FONT_TYPE(unknown);
+    OUT_FONT_TYPE(type1);
+    OUT_FONT_TYPE(type1c);
+    OUT_FONT_TYPE(type1c_ot);
+    OUT_FONT_TYPE(type3);
+    OUT_FONT_TYPE(truetype);
+    OUT_FONT_TYPE(truetype_ot);
+    OUT_FONT_TYPE(cid_type0);
+    OUT_FONT_TYPE(cid_type0c);
+    OUT_FONT_TYPE(cid_type0c_ot);
+    OUT_FONT_TYPE(cid_truetype);
+    OUT_FONT_TYPE(cid_truetype_ot);
+    }
+    return "<unknown font type>";
+#undef OUT_FONT_TYPE
+}
+
 static void print_info(poppler::document *doc)
 {
     std::cout << "Document information:" << std::endl;
@@ -209,7 +230,7 @@ static void print_fonts(poppler::document *doc)
         for (; it != it_end; ++it) {
             std::cout
                 << " " << std::setw(out_width + 10) << it->name()
-                << " " << std::setw(15) << it->type()
+                << " " << std::setw(15) << out_font_info_type(it->type())
                 << " " << std::setw(5) << it->is_embedded()
                 << " " << std::setw(5) << it->is_subset()
                 << " " << it->file()
commit 9c343c821593ebae51ac47b58ad007a82f198652
Author: Pino Toscano <pino at kde.org>
Date:   Thu Dec 31 00:13:09 2009 +0100

    [cpp/tests] poppler-dump: show the orientation of the pages

diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index 8e2b6cf..ef96ca7 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -117,6 +117,21 @@ static std::string out_hex_string(const std::string &str)
     return ret;
 }
 
+static std::string out_page_orientation(poppler::page::orientation_enum o)
+{
+    switch (o) {
+    case poppler::page::landscape:
+        return "landscape (90)";
+    case poppler::page::portrait:
+        return "portrait (0)";
+    case poppler::page::seascape:
+        return "seascape (270)";
+    case poppler::page::upside_down:
+        return "upside_downs (180)";
+    };
+    return "<unknown orientation>";
+}
+
 static void print_info(poppler::document *doc)
 {
     std::cout << "Document information:" << std::endl;
@@ -241,6 +256,7 @@ static void print_page(poppler::page *p)
     std::cout << std::setw(out_width) << "Rect" << ": " << p->page_rect() << std::endl;
     std::cout << std::setw(out_width) << "Label" << ": " << out_ustring(p->label()) << std::endl;
     std::cout << std::setw(out_width) << "Duration" << ": " << p->duration() << std::endl;
+    std::cout << std::setw(out_width) << "Orientation" << ": " << out_page_orientation(p->orientation()) << std::endl;
     std::cout << std::endl;
 }
 
commit bc91fe3824f37cd17a38aac85c817e8ada1b2f43
Author: Pino Toscano <pino at kde.org>
Date:   Wed Dec 30 23:53:31 2009 +0100

    [cpp/tests] poppler-dump: a bit less output in permissions lines

diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index 5e3d33e..8e2b6cf 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -140,7 +140,7 @@ static void print_perm(poppler::document *doc)
 {
     std::cout << "Document permissions:" << std::endl;
 #define OUT_PERM(theperm) \
-    std::cout << std::setw(out_width) << "Perm (" #theperm ")" << ": " \
+    std::cout << std::setw(out_width) << #theperm << ": " \
               << doc->has_permission(poppler::perm_##theperm) << std::endl
     OUT_PERM(print);
     OUT_PERM(change);
commit 1199de8f097a78edb831313841ac0ed3f9ec9905
Author: Pino Toscano <pino at kde.org>
Date:   Wed Dec 30 23:50:36 2009 +0100

    [cpp/tests] poppler-dump: add --show-all to show all the information

diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index de50244..5e3d33e 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -33,6 +33,7 @@
 
 static const int out_width = 30;
 
+bool show_all = false;
 bool show_info = false;
 bool show_perm = false;
 bool show_metadata = false;
@@ -43,6 +44,8 @@ bool show_pages = false;
 bool show_help = false;
 
 static const ArgDesc the_args[] = {
+    { "--show-all",            argFlag,  &show_all,            0,
+      "show all the available information" },
     { "--show-info",           argFlag,  &show_info,           0,
       "show general document information" },
     { "--show-perm",           argFlag,  &show_perm,           0,
@@ -261,6 +264,16 @@ int main(int argc, char *argv[])
 
     std::cout.setf(std::ios_base::boolalpha);
 
+    if (show_all) {
+        show_info = true;
+        show_perm = true;
+        show_metadata = true;
+        show_toc = true;
+        show_fonts = true;
+        show_embedded_files = true;
+        show_pages = true;
+    }
+
     if (show_info) {
         print_info(doc.get());
     }
commit 9522f830b59942adfc91d5f03c274415a4737ccc
Author: Pino Toscano <pino at kde.org>
Date:   Wed Dec 30 23:38:40 2009 +0100

    [cpp] use iconv for the utf8 <-> utf16 conversions

diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp
index 424f947..deae74b 100644
--- a/cpp/poppler-global.cpp
+++ b/cpp/poppler-global.cpp
@@ -20,10 +20,32 @@
 
 #include "DateInfo.h"
 
+#include <cerrno>
 #include <ctime>
 #include <cstring>
 #include <iostream>
 
+#include <iconv.h>
+
+namespace
+{
+
+struct MiniIconv
+{
+    MiniIconv(const char *to_code, const char *from_code)
+        : i_(iconv_open(to_code, from_code))
+    {}
+    ~MiniIconv()
+    { if (is_valid()) iconv_close(i_); }
+    bool is_valid() const
+    { return i_ != (iconv_t)-1; }
+    operator iconv_t() const
+    { return i_; }
+    iconv_t i_;
+};
+
+}
+
 using namespace poppler;
 
 noncopyable::noncopyable()
@@ -54,14 +76,28 @@ byte_array ustring::to_utf_8() const
         return byte_array();
     }
 
-    const value_type *me = data();
-    const size_t len = size() * 2 + 2;
-    byte_array str(len);
-    str[0] = 0xfe;
-    str[1] = 0xff;
-    for (size_t i = 0; i < size(); ++i, ++me) {
-        str[i * 2 + 2] = (*me & 0xff);
-        str[i * 2 + 3] = ((*me >> 8) & 0xff);
+    MiniIconv ic("UTF-8", "UTF-16");
+    if (!ic.is_valid()) {
+        return byte_array();
+    }
+    const value_type *me_data = data();
+    byte_array str(size());
+    char *str_data = &str[0];
+    size_t me_len_char = size() * 2;
+    size_t str_len_left = str.size();
+    size_t ir = iconv(ic, (char **)&me_data, &me_len_char, &str_data, &str_len_left);
+    if ((ir == (size_t)-1) && (errno == E2BIG)) {
+        const size_t delta = str_data - &str[0];
+        str_len_left += str.size();
+        str.resize(str.size() * 2);
+        str_data = &str[delta];
+        ir = iconv(ic, (char **)&me_data, &me_len_char, &str_data, &str_len_left);
+        if (ir == (size_t)-1) {
+            return byte_array();
+        }
+    }
+    if (str_len_left >= 0) {
+        str.resize(str.size() - str_len_left);
     }
     return str;
 }
@@ -90,30 +126,30 @@ ustring ustring::from_utf_8(const char *str, int len)
         }
     }
 
-    int i = 0;
-    bool is_unicode = false;
-    if ((str[0] & 0xff) == 0xfe && (len > 1 && (str[1] & 0xff) == 0xff)) {
-        is_unicode = true;
-        i = 2;
+    MiniIconv ic("UTF-16", "UTF-8");
+    if (!ic.is_valid()) {
+        return ustring();
     }
 
-    const ustring::size_type ret_len = (len - i) / (is_unicode ? 2 : 1);
-    ustring ret(ret_len, 0);
-    size_t ret_index = 0;
-    ustring::value_type u;
-    if (is_unicode) {
-        while (i < len) {
-            u = ((str[i] & 0xff) << 8) | (str[i + 1] & 0xff);
-            i += 2;
-            ret[ret_index++] = u;
-        }
-    } else {
-        while (i < len) {
-            u = str[i] & 0xff;
-            ++i;
-            ret[ret_index++] = u;
+    ustring ret(len, 0);
+    char *ret_data = reinterpret_cast<char *>(&ret[0]);
+    char *str_data = const_cast<char *>(str);
+    size_t str_len_char = len;
+    size_t ret_len_left = ret.size();
+    size_t ir = iconv(ic, &str_data, &str_len_char, &ret_data, &ret_len_left);
+    if ((ir == (size_t)-1) && (errno == E2BIG)) {
+        const size_t delta = ret_data - reinterpret_cast<char *>(&ret[0]);
+        ret_len_left += ret.size();
+        ret.resize(ret.size() * 2);
+        ret_data = reinterpret_cast<char *>(&ret[delta]);
+        ir = iconv(ic, (char **)&str_data, &str_len_char, &ret_data, &ret_len_left);
+        if (ir == (size_t)-1) {
+            return ustring();
         }
     }
+    if (ret_len_left >= 0) {
+        ret.resize(ret.size() - ret_len_left);
+    }
 
     return ret;
 }
commit b156b4031f5daf658f40db8efa2a3016d95b98b5
Author: Pino Toscano <pino at kde.org>
Date:   Wed Dec 30 23:24:23 2009 +0100

    [cpp] add the build system stuff for iconv, mandatory for cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 023229c..18b6a8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,12 @@ if(GLIB_FOUND)
     set(CAIRO_REQ "cairo")
   endif(CAIRO_FOUND)
 endif(GLIB_FOUND)
+if(ENABLE_CPP)
+  macro_optional_find_package(Iconv)
+  set(ENABLE_CPP ${ICONV_FOUND})
+  set(HAVE_ICONV ${ICONV_FOUND})
+  set(ICONV_CONST ${ICONV_SECOND_ARGUMENT_IS_CONST})
+endif(ENABLE_CPP)
 if(ENABLE_ZLIB)
   find_package(ZLIB)
   if(ZLIB_FOUND)
diff --git a/Makefile.am b/Makefile.am
index 6d279ad..aedf60f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -73,6 +73,7 @@ EXTRA_DIST +=							\
 	cmake/modules/FindCairo.cmake				\
 	cmake/modules/FindFontconfig.cmake			\
 	cmake/modules/FindGTK.cmake				\
+	cmake/modules/FindIconv.cmake				\
 	cmake/modules/FindLCMS.cmake				\
 	cmake/modules/FindQt3.cmake				\
 	cmake/modules/FindQt4.cmake				\
diff --git a/cmake/modules/FindIconv.cmake b/cmake/modules/FindIconv.cmake
new file mode 100644
index 0000000..ce40ab2
--- /dev/null
+++ b/cmake/modules/FindIconv.cmake
@@ -0,0 +1,57 @@
+# - Try to find Iconv 
+# Once done this will define 
+# 
+#  ICONV_FOUND - system has Iconv 
+#  ICONV_INCLUDE_DIR - the Iconv include directory 
+#  ICONV_LIBRARIES - Link these to use Iconv 
+#  ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
+# 
+include(CheckCXXSourceCompiles)
+
+IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
+  # Already in cache, be silent
+  SET(ICONV_FIND_QUIETLY TRUE)
+ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
+
+FIND_PATH(ICONV_INCLUDE_DIR iconv.h) 
+ 
+FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
+ 
+IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) 
+   SET(ICONV_FOUND TRUE) 
+ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) 
+
+set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
+set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
+IF(ICONV_FOUND)
+  check_cxx_source_compiles("
+  #include <iconv.h>
+  int main(){
+    iconv_t conv = 0;
+    const char* in = 0;
+    size_t ilen = 0;
+    char* out = 0;
+    size_t olen = 0;
+    iconv(conv, &in, &ilen, &out, &olen);
+    return 0;
+  }
+" ICONV_SECOND_ARGUMENT_IS_CONST )
+ENDIF(ICONV_FOUND)
+set(CMAKE_REQUIRED_INCLUDES)
+set(CMAKE_REQUIRED_LIBRARIES)
+
+IF(ICONV_FOUND) 
+  IF(NOT ICONV_FIND_QUIETLY) 
+    MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") 
+  ENDIF(NOT ICONV_FIND_QUIETLY) 
+ELSE(ICONV_FOUND) 
+  IF(Iconv_FIND_REQUIRED) 
+    MESSAGE(FATAL_ERROR "Could not find Iconv") 
+  ENDIF(Iconv_FIND_REQUIRED) 
+ENDIF(ICONV_FOUND) 
+
+MARK_AS_ADVANCED(
+  ICONV_INCLUDE_DIR
+  ICONV_LIBRARIES
+  ICONV_SECOND_ARGUMENT_IS_CONST
+)
diff --git a/config.h.cmake b/config.h.cmake
index 7b57de0..253e730 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -36,6 +36,9 @@
 /* Defines if gettimeofday is available on your system */
 #cmakedefine HAVE_GETTIMEOFDAY 1
 
+/* Define if you have the iconv() function and it works. */
+#cmakedefine HAVE_ICONV 1
+
 /* Define to 1 if you have the <inttypes.h> header file. */
 #cmakedefine HAVE_INTTYPES_H 1
 
@@ -90,6 +93,9 @@
 /* Define to 1 if you have the <zlib.h> header file. */
 #cmakedefine HAVE_ZLIB_H 1
 
+/* Define as const if the declaration of iconv() needs const. */
+#cmakedefine ICONV_CONST 1
+
 /* Define to 1 if gdk was found */
 #cmakedefine POPPLER_WITH_GDK 1
 
diff --git a/configure.ac b/configure.ac
index a51eede..102a0b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -453,6 +453,12 @@ AC_ARG_ENABLE(poppler-cpp,
                              [Don't compile poppler cpp wrapper.]),
               enable_poppler_cpp=$enableval,
               enable_poppler_cpp="yes")
+if test x$enable_poppler_cpp = xyes; then
+  AM_ICONV()
+  if test x$am_func_iconv != xyes; then
+    enable_poppler_cpp=no
+  fi
+fi
 
 AM_CONDITIONAL(BUILD_POPPLER_CPP, test "x$enable_poppler_cpp" = "xyes")
 
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index b5880de..4c1d7c4 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -22,7 +22,7 @@ set(poppler_cpp_SRCS
 
 add_library(poppler-cpp SHARED ${poppler_cpp_SRCS})
 set_target_properties(poppler-cpp PROPERTIES VERSION 0.1.0 SOVERSION 0)
-target_link_libraries(poppler-cpp poppler)
+target_link_libraries(poppler-cpp poppler ${ICONV_LIBRARIES})
 if(MSVC)
 target_link_libraries(poppler-cpp ${poppler_LIBS})
 endif(MSVC)
diff --git a/cpp/Makefile.am b/cpp/Makefile.am
index 4fb1874..2e3f56d 100644
--- a/cpp/Makefile.am
+++ b/cpp/Makefile.am
@@ -31,6 +31,7 @@ libpoppler_cpp_la_SOURCES =			\
 	poppler-version.cpp
 
 libpoppler_cpp_la_LIBADD = 			\
-	$(top_builddir)/poppler/libpoppler.la
+	$(top_builddir)/poppler/libpoppler.la	\
+	$(LIBICONV)
 
 libpoppler_cpp_la_LDFLAGS = -version-info 1:0:1 @create_shared_lib@
diff --git a/m4/iconv.m4 b/m4/iconv.m4
new file mode 100644
index 0000000..b2156eb
--- /dev/null
+++ b/m4/iconv.m4
@@ -0,0 +1,180 @@
+# iconv.m4 serial AM6 (gettext-0.17)
+dnl Copyright (C) 2000-2002, 2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
+[
+  dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  dnl AC_REQUIRE([AC_LIB_RPATH])
+
+  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+  dnl accordingly.
+  AC_LIB_LINKFLAGS_BODY([iconv])
+])
+
+AC_DEFUN([AM_ICONV_LINK],
+[
+  dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
+  dnl those with the standalone portable GNU libiconv installed).
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+  dnl accordingly.
+  AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
+
+  dnl Add $INCICONV to CPPFLAGS before performing the following checks,
+  dnl because if the user has installed libiconv and not disabled its use
+  dnl via --without-libiconv-prefix, he wants to use it. The first
+  dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
+  am_save_CPPFLAGS="$CPPFLAGS"
+  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
+
+  AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [
+    am_cv_func_iconv="no, consider installing GNU libiconv"
+    am_cv_lib_iconv=no
+    AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+      [iconv_t cd = iconv_open("","");
+       iconv(cd,NULL,NULL,NULL,NULL);
+       iconv_close(cd);],
+      am_cv_func_iconv=yes)
+    if test "$am_cv_func_iconv" != yes; then
+      am_save_LIBS="$LIBS"
+      LIBS="$LIBS $LIBICONV"
+      AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+        [iconv_t cd = iconv_open("","");
+         iconv(cd,NULL,NULL,NULL,NULL);
+         iconv_close(cd);],
+        am_cv_lib_iconv=yes
+        am_cv_func_iconv=yes)
+      LIBS="$am_save_LIBS"
+    fi
+  ])
+  if test "$am_cv_func_iconv" = yes; then
+    AC_CACHE_CHECK([for working iconv], am_cv_func_iconv_works, [
+      dnl This tests against bugs in AIX 5.1 and HP-UX 11.11.
+      am_save_LIBS="$LIBS"
+      if test $am_cv_lib_iconv = yes; then
+        LIBS="$LIBS $LIBICONV"
+      fi
+      AC_TRY_RUN([
+#include <iconv.h>
+#include <string.h>
+int main ()
+{
+  /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
+     returns.  */
+  {
+    iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
+    if (cd_utf8_to_88591 != (iconv_t)(-1))
+      {
+        static const char input[] = "\342\202\254"; /* EURO SIGN */
+        char buf[10];
+        const char *inptr = input;
+        size_t inbytesleft = strlen (input);
+        char *outptr = buf;
+        size_t outbytesleft = sizeof (buf);
+        size_t res = iconv (cd_utf8_to_88591,
+                            (char **) &inptr, &inbytesleft,
+                            &outptr, &outbytesleft);
+        if (res == 0)
+          return 1;
+      }
+  }
+#if 0 /* This bug could be worked around by the caller.  */
+  /* Test against HP-UX 11.11 bug: Positive return value instead of 0.  */
+  {
+    iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
+    if (cd_88591_to_utf8 != (iconv_t)(-1))
+      {
+        static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
+        char buf[50];
+        const char *inptr = input;
+        size_t inbytesleft = strlen (input);
+        char *outptr = buf;
+        size_t outbytesleft = sizeof (buf);
+        size_t res = iconv (cd_88591_to_utf8,
+                            (char **) &inptr, &inbytesleft,
+                            &outptr, &outbytesleft);
+        if ((int)res > 0)
+          return 1;
+      }
+  }
+#endif
+  /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
+     provided.  */
+  if (/* Try standardized names.  */
+      iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
+      /* Try IRIX, OSF/1 names.  */
+      && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
+      /* Try AIX names.  */
+      && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
+      /* Try HP-UX names.  */
+      && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
+    return 1;
+  return 0;
+}], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
+        [case "$host_os" in
+           aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
+           *)            am_cv_func_iconv_works="guessing yes" ;;
+         esac])
+      LIBS="$am_save_LIBS"
+    ])
+    case "$am_cv_func_iconv_works" in
+      *no) am_func_iconv=no am_cv_lib_iconv=no ;;
+      *)   am_func_iconv=yes ;;
+    esac
+  else
+    am_func_iconv=no am_cv_lib_iconv=no
+  fi
+  if test "$am_func_iconv" = yes; then
+    AC_DEFINE(HAVE_ICONV, 1,
+      [Define if you have the iconv() function and it works.])
+  fi
+  if test "$am_cv_lib_iconv" = yes; then
+    AC_MSG_CHECKING([how to link with libiconv])
+    AC_MSG_RESULT([$LIBICONV])
+  else
+    dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
+    dnl either.
+    CPPFLAGS="$am_save_CPPFLAGS"
+    LIBICONV=
+    LTLIBICONV=
+  fi
+  AC_SUBST(LIBICONV)
+  AC_SUBST(LTLIBICONV)
+])
+
+AC_DEFUN([AM_ICONV],
+[
+  AM_ICONV_LINK
+  if test "$am_cv_func_iconv" = yes; then
+    AC_MSG_CHECKING([for iconv declaration])
+    AC_CACHE_VAL(am_cv_proto_iconv, [
+      AC_TRY_COMPILE([
+#include <stdlib.h>
+#include <iconv.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+#if defined(__STDC__) || defined(__cplusplus)
+size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
+#else
+size_t iconv();
+#endif
+], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
+      am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
+    am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
+    AC_MSG_RESULT([$]{ac_t:-
+         }[$]am_cv_proto_iconv)
+    AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
+      [Define as const if the declaration of iconv() needs const.])
+  fi
+])
commit a0cffb8b69e0595a2afe15ecc4928e0df1eeb063
Author: Pino Toscano <pino at kde.org>
Date:   Wed Dec 30 18:57:09 2009 +0100

    [cpp] fixup unicode GooString <-> ustring conversions
    
    better make them use the "hand-made" code, it is more correct for them

diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp
index 1ba3433..51d557c 100644
--- a/cpp/poppler-private.cpp
+++ b/cpp/poppler-private.cpp
@@ -47,7 +47,37 @@ rectf detail::pdfrectangle_to_rectf(const PDFRectangle &pdfrect)
 
 ustring detail::unicode_GooString_to_ustring(GooString *str)
 {
-    return ustring::from_utf_8(str->getCString(), str->getLength());
+    const char *data = str->getCString();
+    const int len = str->getLength();
+
+    int i = 0;
+    bool is_unicode = false;
+    if ((data[0] & 0xff) == 0xfe && (len > 1 && (data[1] & 0xff) == 0xff)) {
+        is_unicode = true;
+        i = 2;
+    }
+    ustring::size_type ret_len = len - i;
+    if (is_unicode) {
+        ret_len >>= 1;
+    }
+    ustring ret(ret_len, 0);
+    size_t ret_index = 0;
+    ustring::value_type u;
+    if (is_unicode) {
+        while (i < len) {
+            u = ((data[i] & 0xff) << 8) | (data[i + 1] & 0xff);
+            i += 2;
+            ret[ret_index++] = u;
+        }
+    } else {
+        while (i < len) {
+            u = data[i] & 0xff;
+            ++i;
+            ret[ret_index++] = u;
+        }
+    }
+
+    return ret;
 }
 
 ustring detail::unicode_to_ustring(const Unicode *u, int length)
@@ -63,7 +93,15 @@ ustring detail::unicode_to_ustring(const Unicode *u, int length)
 
 GooString* detail::ustring_to_unicode_GooString(const ustring &str)
 {
-    const byte_array utf8_data = str.to_utf_8();
-    GooString *goo = new GooString(&utf8_data[0]);
+    const size_t len = str.size() * 2 + 2;
+    const ustring::value_type *me = str.data();
+    byte_array ba(len);
+    ba[0] = 0xfe;
+    ba[1] = 0xff;
+    for (size_t i = 0; i < str.size(); ++i, ++me) {
+        ba[i * 2 + 2] = ((*me >> 8) & 0xff);
+        ba[i * 2 + 3] = (*me & 0xff);
+    }
+    GooString *goo = new GooString(&ba[0]);
     return goo;
 }
commit 283dd326a00c804b6332ee3ca1aaa0d86377b3f3
Author: Pino Toscano <pino at kde.org>
Date:   Sat Dec 19 12:50:10 2009 +0100

    [cpp] fix installation of poppler-version.h with autotools and builddir != srcdir

diff --git a/cpp/Makefile.am b/cpp/Makefile.am
index 8890f83..4fb1874 100644
--- a/cpp/Makefile.am
+++ b/cpp/Makefile.am
@@ -15,7 +15,7 @@ poppler_include_HEADERS =			\
 	poppler-page-transition.h		\
 	poppler-rectangle.h			\
 	poppler-toc.h				\
-	poppler-version.h
+	$(builddir)/poppler-version.h
 
 lib_LTLIBRARIES = libpoppler-cpp.la
 libpoppler_cpp_la_SOURCES =			\


More information about the poppler mailing list