1
0
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:
Lu Wang 2012-08-14 21:48:57 +08:00
parent 1bee39547e
commit 7c344bc2e4
2 changed files with 30 additions and 4 deletions

View File

@ -20,6 +20,8 @@
using std::flush;
using boost::filesystem::file_size;
HTMLRenderer::HTMLRenderer(const Param * param)
:line_opened(false)
,image_count(0)
@ -134,8 +136,9 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
const std::string fn = (format("p%|1$x|.png") % pageNum).str();
if(param->single_html)
{
auto path = tmp_dir / fn;
html_fout << "'data:image/png;base64,";
copy_base64(html_fout, ifstream(tmp_dir / fn));
copy_base64(html_fout, ifstream(path), file_size(path));
html_fout << "'";
}
else

View File

@ -123,17 +123,40 @@ public:
double _[6];
};
// TODO: padding bug of boost
static inline void copy_base64 (ostream & out, istream & in)
static inline void copy_base64 (ostream & out, istream & in, size_t length)
{
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));
switch(length % 3)
{
case 1:
out << '=';
// fall through
case 2:
out << '=';
// fall through
case 0:
default:
break;
}
}
static inline void copy_base64 (ostream & out, istream && in)
static inline void copy_base64 (ostream & out, istream && in, size_t length)
{
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));
switch(length % 3)
{
case 1:
out << '=';
// fall through
case 2:
out << '=';
// fall through
case 0:
default:
break;
}
}
#endif //UTIL_H__