diff options
author | sgerwk <sgerwk> | 2020-05-23 09:49:31 +0200 |
---|---|---|
committer | Albert Astals Cid <tsdgeos@yahoo.es> | 2020-05-23 18:14:56 +0000 |
commit | cdf623865df5343425c2eaea49124c6b45529bea (patch) | |
tree | e976dc95e784ce4a729dbd570a1dbb53f802d436 | |
parent | 5927e0b08f1ad6868d04cb209ee1e17b4ac07b70 (diff) |
use state->getClipBBox() instead of tracking the clipping box
-rw-r--r-- | glib/poppler-page.cc | 2 | ||||
-rw-r--r-- | glib/tests/CMakeLists.txt | 6 | ||||
-rw-r--r-- | poppler/BBoxOutputDev.cc | 78 | ||||
-rw-r--r-- | poppler/BBoxOutputDev.h | 13 |
4 files changed, 34 insertions, 65 deletions
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 7723af16..33023998 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -2234,7 +2234,7 @@ poppler_page_get_bounding_box (PopplerPage *page, g_return_val_if_fail(POPPLER_IS_PAGE (page), false); g_return_val_if_fail(rect != nullptr, false); - bb_out = new BBoxOutputDev(page->page->getCropBox()); + bb_out = new BBoxOutputDev(); gfx = page->page->createGfx(bb_out, 72.0, 72.0, 0, diff --git a/glib/tests/CMakeLists.txt b/glib/tests/CMakeLists.txt index ff776918..10b65b57 100644 --- a/glib/tests/CMakeLists.txt +++ b/glib/tests/CMakeLists.txt @@ -33,11 +33,11 @@ poppler_add_testcase(poppler-check-bb bug7063.pdf 56.8 57.46 244.29 118.79) poppler_add_testcase(poppler-check-bb WithActualText.pdf 100 90.72 331.01 102.35) poppler_add_testcase(poppler-check-bb Issue637.pdf 70.87 53 293 105.37) poppler_add_testcase(poppler-check-bb truetype.pdf 17.5 17.5 577.5 225.62) -poppler_add_testcase(poppler-check-bb form_set_icon.pdf -0.5 -0.5 363.34 272.63) +poppler_add_testcase(poppler-check-bb form_set_icon.pdf 0 0 362.835 272.126) poppler_add_testcase(poppler-check-bb imageretrieve+attachment.pdf 0 0 610.56 792) poppler_add_testcase(poppler-check-bb checkbox_issue_159.pdf 2.84 14.17 553.18 840.87) -poppler_add_testcase(poppler-check-bb NestedLayers.pdf -1 191 613 793) -poppler_add_testcase(poppler-check-bb A6EmbeddedFiles.pdf 17.88 17.88 558.36 755.73) +poppler_add_testcase(poppler-check-bb NestedLayers.pdf 0 191 612 792) +poppler_add_testcase(poppler-check-bb A6EmbeddedFiles.pdf 18 18 558.36 751.92) add_executable(pdfdrawbb pdfdrawbb.c) target_link_libraries(pdfdrawbb poppler-glib) diff --git a/poppler/BBoxOutputDev.cc b/poppler/BBoxOutputDev.cc index c45ce0a8..b37f21c9 100644 --- a/poppler/BBoxOutputDev.cc +++ b/poppler/BBoxOutputDev.cc @@ -15,19 +15,17 @@ #define writingModeHorizontal 0 #define writingModeVertical 1 -BBoxOutputDev::BBoxOutputDev(const PDFRectangle *cropA) : - BBoxOutputDev(cropA, true, true, true) { +BBoxOutputDev::BBoxOutputDev() : + BBoxOutputDev(true, true, true) { } -BBoxOutputDev::BBoxOutputDev(const PDFRectangle *cropA, - bool textA, bool vectorA, bool rasterA) : - BBoxOutputDev(cropA, textA, vectorA, rasterA, true) { +BBoxOutputDev::BBoxOutputDev(bool textA, bool vectorA, bool rasterA) : + BBoxOutputDev(textA, vectorA, rasterA, true) { } -BBoxOutputDev::BBoxOutputDev(const PDFRectangle *cropA, - bool textA, bool vectorA, bool rasterA, bool lwidthA) { +BBoxOutputDev::BBoxOutputDev(bool textA, bool vectorA, bool rasterA, + bool lwidthA) { hasGraphics = false; - crop = *cropA; text = textA; vector = vectorA; raster = rasterA; @@ -55,7 +53,6 @@ double BBoxOutputDev::getHasGraphics() const { } void BBoxOutputDev::endPage() { - bb.clipTo(&crop); } void BBoxOutputDev::stroke(GfxState *state) { @@ -177,49 +174,31 @@ void BBoxOutputDev::drawChar(GfxState *state, updatePoint(&bb, nx + x + dx, ny + y + dy, state); } -void BBoxOutputDev::clip(GfxState *state) { - updateClip(state); -} - -void BBoxOutputDev::eoClip(GfxState *state) { - updateClip(state); -} - -void BBoxOutputDev::clipToStrokePath(GfxState *state) { - updateClip(state); -} - -/* update the crop box with a new path */ -void BBoxOutputDev::updateClip(const GfxState *state) { - PDFRectangle box; - bool hg; - hg = hasGraphics; - hasGraphics = true; - updatePath(&box, state->getPath(), state); - hasGraphics = hg; - crop.clipTo(&box); -} - /* update the bounding box with a new point */ void BBoxOutputDev::updatePoint(PDFRectangle *bbA, double x, double y, const GfxState *state) { Matrix o = {1, 0, 0, 1, 0, 0}; - double tx, ty, fx, fy; + double tx, ty; + double xMin, yMin, xMax, yMax; + + state->getClipBBox(&xMin, &yMin, &xMax, &yMax); o.scale(1, -1); o.translate(0, -state->getPageHeight()); state->transform(x, y, &tx, &ty); - o.transform(tx, ty, &fx, &fy); - - if (! hasGraphics || bbA->x1 > fx) - bbA->x1 = fx; - if (! hasGraphics || bbA->y1 > fy) - bbA->y1 = fy; - if (! hasGraphics || bbA->x2 < fx) - bbA->x2 = fx; - if (! hasGraphics || bbA->y2 < fy) - bbA->y2 = fy; + tx = tx < xMin ? xMin : tx > xMax ? xMax : tx; + ty = ty < yMin ? yMin : ty > yMax ? yMax : ty; + o.transform(tx, ty, &x, &y); + + if (! hasGraphics || bbA->x1 > x) + bbA->x1 = x; + if (! hasGraphics || bbA->y1 > y) + bbA->y1 = y; + if (! hasGraphics || bbA->x2 < x) + bbA->x2 = x; + if (! hasGraphics || bbA->y2 < y) + bbA->y2 = y; hasGraphics = true; } @@ -228,6 +207,7 @@ void BBoxOutputDev::updatePath(PDFRectangle *bbA, const GfxPath *path, const GfxState *state) { int i, j; const GfxSubpath *subpath; + double x, y; double w; if (! vector) return; @@ -235,14 +215,10 @@ void BBoxOutputDev::updatePath(PDFRectangle *bbA, for (i = 0; i < path->getNumSubpaths(); i++) { subpath = path->getSubpath(i); for (j = 0; j < subpath->getNumPoints(); j++) { - updatePoint(bbA, - subpath->getX(j) - w / 2, - subpath->getY(j) - w / 2, - state); - updatePoint(bbA, - subpath->getX(j) + w / 2, - subpath->getY(j) + w / 2, - state); + x = subpath->getX(j); + y = subpath->getY(j); + updatePoint(bbA, x - w / 2, y - w / 2, state); + updatePoint(bbA, x + w / 2, y + w / 2, state); } } } diff --git a/poppler/BBoxOutputDev.h b/poppler/BBoxOutputDev.h index b43da46c..97331388 100644 --- a/poppler/BBoxOutputDev.h +++ b/poppler/BBoxOutputDev.h @@ -18,11 +18,9 @@ public: bool useDrawChar() override { return true; } bool interpretType3Chars() override { return false; } - BBoxOutputDev(const PDFRectangle *cropA); - BBoxOutputDev(const PDFRectangle *cropA, - bool text, bool vector, bool raster); - BBoxOutputDev(const PDFRectangle *cropA, - bool text, bool vector, bool raster, bool lwidth); + BBoxOutputDev(); + BBoxOutputDev(bool text, bool vector, bool raster); + BBoxOutputDev(bool text, bool vector, bool raster, bool lwidth); void endPage() override; void stroke(GfxState *state) override; void fill(GfxState *state) override; @@ -53,9 +51,6 @@ public: int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap, bool maskInterpolate) override; - void clip(GfxState *state) override; - void eoClip(GfxState *state) override; - void clipToStrokePath(GfxState *state) override; double getX1() const; double getY1() const; @@ -65,7 +60,6 @@ public: private: PDFRectangle bb; - PDFRectangle crop; bool hasGraphics; bool text; @@ -78,6 +72,5 @@ private: void updatePath(PDFRectangle *bbA, const GfxPath *path, const GfxState *state); void updateImage(PDFRectangle *bbA, const GfxState *state); - void updateClip(const GfxState *state); }; |