[poppler] poppler/Catalog.cc poppler/Catalog.h poppler/PDFDoc.cc poppler/PDFDoc.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jul 22 22:01:53 UTC 2021
poppler/Catalog.cc | 11 ++++++++++-
poppler/Catalog.h | 8 +++++++-
poppler/PDFDoc.cc | 8 ++++----
poppler/PDFDoc.h | 27 ++++++++++++++++++++-------
4 files changed, 41 insertions(+), 13 deletions(-)
New commits:
commit ef8c8ca8500ce9de91a5903b8561e3e02a81888e
Author: Albert Astals Cid <aacid at kde.org>
Date: Thu Jul 22 17:54:47 2021 +0200
Support reading the Version from the Catalog
Fixes #1097
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 53fdfb5a..616f43d7 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2005-2013, 2015, 2017-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2013, 2015, 2017-2021 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2005 Jeff Muizelaar <jrmuizel at nit.ca>
// Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
// Copyright (C) 2005 Marco Pesenti Gritti <mpg at redhat.com>
@@ -130,6 +130,15 @@ Catalog::Catalog(PDFDoc *docA)
// get the ViewerPreferences dictionary
viewerPreferences = catDict.dictLookup("ViewerPreferences");
+
+ const Object version = catDict.dictLookup("Version");
+ if (version.isName()) {
+ const int res = sscanf(version.getName(), "%d.%d", &catalogPdfMajorVersion, &catalogPdfMinorVersion);
+ if (res != 2) {
+ catalogPdfMajorVersion = -1;
+ catalogPdfMinorVersion = -1;
+ }
+ }
}
Catalog::~Catalog()
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index 6d568b75..fc561e29 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2005, 2007, 2009-2011, 2013, 2017-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2007, 2009-2011, 2013, 2017-2021 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
// Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
// Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
@@ -214,6 +214,9 @@ public:
OCGs *getOptContentConfig() { return optContent; }
+ int getPDFMajorVersion() const { return catalogPdfMajorVersion; }
+ int getPDFMinorVersion() const { return catalogPdfMinorVersion; }
+
enum FormType
{
NoForm,
@@ -305,6 +308,9 @@ private:
NameTree *getJSNameTree();
std::unique_ptr<LinkDest> createLinkDest(Object *obj);
+ int catalogPdfMajorVersion = -1;
+ int catalogPdfMinorVersion = -1;
+
mutable std::recursive_mutex mutex;
};
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 7646fb89..bd4dcde8 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
-// Copyright (C) 2005, 2007-2009, 2011-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2007-2009, 2011-2021 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2008 Julien Rebetez <julienr at svn.gnome.org>
// Copyright (C) 2008, 2010 Pino Toscano <pino at kde.org>
// Copyright (C) 2008, 2010, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -411,8 +411,8 @@ void PDFDoc::checkHeader()
int i;
int bytesRead;
- pdfMajorVersion = 0;
- pdfMinorVersion = 0;
+ headerPdfMajorVersion = 0;
+ headerPdfMinorVersion = 0;
// read up to headerSearchSize bytes from the beginning of the document
for (i = 0; i < headerSearchSize; ++i) {
@@ -441,7 +441,7 @@ void PDFDoc::checkHeader()
error(errSyntaxWarning, -1, "May not be a PDF file (continuing anyway)");
return;
}
- sscanf(p, "%d.%d", &pdfMajorVersion, &pdfMinorVersion);
+ sscanf(p, "%d.%d", &headerPdfMajorVersion, &headerPdfMinorVersion);
// We don't do the version check. Don't add it back in.
}
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index a2d0098b..63ec25b4 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
-// Copyright (C) 2005, 2009, 2014, 2015, 2017-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2009, 2014, 2015, 2017-2021 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2008 Julien Rebetez <julienr at svn.gnome.org>
// Copyright (C) 2008 Pino Toscano <pino at kde.org>
// Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -44,11 +44,14 @@
#ifndef PDFDOC_H
#define PDFDOC_H
+#include <algorithm>
+#include <cstdio>
#include <mutex>
#include "poppler-config.h"
+
#include "poppler_private_export.h"
-#include <cstdio>
+
#include "XRef.h"
#include "Catalog.h"
#include "Page.h"
@@ -278,9 +281,19 @@ public:
PDFSubtypePart getPDFSubtypePart() const { return pdfPart; }
PDFSubtypeConformance getPDFSubtypeConformance() const { return pdfConformance; }
- // Return the PDF version specified by the file.
- int getPDFMajorVersion() const { return pdfMajorVersion; }
- int getPDFMinorVersion() const { return pdfMinorVersion; }
+ // Return the PDF version specified by the file (either header or catalog).
+ int getPDFMajorVersion() const { return std::max(headerPdfMajorVersion, catalog->getPDFMajorVersion()); }
+ int getPDFMinorVersion() const
+ {
+ const int catalogMajorVersion = catalog->getPDFMajorVersion();
+ if (catalogMajorVersion > headerPdfMajorVersion) {
+ return catalog->getPDFMinorVersion();
+ } else if (headerPdfMajorVersion > catalogMajorVersion) {
+ return headerPdfMinorVersion;
+ } else {
+ return std::max(headerPdfMinorVersion, catalog->getPDFMinorVersion());
+ }
+ }
// Return the PDF ID in the trailer dictionary (if any).
bool getID(GooString *permanent_id, GooString *update_id) const;
@@ -365,8 +378,8 @@ private:
GooFile *file;
BaseStream *str;
void *guiData;
- int pdfMajorVersion;
- int pdfMinorVersion;
+ int headerPdfMajorVersion;
+ int headerPdfMinorVersion;
PDFSubtype pdfSubtype;
PDFSubtypePart pdfPart;
PDFSubtypeConformance pdfConformance;
More information about the poppler
mailing list