[poppler] Cached files, reading stdin, http streams and PDFDocBuilder
Hib Eris
hib at hiberis.nl
Mon Apr 5 06:06:00 PDT 2010
Hi Albert and others,
I have rewritten my patches taking your comments into account. I have
attached the new patches.
I am currently working on support for linearized pdf files. This will
allow you to render any page from a pdf document without the need to
download the complete pdf. Expect more patches soon.
Cheers,
Hib
On Sat, Mar 27, 2010 at 4:20 PM, Albert Astals Cid <aacid at kde.org> wrote:
> A Dijous, 25 de febrer de 2010, Hib Eris va escriure:
>> Hi all,
>>
>> After some sleep, I noticed that my patches regarding the
>> PDFDocBuilders could be simplified. So here are all patches updated
>> with this new insight.
>>
>> Hib Eris
>
> Sorry it took too much, some comments:
> * We try not to use the C++ standard library (yeah idiotic decision, but we
> try to go on with it), do you really need <map> ?
> * Please move "enum CachedFileChunkState" inside CachedFile class, and drop
> the CachedFile from the name
> * The same for CachedFileChunk
> * Make CachedFile::getFileName return a GooString, it's not a hot path and
> will help people forgetting to delete it and causing leaks
> * If you really need to do manual reference counting (man this is C++ doing
> manual reference counting is bad) do it like it's done in GfxFont, that is,
> the destructor is private and inc/decRef return void and recRef automatically
> deletes when counter reaches 0
> * Also convert the "if (foo) delete foo;" statements to "delete foo;"
> * In CurlCacheLoader::load you probably leak the range GooString
> * The way builders are created/loaded/chained feels a bit weirdish, i think i
> would prefer something like this (not well though names not the ones i would
> probably use)
>
> class PDFDocLoader
> {
> PDFDoc *load(...) = 0;
> GooStringList supportedProtocols() const = 0;
> };
>
> class PDFDocLoaderFactory
> {
> bool init(); // loads default builders
> bool add(Builder *); // adds a non default builder (so that for example
> the Qt4 frontend can "inject" a builder based in QNetworkAccessManager
> PDFDoc *load(...); // uses supportedProtocols to see which PDFDocLoader
> has to use
> };
>
> What do you think?
>
> Albert
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler
>
-------------- next part --------------
From 397291f0a0a5447fbf1e59f870a8618dca505091 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Sat, 3 Apr 2010 15:08:20 +0200
Subject: [PATCH 01/11] Add support for cached files
---
CMakeLists.txt | 2 +
poppler/CachedFile.cc | 246 +++++++++++++++++++++++++++++++++++++++++++++++++
poppler/CachedFile.h | 113 ++++++++++++++++++++++
poppler/Makefile.am | 2 +
poppler/Stream.cc | 102 ++++++++++++++++++++
poppler/Stream.h | 58 ++++++++++++
6 files changed, 523 insertions(+), 0 deletions(-)
create mode 100644 poppler/CachedFile.cc
create mode 100644 poppler/CachedFile.h
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
//------------------------------------------------------------------------
--
1.6.4.2
From f19ca4a2a213aef06388bd07432373cd4b0403e4 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Tue, 23 Feb 2010 02:02:10 +0100
Subject: [PATCH 02/11] Add support for reading a cached file from stdin
---
CMakeLists.txt | 2 ++
poppler/Makefile.am | 2 ++
poppler/StdinCachedFile.cc | 37 +++++++++++++++++++++++++++++++++++++
poppler/StdinCachedFile.h | 26 ++++++++++++++++++++++++++
4 files changed, 67 insertions(+), 0 deletions(-)
create mode 100644 poppler/StdinCachedFile.cc
create mode 100644 poppler/StdinCachedFile.h
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
+
--
1.6.4.2
From c226271dfb53bf384ceb1b2035df6dea0f6b3396 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Wed, 24 Feb 2010 14:46:59 +0100
Subject: [PATCH 03/11] Use cached files to read from stdin in pdfinfo
This fixes reading from stdin.
---
utils/pdfinfo.cc | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
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) {
--
1.6.4.2
From 4ad2ef6d323629b42e0ae01655adc25ec2816d00 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Tue, 23 Feb 2010 02:29:26 +0100
Subject: [PATCH 04/11] Add HTTP support using libcurl
With libcurl, poppler can handle documents over http.
---
CMakeLists.txt | 18 ++++++++
config.h.cmake | 6 +++
configure.ac | 16 +++++++
poppler/CurlCachedFile.cc | 95 ++++++++++++++++++++++++++++++++++++++++
poppler/CurlCachedFile.h | 39 ++++++++++++++++
poppler/Makefile.am | 20 ++++++++
poppler/poppler-config.h.cmake | 5 ++
poppler/poppler-config.h.in | 5 ++
utils/pdfinfo.cc | 16 ++++++-
9 files changed, 219 insertions(+), 1 deletions(-)
create mode 100644 poppler/CurlCachedFile.cc
create mode 100644 poppler/CurlCachedFile.h
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;
--
1.6.4.2
From 09f44f62b89c47e7e1a0ec5ba6749297fdc341e4 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Sun, 4 Apr 2010 11:17:37 +0200
Subject: [PATCH 05/11] Cleanup PDFDoc
---
poppler/PDFDoc.cc | 40 +++++++++++++++-------------------------
poppler/PDFDoc.h | 3 ++-
2 files changed, 17 insertions(+), 26 deletions(-)
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();
--
1.6.4.2
From ab4616d00dfe038cc89bfb30cd3e8af7a54699f5 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Sun, 4 Apr 2010 11:29:53 +0200
Subject: [PATCH 06/11] Add PDFDoc::ErrorPDFDoc
---
poppler/PDFDoc.cc | 14 ++++++++++++++
poppler/PDFDoc.h | 3 +++
2 files changed, 17 insertions(+), 0 deletions(-)
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();
--
1.6.4.2
From ef3af1851b7aac414afdf7701421cc2519339600 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Sun, 4 Apr 2010 11:05:35 +0200
Subject: [PATCH 07/11] Add PDFDocBuilder
---
CMakeLists.txt | 1 +
poppler/Makefile.am | 1 +
poppler/PDFDocBuilder.h | 32 ++++++++++++++++++++++++++++++++
3 files changed, 34 insertions(+), 0 deletions(-)
create mode 100644 poppler/PDFDocBuilder.h
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 */
--
1.6.4.2
From 40c3b1d6cf78337f1f4e3c17f520bedda70c6874 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Thu, 25 Feb 2010 11:23:28 +0100
Subject: [PATCH 08/11] Add LocalPDFDocBuilder and StdinPDFDocBuilder
---
CMakeLists.txt | 4 +++
poppler/LocalPDFDocBuilder.cc | 45 +++++++++++++++++++++++++++++++++++++++++
poppler/LocalPDFDocBuilder.h | 30 +++++++++++++++++++++++++++
poppler/Makefile.am | 4 +++
poppler/StdinPDFDocBuilder.cc | 42 ++++++++++++++++++++++++++++++++++++++
poppler/StdinPDFDocBuilder.h | 30 +++++++++++++++++++++++++++
6 files changed, 155 insertions(+), 0 deletions(-)
create mode 100644 poppler/LocalPDFDocBuilder.cc
create mode 100644 poppler/LocalPDFDocBuilder.h
create mode 100644 poppler/StdinPDFDocBuilder.cc
create mode 100644 poppler/StdinPDFDocBuilder.h
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 */
--
1.6.4.2
From 2f7a1cff2f70352791861f4fca61b9220e6b9c37 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Wed, 24 Feb 2010 15:24:26 +0100
Subject: [PATCH 09/11] Add CurlPDFDocBuilder
---
CMakeLists.txt | 2 +
poppler/CurlPDFDocBuilder.cc | 46 ++++++++++++++++++++++++++++++++++++++++++
poppler/CurlPDFDocBuilder.h | 30 +++++++++++++++++++++++++++
poppler/Makefile.am | 6 +++-
4 files changed, 82 insertions(+), 2 deletions(-)
create mode 100644 poppler/CurlPDFDocBuilder.cc
create mode 100644 poppler/CurlPDFDocBuilder.h
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
--
1.6.4.2
From 2b5ebb6bcdac2b7541948c02406ae6b023fa4c2d Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Mon, 5 Apr 2010 14:35:52 +0200
Subject: [PATCH 10/11] Add PDFDocFactory
---
CMakeLists.txt | 2 +
poppler/Makefile.am | 2 +
poppler/PDFDocFactory.cc | 71 ++++++++++++++++++++++++++++++++++++++++++++++
poppler/PDFDocFactory.h | 42 +++++++++++++++++++++++++++
4 files changed, 117 insertions(+), 0 deletions(-)
create mode 100644 poppler/PDFDocFactory.cc
create mode 100644 poppler/PDFDocFactory.h
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 */
--
1.6.4.2
From 9b4cbb011b1ae96ae36367497745db04a9c71f04 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib at hiberis.nl>
Date: Mon, 5 Apr 2010 14:36:09 +0200
Subject: [PATCH 11/11] Use PDFDocFactory in utils
---
utils/pdffonts.cc | 16 ++++++++--------
utils/pdfimages.cc | 11 ++++++++++-
utils/pdfinfo.cc | 31 +++++++------------------------
utils/pdftoabw.cc | 10 +++++++++-
utils/pdftohtml.cc | 10 +++++++++-
utils/pdftoppm.cc | 17 +++++++++++------
utils/pdftops.cc | 9 ++++++++-
utils/pdftotext.cc | 14 +++++++-------
8 files changed, 69 insertions(+), 49 deletions(-)
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;
}
--
1.6.4.2
More information about the poppler
mailing list