[poppler] 3 commits - poppler/Annot.cc poppler/Annot.h poppler/Gfx.cc poppler/Gfx.h test/pdf-inspector.cc
Carlos Garcia Campos
carlosgc at kemper.freedesktop.org
Sat Jul 10 07:04:01 PDT 2010
poppler/Annot.cc | 384 +++++++++++++++++++++++---------------------------
poppler/Annot.h | 3
poppler/Gfx.cc | 9 -
poppler/Gfx.h | 2
test/pdf-inspector.cc | 3
5 files changed, 188 insertions(+), 213 deletions(-)
New commits:
commit 5e4d8eeea0b9dba68420c164975418c76a53be85
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Sat Jul 10 15:54:28 2010 +0200
[pdf-inspector] Do not render for printing
diff --git a/test/pdf-inspector.cc b/test/pdf-inspector.cc
index 24bebbd..d4a564d 100644
--- a/test/pdf-inspector.cc
+++ b/test/pdf-inspector.cc
@@ -132,6 +132,7 @@ PdfInspector::PdfInspector(void)
}
doc = NULL;
output = new CairoOutputDev();
+ output->setPrinting (gFalse);
// set up initial widgets
load (NULL);
@@ -236,7 +237,7 @@ PdfInspector::analyze_page (int page)
cairo_surface_destroy (surface);
output->setCairo (cr);
cairo_destroy (cr);
- doc->displayPage (output, page + 1, 72, 72, 0, gFalse, gTrue, gTrue);
+ doc->displayPage (output, page + 1, 72, 72, 0, gFalse, gTrue, gFalse);
output->setCairo (NULL);
// Total time;
commit e6824972a213a888ca0185b7ae0a75fc23f75797
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Sat Jul 10 15:52:15 2010 +0200
[annots] Use a transparency group for markup annots without AP and opacity != 1
Fixes bug #623616.
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 484b4e2..cb66b65 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1246,6 +1246,57 @@ void Annot::drawCircleBottomRight(double cx, double cy, double r) {
appearBuf->append("S\n");
}
+void Annot::createForm(double *bbox, GBool transparencyGroup, Object *resDict, Object *aStream) {
+ Object obj1, obj2;
+ Object appearDict;
+
+ appearDict.initDict(xref);
+ appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
+ appearDict.dictSet("Subtype", obj1.initName("Form"));
+ obj1.initArray(xref);
+ obj1.arrayAdd(obj2.initReal(bbox[0]));
+ obj1.arrayAdd(obj2.initReal(bbox[1]));
+ obj1.arrayAdd(obj2.initReal(bbox[2]));
+ obj1.arrayAdd(obj2.initReal(bbox[3]));
+ appearDict.dictSet("BBox", &obj1);
+ if (transparencyGroup) {
+ Object transDict;
+ transDict.initDict(xref);
+ transDict.dictSet("S", obj1.initName("Transparency"));
+ appearDict.dictSet("Group", &transDict);
+ }
+ if (resDict)
+ appearDict.dictSet("Resources", resDict);
+
+ MemStream *mStream = new MemStream(copyString(appearBuf->getCString()), 0,
+ appearBuf->getLength(), &appearDict);
+ mStream->setNeedFree(gTrue);
+ aStream->initStream(mStream);
+}
+
+void Annot::createResourcesDict(char *formName, Object *formStream,
+ char *stateName,
+ double opacity, char *blendMode,
+ Object *resDict) {
+ Object gsDict, stateDict, formDict, obj1;
+
+ gsDict.initDict(xref);
+ if (opacity != 1) {
+ gsDict.dictSet("CA", obj1.initReal(opacity));
+ gsDict.dictSet("ca", obj1.initReal(opacity));
+ }
+ if (blendMode)
+ gsDict.dictSet("BM", obj1.initName(blendMode));
+ stateDict.initDict(xref);
+ stateDict.dictSet(stateName, &gsDict);
+ formDict.initDict(xref);
+ formDict.dictSet(formName, formStream);
+
+ resDict->initDict(xref);
+ resDict->dictSet("ExtGState", &stateDict);
+ resDict->dictSet("XObject", &formDict);
+}
+
GBool Annot::isVisible(GBool printing) {
// check the flags
if ((flags & flagHidden) ||
@@ -1271,7 +1322,7 @@ void Annot::draw(Gfx *gfx, GBool printing) {
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color, 1,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
@@ -1883,22 +1934,21 @@ void AnnotText::draw(Gfx *gfx, GBool printing) {
appearBuf->append (ANNOT_TEXT_AP_CIRCLE);
appearBuf->append ("Q\n");
- Object appearDict, obj1, obj2;
+ double bbox[4];
+ bbox[0] = bbox[1] = 0;
+ bbox[2] = bbox[3] = 24;
+ if (ca == 1) {
+ createForm(bbox, gFalse, NULL, &appearance);
+ } else {
+ Object aStream, resDict;
- appearDict.initDict(xref);
- appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- appearDict.dictSet("Subtype", obj1.initName("Form"));
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(24));
- obj1.arrayAdd(obj2.initReal(24));
- appearDict.dictSet("BBox", &obj1);
-
- MemStream *appearStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &appearDict);
- appearStream->setNeedFree(gTrue);
- appearance.initStream(appearStream);
+ createForm(bbox, gTrue, NULL, &aStream);
+ delete appearBuf;
+
+ appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ createResourcesDict("Fm0", &aStream, "GS0", ca, NULL, &resDict);
+ createForm(bbox, gFalse, &resDict, &appearance);
+ }
delete appearBuf;
rectx2 = rect->x1 + 24;
@@ -1907,7 +1957,7 @@ void AnnotText::draw(Gfx *gfx, GBool printing) {
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, border, color, ca,
+ gfx->drawAnnot(&obj, border, color,
rect->x1, rect->y1, rectx2, recty2);
obj.free();
}
@@ -1999,7 +2049,7 @@ void AnnotLink::draw(Gfx *gfx, GBool printing) {
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, border, color, 1,
+ gfx->drawAnnot(&obj, border, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
@@ -2368,28 +2418,28 @@ void AnnotLine::draw(Gfx *gfx, GBool printing) {
appearBuf->append ("S\n");
appearBuf->append ("Q\n");
- Object appearDict, obj1, obj2;
+ double bbox[4];
+ bbox[0] = bbox[1] = 0;
+ bbox[2] = rect->x2 - rect->x1;
+ bbox[3] = rect->y2 - rect->y1;
+ if (ca == 1) {
+ createForm(bbox, gFalse, NULL, &appearance);
+ } else {
+ Object aStream, resDict;
- appearDict.initDict(xref);
- appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- appearDict.dictSet("Subtype", obj1.initName("Form"));
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(rect->x2 - rect->x1));
- obj1.arrayAdd(obj2.initReal(rect->y2 - rect->y1));
- appearDict.dictSet("BBox", &obj1);
-
- MemStream *appearStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &appearDict);
- appearStream->setNeedFree(gTrue);
- appearance.initStream(appearStream);
+ createForm(bbox, gTrue, NULL, &aStream);
+ delete appearBuf;
+
+ appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ createResourcesDict("Fm0", &aStream, "GS0", ca, NULL, &resDict);
+ createForm(bbox, gFalse, &resDict, &appearance);
+ }
delete appearBuf;
}
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color, ca,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
@@ -2480,13 +2530,13 @@ AnnotTextMarkup::~AnnotTextMarkup() {
}
}
+
+
void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
Object obj;
double ca = 1;
int i;
Object obj1, obj2;
- Object formDict, resDict;
- MemStream *mStream;
if (!isVisible (printing))
return;
@@ -2581,100 +2631,35 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
appearBuf->append ("f\n");
}
- Object appearDict;
- appearDict.initDict(xref);
- appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- appearDict.dictSet("Subtype", obj1.initName("Form"));
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(rect->x1));
- obj1.arrayAdd(obj2.initReal(rect->y1));
- obj1.arrayAdd(obj2.initReal(rect->x2));
- obj1.arrayAdd(obj2.initReal(rect->y2));
- appearDict.dictSet("BBox", &obj1);
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(1));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(1));
- obj1.arrayAdd(obj2.initReal(-rect->x1));
- obj1.arrayAdd(obj2.initReal(-rect->y1));
- appearDict.dictSet("Matrix", &obj1);
-
- Object aStream;
- mStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &appearDict);
- mStream->setNeedFree(gTrue);
- aStream.initStream(mStream);
+ Object aStream, resDict;
+ double bbox[4];
+ bbox[0] = rect->x1;
+ bbox[1] = rect->y1;
+ bbox[2] = rect->x2;
+ bbox[3] = rect->y2;
+ createForm(bbox, gTrue, NULL, &aStream);
delete appearBuf;
- Object transDict;
- formDict.initDict(xref);
- formDict.dictSet ("Form", &aStream);
- resDict.initDict(xref);
- resDict.dictSet ("XObject", &formDict);
-
- transDict.initDict(xref);
- transDict.dictSet ("S", obj1.initName("Transparency"));
-
- appearBuf = new GooString ("/Form Do");
-
- formDict.initDict(xref);
- formDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- formDict.dictSet("Subtype", obj1.initName("Form"));
- formDict.dictSet("Group", &transDict);
- formDict.dictSet("Resources", &resDict);
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(rect->x2 - rect->x1));
- obj1.arrayAdd(obj2.initReal(rect->y2 - rect->y1));
- formDict.dictSet("BBox", &obj1);
+ appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ createResourcesDict("Fm0", &aStream, "GS0", 1, "Multiply", &resDict);
+ if (ca == 1) {
+ createForm(bbox, gFalse, &resDict, &appearance);
+ } else {
+ createForm(bbox, gTrue, &resDict, &aStream);
+ delete appearBuf;
- mStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &formDict);
- mStream->setNeedFree(gTrue);
- aStream.initStream(mStream);
+ appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ createResourcesDict("Fm0", &aStream, "GS0", ca, NULL, &resDict);
+ createForm(bbox, gFalse, &resDict, &appearance);
+ }
delete appearBuf;
-
- Object stateDict;
-
- formDict.initDict(xref);
- formDict.dictSet ("HAForm", &aStream);
- transDict.initDict(xref);
- transDict.dictSet ("BM", obj1.initName("Multiply"));
- stateDict.initDict(xref);
- stateDict.dictSet ("R0", &transDict);
- resDict.initDict(xref);
- resDict.dictSet ("XObject", &formDict);
- resDict.dictSet ("ExtGState", &stateDict);
-
- appearBuf = new GooString ("/R0 gs\n/HAForm Do");
-
break;
}
-
- formDict.initDict(xref);
- formDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- formDict.dictSet("Subtype", obj1.initName("Form"));
- if (type == typeHighlight)
- formDict.dictSet("Resources", &resDict);
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(rect->x2 - rect->x1));
- obj1.arrayAdd(obj2.initReal(rect->y2 - rect->y1));
- formDict.dictSet("BBox", &obj1);
-
- mStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &formDict);
- mStream->setNeedFree(gTrue);
- appearance.initStream(mStream);
- delete appearBuf;
}
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color, ca,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
@@ -4036,7 +4021,7 @@ void AnnotWidget::draw(Gfx *gfx, GBool printing) {
gfx->pushResources(dict);
delete dict;
}
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color, 1,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
rect->x1, rect->y1, rect->x2, rect->y2);
if (addDingbatsResource) {
gfx->popResources();
@@ -4178,22 +4163,11 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
appearBuf->append ("Q\n");
appearBuf->append ("Q\n");
- Object appearDict;
- appearDict.initDict(xref);
- appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- appearDict.dictSet("Subtype", obj1.initName("Form"));
- appearDict.dictSet("Resources", &resDict);
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initInt(0));
- obj1.arrayAdd(obj2.initInt(0));
- obj1.arrayAdd(obj2.initInt(width));
- obj1.arrayAdd(obj2.initInt(height));
- appearDict.dictSet("BBox", &obj1);
-
- MemStream *appearStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &appearDict);
- appearStream->setNeedFree(gTrue);
- appearance.initStream(appearStream);
+ double bbox[4];
+ bbox[0] = bbox[1] = 0;
+ bbox[2] = width;
+ bbox[3] = height;
+ createForm(bbox, gFalse, &resDict, &appearance);
delete appearBuf;
}
poster.free();
@@ -4201,7 +4175,7 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color, 1,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
@@ -4467,28 +4441,29 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) {
appearBuf->append ("S\n");
appearBuf->append ("Q\n");
- Object appearDict, obj1, obj2;
+ double bbox[4];
+ bbox[0] = bbox[1] = 0;
+ bbox[2] = rect->x2 - rect->x1;
+ bbox[3] = rect->y2 - rect->y1;
+ if (ca == 1) {
+ createForm(bbox, gFalse, NULL, &appearance);
+ } else {
+ Object aStream;
- appearDict.initDict(xref);
- appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- appearDict.dictSet("Subtype", obj1.initName("Form"));
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(rect->x2 - rect->x1));
- obj1.arrayAdd(obj2.initReal(rect->y2 - rect->y1));
- appearDict.dictSet("BBox", &obj1);
-
- MemStream *appearStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &appearDict);
- appearStream->setNeedFree(gTrue);
- appearance.initStream(appearStream);
+ createForm(bbox, gTrue, NULL, &aStream);
+ delete appearBuf;
+
+ Object resDict;
+ appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ createResourcesDict("Fm0", &aStream, "GS0", ca, NULL, &resDict);
+ createForm(bbox, gFalse, &resDict, &appearance);
+ }
delete appearBuf;
}
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color, ca,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
@@ -4923,28 +4898,28 @@ void AnnotFileAttachment::draw(Gfx *gfx, GBool printing) {
appearBuf->append (ANNOT_FILE_ATTACHMENT_AP_TAG);
appearBuf->append ("Q\n");
- Object appearDict, obj1, obj2;
+ double bbox[4];
+ bbox[0] = bbox[1] = 0;
+ bbox[2] = bbox[3] = 24;
+ if (ca == 1) {
+ createForm (bbox, gFalse, NULL, &appearance);
+ } else {
+ Object aStream;
- appearDict.initDict(xref);
- appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- appearDict.dictSet("Subtype", obj1.initName("Form"));
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(24));
- obj1.arrayAdd(obj2.initReal(24));
- appearDict.dictSet("BBox", &obj1);
-
- MemStream *appearStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &appearDict);
- appearStream->setNeedFree(gTrue);
- appearance.initStream(appearStream);
+ createForm (bbox, gTrue, NULL, &aStream);
+ delete appearBuf;
+
+ Object resDict;
+ appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ createResourcesDict("Fm0", &aStream, "GS0", ca, NULL, &resDict);
+ createForm(bbox, gFalse, &resDict, &appearance);
+ }
delete appearBuf;
}
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, border, color, ca,
+ gfx->drawAnnot(&obj, border, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
@@ -5085,28 +5060,27 @@ void AnnotSound::draw(Gfx *gfx, GBool printing) {
appearBuf->append (ANNOT_SOUND_AP_MIC);
appearBuf->append ("Q\n");
- Object appearDict, obj1, obj2;
+ double bbox[4];
+ bbox[0] = bbox[1] = 0;
+ bbox[2] = bbox[3] = 24;
+ if (ca == 1) {
+ createForm(bbox, gFalse, NULL, &appearance);
+ } else {
+ Object aStream, resDict;
- appearDict.initDict(xref);
- appearDict.dictSet("Length", obj1.initInt(appearBuf->getLength()));
- appearDict.dictSet("Subtype", obj1.initName("Form"));
- obj1.initArray(xref);
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(0));
- obj1.arrayAdd(obj2.initReal(24));
- obj1.arrayAdd(obj2.initReal(24));
- appearDict.dictSet("BBox", &obj1);
-
- MemStream *appearStream = new MemStream(copyString(appearBuf->getCString()), 0,
- appearBuf->getLength(), &appearDict);
- appearStream->setNeedFree(gTrue);
- appearance.initStream(appearStream);
+ createForm(bbox, gTrue, NULL, &aStream);
+ delete appearBuf;
+
+ appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ createResourcesDict("Fm0", &aStream, "GS0", ca, NULL, &resDict);
+ createForm(bbox, gFalse, &resDict, &appearance);
+ }
delete appearBuf;
}
// draw the appearance stream
appearance.fetch(xref, &obj);
- gfx->drawAnnot(&obj, border, color, ca,
+ gfx->drawAnnot(&obj, border, color,
rect->x1, rect->y1, rect->x2, rect->y2);
obj.free();
}
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 97f9a49..9228c2e 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -538,6 +538,9 @@ protected:
void drawCircle(double cx, double cy, double r, GBool fill);
void drawCircleTopLeft(double cx, double cy, double r);
void drawCircleBottomRight(double cx, double cy, double r);
+ void createForm(double *bbox, GBool transparencyGroup, Object *resDict, Object *aStream);
+ void createResourcesDict(char *formName, Object *formStream, char *stateName,
+ double opacity, char *blendMode, Object *resDict);
GBool isVisible(GBool printing);
// Updates the field key of the annotation dictionary
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 221caef..50870cc 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -4592,7 +4592,7 @@ void Gfx::opMarkPoint(Object args[], int numArgs) {
// misc
//------------------------------------------------------------------------
-void Gfx::drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor, double opacity,
+void Gfx::drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor,
double xMin, double yMin, double xMax, double yMax) {
Dict *dict, *resDict;
Object matrixObj, bboxObj, resObj;
@@ -4608,13 +4608,6 @@ void Gfx::drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor, double
int dashLength;
int i;
- if (opacity != 1) {
- state->setFillOpacity(opacity);
- out->updateFillOpacity(state);
- state->setStrokeOpacity(opacity);
- out->updateStrokeOpacity(state);
- }
-
//~ can we assume that we're in default user space?
//~ (i.e., baseMatrix = ctm)
diff --git a/poppler/Gfx.h b/poppler/Gfx.h
index f1a8964..cb42b5c 100644
--- a/poppler/Gfx.h
+++ b/poppler/Gfx.h
@@ -159,7 +159,7 @@ public:
// Display an annotation, given its appearance (a Form XObject),
// border style, and bounding box (in default user space).
- void drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor, double opacity,
+ void drawAnnot(Object *str, AnnotBorder *border, AnnotColor *aColor,
double xMin, double yMin, double xMax, double yMax);
// Save graphics state.
commit 70ce0b6ea1a0d61f5048d2ae49c639d74a643b29
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Fri Jul 9 17:04:00 2010 +0200
[annots] Clamp QuadPoints coords to annot rectangle instead of ignore points
Fixes appearance stream generation for document attached to bug #623616.
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 2fe8ae3..484b4e2 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -90,6 +90,10 @@
// = (4 * (sqrt(2) - 1) / 3) * r
#define bezierCircle 0.55228475
+// Ensures that x is between the limits set by low and high.
+// If low is greater than high the result is undefined.
+#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
+
AnnotLineEndingStyle parseAnnotLineEndingStyle(GooString *string) {
if (string != NULL) {
if (!string->cmp("Square")) {
@@ -320,37 +324,37 @@ AnnotQuadrilaterals::AnnotQuadrilaterals(Array *array, PDFRectangle *rect) {
quadrilateralsLength = 0;
if ((arrayLength % 8) == 0) {
- int i = 0;
+ int i;
quadsLength = arrayLength / 8;
quads = (AnnotQuadrilateral **) gmallocn
((quadsLength), sizeof(AnnotQuadrilateral *));
memset(quads, 0, quadsLength * sizeof(AnnotQuadrilateral *));
- while (i < (quadsLength) && correct) {
- for (int j = 0; j < 8 && correct; j++) {
+ for (i = 0; i < quadsLength; i++) {
+ for (int j = 0; j < 8; j++) {
Object obj;
if (array->get(i * 8 + j, &obj)->isNum()) {
- quadArray[j] = obj.getNum();
- if (j % 2 == 1) {
- if (quadArray[j] < rect->y1 || quadArray[j] > rect->y2)
- correct = gFalse;
- } else {
- if (quadArray[j] < rect->x1 || quadArray[j] > rect->x2)
- correct = gFalse;
- }
+ if (j % 2 == 1)
+ quadArray[j] = CLAMP (obj.getNum(), rect->y1, rect->y2);
+ else
+ quadArray[j] = CLAMP (obj.getNum(), rect->x1, rect->x2);
} else {
correct = gFalse;
+ obj.free();
+ error (-1, "Invalid QuadPoint in annot");
+ break;
}
obj.free();
}
- if (correct)
- quads[i] = new AnnotQuadrilateral(quadArray[0], quadArray[1],
- quadArray[2], quadArray[3],
- quadArray[4], quadArray[5],
- quadArray[6], quadArray[7]);
- i++;
+ if (!correct)
+ break;
+
+ quads[i] = new AnnotQuadrilateral(quadArray[0], quadArray[1],
+ quadArray[2], quadArray[3],
+ quadArray[4], quadArray[5],
+ quadArray[6], quadArray[7]);
}
if (correct) {
More information about the poppler
mailing list