1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

use reference instead of pointer

This commit is contained in:
Lu Wang 2013-04-06 17:01:05 +08:00
parent 1ddcaafd57
commit ecebfb46e8
14 changed files with 113 additions and 114 deletions

View File

@ -19,7 +19,7 @@ namespace pdf2htmlEX {
class CairoBackgroundRenderer : public CairoOutputDev
{
public:
CairoBackgroundRenderer(const Param * param)
CairoBackgroundRenderer(const Param & param)
:CairoOutputDev()
, param(param)
{ }
@ -34,7 +34,7 @@ public:
void render_page(PDFDoc * doc, int pageno, const std::string & filename);
protected:
const Param * param;
const Param & param;
};
}

View File

@ -24,7 +24,7 @@ void SplashBackgroundRenderer::drawChar(GfxState *state, double x, double y,
// - OR there is special filling method
// - OR using a writing mode font
// - OR using a Type 3 font
if((param->fallback)
if((param.fallback)
|| ( (state->getFont())
&& ( (state->getFont()->getWMode())
|| (state->getFont()->getType() == fontType3)
@ -42,15 +42,15 @@ static GBool annot_cb(Annot *, void *) {
void SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno, const string & filename)
{
doc->displayPage(this, pageno, param->h_dpi, param->v_dpi,
doc->displayPage(this, pageno, param.h_dpi, param.v_dpi,
0,
(!(param->use_cropbox)),
(!(param.use_cropbox)),
false, false,
nullptr, nullptr, &annot_cb, nullptr);
getBitmap()->writeImgFile(splashFormatPng,
(char*)filename.c_str(),
param->h_dpi, param->v_dpi);
param.h_dpi, param.v_dpi);
}
} // namespace pdf2htmlEX

View File

@ -26,7 +26,7 @@ class SplashBackgroundRenderer : public SplashOutputDev
public:
static const SplashColor white;
SplashBackgroundRenderer(HTMLRenderer * html_renderer, const Param * param)
SplashBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param)
: SplashOutputDev(splashModeRGB8, 4, gFalse, (SplashColorPtr)&white, gTrue, gTrue)
, html_renderer(html_renderer)
, param(param)
@ -53,7 +53,7 @@ public:
protected:
HTMLRenderer * html_renderer;
const Param * param;
const Param & param;
};
} // namespace pdf2htmlEX

View File

@ -37,7 +37,7 @@ namespace pdf2htmlEX {
class HTMLRenderer : public OutputDev
{
public:
HTMLRenderer(const Param * param);
HTMLRenderer(const Param & param);
virtual ~HTMLRenderer();
void process(PDFDoc * doc);
@ -64,7 +64,7 @@ public:
virtual GBool interpretType3Chars() { return gFalse; }
// Does this device need non-text content?
virtual GBool needNonText() { return (param->process_nontext) ? gTrue: gFalse; }
virtual GBool needNonText() { return (param.process_nontext) ? gTrue: gFalse; }
// Does this device need to clip pages to the crop box even when the
// box is the crop box?
@ -316,7 +316,7 @@ protected:
// managers store values actually used in HTML (i.e. scaled)
AllStateManater all_manager;
const Param * param;
const Param & param;
struct {
std::ofstream fs;

View File

@ -220,7 +220,7 @@ void LinearGradient::dumpto (ostream & out)
GBool HTMLRenderer::axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax)
{
if(!(param->css_draw)) return gFalse;
if(!(param.css_draw)) return gFalse;
double x1, y1, x2, y2;
get_shading_bbox(state, shading, x1, y1, x2, y2);
@ -240,7 +240,7 @@ GBool HTMLRenderer::axialShadedFill(GfxState *state, GfxAxialShading *shading, d
//TODO connection style
bool HTMLRenderer::css_do_path(GfxState *state, bool fill, bool test_only)
{
if(!(param->css_draw)) return false;
if(!(param.css_draw)) return false;
GfxPath * path = state->getPath();
/*

View File

@ -135,7 +135,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
obj.streamReset();
filepath = (char*)str_fmt("%s/f%llx%s", param->tmp_dir.c_str(), fn_id, suffix.c_str());
filepath = (char*)str_fmt("%s/f%llx%s", param.tmp_dir.c_str(), fn_id, suffix.c_str());
tmp_files.add(filepath);
ofstream outf(filepath, ofstream::binary);
@ -169,7 +169,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only)
{
if(param->debug)
if(param.debug)
{
cerr << "Embed font: " << filepath << " " << info.id << endl;
}
@ -177,9 +177,9 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
ffw_load_font(filepath.c_str());
ffw_prepare_font();
if(param->debug)
if(param.debug)
{
auto fn = str_fmt("%s/__raw_font_%llx", param->tmp_dir.c_str(), info.id, param->font_suffix.c_str());
auto fn = str_fmt("%s/__raw_font_%llx", param.tmp_dir.c_str(), info.id, param.font_suffix.c_str());
tmp_files.add((char*)fn);
ofstream((char*)fn, ofstream::binary) << ifstream(filepath).rdbuf();
}
@ -198,7 +198,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
/*
* if parm->tounicode is 0, try the provided tounicode map first
*/
info.use_tounicode = (is_truetype_suffix(suffix) || (param->tounicode >= 0));
info.use_tounicode = (is_truetype_suffix(suffix) || (param.tounicode >= 0));
bool has_space = false;
const char * used_map = nullptr;
@ -383,7 +383,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
else
{
// collision detected
if(param->tounicode == 0)
if(param.tounicode == 0)
{
// in auto mode, just drop the tounicode map
if(!retried)
@ -430,7 +430,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
}
}
ffw_set_widths(width_list, max_key + 1, param->stretch_narrow_glyph, param->squeeze_wide_glyph, param->remove_unused_glyph);
ffw_set_widths(width_list, max_key + 1, param.stretch_narrow_glyph, param.squeeze_wide_glyph, param.remove_unused_glyph);
ffw_reencode_raw(cur_mapping, max_key + 1, 1);
@ -461,9 +461,9 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
* Generate the font as desired
*
*/
string cur_tmp_fn = (char*)str_fmt("%s/__tmp_font1%s", param->tmp_dir.c_str(), param->font_suffix.c_str());
string cur_tmp_fn = (char*)str_fmt("%s/__tmp_font1%s", param.tmp_dir.c_str(), param.font_suffix.c_str());
tmp_files.add(cur_tmp_fn);
string other_tmp_fn = (char*)str_fmt("%s/__tmp_font2%s", param->tmp_dir.c_str(), param->font_suffix.c_str());
string other_tmp_fn = (char*)str_fmt("%s/__tmp_font2%s", param.tmp_dir.c_str(), param.font_suffix.c_str());
tmp_files.add(other_tmp_fn);
ffw_save(cur_tmp_fn.c_str());
@ -477,13 +477,13 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
bool hinted = false;
// Call external hinting program if specified
if(param->external_hint_tool != "")
if(param.external_hint_tool != "")
{
hinted = (system((char*)str_fmt("%s \"%s\" \"%s\"", param->external_hint_tool.c_str(), cur_tmp_fn.c_str(), other_tmp_fn.c_str())) == 0);
hinted = (system((char*)str_fmt("%s \"%s\" \"%s\"", param.external_hint_tool.c_str(), cur_tmp_fn.c_str(), other_tmp_fn.c_str())) == 0);
}
// Call internal hinting procedure if specified
if((!hinted) && (param->auto_hint))
if((!hinted) && (param.auto_hint))
{
ffw_load_font(cur_tmp_fn.c_str());
ffw_auto_hint();
@ -505,10 +505,10 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
* We need to reload in order to retrieve/fix accurate ascent/descent, some info won't be written to the font by fontforge until saved.
*/
string fn = (char*)str_fmt("%s/f%llx%s",
(param->single_html ? param->tmp_dir : param->dest_dir).c_str(),
info.id, param->font_suffix.c_str());
(param.single_html ? param.tmp_dir : param.dest_dir).c_str(),
info.id, param.font_suffix.c_str());
if(param->single_html)
if(param.single_html)
tmp_files.add(fn);
ffw_load_font(cur_tmp_fn.c_str());
@ -554,7 +554,7 @@ const FontInfo * HTMLRenderer::install_font(GfxFont * font)
new_font_info.descent = font->getDescent();
new_font_info.is_type3 = (font->getType() == fontType3);
if(param->debug)
if(param.debug)
{
cerr << "Install font: (" << (font->getID()->num) << ' ' << (font->getID()->gen) << ") -> " << "f" << hex << new_fn_id << dec << endl;
}
@ -605,7 +605,7 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, FontInfo & info)
if(path != "")
{
embed_font(path, font, info);
export_remote_font(info, param->font_suffix, font);
export_remote_font(info, param.font_suffix, font);
}
else
{
@ -619,12 +619,12 @@ void HTMLRenderer::install_base_font(GfxFont * font, GfxFontLoc * font_loc, Font
string basename = psname.substr(0, psname.find('-'));
GfxFontLoc * localfontloc = font->locateFont(xref, gFalse);
if(param->embed_base_font)
if(param.embed_base_font)
{
if(localfontloc != nullptr)
{
embed_font(localfontloc->path->getCString(), font, info);
export_remote_font(info, param->font_suffix, font);
export_remote_font(info, param.font_suffix, font);
delete localfontloc;
return;
}
@ -676,12 +676,12 @@ void HTMLRenderer::install_external_font(GfxFont * font, FontInfo & info)
GfxFontLoc * localfontloc = font->locateFont(xref, gFalse);
if(param->embed_external_font)
if(param.embed_external_font)
{
if(localfontloc != nullptr)
{
embed_font(string(localfontloc->path->getCString()), font, info);
export_remote_font(info, param->font_suffix, font);
export_remote_font(info, param.font_suffix, font);
delete localfontloc;
return;
}
@ -747,9 +747,9 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
{
auto fn = str_fmt("f%llx%s", info.id, suffix.c_str());
if(param->single_html)
if(param.single_html)
{
auto path = param->tmp_dir + "/" + (char*)fn;
auto path = param.tmp_dir + "/" + (char*)fn;
ifstream fin(path, ifstream::binary);
if(!fin)
throw "Cannot locate font file: " + path;

View File

@ -38,21 +38,21 @@ using std::abs;
using std::cerr;
using std::endl;
HTMLRenderer::HTMLRenderer(const Param * param)
HTMLRenderer::HTMLRenderer(const Param & param)
:OutputDev()
,line_opened(false)
,preprocessor(param)
,tmp_files(*param)
,tmp_files(param)
,param(param)
{
if(!(param->debug))
if(!(param.debug))
{
//disable error messages of poppler
globalParams->setErrQuiet(gTrue);
}
text_line_buffers.emplace_back(new TextLineBuffer(param, all_manager));
ffw_init(param->debug);
ffw_init(param.debug);
cur_mapping = new int32_t [0x10000];
cur_mapping2 = new char* [0x100];
width_list = new int [0x10000];
@ -62,9 +62,9 @@ HTMLRenderer::HTMLRenderer(const Param * param)
* or may be handled well (whitespace_manager)
* So we can set a large eps here
*/
all_manager.vertical_align.set_eps(param->v_eps);
all_manager.whitespace .set_eps(param->h_eps);
all_manager.left .set_eps(param->h_eps);
all_manager.vertical_align.set_eps(param.v_eps);
all_manager.whitespace .set_eps(param.h_eps);
all_manager.left .set_eps(param.h_eps);
/*
* For othere states, we need accurate values
* optimization will be done separately
@ -97,31 +97,31 @@ void HTMLRenderer::process(PDFDoc *doc)
// Process pages
BackgroundRenderer * bg_renderer = nullptr;
if(param->process_nontext)
if(param.process_nontext)
{
bg_renderer = new BackgroundRenderer(this, param);
bg_renderer->startDoc(doc);
}
int page_count = (param->last_page - param->first_page + 1);
for(int i = param->first_page; i <= param->last_page ; ++i)
int page_count = (param.last_page - param.first_page + 1);
for(int i = param.first_page; i <= param.last_page ; ++i)
{
cerr << "Working: " << (i-param->first_page) << "/" << page_count << '\r' << flush;
cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
if(param->split_pages)
if(param.split_pages)
{
auto filled_template_filename = str_fmt(param->output_filename.c_str(), i);
auto page_fn = str_fmt("%s/%s", param->dest_dir.c_str(), string((char*)filled_template_filename).c_str());
auto filled_template_filename = str_fmt(param.output_filename.c_str(), i);
auto page_fn = str_fmt("%s/%s", param.dest_dir.c_str(), string((char*)filled_template_filename).c_str());
f_pages.fs.open((char*)page_fn, ofstream::binary);
if(!f_pages.fs)
throw string("Cannot open ") + (char*)page_fn + " for writing";
set_stream_flags(f_pages.fs);
}
if(param->process_nontext)
if(param.process_nontext)
{
auto fn = str_fmt("%s/bg%x.png", (param->single_html ? param->tmp_dir : param->dest_dir).c_str(), i);
if(param->single_html)
auto fn = str_fmt("%s/bg%x.png", (param.single_html ? param.tmp_dir : param.dest_dir).c_str(), i);
if(param.single_html)
tmp_files.add((char*)fn);
bg_renderer->render_page(doc, i, (char*)fn);
@ -130,12 +130,12 @@ void HTMLRenderer::process(PDFDoc *doc)
doc->displayPage(this, i,
text_zoom_factor() * DEFAULT_DPI, text_zoom_factor() * DEFAULT_DPI,
0,
(!(param->use_cropbox)),
(!(param.use_cropbox)),
true, // crop
false, // printing
nullptr, nullptr, nullptr, nullptr);
if(param->split_pages)
if(param.split_pages)
{
f_pages.fs.close();
}
@ -146,7 +146,7 @@ void HTMLRenderer::process(PDFDoc *doc)
////////////////////////
// Process Outline
if(param->process_outline)
if(param.process_outline)
process_outline();
post_process();
@ -187,13 +187,13 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
<< " " << CSS::PAGE_CONTENT_BOX_CN << pageNum
<< "\">";
if(param->process_nontext)
if(param.process_nontext)
{
f_pages.fs << "<img class=\"" << CSS::BACKGROUND_IMAGE_CN
<< "\" alt=\"\" src=\"";
if(param->single_html)
if(param.single_html)
{
auto path = str_fmt("%s/bg%x.png", param->tmp_dir.c_str(), pageNum);
auto path = str_fmt("%s/bg%x.png", param.tmp_dir.c_str(), pageNum);
ifstream fin((char*)path, ifstream::binary);
if(!fin)
throw string("Cannot read background image ") + (char*)path;
@ -252,24 +252,24 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
{
vector<double> zoom_factors;
if(is_positive(param->zoom))
if(is_positive(param.zoom))
{
zoom_factors.push_back(param->zoom);
zoom_factors.push_back(param.zoom);
}
if(is_positive(param->fit_width))
if(is_positive(param.fit_width))
{
zoom_factors.push_back((param->fit_width) / preprocessor.get_max_width());
zoom_factors.push_back((param.fit_width) / preprocessor.get_max_width());
}
if(is_positive(param->fit_height))
if(is_positive(param.fit_height))
{
zoom_factors.push_back((param->fit_height) / preprocessor.get_max_height());
zoom_factors.push_back((param.fit_height) / preprocessor.get_max_height());
}
double zoom = (zoom_factors.empty() ? 1.0 : (*min_element(zoom_factors.begin(), zoom_factors.end())));
text_scale_factor1 = max<double>(zoom, param->font_size_multiplier);
text_scale_factor1 = max<double>(zoom, param.font_size_multiplier);
text_scale_factor2 = zoom / text_scale_factor1;
}
@ -282,17 +282,17 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
*
*
* If single-html && split-page
* as there's no place to embed the css file, just leave it alone (into param->dest_dir)
* as there's no place to embed the css file, just leave it alone (into param.dest_dir)
*
* If !single-html
* leave it in param->dest_dir
* leave it in param.dest_dir
*/
auto fn = (param->single_html && (!param->split_pages))
? str_fmt("%s/__css", param->tmp_dir.c_str())
: str_fmt("%s/%s", param->dest_dir.c_str(), param->css_filename.c_str());
auto fn = (param.single_html && (!param.split_pages))
? str_fmt("%s/__css", param.tmp_dir.c_str())
: str_fmt("%s/%s", param.dest_dir.c_str(), param.css_filename.c_str());
if(param->single_html && (!param->split_pages))
if(param.single_html && (!param.split_pages))
tmp_files.add((char*)fn);
f_css.path = (char*)fn;
@ -302,17 +302,17 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
set_stream_flags(f_css.fs);
}
if (param->process_outline)
if (param.process_outline)
{
/*
* The logic for outline is similar to css
*/
auto fn = (param->single_html && (!param->split_pages))
? str_fmt("%s/__outline", param->tmp_dir.c_str())
: str_fmt("%s/%s", param->dest_dir.c_str(), param->outline_filename.c_str());
auto fn = (param.single_html && (!param.split_pages))
? str_fmt("%s/__outline", param.tmp_dir.c_str())
: str_fmt("%s/%s", param.dest_dir.c_str(), param.outline_filename.c_str());
if(param->single_html && (!param->split_pages))
if(param.single_html && (!param.split_pages))
tmp_files.add((char*)fn);
f_outline.path = (char*)fn;
@ -326,7 +326,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
// if split-pages is specified, open & close the file in the process loop
// if not, open the file here:
if(!param->split_pages)
if(!param.split_pages)
{
/*
* If single-html
@ -335,7 +335,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
*
* Otherwise just generate it
*/
auto fn = str_fmt("%s/__pages", param->tmp_dir.c_str());
auto fn = str_fmt("%s/__pages", param.tmp_dir.c_str());
tmp_files.add((char*)fn);
f_pages.path = (char*)fn;
@ -351,7 +351,7 @@ void HTMLRenderer::post_process(void)
dump_css();
// close files if they opened
// it's better to brace single liner LLVM complains
if (param->process_outline)
if (param.process_outline)
{
f_outline.fs.close();
}
@ -359,12 +359,12 @@ void HTMLRenderer::post_process(void)
f_css.fs.close();
//only when split-page == 0, do we have some work left to do
if(param->split_pages)
if(param.split_pages)
return;
ofstream output;
{
auto fn = str_fmt("%s/%s", param->dest_dir.c_str(), param->output_filename.c_str());
auto fn = str_fmt("%s/%s", param.dest_dir.c_str(), param.output_filename.c_str());
output.open((char*)fn, ofstream::binary);
if(!output)
throw string("Cannot open ") + (char*)fn + " for writing";
@ -372,7 +372,7 @@ void HTMLRenderer::post_process(void)
}
// apply manifest
ifstream manifest_fin((char*)str_fmt("%s/%s", param->data_dir.c_str(), MANIFEST_FILENAME.c_str()), ifstream::binary);
ifstream manifest_fin((char*)str_fmt("%s/%s", param.data_dir.c_str(), MANIFEST_FILENAME.c_str()), ifstream::binary);
if(!manifest_fin)
throw "Cannot open the manifest file";
@ -400,7 +400,7 @@ void HTMLRenderer::post_process(void)
if(line[0] == '@')
{
embed_file(output, param->data_dir + "/" + line.substr(1), "", true);
embed_file(output, param.data_dir + "/" + line.substr(1), "", true);
continue;
}
@ -412,7 +412,7 @@ void HTMLRenderer::post_process(void)
}
else if (line == "$outline")
{
if (param->process_outline)
if (param.process_outline)
{
ifstream fin(f_outline.path, ifstream::binary);
if(!fin)
@ -487,14 +487,14 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string &
string fn = get_filename(path);
string suffix = (type == "") ? get_suffix(fn) : type;
auto iter = EMBED_STRING_MAP.find(make_pair(suffix, (bool)param->single_html));
auto iter = EMBED_STRING_MAP.find(make_pair(suffix, (bool)param.single_html));
if(iter == EMBED_STRING_MAP.end())
{
cerr << "Warning: unknown suffix: " << suffix << endl;
return;
}
if(param->single_html)
if(param.single_html)
{
ifstream fin(path, ifstream::binary);
if(!fin)
@ -515,7 +515,7 @@ void HTMLRenderer::embed_file(ostream & out, const string & path, const string &
ifstream fin(path, ifstream::binary);
if(!fin)
throw string("Cannot copy file: ") + path;
auto out_path = param->dest_dir + "/" + fn;
auto out_path = param.dest_dir + "/" + fn;
ofstream out(out_path, ofstream::binary);
if(!out)
throw string("Cannot open file ") + path + " for embedding";

View File

@ -379,7 +379,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
}
// fill color
if((!(param->fallback)) && (all_changed || fill_color_changed))
if((!(param.fallback)) && (all_changed || fill_color_changed))
{
// * PDF Spec. Table 106 Text rendering modes
static const char FILL[8] = { true, false, true, false, true, false, true, false };
@ -404,7 +404,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
}
// stroke color
if((!(param->fallback)) && (all_changed || stroke_color_changed))
if((!(param.fallback)) && (all_changed || stroke_color_changed))
{
// * PDF Spec. Table 106 Text rendering modes
static const char STROKE[8] = { false, true, true, false, false, true, true, false };

View File

@ -87,14 +87,14 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
++nSpaces;
}
if(is_space && (param->space_as_offset))
if(is_space && (param.space_as_offset))
{
// ignore horiz_scaling, as it's merged in CTM
text_line_buffers.back()->append_offset((dx1 * cur_font_size + cur_letter_space + cur_word_space) * draw_text_scale);
}
else
{
if((param->decompose_ligature) && (uLen > 1) && all_of(u, u+uLen, isLegalUnicode))
if((param.decompose_ligature) && (uLen > 1) && all_of(u, u+uLen, isLegalUnicode))
{
text_line_buffers.back()->append_unicodes(u, uLen);
// TODO: decomposed characters may be not with the same width as the original ligature, need to fix it.

View File

@ -25,7 +25,7 @@ using std::endl;
using std::flush;
using std::max;
Preprocessor::Preprocessor(const Param * param)
Preprocessor::Preprocessor(const Param & param)
: OutputDev()
, param(param)
, max_width(0)
@ -42,14 +42,14 @@ Preprocessor::~Preprocessor(void)
void Preprocessor::process(PDFDoc * doc)
{
int page_count = (param->last_page - param->first_page + 1);
for(int i = param->first_page; i <= param->last_page ; ++i)
int page_count = (param.last_page - param.first_page + 1);
for(int i = param.first_page; i <= param.last_page ; ++i)
{
cerr << "Preprocessing: " << (i-param->first_page) << "/" << page_count << '\r' << flush;
cerr << "Preprocessing: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
doc->displayPage(this, i, DEFAULT_DPI, DEFAULT_DPI,
0,
(!(param->use_cropbox)),
(!(param.use_cropbox)),
true, // crop
false, // printing
nullptr, nullptr, nullptr, nullptr);

View File

@ -25,7 +25,7 @@ namespace pdf2htmlEX {
class Preprocessor : public OutputDev {
public:
Preprocessor(const Param * param);
Preprocessor(const Param & param);
virtual ~Preprocessor(void);
void process(PDFDoc * doc);
@ -51,7 +51,7 @@ public:
double get_max_height (void) const { return max_height; }
protected:
const Param * param;
const Param & param;
double max_width, max_height;

View File

@ -194,7 +194,7 @@ void TextLineBuffer::flush(ostream & out)
double actual_offset = 0;
//ignore near-zero offsets
if(abs(target) <= param->h_eps)
if(abs(target) <= param.h_eps)
{
actual_offset = 0;
}
@ -205,7 +205,7 @@ void TextLineBuffer::flush(ostream & out)
if(!(state_iter1->hash_umask & State::umask_by_id(State::WORD_SPACE_ID)))
{
double space_off = state_iter1->single_space_offset();
if(abs(target - space_off) <= param->h_eps)
if(abs(target - space_off) <= param.h_eps)
{
Unicode u = ' ';
outputUnicodes(out, &u, 1);
@ -224,7 +224,7 @@ void TextLineBuffer::flush(ostream & out)
if(is_positive(-actual_offset))
last_text_pos_with_negative_offset = cur_text_idx;
double threshold = state_iter1->em_size() * (param->space_threshold);
double threshold = state_iter1->em_size() * (param.space_threshold);
out << "<span class=\"" << CSS::WHITESPACE_CN
<< ' ' << CSS::WHITESPACE_CN << wid << "\">" << (target > (threshold - EPS) ? " " : "") << "</span>";
@ -268,7 +268,7 @@ void TextLineBuffer::flush(ostream & out)
*/
void TextLineBuffer::optimize()
{
if(!(param->optimize_text))
if(!(param.optimize_text))
return;
assert(!states.empty());
@ -395,7 +395,7 @@ void TextLineBuffer::optimize()
// In some PDF files all spaces are converted into positionig shift
// We may try to change (some of) them to ' ' by adjusting word_space
// for now, we cosider only the no-space scenario
// which also includes the case when param->space_as_offset is set
// which also includes the case when param.space_as_offset is set
// get the text segment covered by current state (*state_iter1)
const auto text_iter1 = text.begin() + text_idx1;
@ -408,7 +408,7 @@ void TextLineBuffer::optimize()
if(offset_count > 0)
{
double threshold = (state_iter1->em_size()) * (param->space_threshold);
double threshold = (state_iter1->em_size()) * (param.space_threshold);
// set word_space for the most frequently used offset
double most_used_width = 0;
size_t max_count = 0;

View File

@ -22,7 +22,7 @@ namespace pdf2htmlEX {
class TextLineBuffer
{
public:
TextLineBuffer (const Param * param, AllStateManater & all_manager)
TextLineBuffer (const Param & param, AllStateManater & all_manager)
: param(param), all_manager(all_manager) { }
class State : public HTMLState {
@ -84,7 +84,7 @@ public:
private:
void optimize(void);
const Param * param;
const Param & param;
AllStateManater & all_manager;
double x, y;

View File

@ -10,10 +10,11 @@
#include <string>
#include <limits>
#include <iostream>
#include <memory>
#include <getopt.h>
#include <poppler-config.h>
#include <goo/GooString.h>
#include <Object.h>
@ -282,9 +283,7 @@ int main(int argc, char **argv)
}
HTMLRenderer * htmlOut = new HTMLRenderer(&param);
htmlOut->process(doc);
delete htmlOut;
unique_ptr<HTMLRenderer>(new HTMLRenderer(param))->process(doc);
finished = true;
}
@ -298,8 +297,8 @@ int main(int argc, char **argv)
}
// clean up
if(doc) delete doc;
if(globalParams) delete globalParams;
delete doc;
delete globalParams;
// check for memory leaks
Object::memCheck(stderr);