Commit cdf62386 authored by sgerwk's avatar sgerwk Committed by Albert Astals Cid

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

parent 5927e0b0
......@@ -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,
......
......@@ -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)
......@@ -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);
}
}
}
......
......@@ -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);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment