[poppler] 5 commits - poppler/Annot.cc poppler/Annot.h

Inigo Martinez inigomartinez at kemper.freedesktop.org
Sat Apr 12 08:41:41 PDT 2008


 poppler/Annot.cc |  267 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 poppler/Annot.h  |  140 +++++++++++++++++++++++++++-
 2 files changed, 398 insertions(+), 9 deletions(-)

New commits:
commit bc2b2ffd2144f951c311e968fba4bc50b7c43ff3
Merge: cd5afe6... bacc1dd...
Author: Iñigo Martínez <inigomartinez at gmail.com>
Date:   Sat Apr 12 17:40:49 2008 +0200

    Fixed merging conflict.
    
    Signed-off-by: Iñigo Martínez <inigomartinez at gmail.com>

commit cd5afe6d9eca687ee224ff7680a8cba28d81a36d
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sat Apr 12 00:44:08 2008 +0200

    Do not take into account Colorspace resource subdictionary for image XObjects
    
    Fixes bug 15125
    The motivation under that change is on section 4.5.2 of the spec:
     Certain objects, such as image XObjects, specify a
     color space as an explicit parameter, often associated with the key ColorSpace.
     In this case, the color space array or name is always defined directly as a PDF
     object, not by an entry in the ColorSpace resource subdictionary. This conven-
     tion also applies when color spaces are defined in terms of other color spaces.

diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 0618ab0..6fc9b8d 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -3627,7 +3627,7 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
       obj1.free();
       dict->lookup("CS", &obj1);
     }
-    if (obj1.isName()) {
+    if (obj1.isName() && inlineImg) {
       res->lookupColorSpace(obj1.getName(), &obj2);
       if (!obj2.isNull()) {
 	obj1.free();
commit ffe09454a0948a6107bcc38f23ba2068151c547d
Author: Iñigo Martínez <inigomartinez at gmail.com>
Date:   Sat Apr 12 17:17:59 2008 +0200

    Initial Annot3D parsing a few general improvements.
    
    Signed-off-by: Iñigo Martínez <inigomartinez at gmail.com>

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 7bc2985..c597f8c 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -184,20 +184,20 @@ AnnotPath::AnnotPath(AnnotCoord **coords, int coordsLength) {
   }
 }
 
-double AnnotPath::getX(int coord) {
-  if (coord > 0 && coord < coordsLength)
+double AnnotPath::getX(int coord) const {
+  if (coord >= 0 && coord < coordsLength)
     return coords[coord]->getX();
   return 0;
 }
 
-double AnnotPath::getY(int coord) {
-  if (coord > 0 && coord < coordsLength)
+double AnnotPath::getY(int coord) const {
+  if (coord >= 0 && coord < coordsLength)
     return coords[coord]->getY();
   return 0;
 }
 
-AnnotCoord *AnnotPath::getCoord(int coord) {
-  if (coord > 0 && coord < coordsLength)
+AnnotCoord *AnnotPath::getCoord(int coord) const {
+  if (coord >= 0 && coord < coordsLength)
     return coords[coord];
   return NULL;
 }
@@ -1167,7 +1167,7 @@ void AnnotMarkup::initialize(XRef *xrefA, Dict *dict, Catalog *catalog, Object *
     date = NULL;
   }
   obj1.free();
-
+    
   if (dict->lookup("IRT", &obj1)->isDict()) {
     inReplyTo = obj1.getDict();
   } else {
@@ -3553,6 +3553,120 @@ void AnnotFileAttachment::initialize(XRef *xrefA, Catalog *catalog, Dict* dict)
 }
 
 //------------------------------------------------------------------------
+// Annot3D
+//------------------------------------------------------------------------
+
+Annot3D::Annot3D(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
+  Annot(xrefA, dict, catalog, obj) {
+  type = type3D;
+  initialize(xrefA, catalog, dict);
+}
+
+Annot3D::~Annot3D() {
+  if (activation)
+    delete activation;
+}
+
+void Annot3D::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
+  Object obj1;
+
+  if (dict->lookup("3DA", &obj1)->isDict()) {
+    activation = new Activation(obj1.getDict());
+  } else {
+    activation = NULL;
+  }
+  obj1.free();
+}
+
+Annot3D::Activation::Activation(Dict *dict) {
+  Object obj1;
+
+  if (dict->lookup("A", &obj1)->isName()) {
+    GooString *name = new GooString(obj1.getName());
+
+    if(!name->cmp("PO")) {
+      aTrigger = aTriggerPageOpened;
+    } else if(!name->cmp("PV")) {
+      aTrigger = aTriggerPageVisible;
+    } else if(!name->cmp("XA")) {
+      aTrigger = aTriggerUserAction;
+    } else {
+      aTrigger = aTriggerUnknown;
+    }
+    delete name;
+  } else {
+    aTrigger = aTriggerUnknown;
+  }
+  obj1.free();
+
+  if(dict->lookup("AIS", &obj1)->isName()) {
+    GooString *name = new GooString(obj1.getName());
+
+    if(!name->cmp("I")) {
+      aState = aStateEnabled;
+    } else if(!name->cmp("L")) {
+      aState = aStateDisabled;
+    } else {
+      aState = aStateUnknown;
+    }
+    delete name;
+  } else {
+    aState = aStateUnknown;
+  }
+  obj1.free();
+
+  if(dict->lookup("D", &obj1)->isName()) {
+    GooString *name = new GooString(obj1.getName());
+
+    if(!name->cmp("PC")) {
+      dTrigger = dTriggerPageClosed;
+    } else if(!name->cmp("PI")) {
+      dTrigger = dTriggerPageInvisible;
+    } else if(!name->cmp("XD")) {
+      dTrigger = dTriggerUserAction;
+    } else {
+      dTrigger = dTriggerUnknown;
+    }
+    delete name;
+  } else {
+    dTrigger = dTriggerUnknown;
+  }
+  obj1.free();
+
+  if(dict->lookup("DIS", &obj1)->isName()) {
+    GooString *name = new GooString(obj1.getName());
+
+    if(!name->cmp("U")) {
+      dState = dStateUninstantiaded;
+    } else if(!name->cmp("I")) {
+      dState = dStateInstantiated;
+    } else if(!name->cmp("L")) {
+      dState = dStateLive;
+    } else {
+      dState = dStateUnknown;
+    }
+    delete name;
+  } else {
+    dState = dStateUnknown;
+  }
+  obj1.free();
+
+  if (dict->lookup("TB", &obj1)->isBool()) {
+    displayToolbar = obj1.getBool();
+  } else {
+    displayToolbar = gTrue;
+  }
+  obj1.free();
+
+  if (dict->lookup("NP", &obj1)->isBool()) {
+    displayNavigation = obj1.getBool();
+  } else {
+    displayNavigation = gFalse;
+  }
+  obj1.free();
+}
+
+//------------------------------------------------------------------------
 // Annots
 //------------------------------------------------------------------------
 
@@ -3645,7 +3759,7 @@ Annot *Annots::createAnnot(XRef *xref, Dict* dict, Catalog *catalog, Object *obj
     } else if (!typeName->cmp("Watermark")) {
       annot = new Annot(xref, dict, catalog, obj);
     } else if (!typeName->cmp("3D")) {
-      annot = new Annot(xref, dict, catalog, obj);
+      annot = new Annot3D(xref, dict, catalog, obj);
     } else {
       annot = new Annot(xref, dict, catalog, obj);
     }
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 4ca7b5c..1c2b70a 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -68,9 +68,9 @@ class AnnotPath {
 public:
   AnnotPath(AnnotCoord **coords, int coordLength);
 
-  double getX(int coord);
-  double getY(int coord);
-  AnnotCoord *getCoord(int coord);
+  double getX(int coord) const;
+  double getY(int coord) const;
+  AnnotCoord *getCoord(int coord) const;
   double getCoordsLength() const { return coordsLength; }
 protected:
   AnnotCoord **coords;
@@ -154,7 +154,7 @@ class AnnotQuadrilaterals {
 public:
 
   AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
-  virtual ~AnnotQuadrilaterals();
+  ~AnnotQuadrilaterals();
 
   double getX1(int quadrilateral);
   double getY1(int quadrilateral);
@@ -217,8 +217,8 @@ public:
   AnnotBorderArray();
   AnnotBorderArray(Array *array);
 
-  virtual double getHorizontalCorner() const { return horizontalCorner; }
-  virtual double getVerticalCorner() const { return verticalCorner; }
+  double getHorizontalCorner() const { return horizontalCorner; }
+  double getVerticalCorner() const { return verticalCorner; }
 
 protected:
   static const int DASH_LIMIT = 10; // implementation note 82 in Appendix H.
@@ -534,7 +534,7 @@ protected:
 class AnnotPopup: public Annot {
 public:
   AnnotPopup(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
-  virtual ~AnnotPopup();
+  ~AnnotPopup();
 
   Dict *getParent() const { return parent; }
   GBool getOpen() const { return open; }
@@ -809,7 +809,7 @@ public:
   };
 
   AnnotFreeText(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
-  virtual ~AnnotFreeText();
+  ~AnnotFreeText();
 
   // getters
   GooString *getAppearanceString() const { return appearanceString; }
@@ -860,7 +860,7 @@ public:
   };
 
   AnnotLine(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
-  virtual ~AnnotLine();
+  ~AnnotLine();
 
   // getters
   AnnotLineEndingStyle getStartStyle() const { return startStyle; }
@@ -1005,8 +1005,8 @@ public:
   ~AnnotInk();
 
   // getters
-  virtual AnnotPath **getInkList() const { return inkList; }
-  virtual int getInkListLength() const { return inkListLength; }
+  AnnotPath **getInkList() const { return inkList; }
+  int getInkListLength() const { return inkListLength; }
 
 private:
 
@@ -1033,8 +1033,8 @@ public:
   ~AnnotFileAttachment();
 
   // getters
-  virtual Object *getFile(Object *obj) { return file.fetch(xref, obj); }
-  virtual GooString *getName() const { return name; }
+  Object *getFile(Object *obj) { return file.fetch(xref, obj); }
+  GooString *getName() const { return name; }
 
 private:
 
@@ -1103,6 +1103,64 @@ private:
 };
 
 //------------------------------------------------------------------------
+// Annot3D
+//------------------------------------------------------------------------
+
+class Annot3D: public Annot {
+  class Activation {
+  public:
+    enum ActivationATrigger {
+      aTriggerUnknown,
+      aTriggerPageOpened,  // PO
+      aTriggerPageVisible, // PV
+      aTriggerUserAction   // XA
+    };
+
+    enum ActivationAState {
+      aStateUnknown,
+      aStateEnabled, // I
+      aStateDisabled // L
+    };
+
+    enum ActivationDTrigger {
+      dTriggerUnknown,
+      dTriggerPageClosed,    // PC
+      dTriggerPageInvisible, // PI
+      dTriggerUserAction     // XD
+    };
+
+    enum ActivationDState {
+      dStateUnknown,
+      dStateUninstantiaded, // U
+      dStateInstantiated,   // I
+      dStateLive            // L
+    };
+
+    Activation(Dict *dict);
+  private:
+    
+    ActivationATrigger aTrigger;  // A   (Default XA)
+    ActivationAState aState;      // AIS (Default L)
+    ActivationDTrigger dTrigger;  // D   (Default PI)
+    ActivationDState dState;      // DIS (Default U)
+    GBool displayToolbar;         // TB  (Default true)
+    GBool displayNavigation;      // NP  (Default false);
+  };
+public:
+
+  Annot3D(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
+  ~Annot3D();
+
+  // getters
+
+private:
+
+  void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
+
+  Activation *activation;  // 3DA
+};
+
+//------------------------------------------------------------------------
 // Annots
 //------------------------------------------------------------------------
 
commit 8757c577241dda31bc59c7d1c208c159ad428877
Author: Iñigo Martínez <inigomartinez at gmail.com>
Date:   Sat Apr 12 10:38:07 2008 +0200

    AnnotFileAttachment support.
    
    Signed-off-by: Iñigo Martínez <inigomartinez at gmail.com>

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5198311..7bc2985 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3519,6 +3519,40 @@ AnnotPath *AnnotInk::parsePathArray(Array *array) {
 }
 
 //------------------------------------------------------------------------
+// AnnotFileAttachment
+//------------------------------------------------------------------------
+
+AnnotFileAttachment::AnnotFileAttachment(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
+  AnnotMarkup(xrefA, dict, catalog, obj) {
+  type = typeFileAttachment;
+  initialize(xrefA, catalog, dict);
+}
+
+AnnotFileAttachment::~AnnotFileAttachment() {
+  file.free();
+
+  if (name)
+    delete name;
+}
+
+void AnnotFileAttachment::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
+  Object obj1;
+
+  if (dict->lookup("FS", &obj1)->isRef()) {
+    obj1.copy(&file);
+  } else {
+    error(-1, "Bad Annot File Attachment");
+  }
+
+  if (dict->lookup("Name", &obj1)->isName()) {
+    name = new GooString(obj1.getName());
+  } else {
+    name = new GooString("PushPin");
+  }
+  obj1.free();
+}
+
+//------------------------------------------------------------------------
 // Annots
 //------------------------------------------------------------------------
 
@@ -3593,9 +3627,9 @@ Annot *Annots::createAnnot(XRef *xref, Dict* dict, Catalog *catalog, Object *obj
     } else if (!typeName->cmp("Caret")) {
       annot = new AnnotCaret(xref, dict, catalog, obj);
     } else if (!typeName->cmp("Ink")) {
-      annot = new Annot(xref, dict, catalog, obj);
+      annot = new AnnotInk(xref, dict, catalog, obj);
     } else if (!typeName->cmp("FileAttachment")) {
-      annot = new Annot(xref, dict, catalog, obj);
+      annot = new AnnotFileAttachment(xref, dict, catalog, obj);
     } else if (!typeName->cmp("Sound")) {
       annot = new Annot(xref, dict, catalog, obj);
     } else if(!typeName->cmp("Movie")) {
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 9c560e4..4ca7b5c 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -1023,6 +1023,31 @@ private:
 };
 
 //------------------------------------------------------------------------
+// AnnotFileAttachment
+//------------------------------------------------------------------------
+
+class AnnotFileAttachment: public AnnotMarkup {
+public:
+
+  AnnotFileAttachment(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
+  ~AnnotFileAttachment();
+
+  // getters
+  virtual Object *getFile(Object *obj) { return file.fetch(xref, obj); }
+  virtual GooString *getName() const { return name; }
+
+private:
+
+  void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
+
+  // required
+  Object file;      // FS
+
+  // optional
+  GooString *name;  // Name
+};
+
+//------------------------------------------------------------------------
 // AnnotWidget
 //------------------------------------------------------------------------
 
commit 36989658149fc9e5e8a049ce070a102f35b7bddc
Author: Iñigo Martínez <inigomartinez at gmail.com>
Date:   Sat Apr 12 09:55:26 2008 +0200

    AnnotInk support.
    
    Signed-off-by: Iñigo Martínez <inigomartinez at gmail.com>

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 1e82fd6..5198311 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -171,6 +171,38 @@ AnnotBorderEffect::AnnotBorderEffect(Dict *dict) {
 }
 
 //------------------------------------------------------------------------
+// AnnotPath
+//------------------------------------------------------------------------
+
+AnnotPath::AnnotPath(AnnotCoord **coords, int coordsLength) {
+  if (!coords) {
+    this->coords = coords;
+    this->coordsLength = coordsLength;
+  } else {
+    this->coords = NULL;
+    this->coordsLength = 0;
+  }
+}
+
+double AnnotPath::getX(int coord) {
+  if (coord > 0 && coord < coordsLength)
+    return coords[coord]->getX();
+  return 0;
+}
+
+double AnnotPath::getY(int coord) {
+  if (coord > 0 && coord < coordsLength)
+    return coords[coord]->getY();
+  return 0;
+}
+
+AnnotCoord *AnnotPath::getCoord(int coord) {
+  if (coord > 0 && coord < coordsLength)
+    return coords[coord];
+  return NULL;
+}
+
+//------------------------------------------------------------------------
 // AnnotCalloutLine
 //------------------------------------------------------------------------
 
@@ -3406,6 +3438,87 @@ void AnnotCaret::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
 }
 
 //------------------------------------------------------------------------
+// AnnotInk
+//------------------------------------------------------------------------
+
+AnnotInk::AnnotInk(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj) :
+  AnnotMarkup(xrefA, dict, catalog, obj) {
+  type = typeInk;
+  initialize(xrefA, catalog, dict);
+}
+
+AnnotInk::~AnnotInk() {
+  if (inkList)
+    delete inkList;
+}
+
+void AnnotInk::initialize(XRef *xrefA, Catalog *catalog, Dict* dict) {
+  Object obj1;
+
+  if (dict->lookup("InkList", &obj1)->isArray()) {
+    Array *array = obj1.getArray();
+    inkListLength = array->getLength();
+    inkList = (AnnotPath **) gmallocn ((inkListLength), sizeof(AnnotPath *));
+    memset(inkList, 0, inkListLength * sizeof(AnnotPath *));
+    for (int i = 0; i < inkListLength; i++) {
+      Object obj2;
+      if (array->get(i, &obj2)->isArray())
+        inkList[i] = this->parsePathArray(obj2.getArray());
+      obj2.free();
+    }
+  } else {
+    inkListLength = 0;
+    inkList = NULL;
+    error(-1, "Bad Annot Ink List");
+    ok = gFalse;
+  }
+  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(coordsLength * 2, &obj1)->isNum()) {
+      x = obj1.getNum();
+    } else {
+      correct = gFalse;
+    }
+    obj1.free();
+
+    if (array->get((coordsLength * 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));
+}
+
+//------------------------------------------------------------------------
 // Annots
 //------------------------------------------------------------------------
 
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 4001ab5..9c560e4 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -61,6 +61,23 @@ protected:
 };
 
 //------------------------------------------------------------------------
+// AnnotPath
+//------------------------------------------------------------------------
+
+class AnnotPath {
+public:
+  AnnotPath(AnnotCoord **coords, int coordLength);
+
+  double getX(int coord);
+  double getY(int coord);
+  AnnotCoord *getCoord(int coord);
+  double getCoordsLength() const { return coordsLength; }
+protected:
+  AnnotCoord **coords;
+  int coordsLength;
+};
+  
+//------------------------------------------------------------------------
 // AnnotCalloutLine
 //------------------------------------------------------------------------
 
@@ -978,6 +995,34 @@ private:
 };
 
 //------------------------------------------------------------------------
+// AnnotInk
+//------------------------------------------------------------------------
+
+class AnnotInk: public AnnotMarkup {
+public:
+
+  AnnotInk(XRef *xrefA, Dict *dict, Catalog *catalog, Object *obj);
+  ~AnnotInk();
+
+  // getters
+  virtual AnnotPath **getInkList() const { return inkList; }
+  virtual int getInkListLength() const { return inkListLength; }
+
+private:
+
+  void initialize(XRef *xrefA, Catalog *catalog, Dict *dict);
+  AnnotPath *parsePathArray(Array *array);
+
+  // required
+  AnnotPath **inkList;       // InkList
+  int inkListLength;
+
+  // optional
+  // inherited from Annot
+  // AnnotBorderBS border;  // BS
+};
+
+//------------------------------------------------------------------------
 // AnnotWidget
 //------------------------------------------------------------------------
 


More information about the poppler mailing list