mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
working on base64
This commit is contained in:
parent
29a2d35202
commit
1bee39547e
@ -30,7 +30,7 @@ Not supported yet
|
||||
Dependency
|
||||
----------------------------
|
||||
* libpoppler with xpdf header >= 0.20.2
|
||||
* boost c++ library (format, program options, gil, filesystem)
|
||||
* boost c++ library (format, program options, gil, filesystem, serialization)
|
||||
* fontforge **Please use [the lastest version](https://github.com/fontforge/fontforge)**
|
||||
|
||||
HOW TO COMPILE
|
||||
|
@ -10,9 +10,9 @@ rm -f $TMPDIR/* 2>/dev/null
|
||||
|
||||
$LIBDIR/pdf2htmlEX $*
|
||||
|
||||
if [ -f $TMPDIR/convert.pe ]; then
|
||||
if [ -f $TMPDIR/pdf2htmlEX.pe ]; then
|
||||
echo -n "Converting fonts: "
|
||||
fontforge -script $TMPDIR/convert.pe 2>/dev/null
|
||||
fontforge -script $TMPDIR/pdf2htmlEX.pe 2>/dev/null
|
||||
echo "."
|
||||
fi
|
||||
|
||||
|
@ -36,7 +36,23 @@ using boost::algorithm::ifind_first;
|
||||
|
||||
void HTMLRenderer::export_remote_font(long long fn_id, const string & suffix, const string & fontfileformat, GfxFont * font)
|
||||
{
|
||||
allcss_fout << format("@font-face{font-family:f%|1$x|;src:url(f%|1$x|%2%)format(\"%3%\");}.f%|1$x|{font-family:f%|1$x|;") % fn_id % suffix % fontfileformat;
|
||||
|
||||
//allcss_fout << format("@font-face{font-family:f%|1$x|;src:url(f%|1$x|%2%)format(\"%3%\");}.f%|1$x|{font-family:f%|1$x|;") % fn_id % suffix % fontfileformat;
|
||||
|
||||
allcss_fout << format("@font-face{font-family:f%|1$x|;src:url(") % fn_id;
|
||||
|
||||
if(param->single_html)
|
||||
{
|
||||
allcss_fout << "'data:font/" << fontfileformat << ";base64,";
|
||||
//TODO
|
||||
allcss_fout << "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
allcss_fout << format("f%|1$x|%2%") % fn_id % suffix;
|
||||
}
|
||||
|
||||
allcss_fout << format(")format(\"%1%\");}.f%|2$x|{font-family:f%|2$x|;") % fontfileformat % fn_id;
|
||||
|
||||
double a = font->getAscent();
|
||||
double d = font->getDescent();
|
||||
|
@ -129,7 +129,21 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
|
||||
|
||||
html_fout << format("<div id=\"page-%3%\" class=\"p\" style=\"width:%1%px;height:%2%px;") % pageWidth % pageHeight % pageNum;
|
||||
|
||||
html_fout << format("background-image:url(p%|3$x|.png);background-position:0 0;background-size:%1%px %2%px;background-repeat:no-repeat;") % pageWidth % pageHeight % pageNum;
|
||||
html_fout << "background-image:url(";
|
||||
|
||||
const std::string fn = (format("p%|1$x|.png") % pageNum).str();
|
||||
if(param->single_html)
|
||||
{
|
||||
html_fout << "'data:image/png;base64,";
|
||||
copy_base64(html_fout, ifstream(tmp_dir / fn));
|
||||
html_fout << "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
html_fout << fn;
|
||||
}
|
||||
|
||||
html_fout << format(");background-position:0 0;background-size:%1%px %2%px;background-repeat:no-repeat;") % pageWidth % pageHeight;
|
||||
|
||||
html_fout << "\">" << endl;
|
||||
|
||||
|
26
src/util.h
26
src/util.h
@ -11,12 +11,26 @@
|
||||
#define UTIL_H__
|
||||
|
||||
#include <algorithm>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/archive/iterators/transform_width.hpp>
|
||||
#include <boost/archive/iterators/base64_from_binary.hpp>
|
||||
|
||||
#include <UTF8.h>
|
||||
|
||||
#include "Consts.h"
|
||||
|
||||
using std::istream;
|
||||
using std::ostream;
|
||||
using std::istream_iterator;
|
||||
using std::ostream_iterator;
|
||||
using std::copy;
|
||||
|
||||
using boost::archive::iterators::base64_from_binary;
|
||||
using boost::archive::iterators::transform_width;
|
||||
|
||||
// mute gcc
|
||||
namespace
|
||||
{
|
||||
@ -109,5 +123,17 @@ public:
|
||||
double _[6];
|
||||
};
|
||||
|
||||
// TODO: padding bug of boost
|
||||
static inline void copy_base64 (ostream & out, istream & in)
|
||||
{
|
||||
typedef base64_from_binary < transform_width < istream_iterator<char>, 6, 8 > > base64_iter;
|
||||
copy(base64_iter(istream_iterator<char>(in)), base64_iter(istream_iterator<char>()), ostream_iterator<char>(out));
|
||||
}
|
||||
|
||||
static inline void copy_base64 (ostream & out, istream && in)
|
||||
{
|
||||
typedef base64_from_binary < transform_width < istream_iterator<char>, 6, 8 > > base64_iter;
|
||||
copy(base64_iter(istream_iterator<char>(in)), base64_iter(istream_iterator<char>()), ostream_iterator<char>(out));
|
||||
}
|
||||
|
||||
#endif //UTIL_H__
|
||||
|
Loading…
Reference in New Issue
Block a user