1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

Merge branch 'master' into devv

This commit is contained in:
Lu Wang 2012-11-16 20:18:25 +08:00
commit d76afd3836
4 changed files with 58 additions and 54 deletions

View File

@ -1,4 +1,4 @@
# pdf2html**EX** # pdf2htmlEX
A beautiful demo is worth a thousand words: A beautiful demo is worth a thousand words:
@ -149,11 +149,12 @@ pdf2htmlEX is inspired by the following projects:
## Contact ## Contact
* Lu Wang <coolwanglu@gmail.com> * Mailing list <pdf2htmlex@googlegroups.com>
* Suggestions and questions are **welcome**. * Please read [**FAQ**](https://github.com/coolwanglu/pdf2htmlEX/wiki/FAQ) before sending emails. Or your message might be ignored.
* Please read [**FAQ**](https://github.com/coolwanglu/pdf2htmlEX/wiki/FAQ) before sending an email to me. Or your message might be ignored.
* Please use the **latest master branch**. * Please use the **latest master branch**.
* Expect me to be much more user-friendly than pdf2htmlEX.
* Lu Wang <coolwanglu@gmail.com>
* Please use the mailing list above unless for personal enquiries.
* Accepting messages in **Chinese**, **English** or **Japanese**. * Accepting messages in **Chinese**, **English** or **Japanese**.

View File

@ -47,42 +47,6 @@ HTMLRenderer::HTMLRenderer(const Param * param)
setErrorCallback(&dummy, nullptr); setErrorCallback(&dummy, nullptr);
} }
/*
* determine scale factors
*/
{
double zoom = 1.0;
vector<double> zoom_factors;
if(_is_positive(param->zoom))
{
zoom_factors.push_back(param->zoom);
}
if(_is_positive(param->fit_width))
{
zoom_factors.push_back((param->fit_width) / preprocessor.get_max_width());
}
if(_is_positive(param->fit_height))
{
zoom_factors.push_back((param->fit_height) / preprocessor.get_max_height());
}
if(zoom_factors.empty())
{
zoom = 1.0;
}
else
{
zoom = *min_element(zoom_factors.begin(), zoom_factors.end());
}
text_scale_factor1 = max<double>(zoom, param->font_size_multiplier);
text_scale_factor2 = zoom / text_scale_factor1;
}
ffw_init(param->debug); ffw_init(param->debug);
cur_mapping = new int32_t [0x10000]; cur_mapping = new int32_t [0x10000];
cur_mapping2 = new char* [0x100]; cur_mapping2 = new char* [0x100];
@ -103,12 +67,8 @@ void HTMLRenderer::process(PDFDoc *doc)
cur_doc = doc; cur_doc = doc;
xref = doc->getXRef(); xref = doc->getXRef();
cerr << "Preprocessing: "; pre_process(doc);
preprocessor.process(doc);
cerr << "Working: ";
BackgroundRenderer * bg_renderer = nullptr; BackgroundRenderer * bg_renderer = nullptr;
if(param->process_nontext) if(param->process_nontext)
{ {
@ -116,10 +76,11 @@ void HTMLRenderer::process(PDFDoc *doc)
bg_renderer->startDoc(doc); bg_renderer->startDoc(doc);
} }
pre_process(); int page_count = (param->last_page - param->first_page);
for(int i = param->first_page; i <= param->last_page ; ++i) for(int i = param->first_page; i <= param->last_page ; ++i)
{ {
cerr << "Working: " << (i-param->first_page) << "/" << page_count << '\r' << flush;
if(param->split_pages) if(param->split_pages)
{ {
auto page_fn = str_fmt("%s/%s%d.page", param->dest_dir.c_str(), param->output_filename.c_str(), i); auto page_fn = str_fmt("%s/%s%d.page", param->dest_dir.c_str(), param->output_filename.c_str(), i);
@ -147,9 +108,10 @@ void HTMLRenderer::process(PDFDoc *doc)
{ {
html_fout.close(); html_fout.close();
} }
cerr << "." << flush;
} }
if(page_count >= 0)
cerr << "Working: " << page_count << "/" << page_count;
cerr << endl;
post_process(); post_process();
@ -258,8 +220,46 @@ void HTMLRenderer::endPage() {
html_fout << "</div></div>" << endl; html_fout << "</div></div>" << endl;
} }
void HTMLRenderer::pre_process() void HTMLRenderer::pre_process(PDFDoc * doc)
{ {
preprocessor.process(doc);
/*
* determine scale factors
*/
{
double zoom = 1.0;
vector<double> zoom_factors;
if(_is_positive(param->zoom))
{
zoom_factors.push_back(param->zoom);
}
if(_is_positive(param->fit_width))
{
zoom_factors.push_back((param->fit_width) / preprocessor.get_max_width());
}
if(_is_positive(param->fit_height))
{
zoom_factors.push_back((param->fit_height) / preprocessor.get_max_height());
}
if(zoom_factors.empty())
{
zoom = 1.0;
}
else
{
zoom = *min_element(zoom_factors.begin(), zoom_factors.end());
}
text_scale_factor1 = max<double>(zoom, param->font_size_multiplier);
text_scale_factor2 = zoom / text_scale_factor1;
}
// we may output utf8 characters, so always use binary // we may output utf8 characters, so always use binary
{ {
/* /*

View File

@ -41,14 +41,17 @@ Preprocessor::~Preprocessor(void)
void Preprocessor::process(PDFDoc * doc) void Preprocessor::process(PDFDoc * doc)
{ {
int page_count = (param->last_page - param->first_page);
for(int i = param->first_page; i <= param->last_page ; ++i) for(int i = param->first_page; i <= param->last_page ; ++i)
{ {
cerr << "Preprocessing: " << (i-param->first_page) << "/" << page_count << '\r' << flush;
doc->displayPage(this, i, DEFAULT_DPI, DEFAULT_DPI, doc->displayPage(this, i, DEFAULT_DPI, DEFAULT_DPI,
0, true, false, false, 0, true, false, false,
nullptr, nullptr, nullptr, nullptr); nullptr, nullptr, nullptr, nullptr);
cerr << "." << flush;
} }
if(page_count >= 0)
cerr << "Preprocessing: " << page_count << "/" << page_count;
cerr << endl; cerr << endl;
} }

View File

@ -150,7 +150,7 @@ class HTMLRenderer : public OutputDev
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// misc // misc
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
void pre_process(); void pre_process(PDFDoc * doc);
void post_process(); void post_process();
// set flags // set flags