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

Make SplashBackgroundRenderer working with --process-covered-text

This commit is contained in:
Duan Yao 2014-06-17 17:05:01 +08:00
parent 55d45acd32
commit a5ac6b4d0d
5 changed files with 26 additions and 19 deletions

View File

@ -88,6 +88,13 @@ void SplashBackgroundRenderer::drawChar(GfxState *state, double x, double y,
{ {
SplashOutputDev::drawChar(state,x,y,dx,dy,originX,originY,code,nBytes,u,uLen); SplashOutputDev::drawChar(state,x,y,dx,dy,originX,originY,code,nBytes,u,uLen);
} }
// If a char is treated as image, it is not subject to cover test
// (see HTMLRenderer::drawString), so don't increase drawn_char_count.
else if (param.process_covered_text) {
if (html_renderer->get_chars_covered()[drawn_char_count])
SplashOutputDev::drawChar(state,x,y,dx,dy,originX,originY,code,nBytes,u,uLen);
drawn_char_count++;
}
} }
void SplashBackgroundRenderer::beginTextObject(GfxState *state) void SplashBackgroundRenderer::beginTextObject(GfxState *state)
@ -122,6 +129,7 @@ static GBool annot_cb(Annot *, void * pflag) {
bool SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno) bool SplashBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
{ {
drawn_char_count = 0;
bool process_annotation = param.process_annotation; bool process_annotation = param.process_annotation;
doc->displayPage(this, pageno, param.h_dpi, param.v_dpi, doc->displayPage(this, pageno, param.h_dpi, param.v_dpi,
0, 0,

View File

@ -70,6 +70,7 @@ protected:
HTMLRenderer * html_renderer; HTMLRenderer * html_renderer;
const Param & param; const Param & param;
std::string format; std::string format;
int drawn_char_count;
}; };
} // namespace pdf2htmlEX } // namespace pdf2htmlEX

View File

@ -347,7 +347,6 @@ protected:
#endif #endif
BackgroundRenderer * bg_renderer; BackgroundRenderer * bg_renderer;
BackgroundRenderer * fallback_bg_renderer; BackgroundRenderer * fallback_bg_renderer;
bool fallback_bg_required;
struct { struct {
std::ofstream fs; std::ofstream fs;

View File

@ -153,12 +153,7 @@ void HTMLRenderer::process(PDFDoc *doc)
false, // printing false, // printing
nullptr, nullptr, nullptr, nullptr); nullptr, nullptr, nullptr, nullptr);
if(param.process_nontext)
{
fallback_bg_required = !bg_renderer->render_page(doc, i);
if (fallback_bg_required && fallback_bg_renderer != nullptr)
fallback_bg_renderer->render_page(doc, i);
}
if(param.split_pages) if(param.split_pages)
{ {
@ -207,13 +202,15 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
this->pageNum = pageNum; this->pageNum = pageNum;
double pageWidth = state->getPageWidth(); html_text_page.set_page_size(state->getPageWidth(), state->getPageHeight());
double pageHeight = state->getPageHeight();
html_text_page.set_page_size(pageWidth, pageHeight); reset_state();
}
void HTMLRenderer::endPage() {
long long wid = all_manager.width.install(html_text_page.get_width());
long long hid = all_manager.height.install(html_text_page.get_height());
long long wid = all_manager.width.install(pageWidth);
long long hid = all_manager.height.install(pageHeight);
(*f_curpage) (*f_curpage)
<< "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum << "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum
<< "\" class=\"" << CSS::PAGE_FRAME_CN << "\" class=\"" << CSS::PAGE_FRAME_CN
@ -246,16 +243,15 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
if(param.process_nontext) if(param.process_nontext)
{ {
if (!fallback_bg_required) if (bg_renderer->render_page(cur_doc, pageNum))
bg_renderer->embed_image(pageNum); bg_renderer->embed_image(pageNum);
else if (fallback_bg_renderer != nullptr) else
fallback_bg_renderer->embed_image(pageNum); {
if (fallback_bg_renderer->render_page(cur_doc, pageNum))
fallback_bg_renderer->embed_image(pageNum);
}
} }
reset_state();
}
void HTMLRenderer::endPage() {
// dump all text // dump all text
html_text_page.dump_text(*f_curpage); html_text_page.dump_text(*f_curpage);
html_text_page.dump_css(f_css.fs); html_text_page.dump_css(f_css.fs);

View File

@ -39,6 +39,9 @@ public:
void set_page_size(double width, double height); void set_page_size(double width, double height);
void clip(const HTMLClipState & clip_state); void clip(const HTMLClipState & clip_state);
double get_width() { return page_width; }
double get_height() { return page_height; }
private: private:
void optimize(void); void optimize(void);