mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-07-05 01:28:39 +00:00
refining
This commit is contained in:
parent
9d99fd9b82
commit
195a6cc581
|
@ -27,7 +27,7 @@
|
||||||
#include "Param.h"
|
#include "Param.h"
|
||||||
#include "Preprocessor.h"
|
#include "Preprocessor.h"
|
||||||
#include "util/const.h"
|
#include "util/const.h"
|
||||||
#include "util/string_formatter.h"
|
#include "util/StringFormatter.h"
|
||||||
#include "util/TmpFiles.h"
|
#include "util/TmpFiles.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -106,6 +106,7 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class HTMLRenderer : public OutputDev
|
class HTMLRenderer : public OutputDev
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -200,7 +201,7 @@ class HTMLRenderer : public OutputDev
|
||||||
void post_process();
|
void post_process();
|
||||||
|
|
||||||
// set flags
|
// 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);
|
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);
|
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;
|
int32_t * cur_mapping;
|
||||||
char ** cur_mapping2;
|
char ** cur_mapping2;
|
||||||
int * width_list;
|
int * width_list;
|
||||||
|
|
||||||
Preprocessor preprocessor;
|
Preprocessor preprocessor;
|
||||||
TmpFiles tmp_files;
|
TmpFiles tmp_files;
|
||||||
|
|
||||||
// for string formatting
|
// for string formatting
|
||||||
string_formatter str_fmt;
|
StringFormatter str_fmt;
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// styles & resources
|
// styles & resources
|
||||||
|
@ -471,8 +473,6 @@ class HTMLRenderer : public OutputDev
|
||||||
std::map<double, long long> rise_map;
|
std::map<double, long long> rise_map;
|
||||||
std::map<double, long long> height_map;
|
std::map<double, long long> height_map;
|
||||||
|
|
||||||
int image_count;
|
|
||||||
|
|
||||||
const Param * param;
|
const Param * param;
|
||||||
std::ofstream html_fout, css_fout;
|
std::ofstream html_fout, css_fout;
|
||||||
std::string html_path, css_path;
|
std::string html_path, css_path;
|
||||||
|
|
|
@ -44,7 +44,6 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
||||||
,line_buf(this)
|
,line_buf(this)
|
||||||
,preprocessor(param)
|
,preprocessor(param)
|
||||||
,tmp_files(*param)
|
,tmp_files(*param)
|
||||||
,image_count(0)
|
|
||||||
,param(param)
|
,param(param)
|
||||||
{
|
{
|
||||||
if(!(param->debug))
|
if(!(param->debug))
|
||||||
|
@ -92,7 +91,7 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||||
html_fout.open((char*)page_fn, ofstream::binary);
|
html_fout.open((char*)page_fn, ofstream::binary);
|
||||||
if(!html_fout)
|
if(!html_fout)
|
||||||
throw string("Cannot open ") + (char*)page_fn + " for writing";
|
throw string("Cannot open ") + (char*)page_fn + " for writing";
|
||||||
fix_stream(html_fout);
|
set_stream_flags(html_fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(param->process_nontext)
|
if(param->process_nontext)
|
||||||
|
@ -291,7 +290,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||||
css_fout.open(css_path, ofstream::binary);
|
css_fout.open(css_path, ofstream::binary);
|
||||||
if(!css_fout)
|
if(!css_fout)
|
||||||
throw string("Cannot open ") + (char*)fn + " for writing";
|
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
|
// 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);
|
html_fout.open(html_path, ofstream::binary);
|
||||||
if(!html_fout)
|
if(!html_fout)
|
||||||
throw string("Cannot open ") + (char*)fn + " for writing";
|
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);
|
output.open((char*)fn, ofstream::binary);
|
||||||
if(!output)
|
if(!output)
|
||||||
throw string("Cannot open ") + (char*)fn + " for writing";
|
throw string("Cannot open ") + (char*)fn + " for writing";
|
||||||
fix_stream(output);
|
set_stream_flags(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply manifest
|
// 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
|
// we output all ID's in hex
|
||||||
// browsers are not happy with scientific notations
|
// browsers are not happy with scientific notations
|
||||||
|
|
|
@ -5,32 +5,32 @@
|
||||||
* 2012.11.29
|
* 2012.11.29
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef STRING_FORMATTER_H__
|
#ifndef STRINGFORMATTER_H__
|
||||||
#define STRING_FORMATTER_H__
|
#define STRINGFORMATTER_H__
|
||||||
|
|
||||||
namespace pdf2htmlEX {
|
namespace pdf2htmlEX {
|
||||||
|
|
||||||
class string_formatter
|
class StringFormatter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class guarded_pointer
|
class GuardedPointer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
guarded_pointer(string_formatter * sf) : sf(sf) { ++(sf->buf_cnt); }
|
GuardedPointer(StringFormatter * sf) : sf(sf) { ++(sf->buf_cnt); }
|
||||||
guarded_pointer(const guarded_pointer & gp) : sf(gp.sf) { ++(sf->buf_cnt); }
|
GuardedPointer(const GuardedPointer & gp) : sf(gp.sf) { ++(sf->buf_cnt); }
|
||||||
~guarded_pointer(void) { --(sf->buf_cnt); }
|
~GuardedPointer(void) { --(sf->buf_cnt); }
|
||||||
operator char* () const { return &(sf->buf.front()); }
|
operator char* () const { return &(sf->buf.front()); }
|
||||||
private:
|
private:
|
||||||
string_formatter * sf;
|
StringFormatter * sf;
|
||||||
};
|
};
|
||||||
|
|
||||||
string_formatter() : buf_cnt(0) { buf.reserve(L_tmpnam); }
|
StringFormatter() : buf_cnt(0) { buf.reserve(L_tmpnam); }
|
||||||
/*
|
/*
|
||||||
* Important:
|
* Important:
|
||||||
* there is only one buffer, so new strings will replace old ones
|
* there is only one buffer, so new strings will replace old ones
|
||||||
*/
|
*/
|
||||||
guarded_pointer operator () (const char * format, ...) {
|
GuardedPointer operator () (const char * format, ...) {
|
||||||
assert((buf_cnt == 0) && "string_formatter: buffer is reused!");
|
assert((buf_cnt == 0) && "StringFormatter: buffer is reused!");
|
||||||
|
|
||||||
va_list vlist;
|
va_list vlist;
|
||||||
va_start(vlist, format);
|
va_start(vlist, format);
|
||||||
|
@ -45,13 +45,13 @@ public:
|
||||||
}
|
}
|
||||||
assert(l >= 0); // we should fail when vsnprintf fail
|
assert(l >= 0); // we should fail when vsnprintf fail
|
||||||
assert(l < (int)buf.capacity());
|
assert(l < (int)buf.capacity());
|
||||||
return guarded_pointer(this);
|
return GuardedPointer(this);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
friend class guarded_pointer;
|
friend class GuardedPointer;
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
int buf_cnt;
|
int buf_cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace pdf2htmlEX
|
} //namespace pdf2htmlEX
|
||||||
#endif //STRING_FORMATTER_H__
|
#endif //STRINGFORMATTER_H__
|
Loading…
Reference in New Issue
Block a user