Use the newly introduced Ref::INVALID()
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index fd2ea0f..668d0c5 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3773,7 +3773,7 @@
     border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   }
 
-  updatedAppearanceStream.num = updatedAppearanceStream.gen = -1;
+  updatedAppearanceStream = Ref::INVALID();
 }
 
 LinkAction* AnnotWidget::getAdditionalAction(AdditionalActionsType type)
@@ -4100,9 +4100,7 @@
         if (forceZapfDingbats) {
           // We are forcing ZaDb but the font does not exist
           // so create a fake one
-          Ref r; // dummy Ref, it's not used at all in this codepath
-          r.num = -1;
-          r.gen = -1;
+          Ref r = Ref::INVALID(); // dummy Ref, it's not used at all in this codepath
           Dict *d = new Dict(xref);
           fontToFree = new Gfx8BitFont(xref, "ZaDb", r, new GooString("ZapfDingbats"), fontType1, r, d);
           delete d;
@@ -4908,7 +4906,7 @@
 {
   // If this the first time updateAppearanceStream() is called on this widget,
   // destroy the AP dictionary because we are going to create a new one.
-  if (updatedAppearanceStream.num == -1) {
+  if (updatedAppearanceStream == Ref::INVALID()) {
     invalidateAppearance(); // Delete AP dictionary and all referenced streams
   }
 
@@ -4928,7 +4926,7 @@
   // If this the first time updateAppearanceStream() is called on this widget,
   // create a new AP dictionary containing the new appearance stream.
   // Otherwise, just update the stream we had created previously.
-  if (updatedAppearanceStream.num == -1) {
+  if (updatedAppearanceStream == Ref::INVALID()) {
     // Write the appearance stream
     updatedAppearanceStream = xref->addIndirectObject(&obj1);
 
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 44282d9..db6f0b8 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -601,7 +601,7 @@
   }
 
   //----- embedded font
-  if (embFontID.num >= 0) {
+  if (embFontID != Ref::INVALID()) {
     embed = true;
     Object refObj(embFontID);
     Object embFontObj = refObj.fetch(xref);
@@ -823,7 +823,7 @@
   Object obj2 = obj1.fetch(xref);
   if (!obj2.isStream()) {
     error(errSyntaxError, -1, "Embedded font file is not a stream");
-    embFontID.num = -1;
+    embFontID = Ref::INVALID();
     *len = 0;
     return nullptr;
   }
@@ -1027,7 +1027,7 @@
 
   // for non-embedded fonts, don't trust the ascent/descent/bbox
   // values from the font descriptor
-  if (builtinFont && embFontID.num < 0) {
+  if (builtinFont && embFontID == Ref::INVALID()) {
     ascent = 0.001 * builtinFont->ascent;
     descent = 0.001 * builtinFont->descent;
     fontBBox[0] = 0.001 * builtinFont->bbox[0];
@@ -1123,7 +1123,7 @@
   ffT1 = nullptr;
   ffT1C = nullptr;
   buf = nullptr;
-  if (type == fontType1 && embFontID.num >= 0) {
+  if (type == fontType1 && embFontID != Ref::INVALID()) {
     if ((buf = readEmbFontFile(xref, &len))) {
       if ((ffT1 = FoFiType1::make(buf, len))) {
 	if (ffT1->getName()) {
@@ -1139,7 +1139,7 @@
       }
       gfree(buf);
     }
-  } else if (type == fontType1C && embFontID.num >= 0) {
+  } else if (type == fontType1C && embFontID != Ref::INVALID()) {
     if ((buf = readEmbFontFile(xref, &len))) {
       if ((ffT1C = FoFiType1C::make(buf, len))) {
 	if (ffT1C->getName()) {
@@ -1159,7 +1159,7 @@
 
   // get default base encoding
   if (!baseEnc) {
-    if (builtinFont && embFontID.num < 0) {
+    if (builtinFont && embFontID == Ref::INVALID()) {
       baseEnc = builtinFont->defaultBaseEnc;
       hasEncoding = true;
     } else if (type == fontTrueType) {
@@ -1197,7 +1197,7 @@
   // T1C->T1 conversion (since the 'seac' operator depends on having
   // the accents in the encoding), so we fill in any gaps from
   // StandardEncoding
-  if (type == fontType1C && embFontID.num >= 0 && baseEncFromFontFile) {
+  if (type == fontType1C && embFontID != Ref::INVALID() && baseEncFromFontFile) {
     for (i = 0; i < 256; ++i) {
       if (!enc[i] && standardEncoding[i]) {
 	enc[i] = (char *)standardEncoding[i];
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 0b1b03e..740a29c 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -218,8 +218,8 @@
   // Invalidate an embedded font
   // Returns false if there is no embedded font.
   bool invalidateEmbeddedFont() {
-    if (embFontID.num >= 0) {
-      embFontID.num = -1;
+    if (embFontID != Ref::INVALID()) {
+      embFontID = Ref::INVALID();
       return true;
     }
     return false;
diff --git a/poppler/Link.cc b/poppler/Link.cc
index bd9e6a6..33b842f 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -638,7 +638,7 @@
 //------------------------------------------------------------------------
 
 LinkMovie::LinkMovie(const Object *obj) {
-  annotRef.num = -1;
+  annotRef = Ref::INVALID();
   annotTitle = nullptr;
 
   const Object &annotationObj = obj->dictLookupNF("Annotation");
@@ -651,7 +651,7 @@
     annotTitle = tmp.getString()->copy();
   }
 
-  if ((annotTitle == nullptr) && (annotRef.num == -1)) {
+  if ((annotTitle == nullptr) && (annotRef == Ref::INVALID())) {
     error(errSyntaxError, -1,
 	  "Movie action is missing both the Annot and T keys");
   }
@@ -733,7 +733,7 @@
   js = nullptr;
   int operationCode = -1;
 
-  screenRef.num = -1;
+  screenRef = Ref::INVALID();
 
   if (obj->isDict()) {
     Object tmp = obj->dictLookup("JS");
diff --git a/poppler/Link.h b/poppler/Link.h
index 801b75c..08949ea 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -360,7 +360,7 @@
   bool hasRenditionObject() const { return renditionObj.isDict(); }
   const Object* getRenditionObject() const { return &renditionObj; }
 
-  bool hasScreenAnnot() const { return screenRef.num != -1; }
+  bool hasScreenAnnot() const { return screenRef != Ref::INVALID(); }
   Ref getScreenAnnot() const { return screenRef; }
 
   RenditionOperation getOperation() const { return operation; }
diff --git a/poppler/StructElement.h b/poppler/StructElement.h
index 9030fb3..4cc052a 100644
--- a/poppler/StructElement.h
+++ b/poppler/StructElement.h
@@ -155,7 +155,7 @@
   bool isGrouping() const;
 
   inline bool isContent() const { return (type == MCID) || isObjectRef(); }
-  inline bool isObjectRef() const { return (type == OBJR && c->ref.num != -1 && c->ref.gen != -1); }
+  inline bool isObjectRef() const { return (type == OBJR && c->ref != Ref::INVALID()); }
 
   int getMCID() const { return c->mcid; }
   Ref getObjectRef() const { return c->ref; }
diff --git a/poppler/StructTreeRoot.h b/poppler/StructTreeRoot.h
index 41b1cd8..58b129c 100644
--- a/poppler/StructTreeRoot.h
+++ b/poppler/StructTreeRoot.h
@@ -5,7 +5,7 @@
 // This file is licensed under the GPLv2 or later
 //
 // Copyright 2013, 2014 Igalia S.L.
-// Copyright 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright 2018, 2019 Albert Astals Cid <aacid@kde.org>
 // Copyright 2018 Adrian Johnson <ajohnson@redneon.com>
 // Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
 //
@@ -64,7 +64,7 @@
     Ref            ref;
     StructElement *element;
 
-    Parent(): element(nullptr) { ref.num = ref.gen = -1; }
+    Parent(): element(nullptr) { ref = Ref::INVALID(); }
     Parent(const Parent &p) = default;
     Parent& operator=(const Parent &) = default;
     ~Parent() {}
diff --git a/qt5/src/poppler-link.cc b/qt5/src/poppler-link.cc
index da3d5d8..099871d 100644
--- a/qt5/src/poppler-link.cc
+++ b/qt5/src/poppler-link.cc
@@ -1,5 +1,5 @@
 /* poppler-link.cc: qt interface to poppler
- * Copyright (C) 2006-2007, 2013, 2016-2018, Albert Astals Cid
+ * Copyright (C) 2006-2007, 2013, 2016-2019, Albert Astals Cid
  * Copyright (C) 2007-2008, Pino Toscano <pino@kde.org>
  * Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
  * Copyright (C) 2012, Tobias Koenig <tokoe@kdab.com>
@@ -626,7 +626,7 @@
 	bool LinkRendition::isReferencedAnnotation( const ScreenAnnotation *annotation ) const
 	{
 		Q_D( const LinkRendition );
-		if ( d->annotationReference.num != -1 && d->annotationReference == annotation->d_ptr->pdfObjectReference() )
+		if ( d->annotationReference != Ref::INVALID() && d->annotationReference == annotation->d_ptr->pdfObjectReference() )
 		{
 			return true;
 		}
@@ -681,7 +681,7 @@
 	bool LinkMovie::isReferencedAnnotation( const MovieAnnotation *annotation ) const
 	{
 		Q_D( const LinkMovie );
-		if ( d->annotationReference.num != -1 && d->annotationReference == annotation->d_ptr->pdfObjectReference() )
+		if ( d->annotationReference != Ref::INVALID() && d->annotationReference == annotation->d_ptr->pdfObjectReference() )
 		{
 			return true;
 		}
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index c6e3d52..3e75062 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -1,7 +1,7 @@
 /* poppler-page.cc: qt interface to poppler
  * Copyright (C) 2005, Net Integration Technologies, Inc.
  * Copyright (C) 2005, Brad Hards <bradh@frogmouth.net>
- * Copyright (C) 2005-2018, Albert Astals Cid <aacid@kde.org>
+ * Copyright (C) 2005-2019, Albert Astals Cid <aacid@kde.org>
  * Copyright (C) 2005, Stefan Kebekus <stefan.kebekus@math.uni-koeln.de>
  * Copyright (C) 2006-2011, Pino Toscano <pino@kde.org>
  * Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
@@ -299,8 +299,7 @@
 
       const QString title = ( lm->hasAnnotTitle() ? UnicodeParsedString( lm->getAnnotTitle() ) : QString() );
 
-      Ref reference;
-      reference.num = reference.gen = -1;
+      Ref reference = Ref::INVALID();
       if ( lm->hasAnnotRef() )
         reference = *lm->getAnnotRef();
 
@@ -329,8 +328,7 @@
     {
       ::LinkRendition *lrn = (::LinkRendition *)a;
 
-      Ref reference;
-      reference.num = reference.gen = -1;
+      Ref reference = Ref::INVALID();
       if ( lrn->hasScreenAnnot() )
         reference = lrn->getScreenAnnot();