Hi Pino

            I am sorry to say about my previous patch. Thank you for your
patience suggestions. This time I sent a new patch with all those changes.
instead of filename i gave fsName (filespecName). Some how I miss that
delete(filename) which included in the patch, yes you are correct we don't
have to delete this otherwise it won't set it.

Thanks
--
A Srinivas

On Thu, Apr 7, 2011 at 12:30 AM, <[email protected]>wrote:

> Send poppler mailing list submissions to
>        [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.freedesktop.org/mailman/listinfo/poppler
> or, via email, send a message with subject or body 'help' to
>        [email protected]
>
> You can reach the person managing the list at
>        [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of poppler digest..."
>
>
> Today's Topics:
>
>   1. Re: Patch: New additions in FileSpec (Pino Toscano)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 6 Apr 2011 12:28:26 +0200
> From: Pino Toscano <[email protected]>
> Subject: Re: [poppler] Patch: New additions in FileSpec
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> Alle mercoled? 6 aprile 2011, srinivas adicherla ha scritto:
> > For i/o checks for fseek() and ftell(),
> > here we don't have to check for 10 bytes.
>
> The point is: I/O can fail, and you have to check for it.
>
> > +static GBool getFileSpecObject(XRef *xref, Stream *stream, const
> > char* fileName, Object *obj)
> > +{
> > +  Object fileSpec, obj1, obj2;
> > +  int length;
> > +
> > +  GooString *filename = new GooString(fileName);
>
> Please give it a slightly different name, otherwise it is easy to
> misread filename and fileName.
>
> > +  char *fileNameUTF16 = pdfDocEncodingToUTF16(filename, &length);
> > +
> > +  fileSpec.initDict(xref);
> > +  fileSpec.dictSet("Type", obj1.initName("Filespec"));
> > +  fileSpec.dictSet("F", obj1.initString(filename));
> > +  fileSpec.dictSet("UF", obj1.initString(new
> > GooString(fileNameUTF16, length)));
> > +
> > +  delete []fileNameUTF16;
> > +  delete(filename);
>
> no, obj1.initString(filename) already takes ownership of filename, so
> you don't delete it.
>
> > +GBool createFilespec (XRef *xref, GooString *filePathA, Object *obj)
>
> "FileSpec", not "Filespec"
>
> > +{
> > [...]
> > +  if (!(size = ftell(fs)))
> > +    return gFalse;
>
> no, any return value >= 0 means success, while -1 means error.
> also, you miss the error() call for ftell() failure
>
> > +  // Extract the video name from the file uri
>
> again video name?!
>
> srinivas, let's be frank now: do you ever *read* your patches, or you
> just do some partially untested changes, rediff and send?
>
> --
> Pino Toscano
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: not available
> Type: application/pgp-signature
> Size: 190 bytes
> Desc: This is a digitally signed message part.
> URL: <
> http://lists.freedesktop.org/archives/poppler/attachments/20110406/fb1a817d/attachment-0001.pgp
> >
>
> ------------------------------
>
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
>
>
> End of poppler Digest, Vol 74, Issue 11
> ***************************************
>
Index: poppler-0.16.2/poppler/FileSpec.cc
===================================================================
--- poppler-0.16.2/poppler/FileSpec.cc	(revision 14)
+++ poppler-0.16.2/poppler/FileSpec.cc	(working copy)
@@ -23,8 +23,26 @@
 
 #include <config.h>
 
+#include "XRef.h"
 #include "FileSpec.h"
+#include "PDFDocEncoding.h"
 
+static const char* getFileNameFromPath (const char *filePath)
+{
+  const char *filename;
+#ifdef _WIN32
+  filename = strrchr(filePath, '\\');
+#else
+  filename = strrchr(filePath, '/');
+#endif
+
+  if (filename)
+    filename++;
+  else
+    filename = filePath;
+  return filename;
+}
+
 GBool getFileSpecName (Object *fileSpec, Object *fileName)
 {
   if (fileSpec->isString()) {
@@ -138,3 +156,67 @@
 
   return gTrue;
 }
+
+static GBool getFileSpecObject(XRef *xref, Stream *stream, const char* fileName, Object *obj)
+{
+  Object fileSpec, obj1, obj2;
+  int length;
+
+  GooString *fsName = new GooString(fileName);
+  char *fileNameUTF16 = pdfDocEncodingToUTF16(fsName, &length);
+
+  fileSpec.initDict(xref);
+  fileSpec.dictSet("Type", obj1.initName("Filespec"));
+  fileSpec.dictSet("F", obj1.initString(fsName));
+  fileSpec.dictSet("UF", obj1.initString(new GooString(fileNameUTF16, length)));
+
+  delete []fileNameUTF16;
+ 
+  obj1.initStream(stream);
+  
+  Ref newRef = xref->addIndirectObject(&obj1);
+  obj2.initRef(newRef.num, newRef.gen);
+  obj1.initDict(xref);
+  obj1.dictSet("F", &obj2);
+  fileSpec.dictSet("EF", &obj1);
+  
+  Ref ref = xref->addIndirectObject(&fileSpec);
+  obj->initRef(ref.num, ref.gen);
+
+  return gTrue;
+}
+
+GBool createFileSpec (XRef *xref, GooString *filePathA, Object *obj)
+{
+  Object obj1, obj2;
+  FILE *fs; 
+  unsigned int size = 0;
+
+  const char *filePath = filePathA->getCString();
+
+  if (!(fs = fopen(filePath, "rb"))) {
+    error(-1, "Couldn't open file '%s'", filePath);
+    obj->initNull();
+    return gFalse;
+  }
+
+  if (fseek(fs, 0, SEEK_END)) {
+    error(-1, "fseek() failed in creating FileSpec Object");
+    return gFalse;
+  }
+
+  if ((size = ftell(fs)) == -1) {
+    error(-1, "ftell() failed in creating FileSpec Object");
+    return gFalse;
+  }
+
+  // Extract the file name from the file path 
+  const char *filename = getFileNameFromPath(filePath);
+
+  obj1.initDict(xref); // file stream eictionary
+  obj1.dictSet("Length", obj2.initInt(size)); 
+ 
+  FileStream *stream = new FileStream(fs, 0, 0, size, &obj1);
+
+  return getFileSpecObject (xref, stream, filename, obj); 
+}
Index: poppler-0.16.2/poppler/FileSpec.h
===================================================================
--- poppler-0.16.2/poppler/FileSpec.h	(revision 14)
+++ poppler-0.16.2/poppler/FileSpec.h	(working copy)
@@ -20,5 +20,6 @@
 
 GBool getFileSpecName (Object *fileSpec, Object *fileName);
 GBool getFileSpecNameForPlatform (Object *fileSpec, Object *fileName);
+GBool createFileSpec (XRef *xref, GooString *filepath, Object *obj);
 
 #endif /* FILE_SPEC_H */
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to