[poppler] poppler/Annot.cc poppler/Annot.h
Carlos Garcia Campos
carlosgc at kemper.freedesktop.org
Sat Mar 5 04:16:59 PST 2011
poppler/Annot.cc | 91 ++++++++++++++++++-------------------------------------
poppler/Annot.h | 4 +-
2 files changed, 34 insertions(+), 61 deletions(-)
New commits:
commit 128dcaf282f418d8c45cea4df6ad4d3167b3e39c
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Sat Mar 5 13:12:49 2011 +0100
annots: Add AnnotBorder::parseDashArray() to parse dash arrays
The code was duplicated in AnnotBorderArray and AnnotBorderBS
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 53aa647..2a7e6d0 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -439,6 +439,32 @@ AnnotBorder::AnnotBorder() {
style = borderSolid;
}
+void AnnotBorder::parseDashArray(Object *dashObj) {
+ GBool correct = gTrue;
+ int tempLength = dashObj->arrayGetLength();
+ double *tempDash = (double *) gmallocn (tempLength, sizeof (double));
+
+ // TODO: check not all zero (Line Dash Pattern Page 217 PDF 8.1)
+ for (int i = 0; i < tempLength && i < DASH_LIMIT && correct; i++) {
+ Object obj1;
+
+ if (dashObj->arrayGet(i, &obj1)->isNum()) {
+ tempDash[i] = obj1.getNum();
+
+ correct = tempDash[i] >= 0;
+ obj1.free();
+ }
+ }
+
+ if (correct) {
+ dashLength = tempLength;
+ dash = tempDash;
+ style = borderDashed;
+ } else {
+ gfree (tempDash);
+ }
+}
+
AnnotBorder::~AnnotBorder() {
if (dash)
gfree (dash);
@@ -480,37 +506,9 @@ AnnotBorderArray::AnnotBorderArray(Array *array) {
correct = gFalse;
obj1.free();
- // TODO: check not all zero ? (Line Dash Pattern Page 217 PDF 8.1)
if (arrayLength == 4) {
- if (array->get(3, &obj1)->isArray()) {
- Array *dashPattern = obj1.getArray();
- int tempLength = dashPattern->getLength();
- double *tempDash = (double *) gmallocn (tempLength, sizeof (double));
-
- for(int i = 0; i < tempLength && i < DASH_LIMIT && correct; i++) {
-
- if (dashPattern->get(i, &obj1)->isNum()) {
- tempDash[i] = obj1.getNum();
-
- if (tempDash[i] < 0)
- correct = gFalse;
-
- } else {
- correct = gFalse;
- }
- obj1.free();
- }
-
- if (correct) {
- dashLength = tempLength;
- dash = tempDash;
- style = borderDashed;
- } else {
- gfree (tempDash);
- }
- } else {
- correct = gFalse;
- }
+ if (array->get(3, &obj1)->isArray())
+ parseDashArray(&obj1);
obj1.free();
}
} else {
@@ -565,42 +563,15 @@ AnnotBorderBS::AnnotBorderBS(Dict *dict) {
obj2.free();
obj1.free();
- // TODO: check not all zero (Line Dash Pattern Page 217 PDF 8.1)
- if (dict->lookup("D", &obj1)->isArray()) {
- GBool correct = gTrue;
- int tempLength = obj1.arrayGetLength();
- double *tempDash = (double *) gmallocn (tempLength, sizeof (double));
-
- for(int i = 0; i < tempLength && correct; i++) {
- Object obj2;
-
- if (obj1.arrayGet(i, &obj2)->isNum()) {
- tempDash[i] = obj2.getNum();
-
- if (tempDash[i] < 0)
- correct = gFalse;
- } else {
- correct = gFalse;
- }
- obj2.free();
- }
-
- if (correct) {
- dashLength = tempLength;
- dash = tempDash;
- style = borderDashed;
- } else {
- gfree (tempDash);
- }
-
- }
+ if (dict->lookup("D", &obj1)->isArray())
+ parseDashArray(&obj1);
+ obj1.free();
if (!dash) {
dashLength = 1;
dash = (double *) gmallocn (dashLength, sizeof (double));
dash[0] = 3;
}
- obj1.free();
}
//------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index ebce276..dcdf9ce 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -231,8 +231,11 @@ public:
virtual AnnotBorderStyle getStyle() const { return style; }
protected:
+ void parseDashArray(Object *dashObj);
+
AnnotBorderType type;
double width;
+ static const int DASH_LIMIT = 10; // implementation note 82 in Appendix H.
int dashLength;
double *dash;
AnnotBorderStyle style;
@@ -251,7 +254,6 @@ public:
double getVerticalCorner() const { return verticalCorner; }
protected:
- static const int DASH_LIMIT = 10; // implementation note 82 in Appendix H.
double horizontalCorner; // (Default 0)
double verticalCorner; // (Default 0)
// double width; // (Default 1) (inherited from AnnotBorder)
More information about the poppler
mailing list