[poppler] glib/tests poppler/BBoxOutputDev.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 30 18:13:27 UTC 2020


 glib/tests/CMakeLists.txt |    1 
 glib/tests/check_bb.c     |   22 +++++++++++++------
 poppler/BBoxOutputDev.cc  |   51 +++++++++++++++++++++++-----------------------
 3 files changed, 42 insertions(+), 32 deletions(-)

New commits:
commit 69794176c8be5ebfa2a60d1261c8532695d18681
Author: sgerwk <sgerwk at aol.com>
Date:   Tue Jun 30 18:13:26 2020 +0000

    fix boundingbox of type3 fonts

diff --git a/glib/tests/CMakeLists.txt b/glib/tests/CMakeLists.txt
index 591c5982..ee3dbb44 100644
--- a/glib/tests/CMakeLists.txt
+++ b/glib/tests/CMakeLists.txt
@@ -40,6 +40,7 @@ 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)
+poppler_add_testcase(poppler-check-bb type3.pdf -p 10 125.80 130 509.30 695 125.80 132 538.03 693)
 
 add_executable(pdfdrawbb pdfdrawbb.c)
 target_link_libraries(pdfdrawbb poppler-glib)
diff --git a/glib/tests/check_bb.c b/glib/tests/check_bb.c
index 3170299a..5ef9f95d 100644
--- a/glib/tests/check_bb.c
+++ b/glib/tests/check_bb.c
@@ -12,8 +12,8 @@
 /*
  * compare floating-point coordinates
  */
-int equal(double a, double b) {
-	return fabs(a - b) < 0.01;
+int equal(double a, double b, double precision) {
+	return fabs(a - b) < precision;
 }
 
 /*
@@ -28,6 +28,7 @@ int main(int argc, char *argv[]) {
 	PopplerRectangle bb, correct;
 	GError *err = NULL;
 	int argx;
+	double precision = 0.01;
 
 				/* open file */
 
@@ -43,6 +44,14 @@ int main(int argc, char *argv[]) {
 		exit(EXIT_FAILURE);
 	}
 
+				/* precision */
+
+	argx = 2;
+	if (! strcmp(argv[argx], "-p")) {
+		precision = atof(argv[argx + 1]);
+		argx += 2;
+	}
+
 				/* pages */
 
 	npages = poppler_document_get_n_pages(doc);
@@ -53,7 +62,6 @@ int main(int argc, char *argv[]) {
 
 				/* check the bounding box */
 
-	argx = 2;
 	for (n = 0; n < poppler_document_get_n_pages(doc); n++) {
 		g_print("    page: %d\n", n + 1);
 
@@ -76,10 +84,10 @@ int main(int argc, char *argv[]) {
 		correct.y2 = atof(argv[argx++]);
 		g_print("        correct:      %g,%g - %g,%g\n",
 			correct.x1, correct.y1, correct.x2, correct.y2);
-		if (! equal(bb.x1, correct.x1) ||
-		    ! equal(bb.x2, correct.x2) ||
-		    ! equal(bb.y1, correct.y1) ||
-		    ! equal(bb.x2, correct.x2)) {
+		if (! equal(bb.x1, correct.x1, precision) ||
+		    ! equal(bb.x2, correct.x2, precision) ||
+		    ! equal(bb.y1, correct.y1, precision) ||
+		    ! equal(bb.x2, correct.x2, precision)) {
 			g_print("bounding box differs from expected\n");
 			exit(EXIT_FAILURE);
 		}
diff --git a/poppler/BBoxOutputDev.cc b/poppler/BBoxOutputDev.cc
index b37f21c9..f909e7eb 100644
--- a/poppler/BBoxOutputDev.cc
+++ b/poppler/BBoxOutputDev.cc
@@ -110,9 +110,8 @@ void BBoxOutputDev::drawChar(GfxState *state,
 	GfxFont *font;
 	double leftent, rightent, ascent, descent;
 	const double *fm, *fb;
-	Matrix fmat;
-	double fontSize;
-	double fx, fy, nx, ny;
+	double fontSize, w, adjust;
+	double fx, fy;
 
 	if (! text)
 		return;
@@ -126,13 +125,6 @@ void BBoxOutputDev::drawChar(GfxState *state,
 
 	fontSize = state->getFontSize();
 
-	if (font->getType() != fontType3)
-		fmat.init(1, 0, 0, 1, 0, 0);
-	else {
-		fm = font->getFontMatrix();
-		fmat.init(fm[0], fm[1], fm[2], fm[3], fm[4], fm[5]);
-	}
-
 	fb = font->getFontBBox();
 	if (font->getWMode() == writingModeHorizontal) {
 		leftent = 0;
@@ -152,26 +144,35 @@ void BBoxOutputDev::drawChar(GfxState *state,
 		ascent = 0;
 		descent = 0;
 	}
-	if (font->getType() == fontType3) {
-		ascent *= 1000;
-		descent *= 1000;
+
+	if (font->getType() != fontType3)
+		adjust = 1;
+	else {
+		// adjust font size for type3 fonts,
+		// similar to TextPage::updateFont()
+		w = ((Gfx8BitFont *) font)->getWidth(code);
+		adjust = w / 0.5;
+		fm = font->getFontMatrix();
+		if (fm[0] != 0)
+			adjust *= fabs(fm[3] / fm[0]);
 	}
 
-	fmat.transform(leftent, descent, &fx, &fy);
-	state->textTransformDelta(fx, fy, &nx, &ny);
-	updatePoint(&bb, nx + x, ny + y, state);
+	ascent *= adjust * fontSize;
+	descent *= adjust * fontSize;
+	leftent *= adjust * fontSize;
+	rightent *= adjust * fontSize;
+
+	state->textTransformDelta(leftent, descent, &fx, &fy);
+	updatePoint(&bb, fx + x, fy + y, state);
 
-	fmat.transform(rightent, ascent, &fx, &fy);
-	state->textTransformDelta(fx, fy, &nx, &ny);
-	updatePoint(&bb, nx + x, ny + y, state);
+	state->textTransformDelta(rightent, ascent, &fx, &fy);
+	updatePoint(&bb, fx + x, fy + y, state);
 
-	fmat.transform(leftent * fontSize, descent * fontSize, &fx, &fy);
-	state->textTransformDelta(fx, fy, &nx, &ny);
-	updatePoint(&bb, nx + x + dx, ny + y + dy, state);
+	state->textTransformDelta(leftent, descent, &fx, &fy);
+	updatePoint(&bb, fx + x + dx, fy + y + dy, state);
 
-	fmat.transform(rightent * fontSize, ascent * fontSize, &fx, &fy);
-	state->textTransformDelta(fx, fy, &nx, &ny);
-	updatePoint(&bb, nx + x + dx, ny + y + dy, state);
+	state->textTransformDelta(rightent, ascent, &fx, &fy);
+	updatePoint(&bb, fx + x + dx, fy + y + dy, state);
 }
 
 /* update the bounding box with a new point */


More information about the poppler mailing list