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

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Mar 25 10:12:39 UTC 2019


 poppler/Annot.cc |   10 ++++++----
 poppler/Annot.h  |    4 ++--
 poppler/Object.h |    6 ++++++
 poppler/Page.cc  |    2 +-
 4 files changed, 15 insertions(+), 7 deletions(-)

New commits:
commit 2b5cccbafc79d561811906dfa5bc288aa9478b10
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Feb 28 17:57:17 2019 +0100

    Rework AnnotPopup parent handling code
    
    The old code was not updating the parent member on setParent

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index dc39507b..fd2ea0fa 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1927,9 +1927,11 @@ AnnotPopup::~AnnotPopup() {
 }
 
 void AnnotPopup::initialize(PDFDoc *docA, Dict *dict) {
-  parent = dict->lookupNF("Parent").copy();
-  if (!parent.isRef()) {
-    parent.setToNull();
+  const Object &parentObj = dict->lookupNF("Parent");
+  if (parentObj.isRef()) {
+    parentRef = parentObj.getRef();
+  } else {
+    parentRef = Ref::INVALID();
   }
 
   Object obj1 = dict->lookup("Open");
@@ -1941,7 +1943,7 @@ void AnnotPopup::initialize(PDFDoc *docA, Dict *dict) {
 }
 
 void AnnotPopup::setParent(Annot *parentA) {
-  const Ref parentRef = parentA->getRef();
+  parentRef = parentA->getRef();
   update ("Parent", Object(parentRef));
 }
 
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 0200bb6a..7bcb6b2d 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -788,7 +788,7 @@ public:
   AnnotPopup(PDFDoc *docA, Object &&dictObject, const Object *obj);
   ~AnnotPopup();
 
-  Object *getParentNF() { return &parent; }
+  bool hasParent() const { return parentRef != Ref::INVALID(); }
   void setParent(Annot *parentA);
   bool getOpen() const { return open; }
   void setOpen(bool openA);
@@ -796,7 +796,7 @@ public:
 protected:
   void initialize(PDFDoc *docA, Dict *dict);
 
-  Object parent; // Parent
+  Ref parentRef; // Parent
   bool open;   // Open
 };
 
diff --git a/poppler/Object.h b/poppler/Object.h
index 77a40cda..914b10ba 100644
--- a/poppler/Object.h
+++ b/poppler/Object.h
@@ -82,12 +82,18 @@ class Stream;
 struct Ref {
   int num;			// object number
   int gen;			// generation number
+
+  static constexpr Ref INVALID() { return {-1, -1}; };
 };
 
 inline bool operator== (const Ref lhs, const Ref rhs) noexcept {
   return lhs.num == rhs.num && lhs.gen == rhs.gen;
 }
 
+inline bool operator!= (const Ref lhs, const Ref rhs) noexcept {
+  return lhs.num != rhs.num || lhs.gen != rhs.gen;
+}
+
 inline bool operator< (const Ref lhs, const Ref rhs) noexcept {
   if (lhs.num != rhs.num)
     return lhs.num < rhs.num;
diff --git a/poppler/Page.cc b/poppler/Page.cc
index 2cb75146..447a94d2 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -401,7 +401,7 @@ void Page::addAnnot(Annot *annot) {
   // so add to the list only Popup annots without a
   // markup annotation associated.
   if (annot->getType() != Annot::typePopup ||
-      static_cast<AnnotPopup*>(annot)->getParentNF()->isNull()) {
+      !static_cast<AnnotPopup*>(annot)->hasParent()) {
     annots->appendAnnot(annot);
   }
   annot->setPage(num, true);


More information about the poppler mailing list