[poppler] 6 commits - goo/GooString.cc poppler/Parser.cc poppler/PDFDoc.cc test/pdf-fullrewrite.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Fri Oct 2 13:07:58 PDT 2009


 goo/GooString.cc        |    4 ++--
 poppler/PDFDoc.cc       |   16 ++++++++++++++--
 poppler/Parser.cc       |    5 +++++
 test/pdf-fullrewrite.cc |    3 ++-
 4 files changed, 23 insertions(+), 5 deletions(-)

New commits:
commit d46f7343e446331489d3fe6711a7cf778e0bd902
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 2 22:04:46 2009 +0200

    Strings can have 0 inside so use the length
    
    Fixes saving some files

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index c723bd7..f1f1a8f 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -684,7 +684,7 @@ void PDFDoc::writeString (GooString* s, OutStream* outStr)
   } else {
     const char* c = s->getCString();
     outStr->printf("(");
-    while(*c!='\0') {
+    for(int i=0; i<s->getLength(); i++) {
       char unescaped = (*c)&0x000000ff;
       //escape if needed
       if (unescaped == '(' || unescaped == ')' || unescaped == '\\')
commit 2bc2040081919340415f576ce8266356deadbfcd
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 2 22:04:03 2009 +0200

    Increase decimals from 5 to 10, a double has that precision
    
    Makes saving more faithful for some files

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index d76b885..c723bd7 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -716,7 +716,7 @@ Guint PDFDoc::writeObject (Object* obj, Ref* ref, OutStream* outStr)
     case objReal:
     {
       GooString s;
-      s.appendf("{0:.5g}", obj->getReal());
+      s.appendf("{0:.10g}", obj->getReal());
       outStr->printf("%s ", s.getCString());
       break;
     }
commit 05eb7342d5234732f27c9c67b7fc1f9e40a4e075
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 2 22:03:40 2009 +0200

    If the stream was wrongly formed save the correct length
    
    Fixes saving of some files

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 4279b33..d76b885 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -771,6 +771,18 @@ Guint PDFDoc::writeObject (Object* obj, Ref* ref, OutStream* outStr)
           obj1.free();
         } else {
           //raw stream copy
+          FilterStream *fs = dynamic_cast<FilterStream*>(stream);
+          if (fs) {
+            BaseStream *bs = fs->getBaseStream();
+            if (bs) {
+              Guint streamEnd;
+                if (xref->getStreamEnd(bs->getStart(), &streamEnd)) {
+                  Object val;
+                  val.initInt(streamEnd - bs->getStart());
+                  stream->getDict()->set("Length", &val);
+                }
+              }
+          }
           writeDictionnary (stream->getDict(), outStr);
           writeRawStream (stream, outStr);
         }
commit b98faa4c162392d9416a5a93c9042b41f82d8657
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 2 22:02:13 2009 +0200

    Return the save status as program status

diff --git a/test/pdf-fullrewrite.cc b/test/pdf-fullrewrite.cc
index 89511f0..9658e55 100644
--- a/test/pdf-fullrewrite.cc
+++ b/test/pdf-fullrewrite.cc
@@ -37,9 +37,10 @@ int main (int argc, char *argv[])
   }
 
 
-  doc->saveAs(outputName, writeForceRewrite);
+  int res = doc->saveAs(outputName, writeForceRewrite);
 
   delete doc;
   delete globalParams;
   delete outputName;
+  return res;
 }
commit f73f59f2c7bb7c7d57eb70cdc1bc30b80a92d0b7
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 2 22:01:45 2009 +0200

    If the Length entry of the stream is wrong, fix it
    
    Fixes saving some files

diff --git a/poppler/Parser.cc b/poppler/Parser.cc
index b531233..05fba86 100644
--- a/poppler/Parser.cc
+++ b/poppler/Parser.cc
@@ -215,6 +215,11 @@ Stream *Parser::makeStream(Object *dict, Guchar *fileKey,
         shift();
       }
       length = lexer->getPos() - pos;
+      if (buf1.isCmd("endstream")) {
+        obj.initInt(length);
+        dict->dictSet("Length", &obj);
+        obj.free();
+      }
     } else {
       // When building the xref we can't use it so use this
       // kludge for broken PDF files: just add 5k to the length, and
commit 91135c7e788bc32e414e1a9c9ab43b326a07e970
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 2 22:00:12 2009 +0200

    increase the range of characters we sanitize
    
    Fixes saving of some files

diff --git a/goo/GooString.cc b/goo/GooString.cc
index 6105966..0d4cb73 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -789,11 +789,11 @@ GooString *GooString::sanitizedName(GBool psmode)
 
   for (i = 0; i < getLength(); ++i) {
     c = getChar(i);
-    if ((psmode && (c <= (char)0x20 || c >= (char)0x7f)) ||
+    if (c <= (char)0x20 || c >= (char)0x7f ||
 	c == ' ' ||
 	c == '(' || c == ')' || c == '<' || c == '>' ||
 	c == '[' || c == ']' || c == '{' || c == '}' ||
-	c == '/' || c == '%') {
+	c == '/' || c == '%' || c == '#') {
       sprintf(buf, "#%02x", c & 0xff);
       name->append(buf);
     } else {


More information about the poppler mailing list