From 62734b24c29a9eb7c262e3a7a0445bdb89bce3cc Mon Sep 17 00:00:00 2001 From: Jakub Kucharski Date: Tue, 23 Feb 2016 15:36:43 +0100 Subject: [PATCH 1/7] Added XRef modification flag --- poppler/PDFDoc.cc | 12 +----------- poppler/XRef.cc | 5 +++++ poppler/XRef.h | 7 +++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index 9fc43e5..703a4fd 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -865,17 +865,7 @@ int PDFDoc::saveAs(GooString *name, PDFWriteMode mode) { } int PDFDoc::saveAs(OutStream *outStr, PDFWriteMode mode) { - - // find if we have updated objects - GBool updated = gFalse; - for(int i=0; igetNumObjects(); i++) { - if (xref->getEntry(i)->getFlag(XRefEntry::Updated)) { - updated = gTrue; - break; - } - } - - if (!updated && mode == writeStandard) { + if (!xref->isModified() && mode == writeStandard) { // simply copy the original file saveWithoutChangesAs (outStr); } else if (mode == writeForceRewrite) { diff --git a/poppler/XRef.cc b/poppler/XRef.cc index 3d032bc..8570819 100644 --- a/poppler/XRef.cc +++ b/poppler/XRef.cc @@ -24,6 +24,7 @@ // Copyright (C) 2012, 2013 Fabio D'Urso // Copyright (C) 2013, 2014 Adrian Johnson // Copyright (C) 2013 Pino Toscano +// Copyright (C) 2016 Jakub Kucharski // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -286,6 +287,7 @@ void XRef::init() { entries = NULL; capacity = 0; size = 0; + modified = gFalse; streamEnds = NULL; streamEndsLen = 0; objStrs = new PopplerCache(5); @@ -1373,6 +1375,7 @@ void XRef::setModifiedObject (Object* o, Ref r) { e->obj.free(); o->copy(&(e->obj)); e->setFlag(XRefEntry::Updated, gTrue); + setModified(); } Ref XRef::addIndirectObject (Object* o) { @@ -1398,6 +1401,7 @@ Ref XRef::addIndirectObject (Object* o) { e->type = xrefEntryUncompressed; o->copy(&e->obj); e->setFlag(XRefEntry::Updated, gTrue); + setModified(); Ref r; r.num = entryIndexToUse; @@ -1419,6 +1423,7 @@ void XRef::removeIndirectObject(Ref r) { e->type = xrefEntryFree; e->gen++; e->setFlag(XRefEntry::Updated, gTrue); + setModified(); } void XRef::writeXRef(XRef::XRefWriter *writer, GBool writeAllEntries) { diff --git a/poppler/XRef.h b/poppler/XRef.h index 8748cb4..739b537 100644 --- a/poppler/XRef.h +++ b/poppler/XRef.h @@ -22,6 +22,7 @@ // Copyright (C) 2012, 2013, 2016 Thomas Freitag // Copyright (C) 2012, 2013 Fabio D'Urso // Copyright (C) 2013 Adrian Johnson +// Copyright (C) 2016 Jakub Kucharski // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -175,6 +176,11 @@ public: XRefEntry *getEntry(int i, GBool complainIfMissing = gTrue); Object *getTrailerDict() { return &trailerDict; } + // Was the XRef modified? + GBool isModified() { return modified; } + // Set the modification flag for XRef to true. + void setModified() { modified = gTrue; } + // Write access void setModifiedObject(Object* o, Ref r); Ref addIndirectObject (Object* o); @@ -203,6 +209,7 @@ private: int errCode; // error code (if is false) GBool xrefReconstructed; // marker, true if xref was already reconstructed Object trailerDict; // trailer dictionary + GBool modified; Goffset *streamEnds; // 'endstream' positions - only used in // damaged files int streamEndsLen; // number of valid entries in streamEnds -- 2.8.3