Use Ref::INVALID more

In this case we have to be a bit more careful since we're changing code that
used to assign to 0,0 and now INVALID is -1, -1 but i'm confident it's
fine

inReplyTo seems to be only used in qt5/src/poppler-annotation.cc and
i've updated the code to use the boolean isInReplyTo instead of checking
the ref number directly

The change in Dict only affects its two callers, one in Annot and one in
Catalog. The one in catalog has been updated, the one in Annot doesn't
seem to need updating (and moreover if you check history before using
the new Dict function was using -1, -1 as ref not initialized)

The change in Array only affects its one caller, in Function, whose code
has been updated

The embFontID change is something that was forgotten in the previous
commit about using Ref::INVALID

The change for iccProfileStreamA is only local to that function and has
been changed to use Ref::INVALID in all its uses
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 3bc776e..a061a1b 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1997,8 +1997,7 @@
   if (irtObj.isRef()) {
     inReplyTo = irtObj.getRef();
   } else {
-    inReplyTo.num = 0;
-    inReplyTo.gen = 0;
+    inReplyTo = Ref::INVALID();
   }
 
   obj1 = dict->lookup("Subj");
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 9f6c9fb..3a93794 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -821,6 +821,7 @@
   double getOpacity() const { return opacity; }
   // getRC
   const GooString *getDate() const { return date.get(); }
+  bool isInReplyTo() const { return inReplyTo != Ref::INVALID(); }
   int getInReplyToID() const { return inReplyTo.num; }
   const GooString *getSubject() const { return subject.get(); }
   AnnotMarkupReplyType getReplyTo() const { return replyTo; }
diff --git a/poppler/Array.cc b/poppler/Array.cc
index cc7dd0c..a6cf4bc 100644
--- a/poppler/Array.cc
+++ b/poppler/Array.cc
@@ -80,13 +80,13 @@
 Object Array::get(int i, Ref *returnRef, int recursion) const
 {
   if (i < 0 || std::size_t(i) >= elems.size()) {
-    *returnRef = { 0, 0 };
+    *returnRef = Ref::INVALID();
     return Object(objNull);
   }
   if (elems[i].getType() == objRef) {
     *returnRef = elems[i].getRef();
   } else {
-    *returnRef = { 0, 0 };
+    *returnRef = Ref::INVALID();
   }
   return elems[i].fetch(xref, recursion);
 }
diff --git a/poppler/Array.h b/poppler/Array.h
index 1d03cbc..be1123c 100644
--- a/poppler/Array.h
+++ b/poppler/Array.h
@@ -68,6 +68,7 @@
 
   // Accessors.
   Object get(int i, int recursion = 0) const;
+  // Same as above but if the returned object is a fetched Ref returns such Ref in returnRef, otherwise returnRef is Ref::INVALID()
   Object get(int i, Ref *returnRef, int recursion = 0) const;
   const Object &getNF(int i) const;
   bool getString(int i, GooString *string) const;
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 905954e..d01e8fc 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -502,7 +502,7 @@
   embeddedFilesObj.dictSet("Names", Object(embeddedFilesNamesArray));
   namesDict->set("EmbeddedFiles", Object(embeddedFilesRef));
 
-  if (namesObjRef.num != 0) {
+  if (namesObjRef != Ref::INVALID()) {
     xref->setModifiedObject(&namesObj, namesObjRef);
   } else {
     xref->setModifiedObject(&catDict, { xref->getRootNum(), xref->getRootGen() });
diff --git a/poppler/Dict.cc b/poppler/Dict.cc
index f1d6c6e..17c2f98 100644
--- a/poppler/Dict.cc
+++ b/poppler/Dict.cc
@@ -173,11 +173,11 @@
     if (entry->second.getType() == objRef) {
       *returnRef = entry->second.getRef();
     } else {
-      *returnRef = { 0, 0 };
+      *returnRef = Ref::INVALID();
     }
     return entry->second.fetch(xref, recursion);
   }
-  *returnRef = { 0, 0 };
+  *returnRef = Ref::INVALID();
   return Object(objNull);
 }
 
diff --git a/poppler/Dict.h b/poppler/Dict.h
index 13da482..6c1424a 100644
--- a/poppler/Dict.h
+++ b/poppler/Dict.h
@@ -76,6 +76,7 @@
   // Look up an entry and return the value.  Returns a null object
   // if <key> is not in the dictionary.
   Object lookup(const char *key, int recursion = 0) const;
+  // Same as above but if the returned object is a fetched Ref returns such Ref in returnRef, otherwise returnRef is Ref::INVALID()
   Object lookup(const char *key, Ref *returnRef, int recursion = 0) const;
   const Object &lookupNF(const char *key) const;
   bool lookupInt(const char *key, const char *alt_key, int *value) const;
diff --git a/poppler/Function.cc b/poppler/Function.cc
index 873c2c0..e7973e2 100644
--- a/poppler/Function.cc
+++ b/poppler/Function.cc
@@ -692,7 +692,7 @@
     std::set<int> usedParentsAux = *usedParents;
     Ref ref;
     Object obj2 = obj1.getArray()->get(i, &ref);
-    if (ref.num != 0) {
+    if (ref != Ref::INVALID()) {
       if (usedParentsAux.find(ref.num) == usedParentsAux.end()) {
         usedParentsAux.insert(ref.num);
       } else {
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index db6f0b8..c74b4b0 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -290,7 +290,7 @@
   bool isType0, err;
 
   t = fontUnknownType;
-  embID->num = embID->gen = -1;
+  *embID = Ref::INVALID();
   err = false;
 
   Object subtype = fontDict->lookup("Subtype");
@@ -348,7 +348,7 @@
 	err = true;
       }
     }
-    if (embID->num == -1 && (obj3 = fontDesc.dictLookupNF("FontFile2").copy(), obj3.isRef())) {
+    if (*embID == Ref::INVALID() && (obj3 = fontDesc.dictLookupNF("FontFile2").copy(), obj3.isRef())) {
       *embID = obj3.getRef();
       if (isType0) {
 	expectedType = fontCIDType2;
@@ -356,7 +356,7 @@
 	err = true;
       }
     }
-    if (embID->num == -1 && (obj3 = fontDesc.dictLookupNF("FontFile3").copy(), obj3.isRef())) {
+    if (*embID == Ref::INVALID() && (obj3 = fontDesc.dictLookupNF("FontFile3").copy(), obj3.isRef())) {
       *embID = obj3.getRef();
       Object obj4 = obj3.fetch(xref);
       if (obj4.isStream()) {
@@ -406,7 +406,7 @@
   }
 
   t = fontUnknownType;
-  if (embID->num >= 0) {
+  if (*embID != Ref::INVALID()) {
     Object obj3(*embID);
     Object obj4 = obj3.fetch(xref);
     if (obj4.isStream()) {
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 740a29c..54ab128 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -213,7 +213,7 @@
   // Get embedded font ID, i.e., a ref for the font file stream.
   // Returns false if there is no embedded font.
   bool getEmbeddedFontID(Ref *embID) const
-    { *embID = embFontID; return embFontID.num >= 0; }
+    { *embID = embFontID; return embFontID != Ref::INVALID(); }
 
   // Invalidate an embedded font
   // Returns false if there is no embedded font.
diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index e3417e0..557ce46 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -1815,7 +1815,6 @@
 
 GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState *state, int recursion) {
   GfxICCBasedColorSpace *cs;
-  Ref iccProfileStreamA;
   int nCompsA;
   GfxColorSpace *altA;
   Dict *dict;
@@ -1827,15 +1826,10 @@
     return nullptr;
   }
   const Object &obj1Ref = arr->getNF(1);
-  if (obj1Ref.isRef()) {
-    iccProfileStreamA = obj1Ref.getRef();
-  } else {
-    iccProfileStreamA.num = 0;
-    iccProfileStreamA.gen = 0;
-  }
+  const Ref iccProfileStreamA = obj1Ref.isRef() ? obj1Ref.getRef() : Ref::INVALID();
 #ifdef USE_CMS
   // check cache
-  if (out && iccProfileStreamA.num > 0) {
+  if (out && iccProfileStreamA != Ref::INVALID()) {
     if (auto *item = out->getIccColorSpaceCache()->lookup(iccProfileStreamA)) {
       cs = static_cast<GfxICCBasedColorSpace*>(item->copy());
       int transformIntent = cs->getIntent();
@@ -1976,7 +1970,7 @@
     cmsCloseProfile(hp);
   }
   // put this colorSpace into cache
-  if (out && iccProfileStreamA.num > 0) {
+  if (out && iccProfileStreamA != Ref::INVALID()) {
     out->getIccColorSpaceCache()->put(iccProfileStreamA, static_cast<GfxICCBasedColorSpace*>(cs->copy()));
   }
 #endif
diff --git a/poppler/Link.h b/poppler/Link.h
index 08949ea..c1079bd 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -310,13 +310,13 @@
   LinkMovie(const Object *obj);
   ~LinkMovie();
 
-  bool isOk() const override { return annotRef.num >= 0 || annotTitle != nullptr; }
+  bool isOk() const override { return hasAnnotRef() || hasAnnotTitle(); }
   LinkActionKind getKind() const override { return actionMovie; }
 
   // a movie action stores either an indirect reference to a movie annotation
   // or the movie annotation title
 
-  bool hasAnnotRef() const { return annotRef.num >= 0; }
+  bool hasAnnotRef() const { return annotRef != Ref::INVALID(); }
   bool hasAnnotTitle() const { return annotTitle != nullptr; }
   const Ref *getAnnotRef() const { return &annotRef; }
   const GooString *getAnnotTitle() const { return annotTitle; }
diff --git a/qt5/src/poppler-annotation-private.h b/qt5/src/poppler-annotation-private.h
index b0072af..937edad 100644
--- a/qt5/src/poppler-annotation-private.h
+++ b/qt5/src/poppler-annotation-private.h
@@ -97,7 +97,7 @@
         AnnotPath * toAnnotPath(const QLinkedList<QPointF> &l) const;
 
         /* Scan page for annotations, parentId=0 searches for root annotations, subtypes empty means all subtypes */
-        static QList<Annotation*> findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentId = 0);
+        static QList<Annotation*> findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentId = -1);
 
         /* Add given annotation to given page */
         static void addAnnotationToPage(::Page *pdfPage, DocumentData *doc, const Annotation * ann);
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index 80a8589..207d6ca 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -1,5 +1,5 @@
 /* poppler-annotation.cc: qt interface to poppler
- * Copyright (C) 2006, 2009, 2012-2015, 2018 Albert Astals Cid <aacid@kde.org>
+ * Copyright (C) 2006, 2009, 2012-2015, 2018, 2019 Albert Astals Cid <aacid@kde.org>
  * Copyright (C) 2006, 2008, 2010 Pino Toscano <pino@kde.org>
  * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral@kde.org>
  * Copyright (C) 2012-2014 Fabio D'Urso <fabiodurso@hotmail.it>
@@ -1741,7 +1741,7 @@
 
     const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup*>(d->pdfAnnot);
 
-    if (markupann && markupann->getInReplyToID() != 0)
+    if (markupann && markupann->isInReplyTo())
     {
         switch (markupann->getReplyTo())
         {
@@ -1764,7 +1764,7 @@
 
     const AnnotText *textann = dynamic_cast<const AnnotText*>(d->pdfAnnot);
 
-    if (textann && textann->getInReplyToID() != 0)
+    if (textann && textann->isInReplyTo())
     {
         switch (textann->getState())
         {