Skip to content

Commit

Permalink
page cache
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Jan 2, 2025
1 parent 276ea93 commit 6e041d0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
14 changes: 7 additions & 7 deletions pdf2htmlEX/src/CoveredTextDetector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace pdf2htmlEX {

CoveredTextDetector::CoveredTextDetector(Param & param): param(param)
CoveredTextDetector::CoveredTextDetector(Param & param): param(&param)
{
}

Expand All @@ -41,10 +41,10 @@ void CoveredTextDetector::add_char_bbox_clipped(cairo_t *cairo, double * bbox, i
char_pts_visible.push_back(pts_visible);

// DCRH: Hide if no points are visible, or if some points are visible and correct_text_visibility == 2
if (pts_visible == 0 || param.correct_text_visibility == 2) {
if (pts_visible == 0 || param->correct_text_visibility == 2) {
chars_covered.push_back(true);
if (pts_visible > 0 && param.correct_text_visibility == 2) {
param.actual_dpi = std::min(param.text_dpi, param.max_dpi); // Char partially covered so increase background resolution
if (pts_visible > 0 && param->correct_text_visibility == 2) {
param->actual_dpi = std::min(param->text_dpi, param->max_dpi); // Char partially covered so increase background resolution
}
} else {
chars_covered.push_back(false);
Expand Down Expand Up @@ -98,13 +98,13 @@ printf("pts_visible=%x\n", pts_visible);
printf("pts_visible=%x\n", pts_visible);
#endif
char_pts_visible[i] = pts_visible;
if (pts_visible == 0 || (pts_visible != (1|2|4|8) && param.correct_text_visibility == 2)) {
if (pts_visible == 0 || (pts_visible != (1|2|4|8) && param->correct_text_visibility == 2)) {
#ifdef DEBUG
printf("Char covered\n");
#endif
chars_covered[i] = true;
if (pts_visible > 0 && param.correct_text_visibility == 2) { // Partially visible text => increase rendering DPI
param.actual_dpi = std::min(param.text_dpi, param.max_dpi);
if (pts_visible > 0 && param->correct_text_visibility == 2) { // Partially visible text => increase rendering DPI
param->actual_dpi = std::min(param->text_dpi, param->max_dpi);
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion pdf2htmlEX/src/CoveredTextDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CoveredTextDetector
// x00, y00, x01, y01; x10, y10, x11, y11;...
std::vector<double> char_bboxes;
std::vector<int> char_pts_visible;
Param & param;
Param * param;
};

}
Expand Down
5 changes: 5 additions & 0 deletions pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ struct HTMLRenderer : OutputDev

CoveredTextDetector covered_text_detector;
DrawingTracer tracer;

struct PageCache {
CoveredTextDetector covered_text_detector;
};
std::unordered_map<int, PageCache> page_cache;
};

} //namespace pdf2htmlEX
Expand Down
26 changes: 26 additions & 0 deletions pdf2htmlEX/src/HTMLRenderer/general.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,31 @@ void HTMLRenderer::process(PDFDoc *doc)

post_process();

if (param.delay_background == 0)
{
bg_renderer = nullptr;
fallback_bg_renderer = nullptr;
}

if(param.quiet == 0)
cerr << endl;
}

bool HTMLRenderer::renderPage(PDFDoc *doc, int pageno)
{
if (param.delay_background == 0)
{
return false;
}

if (page_cache.find(pageno) != page_cache.end())
{
cerr << "Page number " << pageno << " not found in page cache" << endl;
return false;
}

covered_text_detector = page_cache[pageno].covered_text_detector;

if (bg_renderer->render_page(cur_doc, pageno))
{
return true;
Expand All @@ -209,6 +228,13 @@ void HTMLRenderer::setDefaultCTM(const double *ctm)

void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
{
if (param.delay_background && this->pageNum > 0)
{
page_cache[this->pageNum] = {
.covered_text_detector = covered_text_detector,
};
}

covered_text_detector.reset();
tracer.reset(state);

Expand Down

0 comments on commit 6e041d0

Please sign in to comment.