1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 17:48:38 +00:00
This commit is contained in:
Lu Wang 2012-08-15 11:15:33 +08:00
parent dfb258c7a0
commit 5c2fa8ead1
6 changed files with 23 additions and 55 deletions

View File

@ -5,7 +5,7 @@ find_package(PkgConfig)
pkg_check_modules(POPPLER REQUIRED poppler) pkg_check_modules(POPPLER REQUIRED poppler)
include_directories(${POPPLER_INCLUDE_DIRS}) include_directories(${POPPLER_INCLUDE_DIRS})
link_directories ( ${POPPLER_LIBRARY_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}) include_directories(${Boost_INCLUDE_DIRS})
link_directories ( ${Boost_LIBRARY_DIRS} ) link_directories ( ${Boost_LIBRARY_DIRS} )
include_directories(src) 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} -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
configure_file (bin/pdf2htmlEX.in bin/pdf2htmlEX)
configure_file (src/config.h.in src/config.h) configure_file (src/config.h.in src/config.h)
add_executable(pdf2htmlEX add_executable(pdf2htmlEX
@ -37,11 +36,8 @@ add_executable(pdf2htmlEX
src/util.h src/util.h
src/config.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) target_link_libraries(pdf2htmlEX poppler boost_program_options boost_filesystem boost_system)
install (TARGETS pdf2htmlEX DESTINATION lib/pdf2htmlEX) install (TARGETS pdf2htmlEX DESTINATION bin)
install (PROGRAMS "bin/pdf2htmlEX" DESTINATION bin)
file (GLOB libfiles lib/*) file (GLOB libfiles lib/*)
install (FILES ${libfiles} DESTINATION lib/pdf2htmlEX) install (FILES ${libfiles} DESTINATION lib/pdf2htmlEX)

View File

@ -31,7 +31,7 @@ Not supported yet
Dependency Dependency
---------------------------- ----------------------------
* libpoppler with xpdf header >= 0.20.2 * 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)** * fontforge **Please use [the lastest version](https://github.com/fontforge/fontforge)**
HOW TO COMPILE HOW TO COMPILE

View File

@ -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."

View File

@ -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(); const std::string fn = (format("f%|1$x|%2%") % fn_id % suffix).str();
if(param->single_html) 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 else
{ {

View File

@ -131,7 +131,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
if(param->single_html) if(param->single_html)
{ {
auto path = tmp_dir / fn; 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 else
{ {

View File

@ -13,7 +13,6 @@
#include <algorithm> #include <algorithm>
#include <istream> #include <istream>
#include <ostream> #include <ostream>
#include <iterator>
#include <iomanip> #include <iomanip>
#include <GfxState.h> #include <GfxState.h>
@ -24,7 +23,6 @@
using std::istream; using std::istream;
using std::ostream; using std::ostream;
using std::istream_iterator;
using std::endl; using std::endl;
using std::noskipws; using std::noskipws;
@ -120,41 +118,37 @@ public:
double _[6]; double _[6];
}; };
class base64_filter class base64stream
{ {
public: public:
base64_filter(istream & in) base64stream(istream & in)
: in_iter(istream_iterator<char>(in >> noskipws)) : in(&in)
{ } { }
base64_filter(istream && in) base64stream(istream && in)
: in_iter(istream_iterator<char>(in >> noskipws)) : in(&in)
{ } { }
ostream & dumpto(ostream & out) ostream & dumpto(ostream & out)
{ {
unsigned char buf[3]; unsigned char buf[3];
istream_iterator<char> end_iter; while(in->read((char*)buf, 3))
int cnt = 0;
while(in_iter != end_iter)
{ {
buf[cnt++] = *(in_iter++); out << base64_encoding[(buf[0] & 0xfc)>>2]
if(cnt == 3) << base64_encoding[((buf[0] & 0x03)<<4) | ((buf[1] & 0xf0)>>4)]
{ << base64_encoding[((buf[1] & 0x0f)<<2) | ((buf[2] & 0xc0)>>6)]
out << base64_encoding[(buf[0] & 0xfc)>>2]; << base64_encoding[(buf[2] & 0x3f)];
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;
}
} }
auto cnt = in->gcount();
if(cnt > 0) if(cnt > 0)
{ {
for(int i = cnt; i < 3; ++i) for(int i = cnt; i < 3; ++i)
buf[i] = 0; 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) if(cnt > 1)
{ {
out << base64_encoding[(buf[1] & 0x0f)<<2]; out << base64_encoding[(buf[1] & 0x0f)<<2];
@ -171,10 +165,10 @@ public:
private: private:
static constexpr const char * base64_encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static constexpr const char * base64_encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
istream_iterator<char> in_iter; istream * in;
}; };
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, base64_filter && bf) { return bf.dumpto(out); } static inline ostream & operator << (ostream & out, base64stream && bf) { return bf.dumpto(out); }
#endif //UTIL_H__ #endif //UTIL_H__