summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/xpdf/Stream.h
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/Stream.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/Stream.h113
1 files changed, 95 insertions, 18 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/Stream.h b/noncore/unsupported/qpdf/xpdf/Stream.h
index 1f9c561..3319dcc 100644
--- a/noncore/unsupported/qpdf/xpdf/Stream.h
+++ b/noncore/unsupported/qpdf/xpdf/Stream.h
@@ -1,11 +1,11 @@
1//======================================================================== 1//========================================================================
2// 2//
3// Stream.h 3// Stream.h
4// 4//
5// Copyright 1996 Derek B. Noonburg 5// Copyright 1996-2002 Glyph & Cog, LLC
6// 6//
7//======================================================================== 7//========================================================================
8 8
9#ifndef STREAM_H 9#ifndef STREAM_H
10#define STREAM_H 10#define STREAM_H
11 11
@@ -75,14 +75,16 @@ public:
75 // Get next line from stream. 75 // Get next line from stream.
76 virtual char *getLine(char *buf, int size); 76 virtual char *getLine(char *buf, int size);
77 77
78 // Get current position in file. 78 // Get current position in file.
79 virtual int getPos() = 0; 79 virtual int getPos() = 0;
80 80
81 // Go to a position in the stream. 81 // Go to a position in the stream. If <dir> is negative, the
82 virtual void setPos(int pos) = 0; 82 // position is from the end of the file; otherwise the position is
83 // from the start of the file.
84 virtual void setPos(Guint pos, int dir = 0) = 0;
83 85
84 // Get PostScript command for the filter(s). 86 // Get PostScript command for the filter(s).
85 virtual GString *getPSFilter(char *indent); 87 virtual GString *getPSFilter(char *indent);
86 88
87 // Does this stream type potentially contain non-printable chars? 89 // Does this stream type potentially contain non-printable chars?
88 virtual GBool isBinary(GBool last = gTrue) = 0; 90 virtual GBool isBinary(GBool last = gTrue) = 0;
@@ -115,24 +117,26 @@ private:
115 117
116class BaseStream: public Stream { 118class BaseStream: public Stream {
117public: 119public:
118 120
119 BaseStream(Object *dictA); 121 BaseStream(Object *dictA);
120 virtual ~BaseStream(); 122 virtual ~BaseStream();
121 virtual Stream *makeSubStream(int start, int length, Object *dict) = 0; 123 virtual Stream *makeSubStream(Guint start, GBool limited,
122 virtual void setPos(int pos) = 0; 124 Guint length, Object *dict) = 0;
125 virtual void setPos(Guint pos, int dir = 0) = 0;
123 virtual BaseStream *getBaseStream() { return this; } 126 virtual BaseStream *getBaseStream() { return this; }
124 virtual Dict *getDict() { return dict.getDict(); } 127 virtual Dict *getDict() { return dict.getDict(); }
125 128
126 // Get/set position of first byte of stream within the file. 129 // Get/set position of first byte of stream within the file.
127 virtual int getStart() = 0; 130 virtual Guint getStart() = 0;
128 virtual void moveStart(int delta) = 0; 131 virtual void moveStart(int delta) = 0;
129 132
130#ifndef NO_DECRYPTION 133#ifndef NO_DECRYPTION
131 // Set decryption for this stream. 134 // Set decryption for this stream.
132 void doDecryption(Guchar *fileKey, int keyLength, int objNum, int objGen); 135 virtual void doDecryption(Guchar *fileKey, int keyLength,
136 int objNum, int objGen);
133#endif 137#endif
134 138
135#ifndef NO_DECRYPTION 139#ifndef NO_DECRYPTION
136protected: 140protected:
137 141
138 Decrypt *decrypt; 142 Decrypt *decrypt;
@@ -153,13 +157,13 @@ class FilterStream: public Stream {
153public: 157public:
154 158
155 FilterStream(Stream *strA); 159 FilterStream(Stream *strA);
156 virtual ~FilterStream(); 160 virtual ~FilterStream();
157 virtual void close(); 161 virtual void close();
158 virtual int getPos() { return str->getPos(); } 162 virtual int getPos() { return str->getPos(); }
159 virtual void setPos(int pos); 163 virtual void setPos(Guint pos, int dir = 0);
160 virtual BaseStream *getBaseStream() { return str->getBaseStream(); } 164 virtual BaseStream *getBaseStream() { return str->getBaseStream(); }
161 virtual Dict *getDict() { return str->getDict(); } 165 virtual Dict *getDict() { return str->getDict(); }
162 166
163protected: 167protected:
164 168
165 Stream *str; 169 Stream *str;
@@ -239,40 +243,81 @@ private:
239 243
240#define fileStreamBufSize 256 244#define fileStreamBufSize 256
241 245
242class FileStream: public BaseStream { 246class FileStream: public BaseStream {
243public: 247public:
244 248
245 FileStream(FILE *fA, int startA, int lengthA, Object *dictA); 249 FileStream(FILE *fA, Guint startA, GBool limitedA,
250 Guint lengthA, Object *dictA);
246 virtual ~FileStream(); 251 virtual ~FileStream();
247 virtual Stream *makeSubStream(int startA, int lengthA, Object *dictA); 252 virtual Stream *makeSubStream(Guint startA, GBool limitedA,
253 Guint lengthA, Object *dictA);
248 virtual StreamKind getKind() { return strFile; } 254 virtual StreamKind getKind() { return strFile; }
249 virtual void reset(); 255 virtual void reset();
250 virtual void close(); 256 virtual void close();
251 virtual int getChar() 257 virtual int getChar()
252 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } 258 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
253 virtual int lookChar() 259 virtual int lookChar()
254 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } 260 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
255 virtual int getPos() { return bufPos + (bufPtr - buf); } 261 virtual int getPos() { return bufPos + (bufPtr - buf); }
256 virtual void setPos(int pos); 262 virtual void setPos(Guint pos, int dir = 0);
257 virtual GBool isBinary(GBool last = gTrue) { return last; } 263 virtual GBool isBinary(GBool last = gTrue) { return last; }
258 virtual int getStart() { return start; } 264 virtual Guint getStart() { return start; }
259 virtual void moveStart(int delta); 265 virtual void moveStart(int delta);
260 266
261private: 267private:
262 268
263 GBool fillBuf(); 269 GBool fillBuf();
264 270
265 FILE *f; 271 FILE *f;
266 int start; 272 Guint start;
267 int length; 273 GBool limited;
274 Guint length;
268 char buf[fileStreamBufSize]; 275 char buf[fileStreamBufSize];
269 char *bufPtr; 276 char *bufPtr;
270 char *bufEnd; 277 char *bufEnd;
271 int bufPos; 278 Guint bufPos;
272 int savePos; 279 int savePos;
280 GBool saved;
281};
282
283//------------------------------------------------------------------------
284// MemStream
285//------------------------------------------------------------------------
286
287class MemStream: public BaseStream {
288public:
289
290 MemStream(char *bufA, Guint lengthA, Object *dictA);
291 virtual ~MemStream();
292 virtual Stream *makeSubStream(Guint start, GBool limited,
293 Guint lengthA, Object *dictA);
294 virtual StreamKind getKind() { return strWeird; }
295 virtual void reset();
296 virtual void close();
297 virtual int getChar()
298 { return (bufPtr < bufEnd) ? (*bufPtr++ & 0xff) : EOF; }
299 virtual int lookChar()
300 { return (bufPtr < bufEnd) ? (*bufPtr & 0xff) : EOF; }
301 virtual int getPos() { return bufPtr - buf; }
302 virtual void setPos(Guint pos, int dir = 0);
303 virtual GBool isBinary(GBool last = gTrue) { return last; }
304 virtual Guint getStart() { return 0; }
305 virtual void moveStart(int delta);
306#ifndef NO_DECRYPTION
307 virtual void doDecryption(Guchar *fileKey, int keyLength,
308 int objNum, int objGen);
309#endif
310
311private:
312
313 char *buf;
314 Guint length;
315 GBool needFree;
316 char *bufEnd;
317 char *bufPtr;
273}; 318};
274 319
275//------------------------------------------------------------------------ 320//------------------------------------------------------------------------
276// EmbedStream 321// EmbedStream
277// 322//
278// This is a special stream type used for embedded streams (inline 323// This is a special stream type used for embedded streams (inline
@@ -284,21 +329,22 @@ private:
284 329
285class EmbedStream: public BaseStream { 330class EmbedStream: public BaseStream {
286public: 331public:
287 332
288 EmbedStream(Stream *strA, Object *dictA); 333 EmbedStream(Stream *strA, Object *dictA);
289 virtual ~EmbedStream(); 334 virtual ~EmbedStream();
290 virtual Stream *makeSubStream(int start, int length, Object *dictA); 335 virtual Stream *makeSubStream(Guint start, GBool limited,
336 Guint length, Object *dictA);
291 virtual StreamKind getKind() { return str->getKind(); } 337 virtual StreamKind getKind() { return str->getKind(); }
292 virtual void reset() {} 338 virtual void reset() {}
293 virtual int getChar() { return str->getChar(); } 339 virtual int getChar() { return str->getChar(); }
294 virtual int lookChar() { return str->lookChar(); } 340 virtual int lookChar() { return str->lookChar(); }
295 virtual int getPos() { return str->getPos(); } 341 virtual int getPos() { return str->getPos(); }
296 virtual void setPos(int pos); 342 virtual void setPos(Guint pos, int dir = 0);
297 virtual GBool isBinary(GBool last = gTrue) { return last; } 343 virtual GBool isBinary(GBool last = gTrue) { return last; }
298 virtual int getStart(); 344 virtual Guint getStart();
299 virtual void moveStart(int delta); 345 virtual void moveStart(int delta);
300 346
301private: 347private:
302 348
303 Stream *str; 349 Stream *str;
304}; 350};
@@ -656,12 +702,43 @@ private:
656 702
657 int length; 703 int length;
658 int count; 704 int count;
659}; 705};
660 706
661//------------------------------------------------------------------------ 707//------------------------------------------------------------------------
708// ASCIIHexEncoder
709//------------------------------------------------------------------------
710
711class ASCIIHexEncoder: public FilterStream {
712public:
713
714 ASCIIHexEncoder(Stream *strA);
715 virtual ~ASCIIHexEncoder();
716 virtual StreamKind getKind() { return strWeird; }
717 virtual void reset();
718 virtual void close();
719 virtual int getChar()
720 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
721 virtual int lookChar()
722 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
723 virtual GString *getPSFilter(char *indent) { return NULL; }
724 virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
725 virtual GBool isEncoder() { return gTrue; }
726
727private:
728
729 char buf[4];
730 char *bufPtr;
731 char *bufEnd;
732 int lineLen;
733 GBool eof;
734
735 GBool fillBuf();
736};
737
738//------------------------------------------------------------------------
662// ASCII85Encoder 739// ASCII85Encoder
663//------------------------------------------------------------------------ 740//------------------------------------------------------------------------
664 741
665class ASCII85Encoder: public FilterStream { 742class ASCII85Encoder: public FilterStream {
666public: 743public:
667 744