[poppler] 2 commits - poppler/Catalog.cc poppler/Catalog.h qt4/src qt4/tests

Pino Toscano pino at kemper.freedesktop.org
Sat Mar 8 03:18:00 PST 2008


 poppler/Catalog.cc              |   17 +++++++++--------
 poppler/Catalog.h               |    7 ++++++-
 qt4/src/poppler-embeddedfile.cc |    5 +++++
 qt4/src/poppler-qt4.h           |    5 +++++
 qt4/tests/check_attachments.cpp |    7 +++++++
 5 files changed, 32 insertions(+), 9 deletions(-)

New commits:
commit 65a88a95a5c54c890048e8a986df361585d601dd
Author: Pino Toscano <pino at kde.org>
Date:   Sat Mar 8 03:11:36 2008 +0100

    Provide the mime type for an embedded file, if known.
    
    Adapt the unit test for that.

diff --git a/qt4/src/poppler-embeddedfile.cc b/qt4/src/poppler-embeddedfile.cc
index 5d7e8be..3eb2bcd 100644
--- a/qt4/src/poppler-embeddedfile.cc
+++ b/qt4/src/poppler-embeddedfile.cc
@@ -80,6 +80,11 @@ QByteArray EmbeddedFile::checksum() const
 	return QByteArray::fromRawData(goo_checksum->getCString(), goo_checksum->getLength());
 }
 
+QString EmbeddedFile::mimeType() const
+{
+	return QString(m_embeddedFile->embfile->mimeType()->getCString());
+}
+
 QByteArray EmbeddedFile::data()
 {
 	Object obj;
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index ca9ceef..726fd75 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -260,6 +260,11 @@ namespace Poppler {
 	QByteArray checksum() const;
 
 	/**
+	   The MIME type of the file, if known.
+	*/
+	QString mimeType() const;
+
+	/**
 	   The data as a byte array
 	*/
 	QByteArray data();
diff --git a/qt4/tests/check_attachments.cpp b/qt4/tests/check_attachments.cpp
index 7c4a697..2e02ec8 100644
--- a/qt4/tests/check_attachments.cpp
+++ b/qt4/tests/check_attachments.cpp
@@ -43,6 +43,7 @@ void TestAttachments::checkAttach1()
     QCOMPARE( embfile->description(), QString("/home/bradh/coding/svn-vers/KDE/kdeartwork/wallpapers/kroller.png") );
     QCOMPARE( embfile->createDate(), QDateTime( QDate(), QTime() ) );
     QCOMPARE( embfile->modDate(), QDateTime( QDate(), QTime() ) );
+    QCOMPARE( embfile->mimeType(), QString() );
 
     QFile file( "../../../test/unittestcases/kroller.png" );
     QVERIFY(  file.open( QIODevice::ReadOnly ) );
@@ -56,6 +57,7 @@ void TestAttachments::checkAttach1()
     QCOMPARE( embfile2->description(), QString("/usr/share/gnome-about/gnome-64.gif") );
     QCOMPARE( embfile2->modDate(), QDateTime( QDate(), QTime() ) );
     QCOMPARE( embfile2->createDate(), QDateTime( QDate(), QTime() ) );
+    QCOMPARE( embfile2->mimeType(), QString() );
 
     QFile file2( "../../../test/unittestcases/gnome-64.gif" );
     QVERIFY(  file2.open( QIODevice::ReadOnly ) );
@@ -85,18 +87,21 @@ void TestAttachments::checkAttach2()
     QCOMPARE( embfile1->description(), QString("Acro7 Thoughts") );
     QCOMPARE( embfile1->createDate(), QDateTime( QDate( 2003, 8, 4 ), QTime( 13, 54, 54), Qt::UTC ) );
     QCOMPARE( embfile1->modDate(), QDateTime( QDate( 2003, 8, 4 ), QTime( 14, 15, 27), Qt::UTC ) );
+    QCOMPARE( embfile1->mimeType(), QString("text/xml") );
 
     Poppler::EmbeddedFile *embfile2 = fileList.at(1);
     QCOMPARE( embfile2->name(), QString("acro transitions 1.xls") );
     QCOMPARE( embfile2->description(), QString("AcroTransitions") );
     QCOMPARE( embfile2->createDate(), QDateTime( QDate( 2003, 7, 18 ), QTime( 21, 7, 16), Qt::UTC ) );
     QCOMPARE( embfile2->modDate(), QDateTime( QDate( 2003, 7, 22 ), QTime( 13, 4, 40), Qt::UTC ) );
+    QCOMPARE( embfile2->mimeType(), QString("application/excel") );
 
     Poppler::EmbeddedFile *embfile3 = fileList.at(2);
     QCOMPARE( embfile3->name(), QString("apago_pdfe_wide.gif") );
     QCOMPARE( embfile3->description(), QString("PDFE Animation") );
     QCOMPARE( embfile3->createDate(), QDateTime( QDate( 2003, 1, 31 ), QTime( 15, 54, 29), Qt::UTC ) );
     QCOMPARE( embfile3->modDate(), QDateTime( QDate( 2003, 1, 31 ), QTime( 15, 52, 58), Qt::UTC ) );
+    QCOMPARE( embfile3->mimeType(), QString() );
 
     delete doc;
 }
@@ -119,6 +124,7 @@ void TestAttachments::checkAttach3()
     QCOMPARE( embfile->description(), QString("encrypted version of document") );
     QCOMPARE( embfile->createDate(), QDateTime( QDate( 2004, 3, 29 ), QTime( 19, 37, 16), Qt::UTC ) );
     QCOMPARE( embfile->modDate(), QDateTime( QDate( 2004, 3, 29 ), QTime( 19, 37, 16), Qt::UTC ) );
+    QCOMPARE( embfile->mimeType(), QString() );
     delete doc;
 
 }
@@ -141,6 +147,7 @@ void TestAttachments::checkAttach4()
     QCOMPARE( embfile->description(), QString("Altona Export") );
     QCOMPARE( embfile->createDate(), QDateTime( QDate( 2005, 8, 30 ), QTime( 20, 49, 35), Qt::UTC ) );
     QCOMPARE( embfile->modDate(), QDateTime( QDate( 2005, 8, 30 ), QTime( 20, 49, 52), Qt::UTC ) );
+    QCOMPARE( embfile->mimeType(), QString("application/vnd.ms-excel") );
     delete doc;
 
 }
commit 23da27a229c8b3cc2a0a0dd6354c40723934390c
Author: Pino Toscano <pino at kde.org>
Date:   Sat Mar 8 03:10:58 2008 +0100

    Optionally read the mimetype for the embedded files.

diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 0a6b005..ea786c5 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -396,6 +396,7 @@ EmbFile *Catalog::embeddedFile(int i)
     GooString *createDate = new GooString();
     GooString *modDate = new GooString();
     GooString *checksum = new GooString();
+    GooString *mimetype = new GooString();
     Stream *efStream = NULL;
     int size = -1;
     if (obj.isRef()) {
@@ -436,13 +437,13 @@ EmbFile *Catalog::embeddedFile(int i)
 		// dataDict corresponds to Table 3.41 in the PDF1.6 spec.
 		Dict *dataDict = efStream->getDict();
 
-		// subtype is normally mimetype. You can extract it with code like this:
-		// Object subtypeName;
-		// dataDict->lookup( "Subtype", &subtypeName );
-		// It is optional, so this will sometimes return a null object
-		// if (subtypeName.isName()) {
-		//        std::cout << "got subtype name: " << subtypeName.getName() << std::endl;
-		// }
+		// subtype is normally the mimetype
+		Object subtypeName;
+		if (dataDict->lookup("Subtype", &subtypeName)->isName()) {
+		    delete mimetype;
+		    mimetype = new GooString(subtypeName.getName());
+		}
+		subtypeName.free();
 
 		// paramDict corresponds to Table 3.42 in the PDF1.6 spec
 		Object paramDict;
@@ -478,7 +479,7 @@ EmbFile *Catalog::embeddedFile(int i)
 	    obj2.free();
 	}
     }
-    EmbFile *embeddedFile = new EmbFile(fileName, desc, size, createDate, modDate, checksum, strObj);
+    EmbFile *embeddedFile = new EmbFile(fileName, desc, size, createDate, modDate, checksum, mimetype, strObj);
     strObj.free();
     return embeddedFile;
 }
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index 5b6e166..97fa08d 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -65,13 +65,15 @@ public:
 	  int size,
 	  GooString *createDate,
 	  GooString *modDate, GooString *checksum,
+	  GooString *mimetype,
 	  Object objStr) :
     m_name(name),
     m_description(description),
     m_size(size),
     m_createDate(createDate),
     m_modDate(modDate),
-    m_checksum(checksum)
+    m_checksum(checksum),
+    m_mimetype(mimetype)
   {
     objStr.copy(&m_objStr);
   }
@@ -83,6 +85,7 @@ public:
     delete m_modDate;
     delete m_createDate;
     delete m_checksum;
+    delete m_mimetype;
     m_objStr.free();
   }
 
@@ -92,6 +95,7 @@ public:
   GooString *modDate() { return m_modDate; }
   GooString *createDate() { return m_createDate; }
   GooString *checksum() { return m_checksum; }
+  GooString *mimeType() { return m_mimetype; }
   Object &streamObject() { return m_objStr; }
 
 private:
@@ -101,6 +105,7 @@ private:
   GooString *m_createDate;
   GooString *m_modDate;
   GooString *m_checksum;
+  GooString *m_mimetype;
   Object m_objStr;
 };
 


More information about the poppler mailing list