[poppler] 3 commits - poppler/PDFDoc.cc poppler/Stream.h poppler/XRef.cc poppler/XRef.h

Albert Astals Cid aacid at kemper.freedesktop.org
Thu May 16 11:50:37 PDT 2013


 poppler/PDFDoc.cc |    6 +++---
 poppler/Stream.h  |    6 ++----
 poppler/XRef.cc   |   38 ++++++++++++++++++++++++++++----------
 poppler/XRef.h    |   17 +++++++++++++++--
 4 files changed, 48 insertions(+), 19 deletions(-)

New commits:
commit 8640933a3aa7dbafa21765d029e97b4bba76716c
Author: Fabio D'Urso <fabiodurso at hotmail.it>
Date:   Thu Apr 25 19:18:30 2013 +0200

    Fix printf format specifiers (Goffset is a long long, not a int)

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 9cfbc7a..c78d5ca 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -27,7 +27,7 @@
 // Copyright (C) 2010 Srinivas Adicherla <srinivas.adicherla at geodesic.com>
 // Copyright (C) 2010 Philip Lorenz <lorenzph+freedesktop at gmail.com>
 // Copyright (C) 2011-2013 Thomas Freitag <Thomas.Freitag at alfa.de>
-// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
+// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso at hotmail.it>
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2013 Adam Reichold <adamreichold at myopera.com>
 //
@@ -1355,7 +1355,7 @@ void PDFDoc::writeXRefTableTrailer(Dict *trailerDict, XRef *uxref, GBool writeAl
   outStr->printf( "trailer\r\n");
   writeDictionnary(trailerDict, outStr, xRef, 0, NULL, cryptRC4, 0, 0, 0);
   outStr->printf( "\r\nstartxref\r\n");
-  outStr->printf( "%i\r\n", uxrefOffset);
+  outStr->printf( "%lli\r\n", uxrefOffset);
   outStr->printf( "%%%%EOF\r\n");
 }
 
@@ -1376,7 +1376,7 @@ void PDFDoc::writeXRefStreamTrailer (Dict *trailerDict, XRef *uxref, Ref *uxrefS
   obj1.free();
 
   outStr->printf( "startxref\r\n");
-  outStr->printf( "%i\r\n", uxrefOffset);
+  outStr->printf( "%lli\r\n", uxrefOffset);
   outStr->printf( "%%%%EOF\r\n");
 }
 
commit f8e8805bbce3e94b16b77fece0072645c66f6a31
Author: Fabio D'Urso <fabiodurso at hotmail.it>
Date:   Thu Apr 25 19:06:09 2013 +0200

    Re-enable commented-out printf-format attribute on OutStream::printf
    
    The answer to the question "2,3 because the first arg is class
    instance ?" is yes. It's documented behavior:
     Since non-static C++ methods have an implicit this argument, the
     arguments of such methods should be counted from two, not one.
    from http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Function-Attributes.html

diff --git a/poppler/Stream.h b/poppler/Stream.h
index aa58e8c..9b40fd1 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -21,7 +21,7 @@
 // Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2011, 2012 William Bader <williambader at hotmail.com>
 // Copyright (C) 2012, 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
-// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
+// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso at hotmail.it>
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2013 Peter Breitenlohner <peb at mppmu.mpg.de>
 // Copyright (C) 2013 Adam Reichold <adamreichold at myopera.com>
@@ -266,9 +266,7 @@ public:
   // Put a char in the stream
   virtual void put (char c) = 0;
 
-  //FIXME
-  // Printf-like function                         2,3 because the first arg is class instance ?
-  virtual void printf (const char *format, ...) = 0 ; //__attribute__((format(printf, 2,3))) = 0;
+  virtual void printf (const char *format, ...) GCC_PRINTF_FORMAT(2,3) = 0;
 
 private:
   int ref; // reference count
commit 013b2b247268f9b8dcd8e0461580e0bbcf7554c1
Author: Fabio D'Urso <fabiodurso at hotmail.it>
Date:   Thu Apr 25 17:58:25 2013 +0200

    XRef stream writing: Write 32-bit offsets when possible
    
    For compatibility reasons: some pdf readers don't support 64-bit offsets
    yet (for example, poppler 0.22 doesn't)

diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 9df4801..85f8a6f 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -21,7 +21,7 @@
 // Copyright (C) 2009, 2010 Ilya Gorenbein <igorenbein at finjan.com>
 // Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2012, 2013 Thomas Freitag <Thomas.Freitag at kabelmail.de>
-// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
+// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso at hotmail.it>
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
 // Copyright (C) 2013 Pino Toscano <pino at kde.org>
 //
@@ -1461,9 +1461,10 @@ void XRef::writeTableToFile(OutStream* outStr, GBool writeAllEntries) {
   writeXRef(&writer, writeAllEntries);
 }
 
-XRef::XRefStreamWriter::XRefStreamWriter(Object *indexA, GooString *stmBufA) {
+XRef::XRefStreamWriter::XRefStreamWriter(Object *indexA, GooString *stmBufA, int offsetSizeA) {
   index = indexA;
   stmBuf = stmBufA;
+  offsetSize = offsetSizeA;
 }
 
 void XRef::XRefStreamWriter::startSection(int first, int count) {
@@ -1473,17 +1474,28 @@ void XRef::XRefStreamWriter::startSection(int first, int count) {
 }
 
 void XRef::XRefStreamWriter::writeEntry(Goffset offset, int gen, XRefEntryType type) {
+  const int entryTotalSize = 1 + offsetSize + 2; /* type + offset + gen */
   char data[16];
-  int i;
   data[0] = (type==xrefEntryFree) ? 0 : 1;
-  for (i = sizeof(Goffset); i > 0; i--) {
+  for (int i = offsetSize; i > 0; i--) {
     data[i] = offset & 0xff;
     offset >>= 8;
   }
-  i = sizeof(Goffset) + 1;
-  data[i] = (gen >> 8) & 0xff;
-  data[i+1] = gen & 0xff;
-  stmBuf->append(data, i+2);
+  data[offsetSize + 1] = (gen >> 8) & 0xff;
+  data[offsetSize + 2] = gen & 0xff;
+  stmBuf->append(data, entryTotalSize);
+}
+
+XRef::XRefPreScanWriter::XRefPreScanWriter() {
+  hasOffsetsBeyond4GB = gFalse;
+}
+
+void XRef::XRefPreScanWriter::startSection(int first, int count) {
+}
+
+void XRef::XRefPreScanWriter::writeEntry(Goffset offset, int gen, XRefEntryType type) {
+  if (offset >= 0x100000000ll)
+    hasOffsetsBeyond4GB = gTrue;
 }
 
 void XRef::writeStreamToBuffer(GooString *stmBuf, Dict *xrefDict, XRef *xref) {
@@ -1491,7 +1503,13 @@ void XRef::writeStreamToBuffer(GooString *stmBuf, Dict *xrefDict, XRef *xref) {
   index.initArray(xref);
   stmBuf->clear();
 
-  XRefStreamWriter writer(&index, stmBuf);
+  // First pass: determine whether all offsets fit in 4 bytes or not
+  XRefPreScanWriter prescan;
+  writeXRef(&prescan, gFalse);
+  const int offsetSize = prescan.hasOffsetsBeyond4GB ? sizeof(Goffset) : 4;
+
+  // Second pass: actually write the xref stream
+  XRefStreamWriter writer(&index, stmBuf, offsetSize);
   writeXRef(&writer, gFalse);
 
   Object obj1, obj2;
@@ -1499,7 +1517,7 @@ void XRef::writeStreamToBuffer(GooString *stmBuf, Dict *xrefDict, XRef *xref) {
   xrefDict->set("Index", &index);
   obj2.initArray(xref);
   obj2.arrayAdd( obj1.initInt(1) );
-  obj2.arrayAdd( obj1.initInt(sizeof(Goffset)) );
+  obj2.arrayAdd( obj1.initInt(offsetSize) );
   obj2.arrayAdd( obj1.initInt(2) );
   xrefDict->set("W", &obj2);
 }
diff --git a/poppler/XRef.h b/poppler/XRef.h
index c9f17c2..70065d8 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -20,7 +20,7 @@
 // Copyright (C) 2010 Ilya Gorenbein <igorenbein at finjan.com>
 // Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2012, 2013 Thomas Freitag <Thomas.Freitag at kabelmail.de>
-// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
+// Copyright (C) 2012, 2013 Fabio D'Urso <fabiodurso at hotmail.it>
 // Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
 //
 // To see a description of the changes please see the Changelog file that
@@ -243,6 +243,7 @@ private:
     virtual ~XRefWriter() {};
   };
 
+  // XRefWriter subclass that writes a XRef table
   class XRefTableWriter: public XRefWriter {
   public:
     XRefTableWriter(OutStream* outStrA);
@@ -252,14 +253,26 @@ private:
     OutStream* outStr;
   };
 
+  // XRefWriter subclass that writes a XRef stream
   class XRefStreamWriter: public XRefWriter {
   public:
-    XRefStreamWriter(Object *index, GooString *stmBuf);
+    XRefStreamWriter(Object *index, GooString *stmBuf, int offsetSize);
     void startSection(int first, int count);
     void writeEntry(Goffset offset, int gen, XRefEntryType type);
   private:
     Object *index;
     GooString *stmBuf;
+    int offsetSize;
+  };
+
+  // Dummy XRefWriter subclass that only checks if all offsets fit in 4 bytes
+  class XRefPreScanWriter: public XRefWriter {
+  public:
+    XRefPreScanWriter();
+    void startSection(int first, int count);
+    void writeEntry(Goffset offset, int gen, XRefEntryType type);
+
+    GBool hasOffsetsBeyond4GB;
   };
 
   void writeXRef(XRefWriter *writer, GBool writeAllEntries);


More information about the poppler mailing list