diff options
author | Pino Toscano <pino@kde.org> | 2010-02-21 19:56:38 +0100 |
---|---|---|
committer | Pino Toscano <pino@kde.org> | 2010-02-21 19:56:38 +0100 |
commit | a18dab9e53a20a76eb46fa3a868fffdd3c754ce2 (patch) | |
tree | eb468aa272122f67b6e49dba955f8dcef03d3bed | |
parent | fa0989297e95b6adebed71336ea206d1b279ab24 (diff) | |
parent | f3862f7d987aae52a1fd2bb0af27d1cd803a5b84 (diff) |
Merge remote branch 'origin/cpp-frontend'
* origin/cpp-frontend: (34 commits)
[cpp/tests] poppler-dump: show a string for the font type
[cpp/tests] poppler-dump: show the orientation of the pages
[cpp/tests] poppler-dump: a bit less output in permissions lines
[cpp/tests] poppler-dump: add --show-all to show all the information
[cpp] use iconv for the utf8 <-> utf16 conversions
[cpp] add the build system stuff for iconv, mandatory for cpp
[cpp] fixup unicode GooString <-> ustring conversions
[cpp] fix installation of poppler-version.h with autotools and builddir != srcdir
simplify
[cpp/tests] add a simple poppler-dump test
[cpp] use the correct index (instead of an uninitialized variable)
[cpp] properly delete the children of a toc item
[cpp] actually implement toc::root()
[cpp] fix the reference to the vector data
[cpp] fix the reference to the vector data
[cpp] add destructor for 'rectangle'
[cpp] add out stream operators for rect and rectf
[cpp] add namespace to namespace functiond to link properly
[cpp] add default empty parameters for the passwords of the document loading functions
[cpp] add "human friendly" output representation for byte_array
...
Conflicts:
config.h.cmake
40 files changed, 3151 insertions, 4 deletions
@@ -16,6 +16,7 @@ libtool ltmain.sh missing poppler-cairo.pc +poppler-cpp.pc poppler-glib.pc poppler-qt.pc poppler-qt4.pc diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e9811ea..a2f45a5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ option(BUILD_QT3_TESTS "Whether compile the Qt3 test programs." ON) option(BUILD_QT4_TESTS "Whether compile the Qt4 test programs." ON) option(ENABLE_SPLASH "Build the Splash graphics backend." ON) option(ENABLE_UTILS "Compile poppler command line utils." ON) +option(ENABLE_CPP "Compile poppler cpp wrapper." ON) option(ENABLE_ABIWORD "Build the Abiword backend." ON) option(ENABLE_LIBOPENJPEG "Use libopenjpeg for JPX streams." ON) option(ENABLE_LCMS "Use liblcms for color management." ON) @@ -75,6 +76,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) @@ -444,6 +451,9 @@ add_subdirectory(test) if(QT4_FOUND) add_subdirectory(qt4) endif(QT4_FOUND) +if(ENABLE_CPP) + add_subdirectory(cpp) +endif(ENABLE_CPP) set(PKG_CONFIG_VERSION_0_18 TRUE) if(PKGCONFIG_EXECUTABLE) @@ -474,6 +484,9 @@ endif(GLIB_FOUND) if(CAIRO_FOUND) poppler_create_install_pkgconfig(poppler-cairo.pc lib${LIB_SUFFIX}/pkgconfig) endif(CAIRO_FOUND) +if(ENABLE_CPP) + poppler_create_install_pkgconfig(poppler-cpp.pc lib${LIB_SUFFIX}/pkgconfig) +endif(ENABLE_CPP) message("Building Poppler with support for:") @@ -484,6 +497,7 @@ show_end_message("qt wrapper" QT3_FOUND) 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("cpp wrapper" ENABLE_CPP) show_end_message("use libjpeg" ENABLE_LIBJPEG) show_end_message("use libpng" ENABLE_LIBPNG) show_end_message("use zlib" ENABLE_ZLIB) diff --git a/Makefile.am b/Makefile.am index 2a752622..aedf60f4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,18 +25,24 @@ qt4_subdir = qt4 qt4_pc_file = poppler-qt4.pc endif +if BUILD_POPPLER_CPP +cpp_subdir = cpp +cpp_pc_file = poppler-cpp.pc +endif + if BUILD_UTILS utils_subdir = utils endif -SUBDIRS = goo fofi $(splash_subdir) poppler $(utils_subdir) $(glib_subdir) $(qt_subdir) test $(qt4_subdir) +SUBDIRS = goo fofi $(splash_subdir) poppler $(utils_subdir) $(glib_subdir) $(qt_subdir) test $(qt4_subdir) $(cpp_subdir) EXTRA_DIST = \ README-XPDF \ poppler.pc.in \ poppler-cairo.pc.in \ poppler-splash.pc.in \ - poppler-qt.pc.in + poppler-qt.pc.in \ + poppler-cpp.pc.in pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = \ @@ -45,10 +51,12 @@ pkgconfig_DATA = \ $(splash_pc_file) \ $(glib_pc_file) \ $(qt_pc_file) \ - $(qt4_pc_file) + $(qt4_pc_file) \ + $(cpp_pc_file) # Add CMake buildsystem files here so they get added on make dist EXTRA_DIST += \ + cpp/CMakeLists.txt \ glib/demo/CMakeLists.txt \ glib/CMakeLists.txt \ glib/poppler-features.h.cmake \ @@ -65,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 \ @@ -78,6 +87,7 @@ EXTRA_DIST += \ config.h.cmake \ poppler-cairo.pc.cmake \ poppler-config.h.cmake \ + poppler-cpp.pc.cmake \ poppler-glib.pc.cmake \ poppler-qt.pc.cmake \ poppler-qt4.pc.cmake \ diff --git a/cmake/modules/FindIconv.cmake b/cmake/modules/FindIconv.cmake new file mode 100644 index 00000000..ce40ab26 --- /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 0097d8d5..ec120455 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -49,6 +49,9 @@ /* Defines if gmtime_r is available on your system */ #cmakedefine HAVE_GMTIME_R 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 @@ -120,6 +123,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 + /* Enable multithreading support. */ #cmakedefine MULTITHREADED 1 diff --git a/configure.ac b/configure.ac index b8fb411c..5d497c37 100644 --- a/configure.ac +++ b/configure.ac @@ -520,6 +520,25 @@ fi AM_CONDITIONAL(BUILD_POPPLER_QT4, test "x$enable_poppler_qt4" = "xyes") +dnl +dnl CPP frontend +dnl + +AC_ARG_ENABLE(poppler-cpp, + AC_HELP_STRING([--disable-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") + + AC_ARG_ENABLE(gtk-test, AC_HELP_STRING([--disable-gtk-test], [Don't compile GTK+ test program.]), @@ -610,6 +629,7 @@ AC_SUBST(PC_REQUIRES_PRIVATE) AC_SUBST([POPPLER_MAJOR_VERSION],[poppler_version_major]) AC_SUBST([POPPLER_MINOR_VERSION],[poppler_version_minor]) AC_SUBST([POPPLER_MICRO_VERSION],[poppler_version_micro]) +AC_SUBST([POPPLER_VERSION],[poppler_version]) AC_OUTPUT([ Makefile @@ -628,12 +648,16 @@ qt4/Makefile qt4/src/Makefile qt4/tests/Makefile qt4/demos/Makefile +cpp/Makefile +cpp/poppler-version.h +cpp/tests/Makefile poppler.pc poppler-cairo.pc poppler-splash.pc poppler-glib.pc poppler-qt.pc -poppler-qt4.pc]) +poppler-qt4.pc +poppler-cpp.pc]) echo "" @@ -646,6 +670,7 @@ echo " qt wrapper: $enable_poppler_qt" echo " qt4 wrapper: $enable_poppler_qt4" echo " glib wrapper: $enable_poppler_glib" echo " use GDK: $enable_gdk" +echo " cpp wrapper: $enable_poppler_cpp" echo " use gtk-doc: $enable_gtk_doc" echo " use libjpeg: $enable_libjpeg" echo " use libpng: $enable_libpng" diff --git a/cpp/.gitignore b/cpp/.gitignore new file mode 100644 index 00000000..0556b924 --- /dev/null +++ b/cpp/.gitignore @@ -0,0 +1,7 @@ +.deps +.libs +*.la +*.lo +Makefile +Makefile.in +poppler-version.h diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt new file mode 100644 index 00000000..4c1d7c47 --- /dev/null +++ b/cpp/CMakeLists.txt @@ -0,0 +1,42 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) + +configure_file(poppler-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/poppler-version.h @ONLY) + +add_subdirectory(tests) + +set(poppler_cpp_SRCS + poppler-document.cpp + poppler-embedded-file.cpp + poppler-font.cpp + poppler-global.cpp + poppler-page.cpp + poppler-page-transition.cpp + poppler-private.cpp + poppler-rectangle.cpp + poppler-toc.cpp + poppler-version.cpp +) + +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 ${ICONV_LIBRARIES}) +if(MSVC) +target_link_libraries(poppler-cpp ${poppler_LIBS}) +endif(MSVC) +install(TARGETS poppler-cpp RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LIB_SUFFIX} ARCHIVE DESTINATION lib${LIB_SUFFIX}) + +install(FILES + poppler-document.h + poppler-embedded-file.h + poppler-font.h + poppler-global.h + poppler-page.h + poppler-page-transition.h + poppler-rectangle.h + poppler-toc.h + ${CMAKE_CURRENT_BINARY_DIR}/poppler-version.h + DESTINATION include/poppler/cpp) + diff --git a/cpp/Makefile.am b/cpp/Makefile.am new file mode 100644 index 00000000..2e3f56d6 --- /dev/null +++ b/cpp/Makefile.am @@ -0,0 +1,37 @@ +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/goo \ + -I$(top_srcdir)/poppler + +SUBDIRS = . tests + +poppler_includedir = $(includedir)/poppler/cpp +poppler_include_HEADERS = \ + poppler-document.h \ + poppler-embedded-file.h \ + poppler-font.h \ + poppler-global.h \ + poppler-page.h \ + poppler-page-transition.h \ + poppler-rectangle.h \ + poppler-toc.h \ + $(builddir)/poppler-version.h + +lib_LTLIBRARIES = libpoppler-cpp.la +libpoppler_cpp_la_SOURCES = \ + poppler-document.cpp \ + poppler-embedded-file.cpp \ + poppler-font.cpp \ + poppler-global.cpp \ + poppler-page.cpp \ + poppler-page-transition.cpp \ + poppler-private.cpp \ + poppler-rectangle.cpp \ + poppler-toc.cpp \ + poppler-version.cpp + +libpoppler_cpp_la_LIBADD = \ + $(top_builddir)/poppler/libpoppler.la \ + $(LIBICONV) + +libpoppler_cpp_la_LDFLAGS = -version-info 1:0:1 @create_shared_lib@ diff --git a/cpp/poppler-document-private.h b/cpp/poppler-document-private.h new file mode 100644 index 00000000..9820603b --- /dev/null +++ b/cpp/poppler-document-private.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_DOCUMENT_PRIVATE_H +#define POPPLER_DOCUMENT_PRIVATE_H + +#include "poppler-global.h" + +#include "poppler-config.h" +#include "GooString.h" +#include "PDFDoc.h" + +#include <vector> + +namespace poppler +{ + +class document; +class embedded_file; + +class document_private +{ +public: + document_private(GooString *file_path, const std::string &owner_password, + const std::string &user_password); + document_private(byte_array *file_data, const std::string &owner_password, + const std::string &user_password); + ~document_private(); + + static document* check_document(document_private *doc); + + PDFDoc *doc; + byte_array doc_data; + bool is_locked; + std::vector<embedded_file *> embedded_files; + +private: + void init(); + + static unsigned int count; +}; + +} + +#endif diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp new file mode 100644 index 00000000..ab3939b5 --- /dev/null +++ b/cpp/poppler-document.cpp @@ -0,0 +1,391 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-document.h" +#include "poppler-embedded-file.h" +#include "poppler-page.h" +#include "poppler-toc.h" + +#include "poppler-document-private.h" +#include "poppler-embedded-file-private.h" +#include "poppler-private.h" +#include "poppler-toc-private.h" + +#include "Catalog.h" +#include "ErrorCodes.h" +#include "GlobalParams.h" +#include "Outline.h" + +#include <algorithm> +#include <memory> + +using namespace poppler; + +unsigned int poppler::document_private::count = 0U; + +document_private::document_private(GooString *file_path, const std::string &owner_password, + const std::string &user_password) + : doc(0) + , is_locked(false) +{ + GooString goo_owner_password(owner_password.c_str()); + GooString goo_user_password(user_password.c_str()); + doc = new PDFDoc(file_path, &goo_owner_password, &goo_user_password); + init(); +} + +document_private::document_private(byte_array *file_data, + const std::string &owner_password, + const std::string &user_password) + : doc(0) + , is_locked(false) +{ + Object obj; + obj.initNull(); + file_data->swap(doc_data); + MemStream *memstr = new MemStream(&doc_data[0], 0, doc_data.size(), &obj); + GooString goo_owner_password(owner_password.c_str()); + GooString goo_user_password(user_password.c_str()); + doc = new PDFDoc(memstr, &goo_owner_password, &goo_user_password); + init(); +} + +document_private::~document_private() +{ + delete_all(embedded_files); + + delete doc; + + if (count > 0) { + --count; + if (!count) { + delete globalParams; + globalParams = 0; + } + } +} + +void document_private::init() +{ + if (!count) { + globalParams = new GlobalParams(); + setErrorFunction(detail::error_function); + } + count++; +} + +document* document_private::check_document(document_private *doc) +{ + if (doc->doc->isOk() || doc->doc->getErrorCode() == errEncrypted) { + if (doc->doc->getErrorCode() == errEncrypted) { + doc->is_locked = true; + } + return new document(*doc); + } else { + delete doc; + } + return 0; +} + + +document::document(document_private &dd) + : d(&dd) +{ +} + +document::~document() +{ + delete d; +} + +bool document::is_locked() const +{ + return d->is_locked; +} + +bool document::unlock(const std::string &owner_password, const std::string &user_password) +{ + if (d->is_locked) { + document_private *newdoc = 0; + if (d->doc_data.size() > 0) { + newdoc = new document_private(&d->doc_data, + owner_password, user_password); + } else { + newdoc = new document_private(new GooString(d->doc->getFileName()), + owner_password, user_password); + } + if (!newdoc->doc->isOk()) { + d->doc_data.swap(newdoc->doc_data); + delete newdoc; + } else { + delete d; + d = newdoc; + d->is_locked = false; + } + } + return d->is_locked; +} + +document::page_mode_enum document::page_mode() const +{ + switch (d->doc->getCatalog()->getPageMode()) { + case Catalog::pageModeNone: + return use_none; + case Catalog::pageModeOutlines: + return use_outlines; + case Catalog::pageModeThumbs: + return use_thumbs; + case Catalog::pageModeFullScreen: + return fullscreen; + case Catalog::pageModeOC: + return use_oc; + case Catalog::pageModeAttach: + return use_attach; + default: + return use_none; + } +} + +document::page_layout_enum document::page_layout() const +{ + switch (d->doc->getCatalog()->getPageLayout()) { + case Catalog::pageLayoutNone: + return no_layout; + case Catalog::pageLayoutSinglePage: + return single_page; + case Catalog::pageLayoutOneColumn: + return one_column; + case Catalog::pageLayoutTwoColumnLeft: + return two_column_left; + case Catalog::pageLayoutTwoColumnRight: + return two_column_right; + case Catalog::pageLayoutTwoPageLeft: + return two_page_left; + case Catalog::pageLayoutTwoPageRight: + return two_page_right; + default: + return no_layout; + } +} + +void document::get_pdf_version(int *major, int *minor) const +{ + if (major) { + *major = d->doc->getPDFMajorVersion(); + } + if (minor) { + *minor = d->doc->getPDFMinorVersion(); + } +} + +std::vector<std::string> document::info_keys() const +{ + if (d->is_locked) { + return std::vector<std::string>(); + } + + Object info; + if (!d->doc->getDocInfo(&info)->isDict()) { + info.free(); + return std::vector<std::string>(); + } + + Dict *info_dict = info.getDict(); + std::vector<std::string> keys(info_dict->getLength()); + for (int i = 0; i < info_dict->getLength(); ++i) { + keys[i] = std::string(info_dict->getKey(i)); + } + + info.free(); + return keys; +} + +ustring document::info_key(const std::string &key) const +{ + if (d->is_locked) { + return ustring(); + } + + Object info; + if (!d->doc->getDocInfo(&info)->isDict()) { + info.free(); + return ustring(); + } + + Dict *info_dict = info.getDict(); + Object obj; + ustring result; + if (info_dict->lookup(PSTR(key.c_str()), &obj)->isString()) { + result = detail::unicode_GooString_to_ustring(obj.getString()); + } + obj.free(); + info.free(); + return result; +} + +unsigned int document::info_date(const std::string &key) const +{ + if (d->is_locked) { + return (unsigned int)(-1); + } + + Object info; + if (!d->doc->getDocInfo(&info)->isDict()) { + info.free(); + return (unsigned int)(-1); + } + + Dict *info_dict = info.getDict(); + Object obj; + unsigned int result = (unsigned int)(-1); + if (info_dict->lookup(PSTR(key.c_str()), &obj)->isString()) { + result = convert_date(obj.getString()->getCString()); + } + obj.free(); + info.free(); + return result; +} + +bool document::is_encrypted() const +{ + return d->doc->isEncrypted(); +} + +bool document::is_linearized() const +{ + return d->doc->isLinearized(); +} + +bool document::has_permission(permission_enum which) const +{ + switch (which) { + case perm_print: + return d->doc->okToPrint(); + case perm_change: + return d->doc->okToChange(); + case perm_copy: + return d->doc->okToCopy(); + case perm_add_notes: + return d->doc->okToAddNotes(); + case perm_fill_forms: + return d->doc->okToFillForm(); + case perm_accessibility: + return d->doc->okToAccessibility(); + case perm_assemble: + return d->doc->okToAssemble(); + case perm_print_high_resolution: + return d->doc->okToPrintHighRes(); + } + return true; +} + +ustring document::metadata() const +{ + std::auto_ptr<GooString> md(d->doc->getCatalog()->readMetadata()); + if (md.get()) { + return detail::unicode_GooString_to_ustring(md.get()); + } + return ustring(); +} + +int document::pages() const +{ + return d->doc->getNumPages(); +} + +page* document::create_page(const ustring &label) const +{ + std::auto_ptr<GooString> goolabel(detail::ustring_to_unicode_GooString(label)); + int index = 0; + + if (!d->doc->getCatalog()->labelToIndex(goolabel.get(), &index)) { + return 0; + } + return create_page(index); +} + +page* document::create_page(int index) const +{ + return index >= 0 && index < d->doc->getNumPages() ? new page(d, index) : 0; +} + +std::vector<font_info> document::fonts() const +{ + std::vector<font_info> result; + font_iterator it(0, d); + while (it.has_next()) { + const std::vector<font_info> l = it.next(); + std::copy(l.begin(), l.end(), std::back_inserter(result)); + } + return result; +} + +font_iterator* document::create_font_iterator(int start_page) const +{ + return new font_iterator(start_page, d); +} + +toc* document::create_toc() const +{ + return toc_private::load_from_outline(d->doc->getOutline()); +} + +bool document::has_embedded_files() const +{ + return d->doc->getCatalog()->numEmbeddedFiles() > 0; +} + +std::vector<embedded_file *> document::embedded_files() const +{ + if (d->is_locked) { + return std::vector<embedded_file *>(); + } + + if (d->embedded_files.empty() && d->doc->getCatalog()->numEmbeddedFiles() > 0) { + const int num = d->doc->getCatalog()->numEmbeddedFiles(); + d->embedded_files.resize(num); + for (int i = 0; i < num; ++i) { + EmbFile *ef = d->doc->getCatalog()->embeddedFile(i); + d->embedded_files[i] = embedded_file_private::create(ef); + } + } + return d->embedded_files; +} + +document* document::load_from_file(const std::string &file_name, + const std::string &owner_password, + const std::string &user_password) +{ + document_private *doc = new document_private( + new GooString(file_name.c_str()), + owner_password, user_password); + return document_private::check_document(doc); +} + +document* document::load_from_data(byte_array *file_data, + const std::string &owner_password, + const std::string &user_password) +{ + if (!file_data || file_data->size() < 10) { + return 0; + } + + document_private *doc = new document_private( + file_data, owner_password, user_password); + return document_private::check_document(doc); +} diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h new file mode 100644 index 00000000..5d394bb4 --- /dev/null +++ b/cpp/poppler-document.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_DOCUMENT_H +#define POPPLER_DOCUMENT_H + +#include "poppler-global.h" +#include "poppler-font.h" + +namespace poppler +{ + +class document_private; +class embedded_file; +class page; +class toc; + +class POPPLER_CPP_EXPORT document : public poppler::noncopyable +{ +public: + enum page_mode_enum { + use_none, + use_outlines, + use_thumbs, + fullscreen, + use_oc, + use_attach + }; + + enum page_layout_enum { + no_layout, + single_page, + one_column, + two_column_left, + two_column_right, + two_page_left, + two_page_right + }; + + ~document(); + + bool is_locked() const; + bool unlock(const std::string &owner_password, const std::string &user_password); + + page_mode_enum page_mode() const; + page_layout_enum page_layout() const; + void get_pdf_version(int *major, int *minor) const; + std::vector<std::string> info_keys() const; + ustring info_key(const std::string &key) const; + unsigned int /*time_t*/ info_date(const std::string &key) const; + bool is_encrypted() const; + bool is_linearized() const; + bool has_permission(permission_enum which) const; + ustring metadata() const; + + int pages() const; + page* create_page(const ustring &label) const; + page* create_page(int index) const; + + std::vector<font_info> fonts() const; + font_iterator* create_font_iterator(int start_page = 0) const; + + toc* create_toc() const; + + bool has_embedded_files() const; + std::vector<embedded_file *> embedded_files() const; + + static document* load_from_file(const std::string &file_name, + const std::string &owner_password = std::string(), + const std::string &user_password = std::string()); + static document* load_from_data(byte_array *file_data, + const std::string &owner_password = std::string(), + const std::string &user_password = std::string()); + +private: + document(document_private &dd); + + document_private *d; + friend class document_private; +}; + +} + +#endif diff --git a/cpp/poppler-embedded-file-private.h b/cpp/poppler-embedded-file-private.h new file mode 100644 index 00000000..2acea65d --- /dev/null +++ b/cpp/poppler-embedded-file-private.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_EMBEDDED_FILE_PRIVATE_H +#define POPPLER_EMBEDDED_FILE_PRIVATE_H + +class EmbFile; + +namespace poppler +{ + +class embedded_file_private +{ +public: + embedded_file_private(EmbFile *ef); + ~embedded_file_private(); + + static embedded_file* create(EmbFile *ef); + + EmbFile *emb_file; +}; + +} + +#endif diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp new file mode 100644 index 00000000..6dfe321a --- /dev/null +++ b/cpp/poppler-embedded-file.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-embedded-file.h" + +#include "poppler-embedded-file-private.h" +#include "poppler-private.h" + +#include "Object.h" +#include "Stream.h" +#include "Catalog.h" + +using namespace poppler; + +embedded_file_private::embedded_file_private(EmbFile *ef) + : emb_file(ef) +{ +} + +embedded_file_private::~embedded_file_private() +{ + delete emb_file; +} + +embedded_file* embedded_file_private::create(EmbFile *ef) +{ + return new embedded_file(*new embedded_file_private(ef)); +} + + +embedded_file::embedded_file(embedded_file_private &dd) + : d(&dd) +{ +} + +embedded_file::~embedded_file() +{ + delete d; +} + +bool embedded_file::is_valid() const +{ + return d->emb_file->isOk(); +} + +std::string embedded_file::name() const +{ + return std::string(d->emb_file->name()->getCString()); +} + +ustring embedded_file::description() const +{ + return detail::unicode_GooString_to_ustring(d->emb_file->description()); +} + +int embedded_file::size() const +{ + return d->emb_file->size(); +} + +unsigned int embedded_file::modification_date() const +{ + return convert_date(d->emb_file->modDate()->getCString()); +} + +unsigned int embedded_file::creation_date() const +{ + return convert_date(d->emb_file->createDate()->getCString()); +} + +std::string embedded_file::checksum() const +{ + return std::string(d->emb_file->checksum()->getCString()); +} + +std::string embedded_file::mime_type() const +{ + return std::string(d->emb_file->mimeType()->getCString()); +} + +byte_array embedded_file::data() const +{ + if (!is_valid()) { + return byte_array(); + } + + Stream *stream = d->emb_file->streamObject().getStream(); + stream->reset(); + byte_array ret(1024); + size_t data_len = 0; + int i; + while ((i = stream->getChar()) != EOF) { + if (data_len == ret.size()) { + ret.resize(ret.size() * 2); + } + ret[data_len] = (char)i; + ++data_len; + } + ret.resize(data_len); + return ret; +} diff --git a/cpp/poppler-embedded-file.h b/cpp/poppler-embedded-file.h new file mode 100644 index 00000000..04ad7be6 --- /dev/null +++ b/cpp/poppler-embedded-file.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_EMBEDDED_FILE_H +#define POPPLER_EMBEDDED_FILE_H + +#include "poppler-global.h" + +#include <vector> + +namespace poppler +{ + +class embedded_file_private; + +class POPPLER_CPP_EXPORT embedded_file : public poppler::noncopyable +{ +public: + ~embedded_file(); + + bool is_valid() const; + std::string name() const; + ustring description() const; + int size() const; + unsigned int /*time_t*/ modification_date() const; + unsigned int /*time_t*/ creation_date() const; + std::string checksum() const; + std::string mime_type() const; + byte_array data() const; + +private: + embedded_file(embedded_file_private &dd); + + embedded_file_private *d; + friend class embedded_file_private; +}; + +} + +#endif diff --git a/cpp/poppler-font.cpp b/cpp/poppler-font.cpp new file mode 100644 index 00000000..5c3221bf --- /dev/null +++ b/cpp/poppler-font.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-font.h" + +#include "poppler-document-private.h" + +#include "FontInfo.h" + +using namespace poppler; + +class poppler::font_info_private +{ +public: + font_info_private() + : type(font_info::unknown) + , is_embedded(false) + , is_subset(false) + { + } + font_info_private(FontInfo *fi) + : type((font_info::type_enum)fi->getType()) + , is_embedded(fi->getEmbedded()) + , is_subset(fi->getSubset()) + , emb_ref(fi->getEmbRef()) + { + if (fi->getName()) { + font_name = fi->getName()->getCString(); + } + if (fi->getFile()) { + font_file = fi->getFile()->getCString(); + } + } + + std::string font_name; + std::string font_file; + font_info::type_enum type : 5; + bool is_embedded : 1; + bool is_subset : 1; + Ref emb_ref; +}; + + +class poppler::font_iterator_private +{ +public: + font_iterator_private(int start_page, document_private *dd) + : font_info_scanner(dd->doc, start_page) + , total_pages(dd->doc->getNumPages()) + , current_page((std::max)(start_page, 0) - 1) + { + } + ~font_iterator_private() + { + } + + FontInfoScanner font_info_scanner; + int total_pages; + int current_page; +}; + + +font_info::font_info() + : d(new font_info_private()) +{ +} + +font_info::font_info(font_info_private &dd) + : d(&dd) +{ +} + +font_info::font_info(const font_info &fi) + : d(new font_info_private(*fi.d)) +{ +} + +font_info::~font_info() +{ + delete d; +} + +std::string font_info::name() const +{ + return d->font_name; +} + +std::string font_info::file() const +{ + return d->font_file; +} + +bool font_info::is_embedded() const +{ + return d->is_embedded; +} + +bool font_info::is_subset() const +{ + return d->is_subset; +} + +font_info::type_enum font_info::type() const +{ + return d->type; +} + +font_info& font_info::operator=(const font_info &fi) +{ + if (this != &fi) { + *d = *fi.d; + } + return *this; +} + + +font_iterator::font_iterator(int start_page, document_private *dd) + : d(new font_iterator_private(start_page, dd)) +{ +} + +font_iterator::~font_iterator() +{ + delete d; +} + +std::vector<font_info> font_iterator::next() +{ + ++d->current_page; + + GooList *items = d->font_info_scanner.scan(1); + if (!items) { + return std::vector<font_info>(); + } + std::vector<font_info> fonts(items->getLength()); + for (int i = 0; i < items->getLength(); ++i) { + fonts[i] = font_info(*new font_info_private((FontInfo *)items->get(i))); + } + deleteGooList(items, FontInfo); + return fonts; +} + +bool font_iterator::has_next() const +{ + return (d->current_page + 1) < d->total_pages; +} + +int font_iterator::current_page() const +{ + return d->current_page; +} diff --git a/cpp/poppler-font.h b/cpp/poppler-font.h new file mode 100644 index 00000000..854b7a40 --- /dev/null +++ b/cpp/poppler-font.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_FONT_H +#define POPPLER_FONT_H + +#include "poppler-global.h" + +#include <vector> + +namespace poppler +{ + +class document; +class document_private; +class font_info_private; +class font_iterator; +class font_iterator_private; + +class POPPLER_CPP_EXPORT font_info +{ +public: + enum type_enum { + unknown, + type1, + type1c, + type1c_ot, + type3, + truetype, + truetype_ot, + cid_type0, + cid_type0c, + cid_type0c_ot, + cid_truetype, + cid_truetype_ot + }; + + font_info(); + font_info(const font_info &fi); + ~font_info(); + + std::string name() const; + std::string file() const; + bool is_embedded() const; + bool is_subset() const; + type_enum type() const; + + font_info& operator=(const font_info &fi); + +private: + font_info(font_info_private &dd); + + font_info_private *d; + friend class font_iterator; +}; + + +class POPPLER_CPP_EXPORT font_iterator : public poppler::noncopyable +{ +public: + ~font_iterator(); + + std::vector<font_info> next(); + bool has_next() const; + int current_page() const; + +private: + font_iterator(int, document_private *dd); + + font_iterator_private *d; + friend class document; +}; + +} + +#endif diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp new file mode 100644 index 00000000..deae74b8 --- /dev/null +++ b/cpp/poppler-global.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-global.h" + +#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() +{ +} + +noncopyable::~noncopyable() +{ +} + + +ustring::ustring() +{ +} + +ustring::ustring(size_type len, value_type ch) + : std::basic_string<value_type>(len, ch) +{ +} + +ustring::~ustring() +{ +} + +byte_array ustring::to_utf_8() const +{ + if (!size()) { + return byte_array(); + } + + 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; +} + +std::string ustring::to_latin1() const +{ + if (!size()) { + return std::string(); + } + + const size_type mylength = size(); + std::string ret(mylength, '\0'); + const value_type *me = data(); + for (size_type i = 0; i < mylength; ++i) { + ret[i] = (char)*me++; + } + return ret; +} + +ustring ustring::from_utf_8(const char *str, int len) +{ + if (len <= 0) { + len = std::strlen(str); + if (len <= 0) { + return ustring(); + } + } + + MiniIconv ic("UTF-16", "UTF-8"); + if (!ic.is_valid()) { + return ustring(); + } + + 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; +} + +ustring ustring::from_latin1(const std::string &str) +{ + const size_type l = str.size(); + if (!l) { + return ustring(); + } + const char *c = str.data(); + ustring ret(l, 0); + for (size_type i = 0; i < l; ++i) { + ret[i] = *c++; + } + return ret; +} + + +unsigned int poppler::convert_date(const std::string &date) +{ + int year, mon, day, hour, min, sec, tzHours, tzMins; + char tz; + + if (!parseDateString(date.c_str(), &year, &mon, &day, &hour, &min, &sec, + &tz, &tzHours, &tzMins)) { + return (unsigned int)(-1); + } + + struct tm time; + time.tm_sec = sec; + time.tm_min = min; + time.tm_hour = hour; + time.tm_mday = day; + time.tm_mon = mon - 1; + time.tm_year = year - 1900; + time.tm_wday = -1; + time.tm_yday = -1; + time.tm_isdst = -1; + return mktime(&time); +} + +std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array) +{ + stream << "["; + const std::ios_base::fmtflags f = stream.flags(); + std::hex(stream); + const char *data = &array[0]; + const byte_array::size_type out_len = std::min<byte_array::size_type>(array.size(), 50); + for (byte_array::size_type i = 0; i < out_len; ++i) + { + if (i != 0) { + stream << " "; + } + stream << ((data[i] & 0xf0) >> 4) << (data[i] & 0xf); + } + stream.flags(f); + if (out_len < array.size()) { + stream << " ..."; + } + stream << "]"; + return stream; +} diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h new file mode 100644 index 00000000..4b08e8dd --- /dev/null +++ b/cpp/poppler-global.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_GLOBAL_H +#define POPPLER_GLOBAL_H + +#if defined(_WIN32) +# define LIB_EXPORT __declspec(dllexport) +# define LIB_IMPORT __declspec(dllimport) +#else +# define LIB_EXPORT +# define LIB_IMPORT +#endif + +#if defined(poppler_cpp_EXPORTS) +# define POPPLER_CPP_EXPORT LIB_EXPORT +#else +# define POPPLER_CPP_EXPORT LIB_IMPORT +#endif + +#include <iosfwd> +#include <string> +#include <vector> + +namespace poppler +{ + +namespace detail +{ + +class POPPLER_CPP_EXPORT noncopyable +{ +protected: + noncopyable(); + ~noncopyable(); +private: + noncopyable(const noncopyable &); + const noncopyable& operator=(const noncopyable &); +}; + +} + +typedef detail::noncopyable noncopyable; + +enum rotation_enum { rotate_0, rotate_90, rotate_180, rotate_270 }; + +enum page_box_enum { media_box, crop_box, bleed_box, trim_box, art_box }; + +enum permission_enum { perm_print, perm_change, perm_copy, perm_add_notes, + perm_fill_forms, perm_accessibility, perm_assemble, + perm_print_high_resolution }; + +typedef std::vector<char> byte_array; + +class POPPLER_CPP_EXPORT ustring : public std::basic_string<unsigned short> +{ +public: + ustring(); + ustring(size_type len, value_type ch); + ~ustring(); + + byte_array to_utf_8() const; + std::string to_latin1() const; + + static ustring from_utf_8(const char *str, int len = -1); + static ustring from_latin1(const std::string &str); + +private: + // forbid implicit std::string conversions + ustring(const std::string &); + operator std::string() const; + ustring& operator=(const std::string &); +}; + +POPPLER_CPP_EXPORT unsigned int /*time_t*/ convert_date(const std::string &date); + +POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const byte_array &array); + +} + +#endif diff --git a/cpp/poppler-page-private.h b/cpp/poppler-page-private.h new file mode 100644 index 00000000..654478b9 --- /dev/null +++ b/cpp/poppler-page-private.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_PAGE_PRIVATE_H +#define POPPLER_PAGE_PRIVATE_H + +class Page; + +namespace poppler +{ + +class document_private; +class page_transition; + +class page_private +{ +public: + page_private(document_private *doc, int index); + ~page_private(); + + document_private *doc; + Page *page; + int index; + page_transition *transition; +}; + +} + +#endif diff --git a/cpp/poppler-page-transition.cpp b/cpp/poppler-page-transition.cpp new file mode 100644 index 00000000..92ae4fc3 --- /dev/null +++ b/cpp/poppler-page-transition.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-page-transition.h" + +#include "PageTransition.h" + +using namespace poppler; + +class poppler::page_transition_private +{ +public: + page_transition_private(Object *trans) + : pt(trans) + { + } + + PageTransition pt; +}; + + +page_transition::page_transition(Object *params) + : d(new page_transition_private(params)) +{ +} + +page_transition::page_transition(const page_transition &pt) + : d(new page_transition_private(*pt.d)) +{ +} + +page_transition::~page_transition() +{ + delete d; +} + +page_transition::type_enum page_transition::type() const +{ + return (page_transition::type_enum)d->pt.getType(); +} + +int page_transition::duration() const +{ + return d->pt.getDuration(); +} + +page_transition::alignment_enum page_transition::alignment() const +{ + return (page_transition::alignment_enum)d->pt.getAlignment(); +} + +page_transition::direction_enum page_transition::direction() const +{ + return (page_transition::direction_enum)d->pt.getDirection(); +} + +int page_transition::angle() const +{ + return d->pt.getAngle(); +} + +double page_transition::scale() const +{ + return d->pt.getScale(); +} + +bool page_transition::is_rectangular() const +{ + return d->pt.isRectangular(); +} + +page_transition& page_transition::operator=(const page_transition &pt) +{ + if (&pt != this) { + page_transition_private *new_d = new page_transition_private(*pt.d); + delete d; + new_d = d; + } + return *this; +} diff --git a/cpp/poppler-page-transition.h b/cpp/poppler-page-transition.h new file mode 100644 index 00000000..4ecb179a --- /dev/null +++ b/cpp/poppler-page-transition.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_PAGE_TRANSITION_H +#define POPPLER_PAGE_TRANSITION_H + +#include "poppler-global.h" + +class Object; + +namespace poppler +{ + +class page; +class page_transition_private; + +class POPPLER_CPP_EXPORT page_transition +{ +public: + enum type_enum { + replace = 0, + split, + blinds, + box, + wipe, + dissolve, + glitter, + fly, + push, + cover, + uncover, + fade + }; + + enum alignment_enum { + horizontal = 0, + vertical + }; + + enum direction_enum { + inward = 0, + outward + }; + + page_transition(const page_transition &pt); + ~page_transition(); + + type_enum type() const; + int duration() const; + alignment_enum alignment() const; + direction_enum direction() const; + int angle() const; + double scale() const; + bool is_rectangular() const; + + page_transition& operator=(const page_transition &pt); + +private: + page_transition(Object *params); + + page_transition_private *d; + friend class page; +}; + +} + +#endif diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp new file mode 100644 index 00000000..c8ce706e --- /dev/null +++ b/cpp/poppler-page.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-page.h" +#include "poppler-page-transition.h" + +#include "poppler-document-private.h" +#include "poppler-page-private.h" +#include "poppler-private.h" + +using namespace poppler; + +page_private::page_private(document_private *_doc, int _index) + : doc(_doc) + , page(doc->doc->getCatalog()->getPage(_index + 1)) + , index(_index) + , transition(0) +{ +} + +page_private::~page_private() +{ + delete transition; +} + + +page::page(document_private *doc, int index) + : d(new page_private(doc, index)) +{ +} + +page::~page() +{ + delete d; +} + +page::orientation_enum page::orientation() const +{ + const int rotation = d->page->getRotate(); + switch (rotation) { + case 90: + return landscape; + break; + case 180: + return upside_down; + break; + case 270: + return seascape; + break; + default: + return portrait; + } +} + +double page::duration() const +{ + return d->page->getDuration(); +} + +rectf page::page_rect(page_box_enum box) const +{ + PDFRectangle *r = 0; + switch (box) { + case media_box: + r = d->page->getMediaBox(); + break; + case crop_box: + r = d->page->getCropBox(); + break; + case bleed_box: + r = d->page->getBleedBox(); + break; + case trim_box: + r = d->page->getTrimBox(); + break; + case art_box: + r = d->page->getArtBox(); + break; + } + if (r) { + return detail::pdfrectangle_to_rectf(*r); + } + return rectf(); +} + +ustring page::label() const +{ + GooString goo; + if (!d->doc->doc->getCatalog()->indexToLabel(d->index, &goo)) { + return ustring(); + } + + return detail::unicode_GooString_to_ustring(&goo); +} + +page_transition* page::transition() const +{ + if (!d->transition) { + Object o; + if (d->page->getTrans(&o)->isDict()) { + d->transition = new page_transition(&o); + } + o.free(); + } + return d->transition; +} diff --git a/cpp/poppler-page.h b/cpp/poppler-page.h new file mode 100644 index 00000000..65cea520 --- /dev/null +++ b/cpp/poppler-page.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_PAGE_H +#define POPPLER_PAGE_H + +#include "poppler-global.h" +#include "poppler-rectangle.h" + +namespace poppler +{ + +class document; +class document_private; +class page_private; +class page_transition; + +class POPPLER_CPP_EXPORT page : public poppler::noncopyable +{ +public: + enum orientation_enum { + landscape, + portrait, + seascape, + upside_down + }; + + ~page(); + + orientation_enum orientation() const; + double duration() const; + rectf page_rect(page_box_enum box = crop_box) const; + ustring label() const; + + page_transition* transition() const; + +private: + page(document_private *doc, int index); + + page_private *d; + friend class page_private; + friend class document; +}; + +} + +#endif diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp new file mode 100644 index 00000000..51d557cb --- /dev/null +++ b/cpp/poppler-private.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-private.h" + +#include "GooString.h" +#include "Page.h" + +#include <iostream> +#include <sstream> + +using namespace poppler; + +void detail::error_function(int pos, char *msg, va_list args) +{ + std::ostringstream oss; + if (pos >= 0) { + oss << "poppler/error (" << pos << "): "; + } else { + oss << "poppler/error: "; + } + char buffer[4096]; // should be big enough + vsnprintf(buffer, sizeof(buffer) - 1, msg, args); + oss << buffer; + std::cerr << oss.str(); +} + +rectf detail::pdfrectangle_to_rectf(const PDFRectangle &pdfrect) +{ + return rectf(pdfrect.x1, pdfrect.y1, pdfrect.x2 - pdfrect.x1, pdfrect.y2 - pdfrect.y1); +} + +ustring detail::unicode_GooString_to_ustring(GooString *str) +{ + 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) +{ + ustring str(length, 0); + ustring::iterator it = str.begin(), it_end = str.end(); + const Unicode *uu = u; + for (; it != it_end; ++it) { + *it = ustring::value_type(*uu++); + } + return str; +} + +GooString* detail::ustring_to_unicode_GooString(const ustring &str) +{ + 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; +} diff --git a/cpp/poppler-private.h b/cpp/poppler-private.h new file mode 100644 index 00000000..fb3bc6c8 --- /dev/null +++ b/cpp/poppler-private.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_PRIVATE_H +#define POPPLER_PRIVATE_H + +#include "poppler-global.h" +#include "poppler-rectangle.h" + +#include "CharTypes.h" + +#include <stdarg.h> + +class GooString; +class PDFRectangle; + +#define PSTR(str) const_cast<char *>(str) + +namespace poppler +{ + +namespace detail +{ + +void error_function(int pos, char *msg, va_list args); + +rectf pdfrectangle_to_rectf(const PDFRectangle &pdfrect); + +ustring unicode_GooString_to_ustring(GooString *str); +ustring unicode_to_ustring(const Unicode *u, int length); +GooString* ustring_to_unicode_GooString(const ustring &str); + +} + +template <typename ConstIterator> +void delete_all(ConstIterator it, ConstIterator end) +{ + while (it != end) { + delete *it++; + } +} + +template <typename Collection> +void delete_all(const Collection &c) +{ + delete_all(c.begin(), c.end()); +} + +} + +#endif diff --git a/cpp/poppler-rectangle.cpp b/cpp/poppler-rectangle.cpp new file mode 100644 index 00000000..57fd8599 --- /dev/null +++ b/cpp/poppler-rectangle.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-rectangle.h" + +#include <iostream> + +using namespace poppler; + +std::ostream& poppler::operator<<(std::ostream& stream, const rect &r) +{ + stream << "[" << r.x() << "," << r.y() << " " << r.width() << "+" << r.height() << "]"; + return stream; +} + +std::ostream& poppler::operator<<(std::ostream& stream, const rectf &r) +{ + stream << "[" << r.x() << "," << r.y() << " " << r.width() << "+" << r.height() << "]"; + return stream; +} diff --git a/cpp/poppler-rectangle.h b/cpp/poppler-rectangle.h new file mode 100644 index 00000000..18674b24 --- /dev/null +++ b/cpp/poppler-rectangle.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_RECTANGLE_H +#define POPPLER_RECTANGLE_H + +#include "poppler-global.h" + +namespace poppler +{ + +template <typename T> class rectangle +{ +public: + rectangle() + : x1(), y1(), x2(), y2() + {} + rectangle(T _x, T _y, T w, T h) + : x1(_x), y1(_y), x2(x1 + w), y2(y1 + h) + {} + ~rectangle() + {} + + bool is_empty() const + { return (x1 == x2) && (y1 == y2); } + + T x() const + { return x1; } + + T y() const + { return y1; } + + T width() const + { return x2 - x1; } + + T height() const + { return y2 - y1; } + +private: + T x1, y1, x2, y2; +}; + +typedef rectangle<int> rect; +typedef rectangle<double> rectf; + +POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const rect &r); +POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const rectf &r); + +} + +#endif diff --git a/cpp/poppler-toc-private.h b/cpp/poppler-toc-private.h new file mode 100644 index 00000000..e8841ff7 --- /dev/null +++ b/cpp/poppler-toc-private.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_TOC_PRIVATE_H +#define POPPLER_TOC_PRIVATE_H + +#include "poppler-global.h" +#include "poppler-toc.h" + +#include <vector> + +class GooList; +class Outline; +class OutlineItem; + +namespace poppler +{ + +class toc_private +{ +public: + toc_private(); + ~toc_private(); + + static toc* load_from_outline(Outline *outline); + + toc_item root; +}; + + +class toc_item_private +{ +public: + toc_item_private(); + ~toc_item_private(); + + void load(OutlineItem *item); + void load_children(GooList *items); + + std::vector<toc_item*> children; + ustring title; + bool is_open; +}; + +} + +#endif diff --git a/cpp/poppler-toc.cpp b/cpp/poppler-toc.cpp new file mode 100644 index 00000000..1fc0f4d4 --- /dev/null +++ b/cpp/poppler-toc.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-toc.h" + +#include "poppler-toc-private.h" +#include "poppler-private.h" + +#include "GooList.h" +#include "Outline.h" + +using namespace poppler; + +toc_private::toc_private() +{ +} + +toc_private::~toc_private() +{ +} + +toc* toc_private::load_from_outline(Outline *outline) +{ + if (!outline) { + return 0; + } + + GooList *items = outline->getItems(); + if (!items || items->getLength() < 1) { + return 0; + } + + toc *newtoc = new toc(); + newtoc->d->root.d->is_open = true; + newtoc->d->root.d->load_children(items); + + return newtoc; +} + +toc_item_private::toc_item_private() + : is_open(false) +{ +} + +toc_item_private::~toc_item_private() +{ + delete_all(children); +} + +void toc_item_private::load(OutlineItem *item) +{ + const Unicode *title_unicode = item->getTitle(); + const int title_length = item->getTitleLength(); + title = detail::unicode_to_ustring(title_unicode, title_length); + is_open = item->isOpen(); +} + +void toc_item_private::load_children(GooList *items) +{ + const int num_items = items->getLength(); + children.resize(num_items); + for (int i = 0; i < num_items; ++i) { + OutlineItem *item = (OutlineItem *)items->get(i); + + toc_item *new_item = new toc_item(); + new_item->d->load(item); + children[i] = new_item; + + item->open(); + GooList *item_children = item->getKids(); + if (item_children) { + new_item->d->load_children(item_children); + } + } +} + + +toc::toc() + : d(new toc_private()) +{ +} + +toc::~toc() +{ + delete d; +} + +toc_item* toc::root() const +{ + return &d->root; +} + + +toc_item::toc_item() + : d(new toc_item_private()) +{ +} + +toc_item::~toc_item() +{ + delete d; +} + +ustring toc_item::title() const +{ + return d->title; +} + +bool toc_item::is_open() const +{ + return d->is_open; +} + +std::vector<toc_item *> toc_item::children() const +{ + return d->children; +} + +toc_item::iterator toc_item::children_begin() const +{ + return d->children.begin(); +} + +toc_item::iterator toc_item::children_end() const +{ + return d->children.end(); +} diff --git a/cpp/poppler-toc.h b/cpp/poppler-toc.h new file mode 100644 index 00000000..8b09736f --- /dev/null +++ b/cpp/poppler-toc.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_TOC_H +#define POPPLER_TOC_H + +#include "poppler-global.h" + +#include <vector> + +namespace poppler +{ + +class toc_private; +class toc_item; +class toc_item_private; + +class POPPLER_CPP_EXPORT toc : public poppler::noncopyable +{ +public: + ~toc(); + + toc_item* root() const; + +private: + toc(); + + toc_private *d; + + friend class toc_private; +}; + + +class POPPLER_CPP_EXPORT toc_item : public poppler::noncopyable +{ +public: + typedef std::vector<toc_item *>::const_iterator iterator; + + ~toc_item(); + + ustring title() const; + bool is_open() const; + + std::vector<toc_item *> children() const; + iterator children_begin() const; + iterator children_end() const; + +private: + toc_item(); + + toc_item_private *d; + friend class toc; + friend class toc_private; + friend class toc_item_private; +}; + +} + +#endif diff --git a/cpp/poppler-version.cpp b/cpp/poppler-version.cpp new file mode 100644 index 00000000..b39af539 --- /dev/null +++ b/cpp/poppler-version.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "poppler-version.h" + +using namespace poppler; + +std::string poppler::version_string() +{ + return std::string(POPPLER_VERSION); +} + +unsigned int poppler::version_major() +{ + return POPPLER_VERSION_MAJOR; +} + +unsigned int poppler::version_minor() +{ + return POPPLER_VERSION_MINOR; +} + +unsigned int poppler::version_micro() +{ + return POPPLER_VERSION_MICRO; +} diff --git a/cpp/poppler-version.h.in b/cpp/poppler-version.h.in new file mode 100644 index 00000000..cf6bce67 --- /dev/null +++ b/cpp/poppler-version.h.in @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef POPPLER_VERSION_H +#define POPPLER_VERSION_H + +#include "poppler-global.h" + +#define POPPLER_VERSION "@POPPLER_VERSION@" +#define POPPLER_VERSION_MAJOR @POPPLER_MAJOR_VERSION@ +#define POPPLER_VERSION_MINOR @POPPLER_MINOR_VERSION@ +#define POPPLER_VERSION_MICRO @POPPLER_MICRO_VERSION@ + +namespace poppler +{ + +POPPLER_CPP_EXPORT std::string version_string(); +POPPLER_CPP_EXPORT unsigned int version_major(); +POPPLER_CPP_EXPORT unsigned int version_minor(); +POPPLER_CPP_EXPORT unsigned int version_micro(); + +} + +#endif diff --git a/cpp/tests/.gitignore b/cpp/tests/.gitignore new file mode 100644 index 00000000..737f30a2 --- /dev/null +++ b/cpp/tests/.gitignore @@ -0,0 +1 @@ +poppler-dump diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt new file mode 100644 index 00000000..a083afdc --- /dev/null +++ b/cpp/tests/CMakeLists.txt @@ -0,0 +1,24 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_BINARY_DIR}/.. + ${CMAKE_SOURCE_DIR}/utils +) + +# ### temporary +set(BUILD_CPP_TESTS TRUE) + +macro(CPP_ADD_SIMPLETEST exe) + string(REPLACE "-" "" test_name ${exe}) + set(${test_name}_SOURCES + ${ARGN} + ) + poppler_add_test(${exe} BUILD_CPP_TESTS ${${test_name}_SOURCES}) + target_link_libraries(${exe} poppler-cpp) + if(MSVC) + target_link_libraries(${exe} poppler ${poppler_LIBS}) + endif(MSVC) +endmacro(CPP_ADD_SIMPLETEST) + + +cpp_add_simpletest(poppler-dump poppler-dump.cpp ${CMAKE_SOURCE_DIR}/utils/parseargs.c) diff --git a/cpp/tests/Makefile.am b/cpp/tests/Makefile.am new file mode 100644 index 00000000..b01d3b9f --- /dev/null +++ b/cpp/tests/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/utils \ + -I$(top_srcdir)/cpp + +LDADDS = \ + $(top_builddir)/cpp/libpoppler-cpp.la + + +noinst_PROGRAMS = \ + poppler-dump + +poppler_dump_SOURCES = \ + $(top_srcdir)/utils/parseargs.c \ + poppler-dump.cpp +poppler_dump_LDADD = $(LDADDS) + diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp new file mode 100644 index 00000000..745d038f --- /dev/null +++ b/cpp/tests/poppler-dump.cpp @@ -0,0 +1,343 @@ +/* + * Copyright (C) 2009, Pino Toscano <pino@kde.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <poppler-document.h> +#include <poppler-embedded-file.h> +#include <poppler-font.h> +#include <poppler-page.h> +#include <poppler-toc.h> + +#include <cstdlib> +#include <ctime> +#include <iomanip> +#include <iostream> +#include <memory> +#include <sstream> + +#include "parseargs.h" + +static const int out_width = 30; + +bool show_all = false; +bool show_info = false; +bool show_perm = false; +bool show_metadata = false; +bool show_toc = false; +bool show_fonts = false; +bool show_embedded_files = false; +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, + "show document permissions" }, + { "--show-metadata", argFlag, &show_metadata, 0, + "show document metadata" }, + { "--show-toc", argFlag, &show_toc, 0, + "show the TOC" }, + { "--show-fonts", argFlag, &show_fonts, 0, + "show the document fonts" }, + { "--show-embedded-files", argFlag, &show_embedded_files, 0, + "show the document-level embedded files" }, + { "--show-pages", argFlag, &show_pages, 0, + "show pages information" }, + { "-h", argFlag, &show_help, 0, + "print usage information" }, + { "--help", argFlag, &show_help, 0, + "print usage information" }, + { NULL, argFlag, 0, 0, NULL } +}; + +static void error(const std::string &msg) +{ + std::cerr << "Error: " << msg << std::endl; + std::cerr << "Exiting..." << std::endl; + exit(1); +} + +static std::string out_ustring(const poppler::ustring &str) +{ + return str.to_latin1(); +} + +static std::string out_date(std::time_t date) +{ + if (date != std::time_t(-1)) { + struct tm time; + gmtime_r(&date, &time); + char buf[32]; + strftime(buf, sizeof(buf) - 1, "%d/%m/%Y %H:%M:%S", &time); + return std::string(buf); + } + return std::string("n/a"); +} + +static std::string out_size(int size) +{ + if (size >= 0) { + std::ostringstream ss; + ss << size; + return ss.str(); + } + return std::string("n/a"); +} + +static char charToHex(int x) +{ + return x < 10 ? x + '0' : x - 10 + 'a'; +} + +static std::string out_hex_string(const std::string &str) +{ + std::string ret(str.size() * 2, '\0'); + const char *str_p = str.data(); + for (unsigned int i = 0; i < str.size(); ++i, ++str_p) { + ret[i * 2] = charToHex((*str_p & 0xf0) >> 4); + ret[i * 2 + 1] = charToHex(*str_p & 0xf); + } + 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 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; + int major = 0, minor = 0; + doc->get_pdf_version(&major, &minor); + std::cout << std::setw(out_width) << "PDF version" << ": " << major << "." << minor << std::endl; + const std::vector<std::string> keys = doc->info_keys(); + std::vector<std::string>::const_iterator key_it = keys.begin(), key_end = keys.end(); + for (; key_it != key_end; ++key_it) { + std::cout << std::setw(out_width) << *key_it << ": " << out_ustring(doc->info_key(*key_it)) << std::endl; + } + std::cout << std::setw(out_width) << "Date (creation)" << ": " << out_date(doc->info_date("CreationDate")) << std::endl; + std::cout << std::setw(out_width) << "Date (modification)" << ": " << out_date(doc->info_date("ModDate")) << std::endl; + std::cout << std::setw(out_width) << "Number of pages" << ": " << doc->pages() << std::endl; + std::cout << std::setw(out_width) << "Linearized" << ": " << doc->is_linearized() << std::endl; + std::cout << std::setw(out_width) << "Encrypted" << ": " << doc->is_encrypted() << std::endl; + std::cout << std::endl; +} + +static void print_perm(poppler::document *doc) +{ + std::cout << "Document permissions:" << std::endl; +#define OUT_PERM(theperm) \ + std::cout << std::setw(out_width) << #theperm << ": " \ + << doc->has_permission(poppler::perm_##theperm) << std::endl + OUT_PERM(print); + OUT_PERM(change); + OUT_PERM(copy); + OUT_PERM(add_notes); + OUT_PERM(fill_forms); + OUT_PERM(accessibility); + OUT_PERM(assemble); + OUT_PERM(print_high_resolution); + std::cout << std::endl; +#undef OUT_PERM +} + +static void print_metadata(poppler::document *doc) +{ + std::cout << std::setw(out_width) << "Metadata" << ":" << std::endl + << out_ustring(doc->metadata()) << std::endl; + std::cout << std::endl; +} + +static void print_toc_item(poppler::toc_item *item, int indent) +{ + std::cout << std::setw(indent * 2) << " " + << "+ " << out_ustring(item->title()) << " (" << item->is_open() << ")" + << std::endl; + poppler::toc_item::iterator it = item->children_begin(), it_end = item->children_end(); + for (; it != it_end; ++it) { + print_toc_item(*it, indent + 1); + } +} + +static void print_toc(poppler::toc *doctoc) +{ + std::cout << "Document TOC:" << std::endl; + if (doctoc) { + print_toc_item(doctoc->root(), 0); + } else { + std::cout << "<no TOC>" << std::endl; + } + std::cout << std::endl; +} + +static void print_fonts(poppler::document *doc) +{ + std::cout << "Document fonts:" << std::endl; + std::vector<poppler::font_info> fl = doc->fonts(); + if (!fl.empty()) { + std::vector<poppler::font_info>::const_iterator it = fl.begin(), it_end = fl.end(); + const std::ios_base::fmtflags f = std::cout.flags(); + std::left(std::cout); + for (; it != it_end; ++it) { + std::cout + << " " << std::setw(out_width + 10) << it->name() + << " " << std::setw(15) << out_font_info_type(it->type()) + << " " << std::setw(5) << it->is_embedded() + << " " << std::setw(5) << it->is_subset() + << " " << it->file() + << std::endl; + } + std::cout.flags(f); + } else { + std::cout << "<no fonts>" << std::endl; + } + std::cout << std::endl; +} + +static void print_embedded_files(poppler::document *doc) +{ + std::cout << "Document embedded files:" << std::endl; + std::vector<poppler::embedded_file *> ef = doc->embedded_files(); + if (!ef.empty()) { + std::vector<poppler::embedded_file *>::const_iterator it = ef.begin(), it_end = ef.end(); + const std::ios_base::fmtflags f = std::cout.flags(); + std::left(std::cout); + for (; it != it_end; ++it) { + poppler::embedded_file *f = *it; + std::cout + << " " << std::setw(out_width + 10) << f->name() + << " " << std::setw(10) << out_size(f->size()) + << " " << std::setw(20) << out_date(f->creation_date()) + << " " << std::setw(20) << out_date(f->modification_date()) + << std::endl + << " " << (f->description().empty() ? std::string("<no description>") : out_ustring(f->description())) + << std::endl + << " " << std::setw(35) << (f->checksum().empty() ? std::string("<no checksum>") : out_hex_string(f->checksum())) + << " " << (f->mime_type().empty() ? std::string("<no mime type>") : f->mime_type()) + << std::endl; + } + std::cout.flags(f); + } else { + std::cout << "<no embedded files>" << std::endl; + } + std::cout << std::endl; +} + +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; +} + +int main(int argc, char *argv[]) +{ + if (!parseArgs(the_args, &argc, argv) + || argc < 2 || show_help) { + printUsage(argv[0], "DOCUMENT", the_args); + exit(1); + } + + std::string file_name(argv[1]); + + std::auto_ptr<poppler::document> doc(poppler::document::load_from_file(file_name)); + if (!doc.get()) { + error("loading error"); + } + if (doc->is_locked()) { + error("encrypted document"); + } + + 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()); + } + if (show_perm) { + print_perm(doc.get()); + } + if (show_metadata) { + print_metadata(doc.get()); + } + if (show_toc) { + std::auto_ptr<poppler::toc> doctoc(doc->create_toc()); + print_toc(doctoc.get()); + } + if (show_fonts) { + print_fonts(doc.get()); + } + if (show_embedded_files) { + print_embedded_files(doc.get()); + } + if (show_pages) { + const int pages = doc->pages(); + for (int i = 0; i < pages; ++i) { + std::cout << "Page " << (i + 1) << "/" << pages << ":" << std::endl; + std::auto_ptr<poppler::page> p(doc->create_page(i)); + print_page(p.get()); + } + } + + return 0; +} diff --git a/m4/iconv.m4 b/m4/iconv.m4 new file mode 100644 index 00000000..b2156eb3 --- /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 +]) diff --git a/poppler-cpp.pc.cmake b/poppler-cpp.pc.cmake new file mode 100644 index 00000000..eeb11cca --- /dev/null +++ b/poppler-cpp.pc.cmake @@ -0,0 +1,9 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib@LIB_SUFFIX@ +includedir=${prefix}/include + +Name: poppler-cpp +Description: cpp backend for Poppler PDF rendering library +Version: @POPPLER_VERSION@ +Requires: poppler = @POPPLER_VERSION@ diff --git a/poppler-cpp.pc.in b/poppler-cpp.pc.in new file mode 100644 index 00000000..309f0700 --- /dev/null +++ b/poppler-cpp.pc.in @@ -0,0 +1,9 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: poppler-cpp +Description: cpp backend for Poppler PDF rendering library +Version: @VERSION@ +Requires: poppler = @VERSION@ |