[poppler] 3 commits - poppler/Annot.cc poppler/Annot.h
Pino Toscano
pino at kemper.freedesktop.org
Sat Apr 5 07:00:38 PDT 2008
poppler/Annot.cc | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
poppler/Annot.h | 46 ++++++++++++++++++++
2 files changed, 164 insertions(+), 3 deletions(-)
New commits:
commit 4c9a02b7e49666efe10fdc16e7a03d8d520b65ec
Author: Pino Toscano <pino at kde.org>
Date: Sat Apr 5 16:01:58 2008 +0200
First version of AnnotCaret.
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index a23bbe7..982e88c 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3417,6 +3417,40 @@ void AnnotGeometry::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
}
//------------------------------------------------------------------------
+// AnnotCaret
+//------------------------------------------------------------------------
+
+AnnotCaret::AnnotCaret(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
+ AnnotMarkup(xrefA, dict, catalog, obj) {
+ type = typeCaret;
+ initialize(xrefA, catalog, dict);
+}
+
+AnnotCaret::~AnnotCaret() {
+ delete symbol;
+ delete caretRect;
+}
+
+void AnnotCaret::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
+ Object obj1;
+
+ if (dict->lookup("Sy", &obj1)->isName()) {
+ symbol = new GooString(obj1.getName());
+ } else {
+ symbol = new GooString("None");
+ }
+ obj1.free();
+
+ if (dict->lookup("RD", &obj1)->isArray()) {
+ caretRect = parseDiffRectangle(obj1.getArray(), rect);
+ } else {
+ caretRect = NULL;
+ }
+ obj1.free();
+
+}
+
+//------------------------------------------------------------------------
// Annots
//------------------------------------------------------------------------
@@ -3489,7 +3523,7 @@ Annot *Annots::createAnnot(XRef *xref, Dict* dict, Catalog *catalog, Object *obj
} else if (!typeName->cmp("Stamp")) {
annot = new AnnotStamp(xref, dict, catalog, obj);
} else if (!typeName->cmp("Caret")) {
- annot = new Annot(xref, dict, catalog, obj);
+ annot = new AnnotCaret(xref, dict, catalog, obj);
} else if (!typeName->cmp("Ink")) {
annot = new Annot(xref, dict, catalog, obj);
} else if (!typeName->cmp("FileAttachment")) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 51e6040..e0bf89b 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -952,6 +952,28 @@ private:
};
//------------------------------------------------------------------------
+// AnnotGeometry
+//------------------------------------------------------------------------
+
+class AnnotCaret: public AnnotMarkup {
+public:
+
+ AnnotCaret(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
+ ~AnnotCaret();
+
+ // getters
+ GooString *getSymbol() const { return symbol; }
+ PDFRectangle *getCaretRect() const { return caretRect; }
+
+private:
+
+ void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
+
+ GooString *symbol; // Sy (Default None)
+ PDFRectangle *caretRect; // RD (combined with Rect)
+};
+
+//------------------------------------------------------------------------
// AnnotWidget
//------------------------------------------------------------------------
commit d260fe9e514c667b66969b982119429cc922eb07
Author: Pino Toscano <pino at kde.org>
Date: Sat Apr 5 15:54:29 2008 +0200
isolate the code for parsing a "difference rectangle" in an own function
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index cfe7bae..a23bbe7 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -113,6 +113,35 @@ AnnotExternalDataType parseAnnotExternalData(Dict* dict) {
return type;
}
+PDFRectangle *parseDiffRectangle(Array *array, PDFRectangle *rect) {
+ PDFRectangle *newRect = NULL;
+ if (array->getLength() == 4) {
+ // deltas
+ Object obj1;
+ double dx1 = (array->get(0, &obj1)->isNum() ? obj1.getNum() : 0);
+ obj1.free();
+ double dy1 = (array->get(1, &obj1)->isNum() ? obj1.getNum() : 0);
+ obj1.free();
+ double dx2 = (array->get(2, &obj1)->isNum() ? obj1.getNum() : 0);
+ obj1.free();
+ double dy2 = (array->get(3, &obj1)->isNum() ? obj1.getNum() : 0);
+ obj1.free();
+
+ // checking that the numbers are valid (i.e. >= 0),
+ // and that applying the differences still give us a valid rect
+ if (dx1 >= 0 && dy1 >= 0 && dx2 >= 0 && dy2
+ && (rect->x2 - rect->x1 - dx1 - dx2) >= 0
+ && (rect->y2 - rect->y1 - dy1 - dy2) >= 0) {
+ newRect = new PDFRectangle();
+ newRect->x1 = rect->x1 + dx1;
+ newRect->y1 = rect->y1 + dy1;
+ newRect->x2 = rect->x2 - dx2;
+ newRect->y2 = rect->y2 - dy2;
+ }
+ }
+ return newRect;
+}
+
//------------------------------------------------------------------------
// AnnotBorderEffect
//------------------------------------------------------------------------
@@ -3380,29 +3409,8 @@ void AnnotGeometry::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
obj1.free();
geometryRect = NULL;
- if (dict->lookup("RD", &obj1)->isArray() && obj1.arrayGetLength() == 4) {
- // deltas
- Object obj2;
- double dx1 = (obj1.arrayGet(0, &obj2)->isNum() ? obj2.getNum() : 0);
- obj2.free();
- double dy1 = (obj1.arrayGet(1, &obj2)->isNum() ? obj2.getNum() : 0);
- obj2.free();
- double dx2 = (obj1.arrayGet(2, &obj2)->isNum() ? obj2.getNum() : 0);
- obj2.free();
- double dy2 = (obj1.arrayGet(3, &obj2)->isNum() ? obj2.getNum() : 0);
- obj2.free();
-
- // checking that the numbers are valid (i.e. >= 0),
- // and that applying the differences still give us a valid rect
- if (dx1 >= 0 && dy1 >= 0 && dx2 >= 0 && dy2
- && (rect->x2 - rect->x1 - dx1 - dx2) >= 0
- && (rect->y2 - rect->y1 - dy1 - dy2) >= 0) {
- geometryRect = new PDFRectangle();
- geometryRect->x1 = rect->x1 + dx1;
- geometryRect->y1 = rect->y1 + dy1;
- geometryRect->x2 = rect->x2 - dx2;
- geometryRect->y2 = rect->y2 - dy2;
- }
+ if (dict->lookup("RD", &obj1)->isArray()) {
+ geometryRect = parseDiffRectangle(obj1.getArray(), rect);
}
obj1.free();
commit 760833e409c122c0a61f7c87fd3133eebc10b402
Author: Pino Toscano <pino at kde.org>
Date: Sat Apr 5 15:36:43 2008 +0200
First version of AnnotGeometry.
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 19c5f75..cfe7bae 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3336,6 +3336,79 @@ void AnnotStamp::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
}
//------------------------------------------------------------------------
+// AnnotGeometry
+//------------------------------------------------------------------------
+
+AnnotGeometry::AnnotGeometry(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
+ AnnotMarkup(xrefA, dict, catalog, obj) {
+ // the real type will be read in initialize()
+ type = typeSquare;
+ initialize(xrefA, catalog, dict);
+}
+
+AnnotGeometry::~AnnotGeometry() {
+ delete interiorColor;
+ delete borderEffect;
+ delete geometryRect;
+}
+
+void AnnotGeometry::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
+ Object obj1;
+
+ if (dict->lookup("Subtype", &obj1)->isName()) {
+ GooString typeName(obj1.getName());
+ if (!typeName.cmp("Square")) {
+ type = typeSquare;
+ } else if (!typeName.cmp("Circle")) {
+ type = typeCircle;
+ }
+ }
+ obj1.free();
+
+ if (dict->lookup("IC", &obj1)->isArray()) {
+ interiorColor = new AnnotColor(obj1.getArray());
+ } else {
+ interiorColor = NULL;
+ }
+ obj1.free();
+
+ if (dict->lookup("BE", &obj1)->isDict()) {
+ borderEffect = new AnnotBorderEffect(obj1.getDict());
+ } else {
+ borderEffect = NULL;
+ }
+ obj1.free();
+
+ geometryRect = NULL;
+ if (dict->lookup("RD", &obj1)->isArray() && obj1.arrayGetLength() == 4) {
+ // deltas
+ Object obj2;
+ double dx1 = (obj1.arrayGet(0, &obj2)->isNum() ? obj2.getNum() : 0);
+ obj2.free();
+ double dy1 = (obj1.arrayGet(1, &obj2)->isNum() ? obj2.getNum() : 0);
+ obj2.free();
+ double dx2 = (obj1.arrayGet(2, &obj2)->isNum() ? obj2.getNum() : 0);
+ obj2.free();
+ double dy2 = (obj1.arrayGet(3, &obj2)->isNum() ? obj2.getNum() : 0);
+ obj2.free();
+
+ // checking that the numbers are valid (i.e. >= 0),
+ // and that applying the differences still give us a valid rect
+ if (dx1 >= 0 && dy1 >= 0 && dx2 >= 0 && dy2
+ && (rect->x2 - rect->x1 - dx1 - dx2) >= 0
+ && (rect->y2 - rect->y1 - dy1 - dy2) >= 0) {
+ geometryRect = new PDFRectangle();
+ geometryRect->x1 = rect->x1 + dx1;
+ geometryRect->y1 = rect->y1 + dy1;
+ geometryRect->x2 = rect->x2 - dx2;
+ geometryRect->y2 = rect->y2 - dy2;
+ }
+ }
+ obj1.free();
+
+}
+
+//------------------------------------------------------------------------
// Annots
//------------------------------------------------------------------------
@@ -3390,9 +3463,9 @@ Annot *Annots::createAnnot(XRef *xref, Dict* dict, Catalog *catalog, Object *obj
} else if (!typeName->cmp("Line")) {
annot = new AnnotLine(xref, dict, catalog, obj);
} else if (!typeName->cmp("Square")) {
- annot = new Annot(xref, dict, catalog, obj);
+ annot = new AnnotGeometry(xref, dict, catalog, obj);
} else if (!typeName->cmp("Circle")) {
- annot = new Annot(xref, dict, catalog, obj);
+ annot = new AnnotGeometry(xref, dict, catalog, obj);
} else if (!typeName->cmp("Polygon")) {
annot = new Annot(xref, dict, catalog, obj);
} else if (!typeName->cmp("PolyLine")) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index d08b176..51e6040 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -928,6 +928,30 @@ private:
};
//------------------------------------------------------------------------
+// AnnotGeometry
+//------------------------------------------------------------------------
+
+class AnnotGeometry: public AnnotMarkup {
+public:
+
+ AnnotGeometry(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
+ ~AnnotGeometry();
+
+ // getters
+ AnnotColor *getInteriorColor() const { return interiorColor; }
+ AnnotBorderEffect *getBorderEffect() const { return borderEffect; }
+ PDFRectangle *getGeometryRect() const { return geometryRect; }
+
+private:
+
+ void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
+
+ AnnotColor *interiorColor; // IC
+ AnnotBorderEffect *borderEffect; // BE
+ PDFRectangle *geometryRect; // RD (combined with Rect)
+};
+
+//------------------------------------------------------------------------
// AnnotWidget
//------------------------------------------------------------------------
More information about the poppler
mailing list