Commit 13c95f25 authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid
Browse files

Make getPdfVersion return a dedicated version object

That's a bit more modern than the old way where pointers to two
integers had to be passed to the method.

With the new method you can write

  auto pdfVersion = doc->getPdfVersion();
  // access numbers as pdfVersion.major and pdfVersion.minor

instead of

  int major, minor;
  doc->getPdfVersion(&major, &minor);

With C++17 you can even write

  auto [major, minor] = doc->getPdfVersion();

The new method is put alongside the old one in the Qt5 interface.
It replaces the old one in the Qt6 interface.
parent fdb83a88
Pipeline #360289 passed with stage
in 6 minutes and 26 seconds
......@@ -556,6 +556,11 @@ void Document::getPdfVersion(int *major, int *minor) const
*minor = m_doc->doc->getPDFMinorVersion();
}
Document::PdfVersion Document::getPdfVersion() const
{
return PdfVersion { m_doc->doc->getPDFMajorVersion(), m_doc->doc->getPDFMinorVersion() };
}
Page *Document::page(const QString &label) const
{
GooString label_g(label.toLatin1().data());
......
......@@ -1648,9 +1648,27 @@ QString subject = m_doc->info("Subject");
\param minor an optional pointer to a variable where store the
"minor" number of the version
\deprecated Will be removed in the Qt6 interface. Use the method
returning a PdfVersion object instead!
\since 0.12
*/
void getPdfVersion(int *major, int *minor) const;
Q_DECL_DEPRECATED void getPdfVersion(int *major, int *minor) const;
/** \brief The version specification of a pdf file */
struct PdfVersion
{
int major;
int minor;
};
/**
The version of the PDF specification that the document
conforms to
\since 21.08
*/
PdfVersion getPdfVersion() const;
/**
The fonts within the PDF document.
......
......@@ -226,10 +226,9 @@ void TestMetaData::checkVersion()
doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
QVERIFY(doc);
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
QCOMPARE(major, 1);
QCOMPARE(minor, 6);
auto pdfVersion = doc->getPdfVersion();
QCOMPARE(pdfVersion.major, 1);
QCOMPARE(pdfVersion.minor, 6);
delete doc;
}
......
......@@ -28,8 +28,11 @@ int main(int argc, char **argv)
delete doc;
}
} else {
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
auto pdfVersion = doc->getPdfVersion();
if (pdfVersion.major != 1) {
qWarning() << "pdf major version is not '1'";
}
doc->info(QStringLiteral("Title"));
doc->info(QStringLiteral("Subject"));
doc->info(QStringLiteral("Author"));
......
......@@ -36,8 +36,8 @@ int main(int argc, char **argv)
if (!doc) {
qWarning() << "doc not loaded";
} else {
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
auto pdfVersion = doc->getPdfVersion();
Q_UNUSED(pdfVersion);
doc->info(QStringLiteral("Title"));
doc->info(QStringLiteral("Subject"));
doc->info(QStringLiteral("Author"));
......
......@@ -95,9 +95,8 @@ int main(int argc, char **argv)
}
// output some meta-data
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(major).arg(minor));
auto pdfVersion = doc->getPdfVersion();
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(pdfVersion.major).arg(pdfVersion.minor));
qDebug() << " Title: " << doc->info(QStringLiteral("Title"));
qDebug() << " Subject: " << doc->info(QStringLiteral("Subject"));
qDebug() << " Author: " << doc->info(QStringLiteral("Author"));
......
......@@ -150,9 +150,8 @@ int main(int argc, char **argv)
}
// output some meta-data
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(major).arg(minor));
Poppler::Document::PdfVersion pdfVersion = doc->getPdfVersion();
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(pdfVersion.major).arg(pdfVersion.minor));
qDebug() << " Title: " << doc->info(QStringLiteral("Title"));
qDebug() << " Subject: " << doc->info(QStringLiteral("Subject"));
qDebug() << " Author: " << doc->info(QStringLiteral("Author"));
......
......@@ -548,12 +548,9 @@ bool Document::okToAssemble() const
return m_doc->doc->okToAssemble();
}
void Document::getPdfVersion(int *major, int *minor) const
Document::PdfVersion Document::getPdfVersion() const
{
if (major)
*major = m_doc->doc->getPDFMajorVersion();
if (minor)
*minor = m_doc->doc->getPDFMinorVersion();
return PdfVersion { m_doc->doc->getPDFMajorVersion(), m_doc->doc->getPDFMinorVersion() };
}
std::unique_ptr<Page> Document::page(const QString &label) const
......
......@@ -1514,16 +1514,20 @@ QString subject = m_doc->info("Subject");
*/
bool okToAssemble() const;
/** \brief The version specification of a pdf file */
struct PdfVersion
{
int major;
int minor;
};
/**
The version of the PDF specification that the document
conforms to
\param major an optional pointer to a variable where store the
"major" number of the version
\param minor an optional pointer to a variable where store the
"minor" number of the version
\since 21.08
*/
void getPdfVersion(int *major, int *minor) const;
PdfVersion getPdfVersion() const;
/**
The fonts within the PDF document.
......
......@@ -181,10 +181,9 @@ void TestMetaData::checkVersion()
std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(TESTDATADIR "/unittestcases/doublepage.pdf");
QVERIFY(doc);
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
QCOMPARE(major, 1);
QCOMPARE(minor, 6);
auto pdfVersion = doc->getPdfVersion();
QCOMPARE(pdfVersion.major, 1);
QCOMPARE(pdfVersion.minor, 6);
}
void TestMetaData::checkPdfId()
......
......@@ -27,8 +27,8 @@ int main(int argc, char **argv)
qWarning() << "couldn't unlock document";
}
} else {
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
auto pdfVersion = doc->getPdfVersion();
Q_UNUSED(pdfVersion);
doc->info(QStringLiteral("Title"));
doc->info(QStringLiteral("Subject"));
doc->info(QStringLiteral("Author"));
......
......@@ -36,8 +36,8 @@ int main(int argc, char **argv)
if (!doc) {
qWarning() << "doc not loaded";
} else {
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
auto pdfVersion = doc->getPdfVersion();
Q_UNUSED(pdfVersion);
doc->info(QStringLiteral("Title"));
doc->info(QStringLiteral("Subject"));
doc->info(QStringLiteral("Author"));
......
......@@ -91,9 +91,8 @@ int main(int argc, char **argv)
}
// output some meta-data
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(major).arg(minor));
auto pdfVersion = doc->getPdfVersion();
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(pdfVersion.major).arg(pdfVersion.minor));
qDebug() << " Title: " << doc->info(QStringLiteral("Title"));
qDebug() << " Subject: " << doc->info(QStringLiteral("Subject"));
qDebug() << " Author: " << doc->info(QStringLiteral("Author"));
......
......@@ -144,9 +144,8 @@ int main(int argc, char **argv)
}
// output some meta-data
int major = 0, minor = 0;
doc->getPdfVersion(&major, &minor);
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(major).arg(minor));
auto pdfVersion = doc->getPdfVersion();
qDebug() << " PDF Version: " << qPrintable(QStringLiteral("%1.%2").arg(pdfVersion.major).arg(pdfVersion.minor));
qDebug() << " Title: " << doc->info(QStringLiteral("Title"));
qDebug() << " Subject: " << doc->info(QStringLiteral("Subject"));
qDebug() << " Author: " << doc->info(QStringLiteral("Author"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment