[poppler] cpp/poppler-document.cpp cpp/poppler-embedded-file.cpp cpp/poppler-embedded-file-private.h glib/poppler-annot.cc glib/poppler-attachment.cc glib/poppler-document.cc glib/poppler-private.h poppler/Catalog.cc poppler/Catalog.h poppler/FileSpec.cc poppler/FileSpec.h qt4/src qt4/tests

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Fri May 27 06:16:31 PDT 2011


 cpp/poppler-document.cpp               |    4 -
 cpp/poppler-embedded-file-private.h    |   10 +-
 cpp/poppler-embedded-file.cpp          |   42 ++++++----
 glib/poppler-annot.cc                  |    6 -
 glib/poppler-attachment.cc             |   33 ++++----
 glib/poppler-document.cc               |    5 -
 glib/poppler-private.h                 |    3 
 poppler/Catalog.cc                     |  118 ++----------------------------
 poppler/Catalog.h                      |   55 --------------
 poppler/FileSpec.cc                    |  128 +++++++++++++++++++++++++++++++++
 poppler/FileSpec.h                     |   51 ++++++++++++-
 qt4/src/poppler-embeddedfile-private.h |    6 -
 qt4/src/poppler-embeddedfile.cc        |   34 +++++---
 qt4/src/poppler-page.cc                |    5 -
 qt4/src/poppler-private.h              |    4 -
 qt4/tests/check_attachments.cpp        |   12 +--
 16 files changed, 284 insertions(+), 232 deletions(-)

New commits:
commit 04dfb2c984b3c9949466e2b70e26b58029c5a7d3
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sat May 7 12:55:34 2011 +0200

    Make FileSpec a class and move EmbFile from Catalog to FileSpec
    
    Qt and cpp frontends adapted by Pino Toscano

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index c5b2733..4cf7ec0 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -587,8 +587,8 @@ std::vector<embedded_file *> document::embedded_files() const
         const int num = d->doc->getCatalog()->numEmbeddedFiles();
         d->embedded_files.resize(num);
         for (int i = 0; i < num; ++i) {
-            EmbFile *ef = d->doc->getCatalog()->embeddedFile(i);
-            d->embedded_files[i] = embedded_file_private::create(ef);
+            FileSpec *fs = d->doc->getCatalog()->embeddedFile(i);
+            d->embedded_files[i] = embedded_file_private::create(fs);
         }
     }
     return d->embedded_files;
diff --git a/cpp/poppler-embedded-file-private.h b/cpp/poppler-embedded-file-private.h
index 2acea65..1b9b633 100644
--- a/cpp/poppler-embedded-file-private.h
+++ b/cpp/poppler-embedded-file-private.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2009, 2011, 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
@@ -19,7 +19,7 @@
 #ifndef POPPLER_EMBEDDED_FILE_PRIVATE_H
 #define POPPLER_EMBEDDED_FILE_PRIVATE_H
 
-class EmbFile;
+class FileSpec;
 
 namespace poppler
 {
@@ -27,12 +27,12 @@ namespace poppler
 class embedded_file_private
 {
 public:
-    embedded_file_private(EmbFile *ef);
+    embedded_file_private(FileSpec *fs);
     ~embedded_file_private();
 
-    static embedded_file* create(EmbFile *ef);
+    static embedded_file* create(FileSpec *fs);
 
-    EmbFile *emb_file;
+    FileSpec *file_spec;
 };
 
 }
diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp
index 7fe6204..2c5d077 100644
--- a/cpp/poppler-embedded-file.cpp
+++ b/cpp/poppler-embedded-file.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2009-2011, 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
@@ -24,22 +24,23 @@
 #include "Object.h"
 #include "Stream.h"
 #include "Catalog.h"
+#include "FileSpec.h"
 
 using namespace poppler;
 
-embedded_file_private::embedded_file_private(EmbFile *ef)
-    : emb_file(ef)
+embedded_file_private::embedded_file_private(FileSpec *fs)
+    : file_spec(fs)
 {
 }
 
 embedded_file_private::~embedded_file_private()
 {
-    delete emb_file;
+    delete file_spec;
 }
 
-embedded_file* embedded_file_private::create(EmbFile *ef)
+embedded_file* embedded_file_private::create(FileSpec *fs)
 {
-    return new embedded_file(*new embedded_file_private(ef));
+    return new embedded_file(*new embedded_file_private(fs));
 }
 
 /**
@@ -67,7 +68,7 @@ embedded_file::~embedded_file()
  */
 bool embedded_file::is_valid() const
 {
-    return d->emb_file->isOk();
+    return d->file_spec->isOk();
 }
 
 /**
@@ -75,7 +76,8 @@ bool embedded_file::is_valid() const
  */
 std::string embedded_file::name() const
 {
-    return std::string(d->emb_file->name()->getCString());
+    GooString *goo = d->file_spec->getFileName();
+    return goo ? std::string(goo->getCString()) : std::string();
 }
 
 /**
@@ -83,7 +85,8 @@ std::string embedded_file::name() const
  */
 ustring embedded_file::description() const
 {
-    return detail::unicode_GooString_to_ustring(d->emb_file->description());
+    GooString *goo = d->file_spec->getDescription();
+    return goo ? detail::unicode_GooString_to_ustring(goo) : ustring();
 }
 
 /**
@@ -94,7 +97,7 @@ ustring embedded_file::description() const
  */
 int embedded_file::size() const
 {
-    return d->emb_file->size();
+    return d->file_spec->getEmbeddedFile()->size();
 }
 
 /**
@@ -103,7 +106,8 @@ int embedded_file::size() const
  */
 time_type embedded_file::modification_date() const
 {
-    return detail::convert_date(d->emb_file->modDate()->getCString());
+    GooString *goo = d->file_spec->getEmbeddedFile()->modDate();
+    return goo ? detail::convert_date(goo->getCString()) : time_type(-1);
 }
 
 /**
@@ -112,7 +116,8 @@ time_type embedded_file::modification_date() const
  */
 time_type embedded_file::creation_date() const
 {
-    return detail::convert_date(d->emb_file->createDate()->getCString());
+    GooString *goo = d->file_spec->getEmbeddedFile()->createDate();
+    return goo ? detail::convert_date(goo->getCString()) : time_type(-1);
 }
 
 /**
@@ -120,7 +125,10 @@ time_type embedded_file::creation_date() const
  */
 byte_array embedded_file::checksum() const
 {
-    GooString *cs = d->emb_file->checksum();
+    GooString *cs = d->file_spec->getEmbeddedFile()->checksum();
+    if (!cs) {
+        return byte_array();
+    }
     const char *ccs = cs->getCString();
     byte_array data(cs->getLength());
     for (int i = 0; i < cs->getLength(); ++i) {
@@ -134,7 +142,8 @@ byte_array embedded_file::checksum() const
  */
 std::string embedded_file::mime_type() const
 {
-    return std::string(d->emb_file->mimeType()->getCString());
+    GooString *goo = d->file_spec->getEmbeddedFile()->mimeType();
+    return goo ? std::string(goo->getCString()) : std::string();
 }
 
 /**
@@ -147,8 +156,11 @@ byte_array embedded_file::data() const
     if (!is_valid()) {
         return byte_array();
     }
+    Stream *stream = d->file_spec->getEmbeddedFile()->stream();
+    if (!stream) {
+        return byte_array();
+    }
 
-    Stream *stream = d->emb_file->streamObject().getStream();
     stream->reset();
     byte_array ret(1024);
     size_t data_len = 0;
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 62a0879..a69644d 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -1225,9 +1225,9 @@ poppler_annot_file_attachment_get_attachment (PopplerAnnotFileAttachment *popple
 
   annot = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT (poppler_annot)->annot);
 
-  EmbFile *emb_file = new EmbFile (annot->getFile(), annot->getContents());
-  attachment = _poppler_attachment_new (emb_file);
-  delete emb_file;
+  FileSpec *file = new FileSpec (annot->getFile());
+  attachment = _poppler_attachment_new (file);
+  delete file;
 
   return attachment;
 }
diff --git a/glib/poppler-attachment.cc b/glib/poppler-attachment.cc
index 1218b9b..d07f1ab 100644
--- a/glib/poppler-attachment.cc
+++ b/glib/poppler-attachment.cc
@@ -100,32 +100,37 @@ poppler_attachment_finalize (GObject *obj)
 /* Public functions */
 
 PopplerAttachment *
-_poppler_attachment_new (EmbFile *emb_file)
+_poppler_attachment_new (FileSpec *emb_file)
 {
   PopplerAttachment *attachment;
   PopplerAttachmentPrivate *priv;
+  EmbFile *embFile;
 
   g_assert (emb_file != NULL);
 
   attachment = (PopplerAttachment *) g_object_new (POPPLER_TYPE_ATTACHMENT, NULL);
   priv = POPPLER_ATTACHMENT_GET_PRIVATE (attachment);
 
-  if (emb_file->name ())
-    attachment->name = _poppler_goo_string_to_utf8 (emb_file->name ());
-  if (emb_file->description ())
-    attachment->description = _poppler_goo_string_to_utf8 (emb_file->description ());
+  if (emb_file->getFileName ())
+    attachment->name = _poppler_goo_string_to_utf8 (emb_file->getFileName ());
+  if (emb_file->getDescription ())
+    attachment->description = _poppler_goo_string_to_utf8 (emb_file->getDescription ());
 
-  attachment->size = emb_file->size ();
-  
-  _poppler_convert_pdf_date_to_gtime (emb_file->createDate (), (time_t *)&attachment->ctime);
-  _poppler_convert_pdf_date_to_gtime (emb_file->modDate (), (time_t *)&attachment->mtime);
+  embFile = emb_file->getEmbeddedFile();
+  attachment->size = embFile->size ();
 
-  if (emb_file->checksum ()->getLength () > 0)
-	  attachment->checksum = g_string_new_len (emb_file->checksum ()->getCString (),
-						   emb_file->checksum ()->getLength ());
-  
+  if (embFile->createDate ())
+    _poppler_convert_pdf_date_to_gtime (embFile->createDate (), (time_t *)&attachment->ctime);
+  if (embFile->modDate ())
+    _poppler_convert_pdf_date_to_gtime (embFile->modDate (), (time_t *)&attachment->mtime);
+
+  if (embFile->checksum () && embFile->checksum ()->getLength () > 0)
+    attachment->checksum = g_string_new_len (embFile->checksum ()->getCString (),
+                                             embFile->checksum ()->getLength ());
   priv->obj_stream = new Object();
-  emb_file->streamObject().copy(priv->obj_stream);
+  priv->obj_stream->initStream(embFile->stream());
+  // Copy the stream
+  embFile->stream()->incRef();
 
   return attachment;
 }
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index e56b414..745bc9b 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -541,13 +541,14 @@ poppler_document_get_attachments (PopplerDocument *document)
   for (i = 0; i < n_files; i++)
     {
       PopplerAttachment *attachment;
-      EmbFile *emb_file;
+      FileSpec *emb_file;
 
       emb_file = catalog->embeddedFile (i);
-      if (!emb_file->isOk ()) {
+      if (!emb_file->isOk () || !emb_file->getEmbeddedFile()->isOk()) {
         delete emb_file;
 	continue;
       }
+
       attachment = _poppler_attachment_new (emb_file);
       delete emb_file;
 
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index 2becc99..ab39b49 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -16,6 +16,7 @@
 #include <Catalog.h>
 #include <OptionalContent.h>
 #include <CairoOutputDev.h>
+#include <FileSpec.h>
 #endif
 
 struct _PopplerDocument
@@ -110,7 +111,7 @@ PopplerDest   *_poppler_dest_new_goto (PopplerDocument *document,
 				       LinkDest        *link_dest);
 PopplerFormField *_poppler_form_field_new (PopplerDocument *document,
 					   FormWidget      *field);
-PopplerAttachment *_poppler_attachment_new (EmbFile *file);
+PopplerAttachment *_poppler_attachment_new (FileSpec *file);
 PopplerMovie      *_poppler_movie_new (Movie *movie);
 PopplerMedia      *_poppler_media_new (MediaRendition *media);
 PopplerAnnot      *_poppler_annot_new           (Annot *annot);
diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index cee88f0..bc4c5aa 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -51,6 +51,7 @@
 #include "Form.h"
 #include "OptionalContent.h"
 #include "ViewerPreferences.h"
+#include "FileSpec.h"
 
 //------------------------------------------------------------------------
 // Catalog
@@ -447,19 +448,19 @@ LinkDest *Catalog::findDest(GooString *name) {
   return dest;
 }
 
-EmbFile *Catalog::embeddedFile(int i)
+FileSpec *Catalog::embeddedFile(int i)
 {
     Object efDict;
     Object obj;
     obj = getEmbeddedFileNameTree()->getValue(i);
-    EmbFile *embeddedFile = 0;
+    FileSpec *embeddedFile = 0;
     if (obj.isRef()) {
-        GooString desc(getEmbeddedFileNameTree()->getName(i));
-        embeddedFile = new EmbFile(obj.fetch(xref, &efDict), &desc);
-        efDict.free();
+      Object fsDict;
+      embeddedFile = new FileSpec(obj.fetch(xref, &fsDict));
+      fsDict.free();
     } else {
-        Object null;
-        embeddedFile = new EmbFile(&null);
+      Object null;
+      embeddedFile = new FileSpec(&null);
     }
     return embeddedFile;
 }
@@ -736,109 +737,6 @@ GBool Catalog::indexToLabel(int index, GooString *label)
   }
 }
 
-EmbFile::EmbFile(Object *efDict, GooString *description)
-{
-  m_name = 0;
-  m_description = 0;
-  if (description)
-    m_description = description->copy();
-  m_size = -1;
-  m_createDate = 0;
-  m_modDate = 0;
-  m_checksum = 0;
-  m_mimetype = 0;
-  if (efDict->isDict()) {
-    Object fileSpec;
-    Object fileDesc;
-    Object paramDict;
-    Object paramObj;
-    Object obj2;
-    Stream *efStream = NULL;
-    // efDict matches Table 3.40 in the PDF1.6 spec
-    efDict->dictLookup("F", &fileSpec);
-    if (fileSpec.isString()) {
-      m_name = new GooString(fileSpec.getString());
-    }
-    fileSpec.free();
-
-    // the logic here is that the description from the name
-    // dictionary is used if we don't have a more specific
-    // description - see the Note: on page 157 of the PDF1.6 spec
-    efDict->dictLookup("Desc", &fileDesc);
-    if (fileDesc.isString()) {
-      delete m_description;
-      m_description = new GooString(fileDesc.getString());
-    } else {
-      efDict->dictLookup("Description", &fileDesc);
-      if (fileDesc.isString()) {
-        delete m_description;
-        m_description = new GooString(fileDesc.getString());
-      }
-    }
-    fileDesc.free();
-
-    efDict->dictLookup("EF", &obj2);
-    if (obj2.isDict()) {
-      // This gives us the raw data stream bytes
-
-      obj2.dictLookup("F", &m_objStr);
-      if (m_objStr.isStream()) {
-        efStream = m_objStr.getStream();
-
-        // dataDict corresponds to Table 3.41 in the PDF1.6 spec.
-        Dict *dataDict = efStream->getDict();
-
-        // subtype is normally the mimetype
-        Object subtypeName;
-        if (dataDict->lookup("Subtype", &subtypeName)->isName()) {
-          m_mimetype = new GooString(subtypeName.getName());
-        }
-        subtypeName.free();
-
-        // paramDict corresponds to Table 3.42 in the PDF1.6 spec
-        Object paramDict;
-        dataDict->lookup( "Params", &paramDict );
-        if (paramDict.isDict()) {
-          paramDict.dictLookup("ModDate", &paramObj);
-          if (paramObj.isString()) {
-            m_modDate = new GooString(paramObj.getString());
-          }
-          paramObj.free();
-          paramDict.dictLookup("CreationDate", &paramObj);
-          if (paramObj.isString()) {
-            m_createDate = new GooString(paramObj.getString());
-          }
-          paramObj.free();
-          paramDict.dictLookup("Size", &paramObj);
-          if (paramObj.isInt()) {
-            m_size = paramObj.getInt();
-          }
-          paramObj.free();
-          paramDict.dictLookup("CheckSum", &paramObj);
-          if (paramObj.isString()) {
-            m_checksum = new GooString(paramObj.getString());
-          }
-          paramObj.free();
-        }
-        paramDict.free();
-      }
-    }
-    obj2.free();
-  }
-  if (!m_name)
-    m_name = new GooString();
-  if (!m_description)
-    m_description = new GooString();
-  if (!m_createDate)
-    m_createDate = new GooString();
-  if (!m_modDate)
-    m_modDate = new GooString();
-  if (!m_checksum)
-    m_checksum = new GooString();
-  if (!m_mimetype)
-    m_mimetype = new GooString();
-}
-
 int Catalog::getNumPages()
 {
   if (numPages == -1)
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index 7c54753..2b7e77a 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -45,6 +45,7 @@ class PageLabelInfo;
 class Form;
 class OCGs;
 class ViewerPreferences;
+class FileSpec;
 
 //------------------------------------------------------------------------
 // NameTree
@@ -82,58 +83,6 @@ private:
                     // length is the number of real Entry
 };
 
-class EmbFile {
-public:
-  EmbFile(GooString *name, GooString *description, 
-	  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_mimetype(mimetype)
-  {
-    objStr.copy(&m_objStr);
-  }
-  EmbFile(Object *efDict, GooString *description = 0);
-
-  ~EmbFile()
-  {
-    delete m_name;
-    delete m_description;
-    delete m_modDate;
-    delete m_createDate;
-    delete m_checksum;
-    delete m_mimetype;
-    m_objStr.free();
-  }
-
-  GooString *name() { return m_name; }
-  GooString *description() { return m_description; }
-  int size() { return m_size; }
-  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; }
-  bool isOk() { return m_objStr.isStream(); }
-
-private:
-  GooString *m_name;
-  GooString *m_description;
-  int m_size;
-  GooString *m_createDate;
-  GooString *m_modDate;
-  GooString *m_checksum;
-  GooString *m_mimetype;
-  Object m_objStr;
-};
-
 //------------------------------------------------------------------------
 // Catalog
 //------------------------------------------------------------------------
@@ -183,7 +132,7 @@ public:
   int numEmbeddedFiles() { return getEmbeddedFileNameTree()->numEntries(); }
 
   // Get the i'th file embedded (at the Document level) in the document
-  EmbFile *embeddedFile(int i);
+  FileSpec *embeddedFile(int i);
 
   // Get the number of javascript scripts
   int numJS() { return getJSNameTree()->numEntries(); }
diff --git a/poppler/FileSpec.cc b/poppler/FileSpec.cc
index 4df6139..7807864 100644
--- a/poppler/FileSpec.cc
+++ b/poppler/FileSpec.cc
@@ -25,6 +25,134 @@
 
 #include "FileSpec.h"
 
+EmbFile::EmbFile(Object *efStream)
+{
+  m_size = -1;
+  m_createDate = NULL;
+  m_modDate = NULL;
+  m_checksum = NULL;
+  m_mimetype = NULL;
+
+  efStream->copy(&m_objStr);
+
+  if (efStream->isStream()) {
+    // dataDict corresponds to Table 3.41 in the PDF1.6 spec.
+    Dict *dataDict = efStream->streamGetDict();
+
+    // subtype is normally the mimetype
+    Object subtypeName;
+    if (dataDict->lookup("Subtype", &subtypeName)->isName()) {
+      m_mimetype = new GooString(subtypeName.getName());
+    }
+    subtypeName.free();
+
+    // paramDict corresponds to Table 3.42 in the PDF1.6 spec
+    Object paramDict;
+    if (dataDict->lookup("Params", &paramDict)->isDict()) {
+      Object paramObj;
+      if (paramDict.dictLookup("ModDate", &paramObj)->isString())
+        m_modDate = new GooString(paramObj.getString());
+      paramObj.free();
+
+      if (paramDict.dictLookup("CreationDate", &paramObj)->isString())
+        m_createDate = new GooString(paramObj.getString());
+      paramObj.free();
+
+      if (paramDict.dictLookup("Size", &paramObj)->isInt())
+        m_size = paramObj.getInt();
+      paramObj.free();
+
+      if (paramDict.dictLookup("CheckSum", &paramObj)->isString())
+        m_checksum = new GooString(paramObj.getString());
+      paramObj.free();
+    }
+    paramDict.free();
+  }
+}
+
+EmbFile::~EmbFile()
+{
+  delete m_createDate;
+  delete m_modDate;
+  delete m_checksum;
+  delete m_mimetype;
+  m_objStr.free();
+}
+
+FileSpec::FileSpec(Object *fileSpecA)
+{
+  ok = gTrue;
+  fileName = NULL;
+  platformFileName = NULL;
+  embFile = NULL;
+  desc = NULL;
+  fileSpecA->copy(&fileSpec);
+
+  Object obj1;
+  if (!getFileSpecName(fileSpecA, &obj1)) {
+    ok = gFalse;
+    obj1.free();
+    error(-1, "Invalid FileSpec");
+    return;
+  }
+
+  fileName = obj1.getString()->copy();
+  obj1.free();
+
+  if (fileSpec.isDict()) {
+    if (fileSpec.dictLookup("EF", &obj1)->isDict()) {
+      if (!obj1.dictLookupNF("F", &fileStream)->isRef()) {
+        ok = gFalse;
+        fileStream.free();
+        error(-1, "Invalid FileSpec: Embedded file stream is not an indirect reference");
+        obj1.free();
+        return;
+      }
+    }
+    obj1.free();
+  }
+
+  if (fileSpec.dictLookup("Desc", &obj1)->isString())
+    desc = obj1.getString()->copy();
+  obj1.free();
+}
+
+FileSpec::~FileSpec()
+{
+  fileSpec.free();
+  fileStream.free();
+  delete fileName;
+  delete platformFileName;
+  delete embFile;
+  delete desc;
+}
+
+EmbFile *FileSpec::getEmbeddedFile()
+{
+  if (embFile)
+    return embFile;
+
+  Object obj1;
+  XRef *xref = fileSpec.getDict()->getXRef();
+  embFile = new EmbFile(fileStream.fetch(xref, &obj1));
+  obj1.free();
+
+  return embFile;
+}
+
+GooString *FileSpec::getFileNameForPlatform()
+{
+  if (platformFileName)
+    return platformFileName;
+
+  Object obj1;
+  if (getFileSpecNameForPlatform(&fileSpec, &obj1))
+    platformFileName = obj1.getString()->copy();
+  obj1.free();
+
+  return platformFileName;
+}
+
 GBool getFileSpecName (Object *fileSpec, Object *fileName)
 {
   if (fileSpec->isString()) {
diff --git a/poppler/FileSpec.h b/poppler/FileSpec.h
index ec35f3f..e26cdcf 100644
--- a/poppler/FileSpec.h
+++ b/poppler/FileSpec.h
@@ -15,9 +15,58 @@
 #ifndef FILE_SPEC_H
 #define FILE_SPEC_H
 
-#include "goo/gtypes.h"
+#ifdef USE_GCC_PRAGMAS
+#pragma interface
+#endif
+
 #include "Object.h"
 
+class EmbFile {
+public:
+  EmbFile(Object *efStream);
+  ~EmbFile();
+
+  int size() { return m_size; }
+  GooString *modDate() { return m_modDate; }
+  GooString *createDate() { return m_createDate; }
+  GooString *checksum() { return m_checksum; }
+  GooString *mimeType() { return m_mimetype; }
+  Stream *stream() { return isOk() ? m_objStr.getStream() : NULL; }
+  GBool isOk() { return m_objStr.isStream(); }
+
+private:
+  int m_size;
+  GooString *m_createDate;
+  GooString *m_modDate;
+  GooString *m_checksum;
+  GooString *m_mimetype;
+  Object m_objStr;
+};
+
+class FileSpec {
+public:
+  FileSpec(Object *fileSpec);
+  ~FileSpec();
+
+  GBool isOk() { return ok; }
+
+  GooString *getFileName() const { return fileName; }
+  GooString *getFileNameForPlatform();
+  GooString *getDescription() const { return desc; }
+  EmbFile *getEmbeddedFile();
+
+private:
+  GBool ok;
+
+  Object fileSpec;
+
+  GooString *fileName;         // F, UF, DOS, Mac, Unix
+  GooString *platformFileName;
+  Object fileStream;           // Ref to F entry in UF
+  EmbFile *embFile;
+  GooString *desc;             // Desc
+};
+
 GBool getFileSpecName (Object *fileSpec, Object *fileName);
 GBool getFileSpecNameForPlatform (Object *fileSpec, Object *fileName);
 
diff --git a/qt4/src/poppler-embeddedfile-private.h b/qt4/src/poppler-embeddedfile-private.h
index cdd9802..f109d36 100644
--- a/qt4/src/poppler-embeddedfile-private.h
+++ b/qt4/src/poppler-embeddedfile-private.h
@@ -21,7 +21,7 @@
 #ifndef POPPLER_EMBEDDEDFILE_PRIVATE_H
 #define POPPLER_EMBEDDEDFILE_PRIVATE_H
 
-class EmbFile;
+class FileSpec;
 
 namespace Poppler
 {
@@ -29,10 +29,10 @@ namespace Poppler
 class EmbeddedFileData
 {
 public:
-	EmbeddedFileData(EmbFile *ef);
+	EmbeddedFileData(FileSpec *fs);
 	~EmbeddedFileData();
 
-	EmbFile *embfile;
+	FileSpec *filespec;
 };
 
 }
diff --git a/qt4/src/poppler-embeddedfile.cc b/qt4/src/poppler-embeddedfile.cc
index fc1cfec..ad942b7 100644
--- a/qt4/src/poppler-embeddedfile.cc
+++ b/qt4/src/poppler-embeddedfile.cc
@@ -26,6 +26,7 @@
 #include "Object.h"
 #include "Stream.h"
 #include "Catalog.h"
+#include "FileSpec.h"
 
 #include "poppler-private.h"
 #include "poppler-embeddedfile-private.h"
@@ -33,14 +34,14 @@
 namespace Poppler
 {
 
-EmbeddedFileData::EmbeddedFileData(EmbFile *ef)
-	: embfile(ef)
+EmbeddedFileData::EmbeddedFileData(FileSpec *fs)
+	: filespec(fs)
 {
 }
 
 EmbeddedFileData::~EmbeddedFileData()
 {
-	delete embfile;
+	delete filespec;
 }
 
 
@@ -62,47 +63,54 @@ EmbeddedFile::~EmbeddedFile()
 
 QString EmbeddedFile::name() const
 {
-	return QString(m_embeddedFile->embfile->name()->getCString());
+	GooString *goo = m_embeddedFile->filespec->getFileName();
+	return goo ? QString(goo->getCString()) : QString();
 }
 
 QString EmbeddedFile::description() const
 {
-	return UnicodeParsedString(m_embeddedFile->embfile->description());
+	GooString *goo = m_embeddedFile->filespec->getDescription();
+	return goo ? UnicodeParsedString(goo) : QString();
 }
 
 int EmbeddedFile::size() const
 {
-	return m_embeddedFile->embfile->size();
+	return m_embeddedFile->filespec->getEmbeddedFile()->size();
 }
 
 QDateTime EmbeddedFile::modDate() const
 {
-	return convertDate(m_embeddedFile->embfile->modDate()->getCString());
+	GooString *goo = m_embeddedFile->filespec->getEmbeddedFile()->modDate();
+	return goo ? convertDate(goo->getCString()) : QDateTime();
 }
 
 QDateTime EmbeddedFile::createDate() const
 {
-	return convertDate(m_embeddedFile->embfile->createDate()->getCString());
+	GooString *goo = m_embeddedFile->filespec->getEmbeddedFile()->createDate();
+	return goo ? convertDate(goo->getCString()) : QDateTime();
 }
 
 QByteArray EmbeddedFile::checksum() const
 {
-	GooString *goo_checksum = m_embeddedFile->embfile->checksum();
-	return QByteArray::fromRawData(goo_checksum->getCString(), goo_checksum->getLength());
+	GooString *goo = m_embeddedFile->filespec->getEmbeddedFile()->checksum();
+	return goo ? QByteArray::fromRawData(goo->getCString(), goo->getLength()) : QByteArray();
 }
 
 QString EmbeddedFile::mimeType() const
 {
-	return QString(m_embeddedFile->embfile->mimeType()->getCString());
+	GooString *goo = m_embeddedFile->filespec->getEmbeddedFile()->mimeType();
+	return goo ? QString(goo->getCString()) : QString();
 }
 
 QByteArray EmbeddedFile::data()
 {
 	if (!isValid())
 		return QByteArray();
+	Stream *stream = m_embeddedFile->filespec->getEmbeddedFile()->stream();
+	if (!stream)
+		return QByteArray();
 	
 	Object obj;
-	Stream *stream = m_embeddedFile->embfile->streamObject().getStream();
 	stream->reset();
 	int dataLen = 0;
 	QByteArray fileArray;
@@ -117,7 +125,7 @@ QByteArray EmbeddedFile::data()
 
 bool EmbeddedFile::isValid() const
 {
-	return m_embeddedFile->embfile->isOk();
+	return m_embeddedFile->filespec->isOk();
 }
 
 }
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index b92002c..62d16f9 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -42,6 +42,7 @@
 #include <TextOutputDev.h>
 #include <Annot.h>
 #include <Link.h>
+#include <FileSpec.h>
 #include <ArthurOutputDev.h>
 #if defined(HAVE_SPLASH)
 #include <SplashOutputDev.h>
@@ -939,8 +940,8 @@ QList<Annotation*> Page::annotations() const
                 // -> fileIcon
                 f->setFileIconName( QString::fromLatin1( attachann->getName()->getCString() ) );
                 // -> embeddedFile
-                EmbFile *embfile = new EmbFile( attachann->getFile(), attachann->getContents() );
-                f->setEmbeddedFile( new EmbeddedFile( *new EmbeddedFileData( embfile ) ) );
+                FileSpec *filespec = new FileSpec( attachann->getFile() );
+                f->setEmbeddedFile( new EmbeddedFile( *new EmbeddedFileData( filespec ) ) );
                 break;
             }
             case Annot::typeSound:
diff --git a/qt4/src/poppler-private.h b/qt4/src/poppler-private.h
index ea36e7e..6d2b315 100644
--- a/qt4/src/poppler-private.h
+++ b/qt4/src/poppler-private.h
@@ -164,8 +164,8 @@ namespace Poppler {
 		if (!(0 == numEmb)) {
 			// we have some embedded documents, build the list
 			for (int yalv = 0; yalv < numEmb; ++yalv) {
-				EmbFile *ef = doc->getCatalog()->embeddedFile(yalv);
-				m_embeddedFiles.append(new EmbeddedFile(*new EmbeddedFileData(ef)));
+				FileSpec *fs = doc->getCatalog()->embeddedFile(yalv);
+				m_embeddedFiles.append(new EmbeddedFile(*new EmbeddedFileData(fs)));
 			}
 		}
 	}
diff --git a/qt4/tests/check_attachments.cpp b/qt4/tests/check_attachments.cpp
index 2e02ec8..6405351 100644
--- a/qt4/tests/check_attachments.cpp
+++ b/qt4/tests/check_attachments.cpp
@@ -40,7 +40,7 @@ void TestAttachments::checkAttach1()
 
     Poppler::EmbeddedFile *embfile = fileList.at(0);
     QCOMPARE( embfile->name(), QString( "kroller.png" ) );
-    QCOMPARE( embfile->description(), QString("/home/bradh/coding/svn-vers/KDE/kdeartwork/wallpapers/kroller.png") );
+    QCOMPARE( embfile->description(), QString() );
     QCOMPARE( embfile->createDate(), QDateTime( QDate(), QTime() ) );
     QCOMPARE( embfile->modDate(), QDateTime( QDate(), QTime() ) );
     QCOMPARE( embfile->mimeType(), QString() );
@@ -54,7 +54,7 @@ void TestAttachments::checkAttach1()
 
     Poppler::EmbeddedFile *embfile2 = fileList.at(1);
     QCOMPARE( embfile2->name(), QString("gnome-64.gif") );
-    QCOMPARE( embfile2->description(), QString("/usr/share/gnome-about/gnome-64.gif") );
+    QCOMPARE( embfile2->description(), QString() );
     QCOMPARE( embfile2->modDate(), QDateTime( QDate(), QTime() ) );
     QCOMPARE( embfile2->createDate(), QDateTime( QDate(), QTime() ) );
     QCOMPARE( embfile2->mimeType(), QString() );
@@ -84,21 +84,21 @@ void TestAttachments::checkAttach2()
 
     Poppler::EmbeddedFile *embfile1 = fileList.at(0);
     QCOMPARE( embfile1->name(), QString("Acro7 thoughts") );
-    QCOMPARE( embfile1->description(), QString("Acro7 Thoughts") );
+    QCOMPARE( embfile1->description(), QString() );
     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->description(), QString() );
     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->description(), QString() );
     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() );
@@ -121,7 +121,7 @@ void TestAttachments::checkAttach3()
 
     Poppler::EmbeddedFile *embfile = fileList.at(0);
     QCOMPARE( embfile->name(), QString( "ADEX1.xpdf.pgp" ) );
-    QCOMPARE( embfile->description(), QString("encrypted version of document") );
+    QCOMPARE( embfile->description(), QString() );
     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() );


More information about the poppler mailing list