[poppler] 5 commits - cpp/poppler-document.cpp cpp/poppler-document.h cpp/poppler-page-transition.cpp cpp/poppler-private.cpp cpp/poppler-rectangle.cpp cpp/tests poppler/PDFDoc.cc qt4/src qt4/tests

Pino Toscano pino at kemper.freedesktop.org
Wed Sep 22 08:08:10 PDT 2010


 cpp/poppler-document.cpp        |   29 +++++++++++++++++++++++
 cpp/poppler-document.h          |    3 +-
 cpp/poppler-page-transition.cpp |    2 -
 cpp/poppler-private.cpp         |    2 -
 cpp/poppler-rectangle.cpp       |    2 -
 cpp/tests/poppler-dump.cpp      |    6 ++++
 poppler/PDFDoc.cc               |   11 ++++----
 qt4/src/poppler-document.cc     |   16 ++++++++++++
 qt4/src/poppler-qt4.h           |   14 +++++++++++
 qt4/tests/check_metadata.cpp    |   50 ++++++++++++++++++++++++++++++++++++++++
 10 files changed, 126 insertions(+), 9 deletions(-)

New commits:
commit 1aad013e353a9e59bdab8a1b4ce93f2ad7aaf4f2
Author: Pino Toscano <pino at kde.org>
Date:   Wed Sep 22 17:07:38 2010 +0200

    update copyrights

diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index 89f41e5..9ae56fd 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/cpp/poppler-page-transition.cpp b/cpp/poppler-page-transition.cpp
index 91c5b84..03d33b5 100644
--- a/cpp/poppler-page-transition.cpp
+++ b/cpp/poppler-page-transition.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp
index 6f6704a..67fb14e 100644
--- a/cpp/poppler-private.cpp
+++ b/cpp/poppler-private.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/cpp/poppler-rectangle.cpp b/cpp/poppler-rectangle.cpp
index 462280b..83e5cc9 100644
--- a/cpp/poppler-rectangle.cpp
+++ b/cpp/poppler-rectangle.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
commit 2d6d66ebe0215df66e33cb5974c58c324fab50b6
Author: Pino Toscano <pino at kde.org>
Date:   Wed Sep 22 17:07:13 2010 +0200

    [cpp/tests] poppler-dump: show the PDF IDs, if available

diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index cb0ee75..f087e3b 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -175,6 +175,12 @@ static void print_info(poppler::document *doc)
     int major = 0, minor = 0;
     doc->get_pdf_version(&major, &minor);
     std::cout << std::setw(out_width) << "PDF version" << ": " << major << "." << minor << std::endl;
+    std::string permanent_id, update_id;
+    if (doc->get_pdf_id(&permanent_id, &update_id)) {
+        std::cout << std::setw(out_width) << "PDF IDs" << ": P: " << permanent_id << " - U: " << update_id << std::endl;
+    } else {
+        std::cout << std::setw(out_width) << "PDF IDs" << ": <none>" << std::endl;
+    }
     const std::vector<std::string> keys = doc->info_keys();
     std::vector<std::string>::const_iterator key_it = keys.begin(), key_end = keys.end();
     for (; key_it != key_end; ++key_it) {
commit e39fde1b62544b90e73a2fc3609a260991db3a47
Author: Pino Toscano <pino at kde.org>
Date:   Wed Sep 22 16:52:08 2010 +0200

    [cpp] add document::get_pdf_id()
    
    ... to get the IDs of a PDF document, if present.

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 50d21a4..beebff5 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -416,6 +416,35 @@ ustring document::metadata() const
 }
 
 /**
+ Gets the IDs of the current PDF %document, if available.
+
+ \param permanent_id if not NULL, will be set to the permanent ID of the %document
+ \param update_id if not NULL, will be set to the update ID of the %document
+
+ \returns whether the document has the IDs
+
+ \since 0.16
+ */
+bool document::get_pdf_id(std::string *permanent_id, std::string *update_id) const
+{
+    GooString goo_permanent_id;
+    GooString goo_update_id;
+
+    if (!d->doc->getID(permanent_id ? &goo_permanent_id : 0, update_id ? &goo_update_id : 0)) {
+        return false;
+    }
+
+    if (permanent_id) {
+        *permanent_id = goo_permanent_id.getCString();
+    }
+    if (update_id) {
+        *update_id = goo_update_id.getCString();
+    }
+
+    return true;
+}
+
+/**
  Document page count.
 
  \returns the number of pages of the document
diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h
index 665b9e7..89f41e5 100644
--- a/cpp/poppler-document.h
+++ b/cpp/poppler-document.h
@@ -67,6 +67,7 @@ public:
     bool is_linearized() const;
     bool has_permission(permission_enum which) const;
     ustring metadata() const;
+    bool get_pdf_id(std::string *permanent_id, std::string *update_id) const;
 
     int pages() const;
     page* create_page(const ustring &label) const;
commit 299a1849a148fa0a7b3171c45ec68b9901aa93bb
Author: Pino Toscano <pino at kde.org>
Date:   Wed Sep 22 16:36:30 2010 +0200

    [Qt4] add Document::getPdfId()
    
    ... to get the IDs of a PDF document, if present.
    
    also, add two test cases for it in the metadata unit test

diff --git a/qt4/src/poppler-document.cc b/qt4/src/poppler-document.cc
index 41d35b6..77c23a2 100644
--- a/qt4/src/poppler-document.cc
+++ b/qt4/src/poppler-document.cc
@@ -576,6 +576,22 @@ namespace Poppler {
         return scripts;
     }
 
+    bool Document::getPdfId(QByteArray *permanentId, QByteArray *updateId) const
+    {
+        GooString gooPermanentId;
+        GooString gooUpdateId;
+
+        if (!m_doc->doc->getID(permanentId ? &gooPermanentId : 0, updateId ? &gooUpdateId : 0))
+            return false;
+
+        if (permanentId)
+            *permanentId = gooPermanentId.getCString();
+        if (updateId)
+            *updateId = gooUpdateId.getCString();
+
+        return true;
+    }
+
     QDateTime convertDate( char *dateString )
     {
         int year, mon, day, hour, min, sec, tzHours, tzMins;
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 5ddaaf8..8a79a2a 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -1216,6 +1216,20 @@ QString subject = m_doc->info("Subject");
 	QStringList scripts() const;
 
 	/**
+	   The PDF identifiers.
+
+	   \param permanentId an optional pointer to a variable where store the
+	   permanent ID of the document
+	   \param updateId an optional pointer to a variable where store the
+	   update ID of the document
+
+	   \return whether the document has the IDs
+
+	   \since 0.16
+	*/
+	bool getPdfId(QByteArray *permanentId, QByteArray *updateId) const;
+
+	/**
 	   Destructor.
 	*/
 	~Document();
diff --git a/qt4/tests/check_metadata.cpp b/qt4/tests/check_metadata.cpp
index 48f05a6..dc22367 100644
--- a/qt4/tests/check_metadata.cpp
+++ b/qt4/tests/check_metadata.cpp
@@ -20,6 +20,8 @@ private slots:
     void checkUpsideDownOrientation();
     void checkSeascapeOrientation();
     void checkVersion();
+    void checkPdfId();
+    void checkNoPdfId();
 };
 
 void TestMetaData::checkStrings_data()
@@ -221,6 +223,54 @@ void TestMetaData::checkVersion()
     delete doc;
 }
 
+void TestMetaData::checkPdfId()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load("../../../test/unittestcases/A6EmbeddedFiles.pdf");
+    QVERIFY( doc );
+
+    const QByteArray referencePermanentId( "00C9D5B6D8FB11D7A902003065D630AA" );
+    const QByteArray referenceUpdateId( "39AECAE6D8FB11D7A902003065D630AA" );
+
+    {
+    // no IDs wanted, just existance check
+    QVERIFY( doc->getPdfId( 0, 0 ) );
+    }
+    {
+    // only permanent ID
+    QByteArray permanentId;
+    QVERIFY( doc->getPdfId( &permanentId, 0 ) );
+    QCOMPARE( permanentId.toUpper(), referencePermanentId );
+    }
+    {
+    // only update ID
+    QByteArray updateId;
+    QVERIFY( doc->getPdfId( 0, &updateId ) );
+    QCOMPARE( updateId.toUpper(), referenceUpdateId );
+    }
+    {
+    // both IDs
+    QByteArray permanentId;
+    QByteArray updateId;
+    QVERIFY( doc->getPdfId( &permanentId, &updateId ) );
+    QCOMPARE( permanentId.toUpper(), referencePermanentId );
+    QCOMPARE( updateId.toUpper(), referenceUpdateId );
+    }
+
+    delete doc;
+}
+
+void TestMetaData::checkNoPdfId()
+{
+    Poppler::Document *doc;
+    doc = Poppler::Document::load("../../../test/unittestcases/WithActualText.pdf");
+    QVERIFY( doc );
+
+    QVERIFY( !doc->getPdfId( 0, 0 ) );
+
+    delete doc;
+}
+
 QTEST_MAIN(TestMetaData)
 #include "check_metadata.moc"
 
commit dd9bcdb720ac1bf8a022635bcbb3b56e4b75bb15
Author: Pino Toscano <pino at kde.org>
Date:   Wed Sep 22 16:29:46 2010 +0200

    Make the internal get_id() not fail because of null bytes in the ID.
    
    Passing the const char* of the byte string to convert is not enough if its length must be checked,
    as it might fail when the string of the ID contains null bytes.
    Instead, pass the original GooString so its size is properly checked.
    
    Also, remove an hardcoded 16 and make it dependent on pdfIdLength, as used elsewhere in get_id() function.

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 87334e4..8155250 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -16,7 +16,7 @@
 // Copyright (C) 2005, 2006, 2008 Brad Hards <bradh at frogmouth.net>
 // Copyright (C) 2005, 2007-2009 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, 2010 Pino Toscano <pino at kde.org>
 // Copyright (C) 2008, 2010 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2009 Eric Toombs <ewtoombs at uwaterloo.ca>
 // Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
@@ -465,11 +465,12 @@ GBool PDFDoc::isLinearized() {
 }
 
 static GBool
-get_id (const char *encodedid, GooString *id) {
+get_id (GooString *encodedidstring, GooString *id) {
+  const char *encodedid = encodedidstring->getCString();
   char pdfid[pdfIdLength + 1];
   int n;
 
-  if (strlen(encodedid) != 16)
+  if (encodedidstring->getLength() != pdfIdLength / 2)
     return gFalse;
 
   n = sprintf(pdfid, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
@@ -493,7 +494,7 @@ GBool PDFDoc::getID(GooString *permanent_id, GooString *update_id) {
 
     if (permanent_id) {
       if (obj.arrayGet(0, &obj2)->isString()) {
-        if (!get_id (obj2.getString()->getCString(), permanent_id)) {
+        if (!get_id (obj2.getString(), permanent_id)) {
 	  obj2.free();
 	  return gFalse;
 	}
@@ -507,7 +508,7 @@ GBool PDFDoc::getID(GooString *permanent_id, GooString *update_id) {
 
     if (update_id) {
       if (obj.arrayGet(1, &obj2)->isString()) {
-        if (!get_id (obj2.getString()->getCString(), update_id)) {
+        if (!get_id (obj2.getString(), update_id)) {
 	  obj2.free();
 	  return gFalse;
 	}


More information about the poppler mailing list