1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00
This commit is contained in:
Lu Wang 2012-11-29 20:39:30 +08:00
parent 9d99fd9b82
commit 195a6cc581
3 changed files with 24 additions and 25 deletions

View File

@ -27,7 +27,7 @@
#include "Param.h"
#include "Preprocessor.h"
#include "util/const.h"
#include "util/string_formatter.h"
#include "util/StringFormatter.h"
#include "util/TmpFiles.h"
/*
@ -106,6 +106,7 @@ public:
return false;
}
};
class HTMLRenderer : public OutputDev
{
public:
@ -200,7 +201,7 @@ class HTMLRenderer : public OutputDev
void post_process();
// set flags
void fix_stream (std::ostream & out);
void set_stream_flags (std::ostream & out);
std::string dump_embedded_font (GfxFont * font, long long fn_id);
void embed_font(const std::string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only = false);
@ -451,11 +452,12 @@ class HTMLRenderer : public OutputDev
int32_t * cur_mapping;
char ** cur_mapping2;
int * width_list;
Preprocessor preprocessor;
TmpFiles tmp_files;
// for string formatting
string_formatter str_fmt;
StringFormatter str_fmt;
////////////////////////////////////////////////////
// styles & resources
@ -471,8 +473,6 @@ class HTMLRenderer : public OutputDev
std::map<double, long long> rise_map;
std::map<double, long long> height_map;
int image_count;
const Param * param;
std::ofstream html_fout, css_fout;
std::string html_path, css_path;

View File

@ -44,7 +44,6 @@ HTMLRenderer::HTMLRenderer(const Param * param)
,line_buf(this)
,preprocessor(param)
,tmp_files(*param)
,image_count(0)
,param(param)
{
if(!(param->debug))
@ -92,7 +91,7 @@ void HTMLRenderer::process(PDFDoc *doc)
html_fout.open((char*)page_fn, ofstream::binary);
if(!html_fout)
throw string("Cannot open ") + (char*)page_fn + " for writing";
fix_stream(html_fout);
set_stream_flags(html_fout);
}
if(param->process_nontext)
@ -291,7 +290,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
css_fout.open(css_path, ofstream::binary);
if(!css_fout)
throw string("Cannot open ") + (char*)fn + " for writing";
fix_stream(css_fout);
set_stream_flags(css_fout);
}
// if split-pages is specified, open & close the file in the process loop
@ -312,7 +311,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
html_fout.open(html_path, ofstream::binary);
if(!html_fout)
throw string("Cannot open ") + (char*)fn + " for writing";
fix_stream(html_fout);
set_stream_flags(html_fout);
}
}
@ -332,7 +331,7 @@ void HTMLRenderer::post_process()
output.open((char*)fn, ofstream::binary);
if(!output)
throw string("Cannot open ") + (char*)fn + " for writing";
fix_stream(output);
set_stream_flags(output);
}
// apply manifest
@ -390,7 +389,7 @@ void HTMLRenderer::post_process()
}
}
void HTMLRenderer::fix_stream (std::ostream & out)
void HTMLRenderer::set_stream_flags(std::ostream & out)
{
// we output all ID's in hex
// browsers are not happy with scientific notations

View File

@ -5,32 +5,32 @@
* 2012.11.29
*/
#ifndef STRING_FORMATTER_H__
#define STRING_FORMATTER_H__
#ifndef STRINGFORMATTER_H__
#define STRINGFORMATTER_H__
namespace pdf2htmlEX {
class string_formatter
class StringFormatter
{
public:
class guarded_pointer
class GuardedPointer
{
public:
guarded_pointer(string_formatter * sf) : sf(sf) { ++(sf->buf_cnt); }
guarded_pointer(const guarded_pointer & gp) : sf(gp.sf) { ++(sf->buf_cnt); }
~guarded_pointer(void) { --(sf->buf_cnt); }
GuardedPointer(StringFormatter * sf) : sf(sf) { ++(sf->buf_cnt); }
GuardedPointer(const GuardedPointer & gp) : sf(gp.sf) { ++(sf->buf_cnt); }
~GuardedPointer(void) { --(sf->buf_cnt); }
operator char* () const { return &(sf->buf.front()); }
private:
string_formatter * sf;
StringFormatter * sf;
};
string_formatter() : buf_cnt(0) { buf.reserve(L_tmpnam); }
StringFormatter() : buf_cnt(0) { buf.reserve(L_tmpnam); }
/*
* Important:
* there is only one buffer, so new strings will replace old ones
*/
guarded_pointer operator () (const char * format, ...) {
assert((buf_cnt == 0) && "string_formatter: buffer is reused!");
GuardedPointer operator () (const char * format, ...) {
assert((buf_cnt == 0) && "StringFormatter: buffer is reused!");
va_list vlist;
va_start(vlist, format);
@ -45,13 +45,13 @@ public:
}
assert(l >= 0); // we should fail when vsnprintf fail
assert(l < (int)buf.capacity());
return guarded_pointer(this);
return GuardedPointer(this);
}
private:
friend class guarded_pointer;
friend class GuardedPointer;
std::vector<char> buf;
int buf_cnt;
};
} //namespace pdf2htmlEX
#endif //STRING_FORMATTER_H__
#endif //STRINGFORMATTER_H__