[poppler] 2 commits - glib/poppler-page.cc glib/tests poppler/BBoxOutputDev.cc poppler/BBoxOutputDev.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat May 23 18:22:13 UTC 2020


 glib/poppler-page.cc      |   10 ++---
 glib/tests/CMakeLists.txt |   10 +++--
 poppler/BBoxOutputDev.cc  |   78 +++++++++++++++-------------------------------
 poppler/BBoxOutputDev.h   |   13 +------
 4 files changed, 40 insertions(+), 71 deletions(-)

New commits:
commit e4ac9761a269805cc8510a11b47e2381ad668215
Author: sgerwk <sgerwk>
Date:   Sat May 23 10:37:01 2020 +0200

    include annotations in the bounding box

diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 33023998..c3002b91 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -2227,7 +2227,6 @@ poppler_page_get_crop_box (PopplerPage *page, PopplerRectangle *rect)
 gboolean
 poppler_page_get_bounding_box (PopplerPage *page,
                                PopplerRectangle *rect) {
-  Gfx *gfx;
   BBoxOutputDev *bb_out;
   bool hasGraphics;
 
@@ -2236,14 +2235,14 @@ poppler_page_get_bounding_box (PopplerPage *page,
 
   bb_out = new BBoxOutputDev();
 
-  gfx = page->page->createGfx(bb_out,
+  page->page->displaySlice(bb_out,
                               72.0, 72.0, 0,
                               false, /* useMediaBox */
                               true, /* Crop */
                               -1, -1, -1, -1,
                               false, /* printing */
-                              nullptr, nullptr);
-  page->page->display(gfx);
+                              nullptr, nullptr,
+			      nullptr, nullptr);
   hasGraphics = bb_out->getHasGraphics();
   if (hasGraphics) {
     rect->x1 = bb_out->getX1();
@@ -2252,7 +2251,6 @@ poppler_page_get_bounding_box (PopplerPage *page,
     rect->y2 = bb_out->getY2();
   }
 
-  delete gfx;
   delete bb_out;
   return hasGraphics;
 }
diff --git a/glib/tests/CMakeLists.txt b/glib/tests/CMakeLists.txt
index 10b65b57..591c5982 100644
--- a/glib/tests/CMakeLists.txt
+++ b/glib/tests/CMakeLists.txt
@@ -22,7 +22,7 @@ poppler_add_test(poppler-check-bb BUILD_GTK_TESTS ${poppler_check_bb_SRCS})
 target_link_libraries(poppler-check-bb poppler-glib ${GTK3_LIBRARIES})
 poppler_add_testcase(poppler-check-bb shapes+attachments.pdf 42.5 42.5 557.5 557.5)
 poppler_add_testcase(poppler-check-bb orientation.pdf 34 34 83.74 49 793 34 808 97.19 488.02 793 561 808 34 503.61 49 56)
-poppler_add_testcase(poppler-check-bb xr01.pdf 148.71 127.85 308.11 704.57)
+poppler_add_testcase(poppler-check-bb xr01.pdf 148.71 126.35 308.11 704.57)
 poppler_add_testcase(poppler-check-bb xr02.pdf 133.77 124.81 308.11 704.57 133.77 124.80 308.11 704.57)
 poppler_add_testcase(poppler-check-bb russian.pdf 71.5 76.81 197.69 131.09)
 poppler_add_testcase(poppler-check-bb vis_policy_test.pdf 90 77.93 312.01 265.13)
@@ -38,6 +38,8 @@ poppler_add_testcase(poppler-check-bb imageretrieve+attachment.pdf 0 0 610.56 79
 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 0 191 612 792)
 poppler_add_testcase(poppler-check-bb A6EmbeddedFiles.pdf 18 18 558.36 751.92)
+poppler_add_testcase(poppler-check-bb latex-hyperref-checkbox-issue-655.pdf 148.71 123.81 308.11 704.57)
+poppler_add_testcase(poppler-check-bb utf16le-annot.pdf 52.98 55.61 101.23 95.29)
 
 add_executable(pdfdrawbb pdfdrawbb.c)
 target_link_libraries(pdfdrawbb poppler-glib)
commit cdf623865df5343425c2eaea49124c6b45529bea
Author: sgerwk <sgerwk>
Date:   Sat May 23 09:49:31 2020 +0200

    use state->getClipBBox() instead of tracking the clipping box

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);
 };
 


More information about the poppler mailing list