[poppler] 15 commits - CMakeLists.txt config.h.cmake configure.ac goo/GooString.cc goo/GooString.h poppler/CachedFile.cc poppler/CachedFile.h poppler/CurlCachedFile.cc poppler/CurlCachedFile.h poppler/CurlPDFDocBuilder.cc poppler/CurlPDFDocBuilder.h poppler/Form.cc poppler/LocalPDFDocBuilder.cc poppler/LocalPDFDocBuilder.h poppler/Makefile.am poppler/PDFDocBuilder.h poppler/PDFDoc.cc poppler/PDFDocFactory.cc poppler/PDFDocFactory.h poppler/PDFDoc.h poppler/poppler-config.h.cmake poppler/poppler-config.h.in poppler/StdinCachedFile.cc poppler/StdinCachedFile.h poppler/StdinPDFDocBuilder.cc poppler/StdinPDFDocBuilder.h poppler/Stream.cc poppler/Stream.h utils/pdffonts.cc utils/pdfimages.cc utils/pdfinfo.cc utils/pdftoabw.cc utils/pdftohtml.cc utils/pdftoppm.cc utils/pdftops.cc utils/pdftotext.cc
Albert Astals Cid
aacid at kemper.freedesktop.org
Mon Apr 5 08:55:40 PDT 2010
CMakeLists.txt | 31 +++++
config.h.cmake | 6
configure.ac | 16 ++
goo/GooString.cc | 12 -
goo/GooString.h | 21 +--
poppler/CachedFile.cc | 248 +++++++++++++++++++++++++++++++++++++++++
poppler/CachedFile.h | 115 +++++++++++++++++++
poppler/CurlCachedFile.cc | 96 +++++++++++++++
poppler/CurlCachedFile.h | 40 ++++++
poppler/CurlPDFDocBuilder.cc | 47 +++++++
poppler/CurlPDFDocBuilder.h | 31 +++++
poppler/Form.cc | 4
poppler/LocalPDFDocBuilder.cc | 46 +++++++
poppler/LocalPDFDocBuilder.h | 31 +++++
poppler/Makefile.am | 33 +++++
poppler/PDFDoc.cc | 54 ++++----
poppler/PDFDoc.h | 6
poppler/PDFDocBuilder.h | 33 +++++
poppler/PDFDocFactory.cc | 72 +++++++++++
poppler/PDFDocFactory.h | 43 +++++++
poppler/StdinCachedFile.cc | 38 ++++++
poppler/StdinCachedFile.h | 27 ++++
poppler/StdinPDFDocBuilder.cc | 43 +++++++
poppler/StdinPDFDocBuilder.h | 31 +++++
poppler/Stream.cc | 102 ++++++++++++++++
poppler/Stream.h | 58 +++++++++
poppler/poppler-config.h.cmake | 5
poppler/poppler-config.h.in | 5
utils/pdffonts.cc | 18 +-
utils/pdfimages.cc | 13 +-
utils/pdfinfo.cc | 17 +-
utils/pdftoabw.cc | 12 +
utils/pdftohtml.cc | 12 +
utils/pdftoppm.cc | 17 +-
utils/pdftops.cc | 11 +
utils/pdftotext.cc | 16 +-
36 files changed, 1328 insertions(+), 82 deletions(-)
New commits:
commit a9d801b2db20ecb08734ee5cdb703abf11994b6e
Author: Albert Astals Cid <aacid at kde.org>
Date: Mon Apr 5 16:55:02 2010 +0100
Make some paremeters const & to clearly show we just read them
diff --git a/poppler/CachedFile.cc b/poppler/CachedFile.cc
index 835079f..46627c3 100644
--- a/poppler/CachedFile.cc
+++ b/poppler/CachedFile.cc
@@ -6,6 +6,7 @@
//
// Copyright 2009 Stefan Thomas <thomas at eload24.com>
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -68,7 +69,7 @@ int CachedFile::seek(long int offset, int origin)
return 0;
}
-int CachedFile::cache(GooVector<ByteRange>* ranges)
+int CachedFile::cache(const GooVector<ByteRange> &origRanges)
{
GooVector<int> loadChunks;
int numChunks = length/CachedFileChunkSize + 1;
@@ -76,12 +77,13 @@ int CachedFile::cache(GooVector<ByteRange>* ranges)
int startChunk, endChunk;
GooVector<ByteRange> chunk_ranges, all;
ByteRange range;
+ const GooVector<ByteRange> *ranges = &origRanges;
- if (!ranges) {
- ranges = &all;
- range.offset = 0;
- range.length = length;
- ranges->push_back(range);
+ if (ranges->empty()) {
+ range.offset = 0;
+ range.length = length;
+ all.push_back(range);
+ ranges = &all;
}
memset(&chunkNeeded, 0, numChunks);
@@ -124,7 +126,7 @@ int CachedFile::cache(GooVector<ByteRange>* ranges)
if (chunk_ranges.size() > 0) {
CachedFileWriter writer =
CachedFileWriter(this, &loadChunks);
- return loader->load(&chunk_ranges, &writer);
+ return loader->load(chunk_ranges, &writer);
}
return 0;
@@ -168,7 +170,7 @@ int CachedFile::cache(size_t offset, size_t length)
range.offset = offset;
range.length = length;
r.push_back(range);
- return cache(&r);
+ return cache(r);
}
//------------------------------------------------------------------------
diff --git a/poppler/CachedFile.h b/poppler/CachedFile.h
index e004578..eefb2a3 100644
--- a/poppler/CachedFile.h
+++ b/poppler/CachedFile.h
@@ -8,6 +8,7 @@
//
// Copyright 2009 Stefan Thomas <thomas at eload24.com>
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -37,14 +38,13 @@ friend class CachedFileWriter;
public:
CachedFile(CachedFileLoader *cacheLoader, GooString *uri);
- ~CachedFile();
Guint getLength() { return length; }
long int tell();
int seek(long int offset, int origin);
size_t read(void * ptr, size_t unitsize, size_t count);
size_t write(const char *ptr, size_t size, size_t fromByte);
- int cache(GooVector<ByteRange>* ranges);
+ int cache(const GooVector<ByteRange> &ranges);
// Reference counting.
void incRefCnt();
@@ -52,6 +52,8 @@ public:
private:
+ ~CachedFile();
+
enum ChunkState {
chunkStateNew = 0,
chunkStateLoaded
@@ -104,7 +106,7 @@ public:
virtual ~CachedFileLoader() {};
virtual size_t init(GooString *uri, CachedFile *cachedFile) = 0;
- virtual int load(GooVector<ByteRange> *ranges, CachedFileWriter *writer) = 0;
+ virtual int load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer) = 0;
};
diff --git a/poppler/CurlCachedFile.cc b/poppler/CurlCachedFile.cc
index b326fb7..35f5104 100644
--- a/poppler/CurlCachedFile.cc
+++ b/poppler/CurlCachedFile.cc
@@ -6,6 +6,7 @@
//
// Copyright 2009 Stefan Thomas <thomas at eload24.com>
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -67,14 +68,14 @@ size_t load_cb(const char *ptr, size_t size, size_t nmemb, void *data)
return (writer->write) (ptr, size*nmemb);
}
-int CurlCachedFileLoader::load(GooVector<ByteRange> *ranges, CachedFileWriter *writer)
+int CurlCachedFileLoader::load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer)
{
CURLcode r = CURLE_OK;
size_t fromByte, toByte;
- for (size_t i = 0; i < (*ranges).size(); i++) {
+ for (size_t i = 0; i < ranges.size(); i++) {
- fromByte = (*ranges)[i].offset;
- toByte = fromByte + (*ranges)[i].length - 1;
+ fromByte = ranges[i].offset;
+ toByte = fromByte + ranges[i].length - 1;
GooString *range = GooString::format("{0:ud}-{1:ud}", fromByte, toByte);
curl_easy_setopt(curl, CURLOPT_URL, url->getCString());
diff --git a/poppler/CurlCachedFile.h b/poppler/CurlCachedFile.h
index b18b7f8..b5f2e7d 100644
--- a/poppler/CurlCachedFile.h
+++ b/poppler/CurlCachedFile.h
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -25,7 +26,7 @@ public:
CurlCachedFileLoader();
~CurlCachedFileLoader();
size_t init(GooString *url, CachedFile* cachedFile);
- int load(GooVector<ByteRange> *ranges, CachedFileWriter *writer);
+ int load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer);
private:
diff --git a/poppler/CurlPDFDocBuilder.cc b/poppler/CurlPDFDocBuilder.cc
index 251a4eb..948cd7a 100644
--- a/poppler/CurlPDFDocBuilder.cc
+++ b/poppler/CurlPDFDocBuilder.cc
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -20,13 +21,13 @@
//------------------------------------------------------------------------
PDFDoc *
-CurlPDFDocBuilder::buildPDFDoc(GooString* uri,
+CurlPDFDocBuilder::buildPDFDoc(const GooString &uri,
GooString *ownerPassword, GooString *userPassword, void *guiDataA)
{
Object obj;
CachedFile *cachedFile = new CachedFile(
- new CurlCachedFileLoader(), new GooString(uri));
+ new CurlCachedFileLoader(), uri.copy());
obj.initNull();
BaseStream *str = new CachedFileStream(
@@ -35,9 +36,9 @@ CurlPDFDocBuilder::buildPDFDoc(GooString* uri,
return new PDFDoc(str, ownerPassword, userPassword, guiDataA);
}
-GBool CurlPDFDocBuilder::supports(GooString* uri)
+GBool CurlPDFDocBuilder::supports(const GooString &uri)
{
- if (uri->cmpN("http://", 7) == 0 || uri->cmpN("https://", 8) == 0) {
+ if (uri.cmpN("http://", 7) == 0 || uri.cmpN("https://", 8) == 0) {
return gTrue;
} else {
return gFalse;
diff --git a/poppler/CurlPDFDocBuilder.h b/poppler/CurlPDFDocBuilder.h
index e84a4c7..75f9f62 100644
--- a/poppler/CurlPDFDocBuilder.h
+++ b/poppler/CurlPDFDocBuilder.h
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -21,9 +22,9 @@ class CurlPDFDocBuilder : public PDFDocBuilder {
public:
- PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ PDFDoc *buildPDFDoc(const GooString &uri, GooString *ownerPassword = NULL,
GooString *userPassword = NULL, void *guiDataA = NULL);
- GBool supports(GooString* uri);
+ GBool supports(const GooString &uri);
};
diff --git a/poppler/LocalPDFDocBuilder.cc b/poppler/LocalPDFDocBuilder.cc
index c54faac..6f6f1fc 100644
--- a/poppler/LocalPDFDocBuilder.cc
+++ b/poppler/LocalPDFDocBuilder.cc
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -18,24 +19,24 @@
PDFDoc *
LocalPDFDocBuilder::buildPDFDoc(
- GooString* uri, GooString *ownerPassword, GooString
+ const GooString &uri, GooString *ownerPassword, GooString
*userPassword, void *guiDataA)
{
- if (uri->cmpN("file://", 7) == 0) {
- GooString *fileName = new GooString(uri);
+ if (uri.cmpN("file://", 7) == 0) {
+ GooString *fileName = uri.copy();
fileName->del(0, 7);
return new PDFDoc(fileName, ownerPassword, userPassword, guiDataA);
} else {
- GooString *fileName = new GooString(uri);
+ GooString *fileName = uri.copy();
return new PDFDoc(fileName, ownerPassword, userPassword, guiDataA);
}
}
-GBool LocalPDFDocBuilder::supports(GooString* uri)
+GBool LocalPDFDocBuilder::supports(const GooString &uri)
{
- if (uri->cmpN("file://", 7) == 0) {
+ if (uri.cmpN("file://", 7) == 0) {
return gTrue;
- } else if (!strstr(uri->getCString(), "://")) {
+ } else if (!strstr(uri.getCString(), "://")) {
return gTrue;
} else {
return gFalse;
diff --git a/poppler/LocalPDFDocBuilder.h b/poppler/LocalPDFDocBuilder.h
index 439a131..5b90a1e 100644
--- a/poppler/LocalPDFDocBuilder.h
+++ b/poppler/LocalPDFDocBuilder.h
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -21,9 +22,9 @@ class LocalPDFDocBuilder : public PDFDocBuilder {
public:
- PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ PDFDoc *buildPDFDoc(const GooString &uri, GooString *ownerPassword = NULL,
GooString *userPassword = NULL, void *guiDataA = NULL);
- GBool supports(GooString* uri);
+ GBool supports(const GooString &uri);
};
diff --git a/poppler/PDFDocBuilder.h b/poppler/PDFDocBuilder.h
index 8a1350b..43d7b0d 100644
--- a/poppler/PDFDocBuilder.h
+++ b/poppler/PDFDocBuilder.h
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -23,9 +24,9 @@ class PDFDocBuilder {
public:
virtual ~PDFDocBuilder() {};
- virtual PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ virtual PDFDoc *buildPDFDoc(const GooString &uri, GooString *ownerPassword = NULL,
GooString *userPassword = NULL, void *guiDataA = NULL) = 0;
- virtual GBool supports(GooString* uri) = 0;
+ virtual GBool supports(const GooString &uri) = 0;
};
diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc
index d8b5fcc..7829b3e 100644
--- a/poppler/PDFDocFactory.cc
+++ b/poppler/PDFDocFactory.cc
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -48,7 +49,7 @@ PDFDocFactory::~PDFDocFactory()
}
PDFDoc *
-PDFDocFactory::createPDFDoc(GooString* uri, GooString *ownerPassword,
+PDFDocFactory::createPDFDoc(const GooString &uri, GooString *ownerPassword,
GooString *userPassword, void *guiDataA)
{
for (int i = builders->getLength() - 1; i >= 0 ; i--) {
@@ -58,8 +59,8 @@ PDFDocFactory::createPDFDoc(GooString* uri, GooString *ownerPassword,
}
}
- error(-1, "Cannot handle URI '%s'.", uri->getCString());
- GooString *fileName = new GooString(uri);
+ error(-1, "Cannot handle URI '%s'.", uri.getCString());
+ GooString *fileName = uri.copy();
return PDFDoc::ErrorPDFDoc(errOpenFile, fileName);
}
diff --git a/poppler/PDFDocFactory.h b/poppler/PDFDocFactory.h
index 00ee359..609c4c4 100644
--- a/poppler/PDFDocFactory.h
+++ b/poppler/PDFDocFactory.h
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -28,7 +29,7 @@ public:
PDFDocFactory(GooList *pdfDocBuilders = NULL);
~PDFDocFactory();
- PDFDoc *createPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ PDFDoc *createPDFDoc(const GooString &uri, GooString *ownerPassword = NULL,
GooString *userPassword = NULL, void *guiDataA = NULL);
void registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder);
diff --git a/poppler/StdinCachedFile.cc b/poppler/StdinCachedFile.cc
index 9b32136..4bfc31e 100644
--- a/poppler/StdinCachedFile.cc
+++ b/poppler/StdinCachedFile.cc
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -30,7 +31,7 @@ size_t StdinCacheLoader::init(GooString *dummy, CachedFile *cachedFile)
return size;
}
-int StdinCacheLoader::load(GooVector<ByteRange> *ranges, CachedFileWriter *writer)
+int StdinCacheLoader::load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer)
{
return 0;
}
diff --git a/poppler/StdinCachedFile.h b/poppler/StdinCachedFile.h
index 9af086a..11b064b 100644
--- a/poppler/StdinCachedFile.h
+++ b/poppler/StdinCachedFile.h
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -18,7 +19,7 @@ class StdinCacheLoader : public CachedFileLoader {
public:
size_t init(GooString *dummy, CachedFile* cachedFile);
- int load(GooVector<ByteRange> *ranges, CachedFileWriter *writer);
+ int load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer);
};
diff --git a/poppler/StdinPDFDocBuilder.cc b/poppler/StdinPDFDocBuilder.cc
index e260615..571ee46 100644
--- a/poppler/StdinPDFDocBuilder.cc
+++ b/poppler/StdinPDFDocBuilder.cc
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -19,7 +20,7 @@
//------------------------------------------------------------------------
PDFDoc *
-StdinPDFDocBuilder::buildPDFDoc(GooString* uri, GooString *ownerPassword,
+StdinPDFDocBuilder::buildPDFDoc(const GooString &uri, GooString *ownerPassword,
GooString *userPassword, void *guiDataA)
{
Object obj;
@@ -31,9 +32,9 @@ StdinPDFDocBuilder::buildPDFDoc(GooString* uri, GooString *ownerPassword,
ownerPassword, userPassword);
}
-GBool StdinPDFDocBuilder::supports(GooString* uri)
+GBool StdinPDFDocBuilder::supports(const GooString &uri)
{
- if (uri->cmpN("fd://0", 6) == 0) {
+ if (uri.cmpN("fd://0", 6) == 0) {
return gTrue;
} else {
return gFalse;
diff --git a/poppler/StdinPDFDocBuilder.h b/poppler/StdinPDFDocBuilder.h
index fae32c0..2fe60e0 100644
--- a/poppler/StdinPDFDocBuilder.h
+++ b/poppler/StdinPDFDocBuilder.h
@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib at hiberis.nl>
+// Copyright 2010 Albert Astals Cid <aacid at kde.org>
//
//========================================================================
@@ -21,9 +22,9 @@ class StdinPDFDocBuilder : public PDFDocBuilder {
public:
- PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ PDFDoc *buildPDFDoc(const GooString &uri, GooString *ownerPassword = NULL,
GooString *userPassword = NULL, void *guiDataA = NULL);
- GBool supports(GooString* uri);
+ GBool supports(const GooString &uri);
};
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 4849f5f..81b20e4 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Dominic Lachowicz <cinamod at hotmail.com>
-// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
@@ -138,7 +138,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
delete fileName;
if (userPW) {
diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc
index 60766b7..ffa7991 100644
--- a/utils/pdfimages.cc
+++ b/utils/pdfimages.cc
@@ -15,7 +15,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
@@ -127,7 +127,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
delete fileName;
if (userPW) {
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 9644e9d..c645816 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Dom Lachowicz <cinamod at hotmail.com>
-// Copyright (C) 2007-2009 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2010 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
@@ -165,7 +165,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
delete fileName;
if (userPW) {
diff --git a/utils/pdftoabw.cc b/utils/pdftoabw.cc
index 5cb651c..2f7f042 100644
--- a/utils/pdftoabw.cc
+++ b/utils/pdftoabw.cc
@@ -3,7 +3,7 @@
* Copyright (C) 2007 Dominic Lachowicz <cinamod at hotmail.com>
* Copyright (C) 2007 Kouhei Sutou <kou at cozmixng.org>
* Copyright (C) 2009 Jakub Wilk <ubanus at users.sf.net>
- * Copyright (C) 2009 Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2009, 2010 Albert Astals Cid <aacid at kde.org>
* Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
*
* This program is free software; you can redistribute it and/or modify
@@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
delete fileName;
if (userPW) {
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index 7e2ac92..53d9ecb 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -13,7 +13,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
@@ -194,7 +194,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
if (userPW) {
delete userPW;
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 72d2a5d..849e79f 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -266,7 +266,7 @@ int main(int argc, char *argv[]) {
delete fileName;
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
delete fileName;
if (userPW) {
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index c549b4a..58ba731 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -16,7 +16,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2009 Till Kamppeter <till.kamppeter at gmail.com>
// Copyright (C) 2009 Sanjoy Mahajan <sanjoy at mit.edu>
// Copyright (C) 2009 William Bader <williambader at hotmail.com>
@@ -305,7 +305,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
if (userPW) {
delete userPW;
diff --git a/utils/pdftotext.cc b/utils/pdftotext.cc
index 143e754..cb530a9 100644
--- a/utils/pdftotext.cc
+++ b/utils/pdftotext.cc
@@ -16,7 +16,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Dominic Lachowicz <cinamod at hotmail.com>
-// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2009 Jan Jockusch <jan at jockusch.de>
// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
@@ -199,7 +199,7 @@ int main(int argc, char *argv[]) {
fileName = new GooString("fd://0");
}
- doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
if (userPW) {
delete userPW;
commit a04ee3ea6066c97d41fc40d5d97c600a1870855a
Author: Albert Astals Cid <aacid at kde.org>
Date: Mon Apr 5 16:50:58 2010 +0100
forgot my (C)
diff --git a/poppler/Form.cc b/poppler/Form.cc
index d7150fb..4df8a7d 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -5,7 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2006-2008 Julien Rebetez <julienr at svn.gnome.org>
-// Copyright 2007-2009 Albert Astals Cid <aacid at kde.org>
+// Copyright 2007-2010 Albert Astals Cid <aacid at kde.org>
// Copyright 2007-2008 Carlos Garcia Campos <carlosgc at gnome.org>
// Copyright 2007 Adrian Johnson <ajohnson at redneon.com>
// Copyright 2007 Iñigo MartÃnez <inigomartinez at gmail.com>
commit ed723c8ac4a21a50d7d236cdcf7a635defd8dffb
Author: Albert Astals Cid <aacid at kde.org>
Date: Mon Apr 5 16:50:15 2010 +0100
The copy constructor of GooString never worked, so do not use it
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 7ccc96b..d7150fb 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -990,7 +990,7 @@ FormFieldText::FormFieldText(XRef *xrefA, Object *aobj, const Ref& ref)
GooString* FormFieldText::getContentCopy ()
{
if (!content) return NULL;
- return new GooString(*content);
+ return new GooString(content);
}
void FormFieldText::setContentCopy (GooString* new_content)
commit a28be8e4009b86fdfd92da928def194225a736c6
Author: Albert Astals Cid <aacid at kde.org>
Date: Mon Apr 5 16:49:06 2010 +0100
Add some const correctnes to GooString
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 0d4cb73..f1dcbc8 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -18,7 +18,7 @@
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
// Copyright (C) 2007 Jeff Muizelaar <jeff at infidigm.net>
-// Copyright (C) 2008, 2009 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008-2010 Albert Astals Cid <aacid at kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -197,7 +197,7 @@ GooString::GooString(GooString *str, int idx, int lengthA) {
Set(str->getCString() + idx, lengthA);
}
-GooString::GooString(GooString *str) {
+GooString::GooString(const GooString *str) {
s = NULL;
length = 0;
Set(str->getCString(), str->length);
@@ -684,7 +684,7 @@ GooString *GooString::lowerCase() {
return this;
}
-int GooString::cmp(GooString *str) {
+int GooString::cmp(GooString *str) const {
int n1, n2, i, x;
char *p1, *p2;
@@ -699,7 +699,7 @@ int GooString::cmp(GooString *str) {
return n1 - n2;
}
-int GooString::cmpN(GooString *str, int n) {
+int GooString::cmpN(GooString *str, int n) const {
int n1, n2, i, x;
char *p1, *p2;
@@ -719,7 +719,7 @@ int GooString::cmpN(GooString *str, int n) {
return n1 - n2;
}
-int GooString::cmp(const char *sA) {
+int GooString::cmp(const char *sA) const {
int n1, i, x;
const char *p1, *p2;
@@ -739,7 +739,7 @@ int GooString::cmp(const char *sA) {
return 0;
}
-int GooString::cmpN(const char *sA, int n) {
+int GooString::cmpN(const char *sA, int n) const {
int n1, i, x;
const char *p1, *p2;
diff --git a/goo/GooString.h b/goo/GooString.h
index 731f640..e77308d 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -17,7 +17,7 @@
//
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
-// Copyright (C) 2008, 2009 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008-2010 Albert Astals Cid <aacid at kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -42,7 +42,7 @@ public:
GooString();
// Create a string from a C string.
- GooString(const char *sA);
+ explicit GooString(const char *sA);
// Create a string from <lengthA> chars at <sA>. This string
// can contain null characters.
@@ -58,8 +58,8 @@ public:
GooString* Set(const char *s1, int s1Len=CALC_STRING_LEN, const char *s2=NULL, int s2Len=CALC_STRING_LEN);
// Copy a string.
- GooString(GooString *str);
- GooString *copy() { return new GooString(this); }
+ explicit GooString(const GooString *str);
+ GooString *copy() const { return new GooString(this); }
// Concatenate two strings.
GooString(GooString *str1, GooString *str2);
@@ -98,7 +98,7 @@ public:
int getLength() { return length; }
// Get C string.
- char *getCString() { return s; }
+ char *getCString() const { return s; }
// Get <i>th character.
char getChar(int i) { return s[i]; }
@@ -131,10 +131,10 @@ public:
GooString *lowerCase();
// Compare two strings: -1:< 0:= +1:>
- int cmp(GooString *str);
- int cmpN(GooString *str, int n);
- int cmp(const char *sA);
- int cmpN(const char *sA, int n);
+ int cmp(GooString *str) const;
+ int cmpN(GooString *str, int n) const;
+ int cmp(const char *sA) const;
+ int cmpN(const char *sA, int n) const;
GBool hasUnicodeMarker(void);
@@ -145,6 +145,9 @@ public:
GooString *sanitizedName(GBool psmode);
private:
+ GooString(const GooString &other);
+ GooString& operator=(const GooString &other);
+
// you can tweak this number for a different speed/memory usage tradeoffs.
// In libc malloc() rounding is 16 so it's best to choose a value that
// results in sizeof(GooString) be a multiple of 16.
commit 46aee9e4d225b88a3dfd4afbe57259f337bb15d3
Author: Hib Eris <hib at hiberis.nl>
Date: Mon Apr 5 14:36:09 2010 +0200
Use PDFDocFactory in utils
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 752fa15..4849f5f 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -15,6 +15,7 @@
//
// Copyright (C) 2006 Dominic Lachowicz <cinamod at hotmail.com>
// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -38,6 +39,7 @@
#include "GfxFont.h"
#include "Annot.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
static char *fontTypeNames[] = {
"unknown",
@@ -131,16 +133,14 @@ int main(int argc, char *argv[]) {
} else {
userPW = NULL;
}
-
- if(fileName->cmp("-") != 0) {
- doc = new PDFDoc(fileName, ownerPW, userPW);
- } else {
- Object obj;
-
- obj.initNull();
- doc = new PDFDoc(new FileStream(stdin, 0, gFalse, 0, &obj), ownerPW, userPW);
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
}
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ delete fileName;
+
if (userPW) {
delete userPW;
}
diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc
index b821c79..60766b7 100644
--- a/utils/pdfimages.cc
+++ b/utils/pdfimages.cc
@@ -16,6 +16,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -40,6 +41,7 @@
#include "Catalog.h"
#include "Page.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
#include "ImageOutputDev.h"
#include "Error.h"
@@ -120,7 +122,14 @@ int main(int argc, char *argv[]) {
} else {
userPW = NULL;
}
- doc = new PDFDoc(fileName, ownerPW, userPW);
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
+ }
+
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ delete fileName;
+
if (userPW) {
delete userPW;
}
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 48504d2..9644e9d 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -43,15 +43,12 @@
#include "Catalog.h"
#include "Page.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
#include "CharTypes.h"
#include "UnicodeMap.h"
#include "PDFDocEncoding.h"
#include "Error.h"
#include "DateInfo.h"
-#include "StdinCachedFile.h"
-#if ENABLE_LIBCURL
-#include "CurlCachedFile.h"
-#endif
static void printInfoString(Dict *infoDict, char *key, char *text,
UnicodeMap *uMap);
@@ -163,28 +160,14 @@ int main(int argc, char *argv[]) {
userPW = NULL;
}
-#if ENABLE_LIBCURL
- if (fileName->cmpN("http://", 7) == 0 ||
- fileName->cmpN("https://", 8) == 0) {
- Object obj;
-
- obj.initNull();
- CachedFile *cachedFile = new CachedFile(new CurlCachedFileLoader(), fileName);
- doc = new PDFDoc(new CachedFileStream(cachedFile, 0, gFalse, 0, &obj),
- ownerPW, userPW);
- } else
-#endif
- if (fileName->cmp("-") != 0) {
- doc = new PDFDoc(fileName, ownerPW, userPW);
- } else {
- Object obj;
-
- obj.initNull();
- CachedFile *cachedFile = new CachedFile(new StdinCacheLoader(), NULL);
- doc = new PDFDoc(new CachedFileStream(cachedFile, 0, gFalse, 0, &obj),
- ownerPW, userPW);
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
}
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ delete fileName;
+
if (userPW) {
delete userPW;
}
diff --git a/utils/pdftoabw.cc b/utils/pdftoabw.cc
index 9c71c76..5cb651c 100644
--- a/utils/pdftoabw.cc
+++ b/utils/pdftoabw.cc
@@ -4,6 +4,7 @@
* Copyright (C) 2007 Kouhei Sutou <kou at cozmixng.org>
* Copyright (C) 2009 Jakub Wilk <ubanus at users.sf.net>
* Copyright (C) 2009 Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
*
* 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
@@ -41,6 +42,7 @@
#include "Catalog.h"
#include "Page.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
#include "ABWOutputDev.h"
#include "PSOutputDev.h"
#include "GlobalParams.h"
@@ -136,7 +138,13 @@ int main(int argc, char *argv[]) {
userPW = NULL;
}
- doc = new PDFDoc(fileName, ownerPW, userPW);
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
+ }
+
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ delete fileName;
if (userPW) {
delete userPW;
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index 41312de..7e2ac92 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -14,6 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -41,6 +42,7 @@
#include "Catalog.h"
#include "Page.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
#include "HtmlOutputDev.h"
#include "PSOutputDev.h"
#include "GlobalParams.h"
@@ -187,7 +189,13 @@ int main(int argc, char *argv[]) {
fileName = new GooString(argv[1]);
- doc = new PDFDoc(fileName, ownerPW, userPW);
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
+ }
+
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+
if (userPW) {
delete userPW;
}
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 7d1e3bf..72d2a5d 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -20,6 +20,7 @@
// Copyright (C) 2009 Stefan Thomas <thomas at eload24.com>
// Copyright (C) 2009, 2010 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2010 Adrian Johnson <ajohnson at redneon.com>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -36,6 +37,7 @@
#include "GlobalParams.h"
#include "Object.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
#include "splash/SplashBitmap.h"
#include "splash/Splash.h"
#include "SplashOutputDev.h"
@@ -256,14 +258,17 @@ int main(int argc, char *argv[]) {
} else {
userPW = NULL;
}
- if(fileName != NULL && fileName->cmp("-") != 0) {
- doc = new PDFDoc(fileName, ownerPW, userPW);
- } else {
- Object obj;
- obj.initNull();
- doc = new PDFDoc(new FileStream(stdin, 0, gFalse, 0, &obj), ownerPW, userPW);
+ if (fileName == NULL) {
+ fileName = new GooString("fd://0");
+ }
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
}
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+ delete fileName;
+
if (userPW) {
delete userPW;
}
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index 69d5c32..c549b4a 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -44,6 +44,7 @@
#include "Catalog.h"
#include "Page.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
#include "PSOutputDev.h"
#include "Error.h"
@@ -299,7 +300,13 @@ int main(int argc, char *argv[]) {
} else {
userPW = NULL;
}
- doc = new PDFDoc(fileName, ownerPW, userPW);
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
+ }
+
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+
if (userPW) {
delete userPW;
}
diff --git a/utils/pdftotext.cc b/utils/pdftotext.cc
index 4ebda19..143e754 100644
--- a/utils/pdftotext.cc
+++ b/utils/pdftotext.cc
@@ -18,6 +18,7 @@
// Copyright (C) 2006 Dominic Lachowicz <cinamod at hotmail.com>
// Copyright (C) 2007-2008 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2009 Jan Jockusch <jan at jockusch.de>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -43,6 +44,7 @@
#include "Catalog.h"
#include "Page.h"
#include "PDFDoc.h"
+#include "PDFDocFactory.h"
#include "TextOutputDev.h"
#include "CharTypes.h"
#include "UnicodeMap.h"
@@ -192,15 +194,13 @@ int main(int argc, char *argv[]) {
userPW = NULL;
}
- if(fileName->cmp("-") != 0) {
- doc = new PDFDoc(fileName, ownerPW, userPW);
- } else {
- Object obj;
-
- obj.initNull();
- doc = new PDFDoc(new FileStream(stdin, 0, gFalse, 0, &obj), ownerPW, userPW);
+ if (fileName->cmp("-") == 0) {
+ delete fileName;
+ fileName = new GooString("fd://0");
}
+ doc = PDFDocFactory().createPDFDoc(fileName, ownerPW, userPW);
+
if (userPW) {
delete userPW;
}
commit d487a90688c4431075c9e4db040b3b02625e208f
Author: Hib Eris <hib at hiberis.nl>
Date: Mon Apr 5 14:35:52 2010 +0200
Add PDFDocFactory
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 562f89c..0725747 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -260,6 +260,7 @@ set(poppler_SRCS
poppler/Parser.cc
poppler/PDFDoc.cc
poppler/PDFDocEncoding.cc
+ poppler/PDFDocFactory.cc
poppler/PopplerCache.cc
poppler/ProfileData.cc
poppler/PreScanOutputDev.cc
@@ -406,6 +407,7 @@ if(ENABLE_XPDF_HEADERS)
poppler/PDFDoc.h
poppler/PDFDocBuilder.h
poppler/PDFDocEncoding.h
+ poppler/PDFDocFactory.h
poppler/PopplerCache.h
poppler/ProfileData.h
poppler/PreScanOutputDev.h
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index 6717734..5dd8082 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -223,6 +223,7 @@ poppler_include_HEADERS = \
PDFDoc.h \
PDFDocBuilder.h \
PDFDocEncoding.h \
+ PDFDocFactory.h \
PopplerCache.h \
ProfileData.h \
PreScanOutputDev.h \
@@ -299,6 +300,7 @@ libpoppler_la_SOURCES = \
Parser.cc \
PDFDoc.cc \
PDFDocEncoding.cc \
+ PDFDocFactory.cc \
PopplerCache.cc \
ProfileData.cc \
PreScanOutputDev.cc \
diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc
new file mode 100644
index 0000000..d8b5fcc
--- /dev/null
+++ b/poppler/PDFDocFactory.cc
@@ -0,0 +1,71 @@
+//========================================================================
+//
+// PDFDocFactory.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "PDFDocFactory.h"
+
+#include "goo/GooList.h"
+#include "goo/GooString.h"
+#include "PDFDoc.h"
+#include "LocalPDFDocBuilder.h"
+#include "StdinPDFDocBuilder.h"
+#if ENABLE_LIBCURL
+#include "CurlPDFDocBuilder.h"
+#endif
+#include "ErrorCodes.h"
+
+//------------------------------------------------------------------------
+// PDFDocFactory
+//------------------------------------------------------------------------
+
+PDFDocFactory::PDFDocFactory(GooList *pdfDocBuilders)
+{
+ if (pdfDocBuilders) {
+ builders = pdfDocBuilders;
+ } else {
+ builders = new GooList();
+ }
+#if ENABLE_LIBCURL
+ builders->insert(0, new CurlPDFDocBuilder());
+#endif
+ builders->insert(0, new StdinPDFDocBuilder());
+ builders->insert(0, new LocalPDFDocBuilder());
+}
+
+PDFDocFactory::~PDFDocFactory()
+{
+ if (builders) {
+ deleteGooList(builders, PDFDocBuilder);
+ }
+}
+
+PDFDoc *
+PDFDocFactory::createPDFDoc(GooString* uri, GooString *ownerPassword,
+ GooString *userPassword, void *guiDataA)
+{
+ for (int i = builders->getLength() - 1; i >= 0 ; i--) {
+ PDFDocBuilder *builder = (PDFDocBuilder *) builders->get(i);
+ if (builder->supports(uri)) {
+ return builder->buildPDFDoc(uri, ownerPassword, userPassword, guiDataA);
+ }
+ }
+
+ error(-1, "Cannot handle URI '%s'.", uri->getCString());
+ GooString *fileName = new GooString(uri);
+ return PDFDoc::ErrorPDFDoc(errOpenFile, fileName);
+}
+
+void PDFDocFactory::registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder)
+{
+ builders->append(pdfDocBuilder);
+}
+
+
diff --git a/poppler/PDFDocFactory.h b/poppler/PDFDocFactory.h
new file mode 100644
index 0000000..00ee359
--- /dev/null
+++ b/poppler/PDFDocFactory.h
@@ -0,0 +1,42 @@
+//========================================================================
+//
+// PDFDocFactory.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef PDFDOCFACTORY_H
+#define PDFDOCFACTORY_H
+
+#include "PDFDoc.h"
+
+class GooList;
+class GooString;
+class PDFDocBuilder;
+
+//------------------------------------------------------------------------
+// PDFDocFactory
+//------------------------------------------------------------------------
+
+class PDFDocFactory {
+
+public:
+
+ PDFDocFactory(GooList *pdfDocBuilders = NULL);
+ ~PDFDocFactory();
+
+ PDFDoc *createPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ GooString *userPassword = NULL, void *guiDataA = NULL);
+
+ void registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder);
+
+private:
+
+ GooList *builders;
+
+};
+
+#endif /* PDFDOCFACTORY_H */
commit 869135920831fb0d15db734f3dcd7a67146cc241
Author: Hib Eris <hib at hiberis.nl>
Date: Wed Feb 24 15:24:26 2010 +0100
Add CurlPDFDocBuilder
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cc255a5..562f89c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -322,6 +322,7 @@ endif(ENABLE_ZLIB)
if(ENABLE_LIBCURL)
set(poppler_SRCS ${poppler_SRCS}
poppler/CurlCachedFile.cc
+ poppler/CurlPDFDocBuilder.cc
)
set(poppler_LIBS ${poppler_LIBS} ${CURL_LIBRARIES})
endif(ENABLE_LIBCURL)
@@ -462,6 +463,7 @@ if(ENABLE_XPDF_HEADERS)
if(ENABLE_LIBCURL)
install(FILES
poppler/CurlCachedFile.h
+ poppler/CurlPDFDocBuilder.h
DESTINATION include/poppler)
endif(ENABLE_LIBCURL)
if(LIBOPENJPEG_FOUND)
diff --git a/poppler/CurlPDFDocBuilder.cc b/poppler/CurlPDFDocBuilder.cc
new file mode 100644
index 0000000..251a4eb
--- /dev/null
+++ b/poppler/CurlPDFDocBuilder.cc
@@ -0,0 +1,46 @@
+//========================================================================
+//
+// CurlPDFDocBuilder.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "CurlPDFDocBuilder.h"
+
+#include "CachedFile.h"
+#include "CurlCachedFile.h"
+
+//------------------------------------------------------------------------
+// CurlPDFDocBuilder
+//------------------------------------------------------------------------
+
+PDFDoc *
+CurlPDFDocBuilder::buildPDFDoc(GooString* uri,
+ GooString *ownerPassword, GooString *userPassword, void *guiDataA)
+{
+ Object obj;
+
+ CachedFile *cachedFile = new CachedFile(
+ new CurlCachedFileLoader(), new GooString(uri));
+
+ obj.initNull();
+ BaseStream *str = new CachedFileStream(
+ cachedFile, 0, gFalse, cachedFile->getLength(), &obj);
+
+ return new PDFDoc(str, ownerPassword, userPassword, guiDataA);
+}
+
+GBool CurlPDFDocBuilder::supports(GooString* uri)
+{
+ if (uri->cmpN("http://", 7) == 0 || uri->cmpN("https://", 8) == 0) {
+ return gTrue;
+ } else {
+ return gFalse;
+ }
+};
+
diff --git a/poppler/CurlPDFDocBuilder.h b/poppler/CurlPDFDocBuilder.h
new file mode 100644
index 0000000..e84a4c7
--- /dev/null
+++ b/poppler/CurlPDFDocBuilder.h
@@ -0,0 +1,30 @@
+//========================================================================
+//
+// CurlPDFDocBuilder.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef CURLPDFDOCBUILDER_H
+#define CURLPDFDOCBUILDER_H
+
+#include "PDFDocBuilder.h"
+
+//------------------------------------------------------------------------
+// CurlPDFDocBuilder
+//------------------------------------------------------------------------
+
+class CurlPDFDocBuilder : public PDFDocBuilder {
+
+public:
+
+ PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ GooString *userPassword = NULL, void *guiDataA = NULL);
+ GBool supports(GooString* uri);
+
+};
+
+#endif /* CURLPDFDOCBUILDER_H */
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index 3eb84fd..6717734 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -111,10 +111,12 @@ libcurl_includes = \
$(LIBCURL_CFLAGS)
curl_headers = \
- CurlCachedFile.h
+ CurlCachedFile.h \
+ CurlPDFDocBuilder.h
curl_sources = \
- CurlCachedFile.cc
+ CurlCachedFile.cc \
+ CurlPDFDocBuilder.cc
endif
commit ec5c6117a64f9cb03560091c4d7948d4287b6975
Author: Hib Eris <hib at hiberis.nl>
Date: Thu Feb 25 11:23:28 2010 +0100
Add LocalPDFDocBuilder and StdinPDFDocBuilder
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3245730..cc255a5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -249,6 +249,7 @@ set(poppler_SRCS
poppler/JBIG2Stream.cc
poppler/Lexer.cc
poppler/Link.cc
+ poppler/LocalPDFDocBuilder.cc
poppler/NameToCharCode.cc
poppler/Object.cc
poppler/OptionalContent.cc
@@ -272,6 +273,7 @@ set(poppler_SRCS
poppler/PageLabelInfo.cc
poppler/SecurityHandler.cc
poppler/StdinCachedFile.cc
+ poppler/StdinPDFDocBuilder.cc
poppler/Sound.cc
poppler/XpdfPluginAPI.cc
poppler/Movie.cc
@@ -390,6 +392,7 @@ if(ENABLE_XPDF_HEADERS)
poppler/JBIG2Stream.h
poppler/Lexer.h
poppler/Link.h
+ poppler/LocalPDFDocBuilder.h
poppler/Movie.h
poppler/NameToCharCode.h
poppler/Object.h
@@ -424,6 +427,7 @@ if(ENABLE_XPDF_HEADERS)
poppler/TextOutputDev.h
poppler/SecurityHandler.h
poppler/StdinCachedFile.h
+ poppler/StdinPDFDocBuilder.h
poppler/UTF8.h
poppler/XpdfPluginAPI.h
poppler/Sound.h
diff --git a/poppler/LocalPDFDocBuilder.cc b/poppler/LocalPDFDocBuilder.cc
new file mode 100644
index 0000000..c54faac
--- /dev/null
+++ b/poppler/LocalPDFDocBuilder.cc
@@ -0,0 +1,45 @@
+//========================================================================
+//
+// LocalPDFDocBuilder.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "LocalPDFDocBuilder.h"
+
+//------------------------------------------------------------------------
+// LocalPDFDocBuilder
+//------------------------------------------------------------------------
+
+PDFDoc *
+LocalPDFDocBuilder::buildPDFDoc(
+ GooString* uri, GooString *ownerPassword, GooString
+ *userPassword, void *guiDataA)
+{
+ if (uri->cmpN("file://", 7) == 0) {
+ GooString *fileName = new GooString(uri);
+ fileName->del(0, 7);
+ return new PDFDoc(fileName, ownerPassword, userPassword, guiDataA);
+ } else {
+ GooString *fileName = new GooString(uri);
+ return new PDFDoc(fileName, ownerPassword, userPassword, guiDataA);
+ }
+}
+
+GBool LocalPDFDocBuilder::supports(GooString* uri)
+{
+ if (uri->cmpN("file://", 7) == 0) {
+ return gTrue;
+ } else if (!strstr(uri->getCString(), "://")) {
+ return gTrue;
+ } else {
+ return gFalse;
+ }
+}
+
+
diff --git a/poppler/LocalPDFDocBuilder.h b/poppler/LocalPDFDocBuilder.h
new file mode 100644
index 0000000..439a131
--- /dev/null
+++ b/poppler/LocalPDFDocBuilder.h
@@ -0,0 +1,30 @@
+//========================================================================
+//
+// LocalPDFDocBuilder.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef LOCALPDFDOCBUILDER_H
+#define LOCALPDFDOCBUILDER_H
+
+#include "PDFDocBuilder.h"
+
+//------------------------------------------------------------------------
+// LocalPDFDocBuilder
+//------------------------------------------------------------------------
+
+class LocalPDFDocBuilder : public PDFDocBuilder {
+
+public:
+
+ PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ GooString *userPassword = NULL, void *guiDataA = NULL);
+ GBool supports(GooString* uri);
+
+};
+
+#endif /* LOCALPDFDOCBUILDER_H */
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index a013460..3eb84fd 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -208,6 +208,7 @@ poppler_include_HEADERS = \
JBIG2Stream.h \
Lexer.h \
Link.h \
+ LocalPDFDocBuilder.h \
Movie.h \
NameToCharCode.h \
Object.h \
@@ -226,6 +227,7 @@ poppler_include_HEADERS = \
PSTokenizer.h \
Rendition.h \
StdinCachedFile.h \
+ StdinPDFDocBuilder.h \
Stream-CCITT.h \
Stream.h \
UnicodeMap.h \
@@ -283,6 +285,7 @@ libpoppler_la_SOURCES = \
JBIG2Stream.cc \
Lexer.cc \
Link.cc \
+ LocalPDFDocBuilder.cc \
Movie.cc \
NameToCharCode.cc \
Object.cc \
@@ -300,6 +303,7 @@ libpoppler_la_SOURCES = \
PSTokenizer.cc \
Rendition.cc \
StdinCachedFile.cc \
+ StdinPDFDocBuilder.cc \
Stream.cc \
UnicodeMap.cc \
UnicodeTypeTable.cc \
diff --git a/poppler/StdinPDFDocBuilder.cc b/poppler/StdinPDFDocBuilder.cc
new file mode 100644
index 0000000..e260615
--- /dev/null
+++ b/poppler/StdinPDFDocBuilder.cc
@@ -0,0 +1,42 @@
+//========================================================================
+//
+// StdinPDFDocBuilder.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "StdinPDFDocBuilder.h"
+#include "CachedFile.h"
+#include "StdinCachedFile.h"
+
+//------------------------------------------------------------------------
+// StdinPDFDocBuilder
+//------------------------------------------------------------------------
+
+PDFDoc *
+StdinPDFDocBuilder::buildPDFDoc(GooString* uri, GooString *ownerPassword,
+ GooString *userPassword, void *guiDataA)
+{
+ Object obj;
+
+ obj.initNull();
+ CachedFile *cachedFile = new CachedFile(new StdinCacheLoader(), NULL);
+ return new PDFDoc(new CachedFileStream(cachedFile, 0, gFalse,
+ cachedFile->getLength(), &obj),
+ ownerPassword, userPassword);
+}
+
+GBool StdinPDFDocBuilder::supports(GooString* uri)
+{
+ if (uri->cmpN("fd://0", 6) == 0) {
+ return gTrue;
+ } else {
+ return gFalse;
+ }
+}
+
diff --git a/poppler/StdinPDFDocBuilder.h b/poppler/StdinPDFDocBuilder.h
new file mode 100644
index 0000000..fae32c0
--- /dev/null
+++ b/poppler/StdinPDFDocBuilder.h
@@ -0,0 +1,30 @@
+//========================================================================
+//
+// StdinPDFDocBuilder.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef STDINPDFDOCBUILDER_H
+#define STDINPDFDOCBUILDER_H
+
+#include "PDFDocBuilder.h"
+
+//------------------------------------------------------------------------
+// StdinPDFDocBuilder
+//------------------------------------------------------------------------
+
+class StdinPDFDocBuilder : public PDFDocBuilder {
+
+public:
+
+ PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ GooString *userPassword = NULL, void *guiDataA = NULL);
+ GBool supports(GooString* uri);
+
+};
+
+#endif /* STDINPDFDOCBUILDER_H */
commit 919b735d1c0b99bf72280aff8db87ba503954498
Author: Hib Eris <hib at hiberis.nl>
Date: Sun Apr 4 11:05:35 2010 +0200
Add PDFDocBuilder
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70b0e06..3245730 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -400,6 +400,7 @@ if(ENABLE_XPDF_HEADERS)
poppler/PageTransition.h
poppler/Parser.h
poppler/PDFDoc.h
+ poppler/PDFDocBuilder.h
poppler/PDFDocEncoding.h
poppler/PopplerCache.h
poppler/ProfileData.h
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index 5cd68a4..a013460 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -218,6 +218,7 @@ poppler_include_HEADERS = \
PageTransition.h \
Parser.h \
PDFDoc.h \
+ PDFDocBuilder.h \
PDFDocEncoding.h \
PopplerCache.h \
ProfileData.h \
diff --git a/poppler/PDFDocBuilder.h b/poppler/PDFDocBuilder.h
new file mode 100644
index 0000000..8a1350b
--- /dev/null
+++ b/poppler/PDFDocBuilder.h
@@ -0,0 +1,32 @@
+//========================================================================
+//
+// PDFDocBuilder.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef PDFDOCBUILDER_H
+#define PDFDOCBUILDER_H
+
+#include "PDFDoc.h"
+class GooString;
+
+//------------------------------------------------------------------------
+// PDFDocBuilder
+//------------------------------------------------------------------------
+
+class PDFDocBuilder {
+
+public:
+
+ virtual ~PDFDocBuilder() {};
+ virtual PDFDoc *buildPDFDoc(GooString* uri, GooString *ownerPassword = NULL,
+ GooString *userPassword = NULL, void *guiDataA = NULL) = 0;
+ virtual GBool supports(GooString* uri) = 0;
+
+};
+
+#endif /* PDFDOCBUILDER_H */
commit 1ab07faf05661d6d92186974c4b1c279b6178747
Author: Hib Eris <hib at hiberis.nl>
Date: Sun Apr 4 11:29:53 2010 +0200
Add PDFDoc::ErrorPDFDoc
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 12aff3c..78b6593 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -88,6 +88,11 @@ void PDFDoc::init()
#endif
}
+PDFDoc::PDFDoc()
+{
+ init();
+}
+
PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
GooString *userPassword, void *guiDataA) {
Object obj;
@@ -902,3 +907,12 @@ void PDFDoc::writeTrailer (Guint uxrefOffset, int uxrefSize, OutStream* outStr,
delete trailerDict;
}
+
+PDFDoc *PDFDoc::ErrorPDFDoc(int errorCode, GooString *fileNameA)
+{
+ PDFDoc *doc = new PDFDoc();
+ doc->errCode = errorCode;
+ doc->fileName = fileNameA;
+
+ return doc;
+}
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 08e9da8..79f6d6d 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -74,6 +74,8 @@ public:
GooString *userPassword = NULL, void *guiDataA = NULL);
~PDFDoc();
+ static PDFDoc *ErrorPDFDoc(int errorCode, GooString *fileNameA = NULL);
+
// Was PDF document successfully opened?
GBool isOk() { return ok; }
@@ -227,6 +229,7 @@ private:
void saveIncrementalUpdate (OutStream* outStr);
void saveCompleteRewrite (OutStream* outStr);
+ PDFDoc();
void init();
GBool setup(GooString *ownerPassword, GooString *userPassword);
GBool checkFooter();
commit efc7e5efeddd8f70b7c74573d3194aba0a7d4631
Author: Hib Eris <hib at hiberis.nl>
Date: Sun Apr 4 11:17:37 2010 +0200
Cleanup PDFDoc
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index b088f6c..12aff3c 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -21,6 +21,7 @@
// Copyright (C) 2009 Eric Toombs <ewtoombs at uwaterloo.ca>
// Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
// Copyright (C) 2009 Axel Struebing <axel.struebing at freenet.de>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -73,15 +74,11 @@
// PDFDoc
//------------------------------------------------------------------------
-PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
- GooString *userPassword, void *guiDataA) {
- Object obj;
-
+void PDFDoc::init()
+{
ok = gFalse;
errCode = errNone;
-
- guiData = guiDataA;
-
+ fileName = NULL;
file = NULL;
str = NULL;
xref = NULL;
@@ -89,8 +86,16 @@ PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
#ifndef DISABLE_OUTLINE
outline = NULL;
#endif
+}
+
+PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
+ GooString *userPassword, void *guiDataA) {
+ Object obj;
+
+ init();
fileName = fileNameA;
+ guiData = guiDataA;
// try to open file
#ifdef VMS
@@ -124,19 +129,10 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword,
Object obj;
int i;
- ok = gFalse;
- errCode = errNone;
+ init();
guiData = guiDataA;
- file = NULL;
- str = NULL;
- xref = NULL;
- catalog = NULL;
-#ifndef DISABLE_OUTLINE
- outline = NULL;
-#endif
-
//~ file name should be stored in Unicode (?)
fileName = new GooString();
for (i = 0; i < fileNameLen; ++i) {
@@ -174,21 +170,15 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword,
PDFDoc::PDFDoc(BaseStream *strA, GooString *ownerPassword,
GooString *userPassword, void *guiDataA) {
- ok = gFalse;
- errCode = errNone;
+
+ init();
guiData = guiDataA;
if (strA->getFileName()) {
fileName = strA->getFileName()->copy();
} else {
fileName = NULL;
}
- file = NULL;
str = strA;
- xref = NULL;
- catalog = NULL;
-#ifndef DISABLE_OUTLINE
- outline = NULL;
-#endif
ok = setup(ownerPassword, userPassword);
}
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 3db4b91..08e9da8 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -20,6 +20,7 @@
// Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
// Copyright (C) 2009 Eric Toombs <ewtoombs at uwaterloo.ca>
// Copyright (C) 2009 Kovid Goyal <kovid at kovidgoyal.net>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -226,7 +227,7 @@ private:
void saveIncrementalUpdate (OutStream* outStr);
void saveCompleteRewrite (OutStream* outStr);
-
+ void init();
GBool setup(GooString *ownerPassword, GooString *userPassword);
GBool checkFooter();
void checkHeader();
commit 08a3435e67ebf21beac2fefcbd21ad65f9293fd1
Author: Hib Eris <hib at hiberis.nl>
Date: Tue Feb 23 02:29:26 2010 +0100
Add HTTP support using libcurl
With libcurl, poppler can handle documents over http.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7922dad..70b0e06 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,7 @@ option(ENABLE_CPP "Compile poppler cpp wrapper." ON)
option(ENABLE_ABIWORD "Build the Abiword backend." ON)
option(ENABLE_LIBOPENJPEG "Use libopenjpeg for JPX streams." ON)
option(ENABLE_LCMS "Use liblcms for color management." ON)
+option(ENABLE_LIBCURL "Build libcurl based HTTP support." OFF)
option(ENABLE_ZLIB "Build with zlib (not totally safe)." OFF)
option(USE_EXCEPTIONS "Throw exceptions to deal with not enough memory and similar problems." OFF)
option(USE_FIXEDPOINT "Use fixed point arithmetic in the Splash backend" OFF)
@@ -132,6 +133,11 @@ if(ENABLE_LCMS)
find_package(LCMS)
set(USE_CMS ${LCMS_FOUND})
endif(ENABLE_LCMS)
+if(ENABLE_LIBCURL)
+ find_package(CURL)
+ include_directories(${CURL_INCLUDE_DIR})
+ set(POPPLER_HAS_CURL_SUPPORT ON)
+endif(ENABLE_LIBCURL)
add_definitions(-DHAVE_CONFIG_H=1)
if(FONTCONFIG_FOUND)
@@ -311,6 +317,12 @@ if(ENABLE_ZLIB)
)
set(poppler_LIBS ${poppler_LIBS} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB)
+if(ENABLE_LIBCURL)
+ set(poppler_SRCS ${poppler_SRCS}
+ poppler/CurlCachedFile.cc
+ )
+ set(poppler_LIBS ${poppler_LIBS} ${CURL_LIBRARIES})
+endif(ENABLE_LIBCURL)
if(LIBOPENJPEG_FOUND)
set(poppler_SRCS ${poppler_SRCS}
poppler/JPEG2000Stream.cc
@@ -442,6 +454,11 @@ if(ENABLE_XPDF_HEADERS)
fofi/FoFiType1.h
fofi/FoFiType1C.h
DESTINATION include/poppler/fofi)
+ if(ENABLE_LIBCURL)
+ install(FILES
+ poppler/CurlCachedFile.h
+ DESTINATION include/poppler)
+ endif(ENABLE_LIBCURL)
if(LIBOPENJPEG_FOUND)
install(FILES
poppler/JPEG2000Stream.h
@@ -552,6 +569,7 @@ show_end_message("use gtk-doc" "not supported with this CMake build system")
show_end_message_yesno("use libjpeg" ENABLE_LIBJPEG)
show_end_message_yesno("use libpng" ENABLE_LIBPNG)
show_end_message_yesno("use zlib" ENABLE_ZLIB)
+show_end_message_yesno("use curl" ENABLE_LIBCURL)
show_end_message_yesno("use libopenjpeg" LIBOPENJPEG_FOUND)
show_end_message_yesno("use cms" USE_CMS)
show_end_message_yesno("command line utils" ENABLE_UTILS)
diff --git a/config.h.cmake b/config.h.cmake
index 70d8d5d..0879aeb 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -1,5 +1,8 @@
/* config.h. Generated from config.h.cmake by cmake. */
+/* Build against libcurl. */
+#cmakedefine ENABLE_LIBCURL 1
+
/* Use libjpeg instead of builtin jpeg decoder. */
#cmakedefine ENABLE_LIBJPEG 1
@@ -153,6 +156,9 @@
/* Poppler data dir */
#define POPPLER_DATADIR "${CMAKE_INSTALL_PREFIX}/share/poppler"
+/* Support for curl based doc builder is compiled in. */
+#cmakedefine POPPLER_HAS_CURL_SUPPORT 1
+
/* Have GDK */
#cmakedefine POPPLER_WITH_GDK 1
diff --git a/configure.ac b/configure.ac
index 68509ee..72041d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -210,6 +210,21 @@ AM_CONDITIONAL(BUILD_ZLIB, test x$enable_zlib = xyes)
AH_TEMPLATE([ENABLE_ZLIB],
[Use zlib instead of builtin zlib decoder.])
+dnl Test for libcurl
+AC_ARG_ENABLE(libcurl,
+ AC_HELP_STRING([--enable-libcurl],
+ [Build with libcurl based HTTP support.]),
+ enable_libcurl=$enableval,
+ enable_libcurl="no")
+
+if test x$enable_libcurl = xyes; then
+ PKG_CHECK_MODULES(LIBCURL, libcurl)
+ AC_DEFINE(ENABLE_LIBCURL, 1, [Build against libcurl.])
+ AC_DEFINE(POPPLER_HAS_CURL_SUPPORT, 1,
+ [Support for curl based doc builder is compiled in.])
+fi
+
+AM_CONDITIONAL(BUILD_LIBCURL, test x$enable_libcurl = xyes)
dnl Test for libjpeg
AC_ARG_ENABLE(libjpeg,
@@ -651,6 +666,7 @@ echo " use gtk-doc: $enable_gtk_doc"
echo " use libjpeg: $enable_libjpeg"
echo " use libpng: $enable_libpng"
echo " use zlib: $enable_zlib"
+echo " use libcurl: $enable_libcurl"
echo " use libopenjpeg: $enable_libopenjpeg"
echo " use cms: $enable_cms"
echo " command line utils: $enable_utils"
diff --git a/poppler/CurlCachedFile.cc b/poppler/CurlCachedFile.cc
new file mode 100644
index 0000000..b326fb7
--- /dev/null
+++ b/poppler/CurlCachedFile.cc
@@ -0,0 +1,95 @@
+//========================================================================
+//
+// CurlCachedFile.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2009 Stefan Thomas <thomas at eload24.com>
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "CurlCachedFile.h"
+
+#include "goo/GooString.h"
+#include "goo/GooVector.h"
+
+//------------------------------------------------------------------------
+
+CurlCachedFileLoader::CurlCachedFileLoader()
+{
+ url = NULL;
+ cachedFile = NULL;
+ curl = NULL;
+}
+
+CurlCachedFileLoader::~CurlCachedFileLoader() {
+ curl_easy_cleanup(curl);
+}
+
+static size_t
+noop_cb(char *ptr, size_t size, size_t nmemb, void *ptr2)
+{
+ return size*nmemb;
+}
+
+size_t
+CurlCachedFileLoader::init(GooString *urlA, CachedFile *cachedFileA)
+{
+ long code = NULL;
+ double contentLength = -1;
+ size_t size;
+
+ url = urlA;
+ cachedFile = cachedFileA;
+ curl = curl_easy_init();
+
+ curl_easy_setopt(curl, CURLOPT_URL, url->getCString());
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1);
+ curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &noop_cb);
+ curl_easy_perform(curl);
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
+ curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength);
+ curl_easy_reset(curl);
+
+ size = contentLength;
+
+ return size;
+}
+
+static
+size_t load_cb(const char *ptr, size_t size, size_t nmemb, void *data)
+{
+ CachedFileWriter *writer = (CachedFileWriter *) data;
+ return (writer->write) (ptr, size*nmemb);
+}
+
+int CurlCachedFileLoader::load(GooVector<ByteRange> *ranges, CachedFileWriter *writer)
+{
+ CURLcode r = CURLE_OK;
+ size_t fromByte, toByte;
+ for (size_t i = 0; i < (*ranges).size(); i++) {
+
+ fromByte = (*ranges)[i].offset;
+ toByte = fromByte + (*ranges)[i].length - 1;
+ GooString *range = GooString::format("{0:ud}-{1:ud}", fromByte, toByte);
+
+ curl_easy_setopt(curl, CURLOPT_URL, url->getCString());
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, load_cb);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, writer);
+ curl_easy_setopt(curl, CURLOPT_RANGE, range->getCString());
+ r = curl_easy_perform(curl);
+ curl_easy_reset(curl);
+
+ delete range;
+
+ if (r != CURLE_OK) break;
+ }
+ return r;
+}
+
+//------------------------------------------------------------------------
+
diff --git a/poppler/CurlCachedFile.h b/poppler/CurlCachedFile.h
new file mode 100644
index 0000000..b18b7f8
--- /dev/null
+++ b/poppler/CurlCachedFile.h
@@ -0,0 +1,39 @@
+//========================================================================
+//
+// CurlCachedFile.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef CURLCACHELOADER_H
+#define CURLCACHELOADER_H
+
+#include "poppler-config.h"
+#include "CachedFile.h"
+
+#include <curl/curl.h>
+
+//------------------------------------------------------------------------
+
+class CurlCachedFileLoader : public CachedFileLoader {
+
+public:
+
+ CurlCachedFileLoader();
+ ~CurlCachedFileLoader();
+ size_t init(GooString *url, CachedFile* cachedFile);
+ int load(GooVector<ByteRange> *ranges, CachedFileWriter *writer);
+
+private:
+
+ GooString *url;
+ CachedFile *cachedFile;
+ CURL *curl;
+
+};
+
+#endif
+
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index a6bb9e9..5cd68a4 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -102,6 +102,22 @@ zlib_libs = \
endif
+if BUILD_LIBCURL
+
+libcurl_libs = \
+ $(LIBCURL_LIBS)
+
+libcurl_includes = \
+ $(LIBCURL_CFLAGS)
+
+curl_headers = \
+ CurlCachedFile.h
+
+curl_sources = \
+ CurlCachedFile.cc
+
+endif
+
if BUILD_ABIWORD_OUTPUT
abiword_sources = \
@@ -130,6 +146,7 @@ INCLUDES = \
$(arthur_includes) \
$(abiword_includes) \
$(libpng_includes) \
+ $(libcurl_includes) \
$(FREETYPE_CFLAGS) \
$(FONTCONFIG_CFLAGS)
@@ -149,6 +166,7 @@ libpoppler_la_LIBADD = \
$(libjpeg_libs) \
$(libpng_libs) \
$(zlib_libs) \
+ $(libcurl_libs) \
$(libjpeg2000_libs) \
$(abiword_libs) \
$(FREETYPE_LIBS) \
@@ -163,6 +181,7 @@ if ENABLE_XPDF_HEADERS
poppler_includedir = $(includedir)/poppler
poppler_include_HEADERS = \
$(splash_headers) \
+ $(curl_headers) \
Annot.h \
Array.h \
BuiltinFont.h \
@@ -237,6 +256,7 @@ libpoppler_la_SOURCES = \
$(zlib_sources) \
$(libjpeg2000_sources) \
$(abiword_sources) \
+ $(curl_sources) \
Annot.cc \
Array.cc \
BuiltinFont.cc \
diff --git a/poppler/poppler-config.h.cmake b/poppler/poppler-config.h.cmake
index 7656e4f..95e95cc 100644
--- a/poppler/poppler-config.h.cmake
+++ b/poppler/poppler-config.h.cmake
@@ -49,6 +49,11 @@
#cmakedefine WITH_FONTCONFIGURATION_WIN32 1
#endif
+/* Support for curl is compiled in. */
+#ifndef POPPLER_HAS_CURL_SUPPORT
+#cmakedefine POPPLER_HAS_CURL_SUPPORT 1
+#endif
+
// Also, there's a couple of preprocessor symbols in the header files
// that are used but never defined: DISABLE_OUTLINE, DEBUG_MEM and
diff --git a/poppler/poppler-config.h.in b/poppler/poppler-config.h.in
index f8db4ba..7b0644c 100644
--- a/poppler/poppler-config.h.in
+++ b/poppler/poppler-config.h.in
@@ -49,6 +49,11 @@
#undef WITH_FONTCONFIGURATION_WIN32
#endif
+/* Support for curl is compiled in. */
+#ifndef POPPLER_HAS_CURL_SUPPORT
+#undef POPPLER_HAS_CURL_SUPPORT
+#endif
+
// Also, there's a couple of preprocessor symbols in the header files
// that are used but never defined: DISABLE_OUTLINE, DEBUG_MEM and
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index ceddd47..48504d2 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -49,6 +49,9 @@
#include "Error.h"
#include "DateInfo.h"
#include "StdinCachedFile.h"
+#if ENABLE_LIBCURL
+#include "CurlCachedFile.h"
+#endif
static void printInfoString(Dict *infoDict, char *key, char *text,
UnicodeMap *uMap);
@@ -160,7 +163,18 @@ int main(int argc, char *argv[]) {
userPW = NULL;
}
- if(fileName->cmp("-") != 0) {
+#if ENABLE_LIBCURL
+ if (fileName->cmpN("http://", 7) == 0 ||
+ fileName->cmpN("https://", 8) == 0) {
+ Object obj;
+
+ obj.initNull();
+ CachedFile *cachedFile = new CachedFile(new CurlCachedFileLoader(), fileName);
+ doc = new PDFDoc(new CachedFileStream(cachedFile, 0, gFalse, 0, &obj),
+ ownerPW, userPW);
+ } else
+#endif
+ if (fileName->cmp("-") != 0) {
doc = new PDFDoc(fileName, ownerPW, userPW);
} else {
Object obj;
commit a87abf6ad9fb66d35a70c9412adc5d8ba2889b96
Author: Hib Eris <hib at hiberis.nl>
Date: Wed Feb 24 14:46:59 2010 +0100
Use cached files to read from stdin in pdfinfo
This fixes reading from stdin.
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index bfbe0b3..ceddd47 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -15,6 +15,7 @@
//
// Copyright (C) 2006 Dom Lachowicz <cinamod at hotmail.com>
// Copyright (C) 2007-2009 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -47,6 +48,7 @@
#include "PDFDocEncoding.h"
#include "Error.h"
#include "DateInfo.h"
+#include "StdinCachedFile.h"
static void printInfoString(Dict *infoDict, char *key, char *text,
UnicodeMap *uMap);
@@ -164,7 +166,9 @@ int main(int argc, char *argv[]) {
Object obj;
obj.initNull();
- doc = new PDFDoc(new FileStream(stdin, 0, gFalse, 0, &obj), ownerPW, userPW);
+ CachedFile *cachedFile = new CachedFile(new StdinCacheLoader(), NULL);
+ doc = new PDFDoc(new CachedFileStream(cachedFile, 0, gFalse, 0, &obj),
+ ownerPW, userPW);
}
if (userPW) {
commit 958b04b14baf03c07492fa1cbd225d9968b9efc1
Author: Hib Eris <hib at hiberis.nl>
Date: Tue Feb 23 02:02:10 2010 +0100
Add support for reading a cached file from stdin
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5e6988..7922dad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -265,6 +265,7 @@ set(poppler_SRCS
poppler/TextOutputDev.cc
poppler/PageLabelInfo.cc
poppler/SecurityHandler.cc
+ poppler/StdinCachedFile.cc
poppler/Sound.cc
poppler/XpdfPluginAPI.cc
poppler/Movie.cc
@@ -409,6 +410,7 @@ if(ENABLE_XPDF_HEADERS)
poppler/PSOutputDev.h
poppler/TextOutputDev.h
poppler/SecurityHandler.h
+ poppler/StdinCachedFile.h
poppler/UTF8.h
poppler/XpdfPluginAPI.h
poppler/Sound.h
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index f225110..a6bb9e9 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -205,6 +205,7 @@ poppler_include_HEADERS = \
PreScanOutputDev.h \
PSTokenizer.h \
Rendition.h \
+ StdinCachedFile.h \
Stream-CCITT.h \
Stream.h \
UnicodeMap.h \
@@ -277,6 +278,7 @@ libpoppler_la_SOURCES = \
PreScanOutputDev.cc \
PSTokenizer.cc \
Rendition.cc \
+ StdinCachedFile.cc \
Stream.cc \
UnicodeMap.cc \
UnicodeTypeTable.cc \
diff --git a/poppler/StdinCachedFile.cc b/poppler/StdinCachedFile.cc
new file mode 100644
index 0000000..9b32136
--- /dev/null
+++ b/poppler/StdinCachedFile.cc
@@ -0,0 +1,37 @@
+//========================================================================
+//
+// StdinCachedFile.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+
+#include "StdinCachedFile.h"
+
+#include <stdio.h>
+
+size_t StdinCacheLoader::init(GooString *dummy, CachedFile *cachedFile)
+{
+ size_t read, size = 0;
+ char buf[CachedFileChunkSize];
+
+ CachedFileWriter writer = CachedFileWriter (cachedFile, NULL);
+ do {
+ read = fread(buf, 1, CachedFileChunkSize, stdin);
+ (writer.write) (buf, CachedFileChunkSize);
+ size += read;
+ }
+ while (read == CachedFileChunkSize);
+
+ return size;
+}
+
+int StdinCacheLoader::load(GooVector<ByteRange> *ranges, CachedFileWriter *writer)
+{
+ return 0;
+}
+
diff --git a/poppler/StdinCachedFile.h b/poppler/StdinCachedFile.h
new file mode 100644
index 0000000..9af086a
--- /dev/null
+++ b/poppler/StdinCachedFile.h
@@ -0,0 +1,26 @@
+//========================================================================
+//
+// StdinCachedFile.h
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef STDINCACHELOADER_H
+#define STDINCACHELOADER_H
+
+#include "CachedFile.h"
+
+class StdinCacheLoader : public CachedFileLoader {
+
+public:
+
+ size_t init(GooString *dummy, CachedFile* cachedFile);
+ int load(GooVector<ByteRange> *ranges, CachedFileWriter *writer);
+
+};
+
+#endif
+
commit 9539f75bd06150a3868209c5b04a75f5253722cc
Author: Hib Eris <hib at hiberis.nl>
Date: Sat Apr 3 15:08:20 2010 +0200
Add support for cached files
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8411441..b5e6988 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -222,6 +222,7 @@ set(poppler_SRCS
poppler/Array.cc
poppler/BuiltinFont.cc
poppler/BuiltinFontTables.cc
+ poppler/CachedFile.cc
poppler/Catalog.cc
poppler/CharCodeToUnicode.cc
poppler/CMap.cc
@@ -353,6 +354,7 @@ if(ENABLE_XPDF_HEADERS)
poppler/Array.h
poppler/BuiltinFont.h
poppler/BuiltinFontTables.h
+ poppler/CachedFile.h
poppler/Catalog.h
poppler/CharCodeToUnicode.h
poppler/CMap.h
diff --git a/poppler/CachedFile.cc b/poppler/CachedFile.cc
new file mode 100644
index 0000000..835079f
--- /dev/null
+++ b/poppler/CachedFile.cc
@@ -0,0 +1,246 @@
+//========================================================================
+//
+// CachedFile.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2009 Stefan Thomas <thomas at eload24.com>
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#include <config.h>
+#include "CachedFile.h"
+
+//------------------------------------------------------------------------
+// CachedFile
+//------------------------------------------------------------------------
+
+CachedFile::CachedFile(CachedFileLoader *cachedFileLoaderA, GooString *uriA)
+{
+ uri = uriA;
+ loader = cachedFileLoaderA;
+
+ streamPos = 0;
+ chunks = new GooVector<Chunk>();
+
+ length = loader->init(uri, this);
+ refCnt = 1;
+
+ chunks->resize(length/CachedFileChunkSize + 1);
+}
+
+CachedFile::~CachedFile()
+{
+ delete uri;
+ delete loader;
+ delete chunks;
+}
+
+void CachedFile::incRefCnt() {
+ refCnt++;
+}
+
+void CachedFile::decRefCnt() {
+ if (--refCnt == 0)
+ delete this;
+}
+
+long int CachedFile::tell() {
+ return streamPos;
+}
+
+int CachedFile::seek(long int offset, int origin)
+{
+ if (origin == SEEK_SET) {
+ streamPos = offset;
+ } else if (origin == SEEK_CUR) {
+ streamPos += offset;
+ } else {
+ streamPos = length + offset;
+ }
+
+ if (streamPos > length) {
+ streamPos = 0;
+ return 1;
+ }
+
+ return 0;
+}
+
+int CachedFile::cache(GooVector<ByteRange>* ranges)
+{
+ GooVector<int> loadChunks;
+ int numChunks = length/CachedFileChunkSize + 1;
+ char chunkNeeded[numChunks];
+ int startChunk, endChunk;
+ GooVector<ByteRange> chunk_ranges, all;
+ ByteRange range;
+
+ if (!ranges) {
+ ranges = &all;
+ range.offset = 0;
+ range.length = length;
+ ranges->push_back(range);
+ }
+
+ memset(&chunkNeeded, 0, numChunks);
+ for (size_t i = 0; i < ranges->size(); i++) {
+
+ if ((*ranges)[i].length == 0) continue;
+ if ((*ranges)[i].offset >= length) continue;
+
+ size_t start = (*ranges)[i].offset;
+ size_t end = start + (*ranges)[i].length - 1;
+ if (end >= length) end = length - 1;
+
+ startChunk = start / CachedFileChunkSize;
+ endChunk = end / CachedFileChunkSize;
+ for (int chunk = startChunk; chunk <= endChunk; chunk++) {
+ if ((*chunks)[chunk].state == chunkStateNew) {
+ chunkNeeded[chunk] = 1;
+ }
+ }
+ }
+
+ int chunk = 0;
+ while (chunk < numChunks) {
+ while (!chunkNeeded[chunk] && (++chunk != numChunks)) ;
+ if (chunk == numChunks) break;
+ startChunk = chunk;
+ loadChunks.push_back(chunk);
+
+ while ((++chunk != numChunks) && chunkNeeded[chunk]) {
+ loadChunks.push_back(chunk);
+ }
+ endChunk = chunk - 1;
+
+ range.offset = startChunk * CachedFileChunkSize;
+ range.length = (endChunk - startChunk + 1) * CachedFileChunkSize;
+
+ chunk_ranges.push_back(range);
+ }
+
+ if (chunk_ranges.size() > 0) {
+ CachedFileWriter writer =
+ CachedFileWriter(this, &loadChunks);
+ return loader->load(&chunk_ranges, &writer);
+ }
+
+ return 0;
+}
+
+size_t CachedFile::read(void *ptr, size_t unitsize, size_t count)
+{
+ size_t bytes = unitsize*count;
+ if (length < (streamPos + bytes)) {
+ bytes = length - streamPos;
+ }
+
+ if (bytes == 0) return 0;
+
+ // Load data
+ if (cache(streamPos, bytes) != 0) return 0;
+
+ // Copy data to buffer
+ size_t toCopy = bytes;
+ while (toCopy) {
+ int chunk = streamPos / CachedFileChunkSize;
+ int offset = streamPos % CachedFileChunkSize;
+ size_t len = CachedFileChunkSize-offset;
+
+ if (len > toCopy)
+ len = toCopy;
+
+ memcpy(ptr, (*chunks)[chunk].data + offset, len);
+ streamPos += len;
+ toCopy -= len;
+ ptr = (char*)ptr + len;
+ }
+
+ return bytes;
+}
+
+int CachedFile::cache(size_t offset, size_t length)
+{
+ GooVector<ByteRange> r;
+ ByteRange range;
+ range.offset = offset;
+ range.length = length;
+ r.push_back(range);
+ return cache(&r);
+}
+
+//------------------------------------------------------------------------
+// CachedFileWriter
+//------------------------------------------------------------------------
+
+CachedFileWriter::CachedFileWriter(CachedFile *cachedFileA, GooVector<int> *chunksA)
+{
+ cachedFile = cachedFileA;
+ chunks = chunksA;
+
+ if (chunks) {
+ offset = 0;
+ it = (*chunks).begin();
+ }
+}
+
+CachedFileWriter::~CachedFileWriter()
+{
+}
+
+size_t CachedFileWriter::write(const char *ptr, size_t size)
+{
+ const char *cp = ptr;
+ size_t len = size;
+ size_t nfree, ncopy;
+ size_t written = 0;
+ size_t chunk;
+
+ if (!len) return 0;
+
+ while (len) {
+ if (chunks) {
+ if (offset == CachedFileChunkSize) {
+ it++;
+ if (it == (*chunks).end()) return written;
+ offset = 0;
+ }
+ chunk = *it;
+ } else {
+ offset = cachedFile->length % CachedFileChunkSize;
+ chunk = cachedFile->length / CachedFileChunkSize;
+ }
+
+ if (chunk >= cachedFile->chunks->size()) {
+ cachedFile->chunks->resize(chunk + 1);
+ }
+
+ nfree = CachedFileChunkSize - offset;
+ ncopy = (len >= nfree) ? nfree : len;
+ memcpy(&((*cachedFile->chunks)[chunk].data[offset]), cp, ncopy);
+ len -= ncopy;
+ cp += ncopy;
+ offset += ncopy;
+ written += ncopy;
+
+ if (!chunks) {
+ cachedFile->length += ncopy;
+ }
+
+ if (offset == CachedFileChunkSize) {
+ (*cachedFile->chunks)[chunk].state = CachedFile::chunkStateLoaded;
+ }
+ }
+
+ if ((chunk == (cachedFile->length / CachedFileChunkSize)) &&
+ (offset == (cachedFile->length % CachedFileChunkSize))) {
+ (*cachedFile->chunks)[chunk].state = CachedFile::chunkStateLoaded;
+ }
+
+ return written;
+}
+
+//------------------------------------------------------------------------
+
diff --git a/poppler/CachedFile.h b/poppler/CachedFile.h
new file mode 100644
index 0000000..e004578
--- /dev/null
+++ b/poppler/CachedFile.h
@@ -0,0 +1,113 @@
+//========================================================================
+//
+// CachedFile.h
+//
+// Caching files support.
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright 2009 Stefan Thomas <thomas at eload24.com>
+// Copyright 2010 Hib Eris <hib at hiberis.nl>
+//
+//========================================================================
+
+#ifndef CACHEDFILE_H
+#define CACHEDFILE_H
+
+#include "poppler-config.h"
+
+#include "goo/gtypes.h"
+#include "Object.h"
+#include "Stream.h"
+#include "goo/GooVector.h"
+
+//------------------------------------------------------------------------
+
+#define CachedFileChunkSize 8192
+
+class GooString;
+class CachedFileLoader;
+
+//------------------------------------------------------------------------
+
+class CachedFile {
+
+friend class CachedFileWriter;
+
+public:
+
+ CachedFile(CachedFileLoader *cacheLoader, GooString *uri);
+ ~CachedFile();
+
+ Guint getLength() { return length; }
+ long int tell();
+ int seek(long int offset, int origin);
+ size_t read(void * ptr, size_t unitsize, size_t count);
+ size_t write(const char *ptr, size_t size, size_t fromByte);
+ int cache(GooVector<ByteRange>* ranges);
+
+ // Reference counting.
+ void incRefCnt();
+ void decRefCnt();
+
+private:
+
+ enum ChunkState {
+ chunkStateNew = 0,
+ chunkStateLoaded
+ };
+
+ typedef struct {
+ ChunkState state;
+ char data[CachedFileChunkSize];
+ } Chunk;
+
+ int cache(size_t offset, size_t length);
+
+ CachedFileLoader *loader;
+ GooString *uri;
+
+ size_t length;
+ size_t streamPos;
+
+ GooVector<Chunk> *chunks;
+
+ int refCnt; // reference count
+
+};
+
+//------------------------------------------------------------------------
+
+class CachedFileWriter {
+
+public:
+
+ CachedFileWriter(CachedFile *cachedFile, GooVector<int> *chunksA);
+ ~CachedFileWriter();
+
+ size_t write(const char *ptr, size_t size);
+
+private:
+
+ CachedFile *cachedFile;
+ GooVector<int> *chunks;
+ GooVector<int>::iterator it;
+ size_t offset;
+
+};
+
+//------------------------------------------------------------------------
+
+class CachedFileLoader {
+
+public:
+
+ virtual ~CachedFileLoader() {};
+ virtual size_t init(GooString *uri, CachedFile *cachedFile) = 0;
+ virtual int load(GooVector<ByteRange> *ranges, CachedFileWriter *writer) = 0;
+
+};
+
+//------------------------------------------------------------------------
+
+#endif
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index 3bcb922..f225110 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -167,6 +167,7 @@ poppler_include_HEADERS = \
Array.h \
BuiltinFont.h \
BuiltinFontTables.h \
+ CachedFile.h \
Catalog.h \
CharCodeToUnicode.h \
CMap.h \
@@ -239,6 +240,7 @@ libpoppler_la_SOURCES = \
Array.cc \
BuiltinFont.cc \
BuiltinFontTables.cc \
+ CachedFile.cc \
Catalog.cc \
CharCodeToUnicode.cc \
CMap.cc \
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 6634317..0771e25 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -19,6 +19,8 @@
// Copyright (C) 2008 Julien Rebetez <julien at fhtagn.net>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
// Copyright (C) 2009 Glenn Ganz <glenn.ganz at uptime.ch>
+// Copyright (C) 2009 Stefan Thomas <thomas at eload24.com>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -50,6 +52,7 @@
#include "Stream.h"
#include "JBIG2Stream.h"
#include "Stream-CCITT.h"
+#include "CachedFile.h"
#ifdef ENABLE_LIBJPEG
#include "DCTStream.h"
@@ -794,6 +797,105 @@ void FileStream::moveStart(int delta) {
}
//------------------------------------------------------------------------
+// CachedFileStream
+//------------------------------------------------------------------------
+
+CachedFileStream::CachedFileStream(CachedFile *ccA, Guint startA,
+ GBool limitedA, Guint lengthA, Object *dictA)
+ : BaseStream(dictA)
+{
+ cc = ccA;
+ start = startA;
+ limited = limitedA;
+ length = lengthA;
+ bufPtr = bufEnd = buf;
+ bufPos = start;
+ savePos = 0;
+ saved = gFalse;
+}
+
+CachedFileStream::~CachedFileStream()
+{
+ close();
+ cc->decRefCnt();
+}
+
+Stream *CachedFileStream::makeSubStream(Guint startA, GBool limitedA,
+ Guint lengthA, Object *dictA)
+{
+ cc->incRefCnt();
+ return new CachedFileStream(cc, startA, limitedA, lengthA, dictA);
+}
+
+void CachedFileStream::reset()
+{
+ savePos = (Guint)cc->tell();
+ cc->seek(start, SEEK_SET);
+
+ saved = gTrue;
+ bufPtr = bufEnd = buf;
+ bufPos = start;
+}
+
+void CachedFileStream::close()
+{
+ if (saved) {
+ cc->seek(savePos, SEEK_SET);
+ saved = gFalse;
+ }
+}
+
+GBool CachedFileStream::fillBuf()
+{
+ int n;
+
+ bufPos += bufEnd - buf;
+ bufPtr = bufEnd = buf;
+ if (limited && bufPos >= start + length) {
+ return gFalse;
+ }
+ if (limited && bufPos + cachedStreamBufSize > start + length) {
+ n = start + length - bufPos;
+ } else {
+ n = cachedStreamBufSize;
+ }
+ cc->read(buf, 1, n);
+ bufEnd = buf + n;
+ if (bufPtr >= bufEnd) {
+ return gFalse;
+ }
+ return gTrue;
+}
+
+void CachedFileStream::setPos(Guint pos, int dir)
+{
+ Guint size;
+
+ if (dir >= 0) {
+ cc->seek(pos, SEEK_SET);
+ bufPos = pos;
+ } else {
+ cc->seek(0, SEEK_END);
+ size = (Guint)cc->tell();
+
+ if (pos > size)
+ pos = (Guint)size;
+
+ cc->seek(-(int)pos, SEEK_END);
+ bufPos = (Guint)cc->tell();
+ }
+
+ bufPtr = bufEnd = buf;
+}
+
+void CachedFileStream::moveStart(int delta)
+{
+ start += delta;
+ bufPtr = bufEnd = buf;
+ bufPos = start;
+}
+
+//------------------------------------------------------------------------
// MemStream
//------------------------------------------------------------------------
diff --git a/poppler/Stream.h b/poppler/Stream.h
index 9c0068e..49ae8fb 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -17,6 +17,8 @@
// Copyright (C) 2008 Julien Rebetez <julien at fhtagn.net>
// Copyright (C) 2008 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
+// Copyright (C) 2009 Stefan Thomas <thomas at eload24.com>
+// Copyright (C) 2010 Hib Eris <hib at hiberis.nl>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -32,14 +34,17 @@
#include <stdio.h>
#include "goo/gtypes.h"
+#include "goo/GooVector.h"
#include "Object.h"
class BaseStream;
+class CachedFile;
//------------------------------------------------------------------------
enum StreamKind {
strFile,
+ strCachedFile,
strASCIIHex,
strASCII85,
strLZW,
@@ -69,6 +74,13 @@ enum CryptAlgorithm {
};
//------------------------------------------------------------------------
+
+typedef struct _ByteRange {
+ Guint offset;
+ Guint length;
+} ByteRange;
+
+//------------------------------------------------------------------------
// Stream (base class)
//------------------------------------------------------------------------
@@ -399,6 +411,52 @@ private:
};
//------------------------------------------------------------------------
+// CachedFileStream
+//------------------------------------------------------------------------
+
+#define cachedStreamBufSize 1024
+
+class CachedFileStream: public BaseStream {
+public:
+
+ CachedFileStream(CachedFile *ccA, Guint startA, GBool limitedA,
+ Guint lengthA, Object *dictA);
+ virtual ~CachedFileStream();
+ virtual Stream *makeSubStream(Guint startA, GBool limitedA,
+ Guint lengthA, Object *dictA);
+ virtual StreamKind getKind() { return strCachedFile; }
+ virtual void reset();
+ virtual void close();
+ virtual int getChar()
+ { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
+ virtual int lookChar()
+ { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
+ virtual int getPos() { return bufPos + (bufPtr - buf); }
+ virtual void setPos(Guint pos, int dir = 0);
+ virtual Guint getStart() { return start; }
+ virtual void moveStart(int delta);
+
+ virtual int getUnfilteredChar () { return getChar(); }
+ virtual void unfilteredReset () { reset(); }
+
+private:
+
+ GBool fillBuf();
+
+ CachedFile *cc;
+ Guint start;
+ GBool limited;
+ Guint length;
+ char buf[cachedStreamBufSize];
+ char *bufPtr;
+ char *bufEnd;
+ Guint bufPos;
+ int savePos;
+ GBool saved;
+};
+
+
+//------------------------------------------------------------------------
// MemStream
//------------------------------------------------------------------------
More information about the poppler
mailing list