[poppler] poppler/Annot.cc poppler/Annot.h

Inigo Martinez inigomartinez at kemper.freedesktop.org
Sat Apr 12 16:07:53 PDT 2008


 poppler/Annot.cc |   96 +++++++++++++++++++++++++++++--------------------------
 poppler/Annot.h  |    4 +-
 2 files changed, 55 insertions(+), 45 deletions(-)

New commits:
commit 01aa052ed761a4ada471d196985825986bb58627
Author: Iñigo Martínez <inigomartinez at gmail.com>
Date:   Sun Apr 13 01:13:49 2008 +0200

    Extend AnnotPath behaviour to include cooordinate array parsing.
    
    Signed-off-by: Iñigo Martínez <inigomartinez at gmail.com>

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 641dc72..65cabb1 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -175,6 +175,12 @@ AnnotBorderEffect::AnnotBorderEffect(Dict *dict) {
 // AnnotPath
 //------------------------------------------------------------------------
 
+AnnotPath::AnnotPath(Array *array) {
+  coords = NULL;
+  coordsLength = 0;
+  parsePathArray(array);
+}
+
 AnnotPath::AnnotPath(AnnotCoord **coords, int coordsLength) {
   this->coords = coords;
   this->coordsLength = coordsLength;
@@ -206,6 +212,51 @@ AnnotCoord *AnnotPath::getCoord(int coord) const {
   return NULL;
 }
 
+void AnnotPath::parsePathArray(Array *array) {
+  int tempLength;
+  AnnotCoord **tempCoords;
+  GBool correct = gTrue;
+
+  if (array->getLength() % 2) {
+    error(-1, "Bad Annot Path");
+    return;
+  }
+
+  tempLength = array->getLength() / 2;
+  tempCoords = (AnnotCoord **) gmallocn (tempLength, sizeof(AnnotCoord *));
+  memset(tempCoords, 0, tempLength * sizeof(AnnotCoord *));
+  for (int i = 0; i < tempLength && correct; i++) {
+    Object obj1;
+    double x = 0, y = 0;
+
+    if (array->get(i * 2, &obj1)->isNum()) {
+      x = obj1.getNum();
+    } else {
+      correct = gFalse;
+    }
+    obj1.free();
+
+    if (array->get((i * 2) + 1, &obj1)->isNum()) {
+      y = obj1.getNum();
+    } else {
+      correct = gFalse;
+    }
+    obj1.free();
+
+    if (!correct) {
+      for (int j = i - 1; j >= 0; j--)
+        delete tempCoords[j];
+      gfree (tempCoords);
+      return;
+    }
+
+    tempCoords[i] = new AnnotCoord(x, y);
+  }
+
+  coords = tempCoords;
+  coordsLength = tempLength;
+}
+
 //------------------------------------------------------------------------
 // AnnotCalloutLine
 //------------------------------------------------------------------------
@@ -3464,7 +3515,7 @@ void AnnotInk::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
     for (int i = 0; i < inkListLength; i++) {
       Object obj2;
       if (array->get(i, &obj2)->isArray())
-        inkList[i] = this->parsePathArray(obj2.getArray());
+        inkList[i] = new AnnotPath(obj2.getArray());
       obj2.free();
     }
   } else {
@@ -3476,49 +3527,6 @@ void AnnotInk::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
   obj1.free();
 }
 
-AnnotPath *AnnotInk::parsePathArray(Array *array) {
-  int coordsLength;
-  AnnotCoord **coords;
-  GBool correct = gTrue;
-
-  if (array->getLength() % 2) {
-    error(-1, "Bad Annot Ink Path");
-    return NULL;
-  }
-
-  coordsLength = array->getLength() / 2;
-  coords = (AnnotCoord **) gmallocn (coordsLength, sizeof(AnnotCoord *));
-  memset(coords, 0, coordsLength * sizeof(AnnotCoord *));
-  for (int i = 0; i < coordsLength && correct; i++) {
-    Object obj1;
-    double x = 0, y = 0;
-
-    if (array->get(i * 2, &obj1)->isNum()) {
-      x = obj1.getNum();
-    } else {
-      correct = gFalse;
-    }
-    obj1.free();
-
-    if (array->get((i * 2) + 1, &obj1)->isNum()) {
-      y = obj1.getNum();
-    } else {
-      correct = gFalse;
-    }
-    obj1.free();
-
-    if (!correct) {
-      for (int j = i - 1; j >= 0; j--)
-        delete coords[j];
-      gfree (coords);
-      return NULL;
-    }
-
-    coords[i] = new AnnotCoord(x, y);
-  }
-  return (new AnnotPath(coords, coordsLength));
-}
-
 //------------------------------------------------------------------------
 // AnnotFileAttachment
 //------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 17c3c8f..dab63f5 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -67,6 +67,7 @@ protected:
 
 class AnnotPath {
 public:
+  AnnotPath(Array *array);
   AnnotPath(AnnotCoord **coords, int coordLength);
   ~AnnotPath();
 
@@ -77,6 +78,8 @@ public:
 protected:
   AnnotCoord **coords;
   int coordsLength;
+
+  void parsePathArray(Array *array);
 };
   
 //------------------------------------------------------------------------
@@ -1013,7 +1016,6 @@ public:
 private:
 
   void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
-  AnnotPath *parsePathArray(Array *array);
 
   // required
   AnnotPath **inkList;       // InkList


More information about the poppler mailing list