poppler/Annot.cc | 3 +-- poppler/Annot.h | 1 + poppler/Array.cc | 4 ++-- poppler/Array.h | 1 + poppler/Catalog.cc | 2 +- poppler/Dict.cc | 4 ++-- poppler/Dict.h | 1 + poppler/Function.cc | 2 +- poppler/GfxFont.cc | 8 ++++---- poppler/GfxFont.h | 2 +- poppler/GfxState.cc | 12 +++--------- poppler/Link.h | 4 ++-- qt5/src/poppler-annotation-private.h | 2 +- qt5/src/poppler-annotation.cc | 6 +++--- 14 files changed, 24 insertions(+), 28 deletions(-)
New commits: commit 3fe46034a9621b2769d20a15a662334e4270d32c Author: Albert Astals Cid <aa...@kde.org> Date: Fri Mar 29 10:52:19 2019 +0100 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 3bc776ec..a061a1b7 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -1997,8 +1997,7 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict) { 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 9f6c9fb1..3a937944 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -821,6 +821,7 @@ public: 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 cc7dd0c1..a6cf4bcc 100644 --- a/poppler/Array.cc +++ b/poppler/Array.cc @@ -80,13 +80,13 @@ Object Array::get(int i, int recursion) const { 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 1d03cbc9..be1123cf 100644 --- a/poppler/Array.h +++ b/poppler/Array.h @@ -68,6 +68,7 @@ public: // 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 905954e3..d01e8fca 100644 --- a/poppler/Catalog.cc +++ b/poppler/Catalog.cc @@ -502,7 +502,7 @@ void Catalog::addEmbeddedFile(GooFile *file, const std::string &fileName) 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 f1d6c6e1..17c2f98e 100644 --- a/poppler/Dict.cc +++ b/poppler/Dict.cc @@ -173,11 +173,11 @@ Object Dict::lookup(const char *key, Ref *returnRef, int recursion) const { 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 13da4822..6c1424a5 100644 --- a/poppler/Dict.h +++ b/poppler/Dict.h @@ -76,6 +76,7 @@ public: // 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 873c2c0a..e7973e20 100644 --- a/poppler/Function.cc +++ b/poppler/Function.cc @@ -692,7 +692,7 @@ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict, std::set<int> 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 db6f0b8d..c74b4b0d 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -290,7 +290,7 @@ GfxFontType GfxFont::getFontType(XRef *xref, Dict *fontDict, Ref *embID) { bool isType0, err; t = fontUnknownType; - embID->num = embID->gen = -1; + *embID = Ref::INVALID(); err = false; Object subtype = fontDict->lookup("Subtype"); @@ -348,7 +348,7 @@ GfxFontType GfxFont::getFontType(XRef *xref, Dict *fontDict, Ref *embID) { 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 @@ GfxFontType GfxFont::getFontType(XRef *xref, Dict *fontDict, Ref *embID) { 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 @@ GfxFontType GfxFont::getFontType(XRef *xref, Dict *fontDict, Ref *embID) { } 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 740a29c2..54ab128a 100644 --- a/poppler/GfxFont.h +++ b/poppler/GfxFont.h @@ -213,7 +213,7 @@ public: // 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 e3417e0f..557ce46d 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -1815,7 +1815,6 @@ GfxColorSpace *GfxICCBasedColorSpace::copy() { 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 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState 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 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState 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 08949ea8..c1079bd5 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -310,13 +310,13 @@ public: 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 b0072af9..937edad4 100644 --- a/qt5/src/poppler-annotation-private.h +++ b/qt5/src/poppler-annotation-private.h @@ -97,7 +97,7 @@ class AnnotationPrivate : public QSharedData 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 80a8589f..207d6ca4 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 <aa...@kde.org> + * Copyright (C) 2006, 2009, 2012-2015, 2018, 2019 Albert Astals Cid <aa...@kde.org> * Copyright (C) 2006, 2008, 2010 Pino Toscano <p...@kde.org> * Copyright (C) 2012, Guillermo A. Amaral B. <gama...@kde.org> * Copyright (C) 2012-2014 Fabio D'Urso <fabiodu...@hotmail.it> @@ -1741,7 +1741,7 @@ Annotation::RevScope Annotation::revisionScope() const 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 @@ Annotation::RevType Annotation::revisionType() const const AnnotText *textann = dynamic_cast<const AnnotText*>(d->pdfAnnot); - if (textann && textann->getInReplyToID() != 0) + if (textann && textann->isInReplyTo()) { switch (textann->getState()) { _______________________________________________ poppler mailing list poppler@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/poppler