diff --git a/CMakeLists.txt b/CMakeLists.txt index e35c430..a576161 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ find_package(PkgConfig) pkg_check_modules(POPPLER REQUIRED poppler) include_directories(${POPPLER_INCLUDE_DIRS}) link_directories ( ${POPPLER_LIBRARY_DIRS} ) -find_package(Boost REQUIRED COMPONENTS program_options filesystem) +find_package(Boost REQUIRED COMPONENTS program_options filesystem system) include_directories(${Boost_INCLUDE_DIRS}) link_directories ( ${Boost_LIBRARY_DIRS} ) include_directories(src) @@ -17,7 +17,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") -configure_file (bin/pdf2htmlEX.in bin/pdf2htmlEX) configure_file (src/config.h.in src/config.h) add_executable(pdf2htmlEX @@ -37,11 +36,8 @@ add_executable(pdf2htmlEX src/util.h src/config.h) -#link boost::system temporarily... maybe a bug of boost -#target_link_libraries(pdf2htmlEX poppler boost_program_options boost_filesystem) target_link_libraries(pdf2htmlEX poppler boost_program_options boost_filesystem boost_system) -install (TARGETS pdf2htmlEX DESTINATION lib/pdf2htmlEX) -install (PROGRAMS "bin/pdf2htmlEX" DESTINATION bin) +install (TARGETS pdf2htmlEX DESTINATION bin) file (GLOB libfiles lib/*) install (FILES ${libfiles} DESTINATION lib/pdf2htmlEX) diff --git a/README.md b/README.md index d51c909..5b54a56 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Not supported yet Dependency ---------------------------- * libpoppler with xpdf header >= 0.20.2 -* boost c++ library (format, program options, gil, filesystem, serialization) +* boost c++ library (format, program options, gil, filesystem, serialization, system(which is actually required by filesystem)) * fontforge **Please use [the lastest version](https://github.com/fontforge/fontforge)** HOW TO COMPILE diff --git a/bin/pdf2htmlEX.in b/bin/pdf2htmlEX.in deleted file mode 100755 index 6b17094..0000000 --- a/bin/pdf2htmlEX.in +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -set -e - -LIBDIR=@CMAKE_INSTALL_PREFIX@/lib/pdf2htmlEX -TMPDIR=/tmp/pdf2htmlEX - -# prepare the temporary directory -test -d $TMPDIR || mkdir -p $TMPDIR -rm -f $TMPDIR/* 2>/dev/null - -$LIBDIR/pdf2htmlEX $* - -if [ -f $TMPDIR/pdf2htmlEX.pe ]; then - echo -n "Converting fonts: " - fontforge -script $TMPDIR/pdf2htmlEX.pe 2>/dev/null - echo "." -fi - -#clean -#rm -f $TMPDIR/* 2>/dev/null - -echo "Done." diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc index f7cf8f2..d15e0d4 100644 --- a/src/HTMLRenderer/export.cc +++ b/src/HTMLRenderer/export.cc @@ -22,7 +22,7 @@ void HTMLRenderer::export_remote_font(long long fn_id, const string & suffix, co const std::string fn = (format("f%|1$x|%2%") % fn_id % suffix).str(); if(param->single_html) { - allcss_fout << "'data:font/" << fontfileformat << ";base64," << base64_filter(ifstream(tmp_dir / fn, ifstream::binary)) << "'"; + allcss_fout << "'data:font/" << fontfileformat << ";base64," << base64stream(ifstream(tmp_dir / fn, ifstream::binary)) << "'"; } else { diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 0373168..8ab8bee 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -131,7 +131,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state) if(param->single_html) { auto path = tmp_dir / fn; - html_fout << "'data:image/png;base64," << base64_filter(ifstream(path, ifstream::binary)) << "'"; + html_fout << "'data:image/png;base64," << base64stream(ifstream(path, ifstream::binary)) << "'"; } else { diff --git a/src/util.h b/src/util.h index e638efb..865e8ba 100644 --- a/src/util.h +++ b/src/util.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -24,7 +23,6 @@ using std::istream; using std::ostream; -using std::istream_iterator; using std::endl; using std::noskipws; @@ -120,41 +118,37 @@ public: double _[6]; }; -class base64_filter +class base64stream { public: - base64_filter(istream & in) - : in_iter(istream_iterator(in >> noskipws)) + base64stream(istream & in) + : in(&in) { } - base64_filter(istream && in) - : in_iter(istream_iterator(in >> noskipws)) + base64stream(istream && in) + : in(&in) { } ostream & dumpto(ostream & out) { unsigned char buf[3]; - istream_iterator end_iter; - int cnt = 0; - while(in_iter != end_iter) + while(in->read((char*)buf, 3)) { - buf[cnt++] = *(in_iter++); - if(cnt == 3) - { - out << base64_encoding[(buf[0] & 0xfc)>>2]; - out << base64_encoding[((buf[0] & 0x03)<<4) | ((buf[1] & 0xf0)>>4)]; - out << base64_encoding[((buf[1] & 0x0f)<<2) | ((buf[2] & 0xc0)>>6)]; - out << base64_encoding[(buf[2] & 0x3f)]; - cnt = 0; - } + out << base64_encoding[(buf[0] & 0xfc)>>2] + << base64_encoding[((buf[0] & 0x03)<<4) | ((buf[1] & 0xf0)>>4)] + << base64_encoding[((buf[1] & 0x0f)<<2) | ((buf[2] & 0xc0)>>6)] + << base64_encoding[(buf[2] & 0x3f)]; } + auto cnt = in->gcount(); if(cnt > 0) { for(int i = cnt; i < 3; ++i) buf[i] = 0; - out << base64_encoding[(buf[0] & 0xfc)>>2]; - out << base64_encoding[((buf[0] & 0x03)<<4) | ((buf[1] & 0xf0)>>4)]; + + out << base64_encoding[(buf[0] & 0xfc)>>2] + << base64_encoding[((buf[0] & 0x03)<<4) | ((buf[1] & 0xf0)>>4)]; + if(cnt > 1) { out << base64_encoding[(buf[1] & 0x0f)<<2]; @@ -171,10 +165,10 @@ public: private: static constexpr const char * base64_encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - istream_iterator in_iter; + istream * in; }; -static inline ostream & operator << (ostream & out, base64_filter & bf) { return bf.dumpto(out); } -static inline ostream & operator << (ostream & out, base64_filter && bf) { return bf.dumpto(out); } +static inline ostream & operator << (ostream & out, base64stream & bf) { return bf.dumpto(out); } +static inline ostream & operator << (ostream & out, base64stream && bf) { return bf.dumpto(out); } #endif //UTIL_H__