poppler/Annot.cc   |    4 -
 poppler/Annot.h    |    2 
 poppler/Catalog.cc |  205 ++++++++++++++++++++++++++++-------------------------
 poppler/Catalog.h  |    1 
 4 files changed, 116 insertions(+), 96 deletions(-)

New commits:
commit 4b87196b7829c87d15af4e8b4138ca97548fb519
Author: Pino Toscano <[EMAIL PROTECTED]>
Date:   Sun Apr 13 00:18:24 2008 +0200

    Isolate the embedded file reading logic into a new EmbFile constructor.
    
    This way, it can be shared and reused in various places (Catalog, 
AnnotFileAttachment, etc).

diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 7858247..7fc1cbe 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -388,103 +388,17 @@ LinkDest *Catalog::findDest(GooString *name) {
 EmbFile *Catalog::embeddedFile(int i)
 {
     Object efDict;
-    Object fileSpec;
-    Object fileDesc;
-    Object paramDict;
-    Object paramObj;
-    Object strObj;
-    Object obj, obj2;
+    Object obj;
     obj = embeddedFileNameTree.getValue(i);
-    GooString *fileName = new GooString();
-    GooString *desc = new GooString(embeddedFileNameTree.getName(i));
-    GooString *createDate = new GooString();
-    GooString *modDate = new GooString();
-    GooString *checksum = new GooString();
-    GooString *mimetype = new GooString();
-    Stream *efStream = NULL;
-    int size = -1;
+    EmbFile *embeddedFile = 0;
     if (obj.isRef()) {
-       if (obj.fetch(xref, &efDict)->isDict()) {
-           // efDict matches Table 3.40 in the PDF1.6 spec
-           efDict.dictLookup("F", &fileSpec);
-           if (fileSpec.isString()) {
-               delete fileName;
-               fileName = 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 desc;
-               desc = new GooString(fileDesc.getString());
-           } else {
-               efDict.dictLookup("Description", &fileDesc);
-               if (fileDesc.isString()) {
-                   delete desc;
-                   desc = new GooString(fileDesc.getString());
-               }
-           }
-           fileDesc.free();
-           
-           efDict.dictLookup("EF", &obj2);
-           if (obj2.isDict()) {
-               // This gives us the raw data stream bytes
-
-               obj2.dictLookup("F", &strObj);
-               if (strObj.isStream()) {
-                   efStream = strObj.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()) {
-                   delete mimetype;
-                   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()) {
-                       delete modDate;
-                       modDate = new GooString(paramObj.getString());
-                   }
-                   paramObj.free();
-                   paramDict.dictLookup("CreationDate", &paramObj);
-                   if (paramObj.isString()) {
-                       delete createDate;
-                       createDate = new GooString(paramObj.getString());
-                   }
-                   paramObj.free();
-                   paramDict.dictLookup("Size", &paramObj);
-                   if (paramObj.isInt()) {
-                       size = paramObj.getInt();
-                   }
-                   paramObj.free();
-                   paramDict.dictLookup("CheckSum", &paramObj);
-                   if (paramObj.isString()) {
-                       delete checksum;
-                       checksum = new GooString(paramObj.getString());
-                   }
-                   paramObj.free();
-               }
-               paramDict.free();
-           }
-           efDict.free();
-           obj2.free();
-       }
+        GooString desc(embeddedFileNameTree.getName(i));
+        embeddedFile = new EmbFile(obj.fetch(xref, &efDict), &desc);
+        efDict.free();
+    } else {
+        Object null;
+        embeddedFile = new EmbFile(&null);
     }
-    EmbFile *embeddedFile = new EmbFile(fileName, desc, size, createDate, 
modDate, checksum, mimetype, strObj);
-    strObj.free();
     return embeddedFile;
 }
 
@@ -683,3 +597,106 @@ GBool Catalog::indexToLabel(int index, GooString *label)
     return gTrue;
   }
 }
+
+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();
+}
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index b06b13d..295264b 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -77,6 +77,7 @@ public:
   {
     objStr.copy(&m_objStr);
   }
+  EmbFile(Object *efDict, GooString *description = 0);
 
   ~EmbFile()
   {
commit 45b407e51905948690065749085a4af1cbb29a8e
Author: Pino Toscano <[EMAIL PROTECTED]>
Date:   Sun Apr 13 00:14:38 2008 +0200

    correctly get the FileSpec dictionary

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 03236b7..bb71b13 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -3542,11 +3542,13 @@ AnnotFileAttachment::~AnnotFileAttachment() {
 void AnnotFileAttachment::initialize(XRef *xrefA, Catalog *catalog, Dict* 
dict) {
   Object obj1;
 
-  if (dict->lookup("FS", &obj1)->isRef()) {
+  if (dict->lookup("FS", &obj1)->isDict()) {
     obj1.copy(&file);
   } else {
     error(-1, "Bad Annot File Attachment");
+    ok = gFalse;
   }
+  obj1.free();
 
   if (dict->lookup("Name", &obj1)->isName()) {
     name = new GooString(obj1.getName());
diff --git a/poppler/Annot.h b/poppler/Annot.h
index ca2fba4..6ec3bfd 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -1034,7 +1034,7 @@ public:
   ~AnnotFileAttachment();
 
   // getters
-  Object *getFile(Object *obj) { return file.fetch(xref, obj); }
+  Object *getFile() { return &file; }
   GooString *getName() const { return name; }
 
 private:
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to