wxMaxima
Loading...
Searching...
No Matches
pdfparser.h
Go to the documentation of this file.
1
2// Name: pdfparser.h
3// Purpose:
4// Author: Ulrich Telle
5// Created: 2006-05-15
6// Copyright: (c) Ulrich Telle
7// Licence: wxWindows licence
9
11
12#ifndef _PDF_PARSER_H_
13#define _PDF_PARSER_H_
14
15// wxWidgets headers
16#include <wx/dynarray.h>
17#include <wx/filesys.h>
18#include <wx/mstream.h>
19#include <wx/string.h>
20
21// wxPdfDocument headers
22#include "wx/pdfdocdef.h"
23#include "wx/pdfarraydouble.h"
24#include "wx/pdfobjects.h"
25
26class WXDLLIMPEXP_FWD_PDFDOC wxPdfEncrypt;
27class WXDLLIMPEXP_FWD_PDFDOC wxPdfInfo;
28
30// Permission bit 3: Print
31// Permission bit 5: Copy or extract text and graphics
32// Permission bit 10: Extract text and graphics
33// THIS MUST NOT BE CHANGED!
34#define REQUIRED_PERMISSIONS 0x0214
35
37#define TOKEN_COMMENT 1
38#define TOKEN_BOOLEAN 2
39#define TOKEN_NUMBER 3
40#define TOKEN_STRING 4
41#define TOKEN_NAME 5
42#define TOKEN_START_ARRAY 6
43#define TOKEN_END_ARRAY 7
44#define TOKEN_START_DICTIONARY 8
45#define TOKEN_END_DICTIONARY 9
46#define TOKEN_REFERENCE 10
47#define TOKEN_NULL 12
48#define TOKEN_OTHER 13
49
51
56class WXDLLIMPEXP_PDFDOC wxPdfTokenizer
57{
58public:
60
63 wxPdfTokenizer(wxInputStream* inputStream);
64
66 virtual ~wxPdfTokenizer();
67
69
73 off_t Seek(off_t pos);
74
76
79 off_t Tell();
80
82
85 void BackOnePosition(int ch);
86
88
91 off_t GetLength();
92
94
97 int ReadChar();
98
100
104 wxMemoryOutputStream* ReadBuffer(size_t size);
105
107
110 off_t GetStartXRef();
111
113
117 wxString ReadString(int size);
118
120
123 wxString CheckPdfHeader();
124
126
129 bool NextToken();
130
132
135 void NextValidToken();
136
138
141 int GetTokenType() const;
142
144
147 wxString GetStringValue() const;
148
150
153 int GetIntValue() const;
154
156
159 bool IsHexString() const { return m_hexString; }
160
162
165 int GetReference() const;
166
168
171 int GetGeneration() const;
172
174
178 static bool IsWhitespace(int ch);
179
181
185 static bool IsDelimiter(int ch);
186
188
192 static bool IsDelimiterOrWhitespace(int ch);
193
195
199 static int GetHex(int v);
200
201private:
202 wxInputStream* m_inputStream;
203 int m_type;
204 wxString m_stringValue;
205 int m_reference;
206 int m_generation;
207 bool m_hexString;
208
209};
210
212
216class WXDLLIMPEXP_PDFDOC wxPdfXRefEntry
217{
218public:
221
223 virtual ~wxPdfXRefEntry();
224
225 int m_type;
228};
229
230WX_DECLARE_USER_EXPORTED_OBJARRAY(wxPdfXRefEntry, wxPdfXRef, WXDLLIMPEXP_PDFDOC);
231
233
238class WXDLLIMPEXP_PDFDOC wxPdfParser
239{
240public:
242
246 wxPdfParser(const wxString& filename,
247 const wxString& password = wxEmptyString);
248
250 virtual ~wxPdfParser();
251
253
256 bool IsOk() const;
257
259
262 wxString GetPdfVersion() const { return m_pdfVersion; }
263
265
268 unsigned int GetPageCount() const;
269
271
275 bool GetSourceInfo(wxPdfInfo& info);
276
278
281 wxPdfObjectQueue* GetObjectQueue() { return m_objectQueue; }
282
284
287 wxPdfObjectMap* GetObjectMap() { return m_objectMap; }
288
290
295 void AppendObject(int originalObjectId, int actualObjectId, wxPdfObject* obj);
296
298
302 wxPdfObject* GetPageResources(unsigned int pageno);
303
305
309 void GetContent(unsigned int pageno, wxArrayPtrVoid& contents);
310
312
316 wxPdfArrayDouble* GetPageMediaBox(unsigned int pageno);
317
319
323 wxPdfArrayDouble* GetPageCropBox(unsigned int pageno);
324
326
330 wxPdfArrayDouble* GetPageBleedBox(unsigned int pageno);
331
333
337 wxPdfArrayDouble* GetPageTrimBox(unsigned int pageno);
338
340
344 wxPdfArrayDouble* GetPageArtBox(unsigned int pageno);
345
347
351 int GetPageRotation (unsigned int pageno);
352
354
359 wxPdfObject* ResolveObject(wxPdfObject* obj);
360
362
365 void SetUseRawStream(bool useRawStream) { m_useRawStream = useRawStream; }
366
368
371 bool GetUseRawStream() const { return m_useRawStream; }
372
373protected:
375 wxPdfObject* GetPageResources(wxPdfObject* page);
376
378 void GetPageContent(wxPdfObject* contentRef, wxArrayPtrVoid& contents);
379
381 wxPdfArrayDouble* GetPageBox(wxPdfDictionary* page, const wxString& boxIndex);
382
384 int GetPageRotation (wxPdfDictionary* page);
385
387 bool ParseDocument();
388
390 bool SetupDecryptor();
391
393 bool ParseXRef();
394
396 bool ParsePageTree(wxPdfDictionary* pages);
397
399 wxPdfDictionary* ParseXRefSection();
400
402 bool ParseXRefStream(int ptr, bool setTrailer);
403
405 wxPdfObject* ParseObject();
406
408 wxPdfDictionary* ParseDictionary();
409
411 wxPdfArray* ParseArray();
412
414 wxPdfObject* ParseSpecificObject(int idx);
415
417 wxPdfObject* ParseDirectObject(int k);
418
420 wxPdfObject* ParseObjectStream(wxPdfStream* stream, int idx);
421
423 void GetStreamBytes(wxPdfStream* stream);
424
426 void GetStreamBytesRaw(wxPdfStream* stream);
427
429 wxMemoryOutputStream* DecodePredictor(wxMemoryOutputStream* in, wxPdfObject* dicPar);
430
432
436 wxMemoryOutputStream* FlateDecode(wxMemoryOutputStream* osIn);
437
439
443 wxMemoryOutputStream* ASCIIHexDecode(wxMemoryOutputStream* osIn);
444
446
450 wxMemoryOutputStream* ASCII85Decode(wxMemoryOutputStream* osIn);
451
453
457 wxMemoryOutputStream* LZWDecode(wxMemoryOutputStream* osIn);
458
460 static wxFileSystem* GetFileSystem();
461
462private:
464 void ReserveXRef(size_t count);
465
466 bool m_initialized;
467 int m_fileSize;
468 wxString m_filename;
469 wxString m_password;
470 wxString m_pdfVersion;
471 wxFSFile* m_pdfFile;
472 wxPdfTokenizer* m_tokens;
473 wxPdfDictionary* m_trailer;
474 wxPdfDictionary* m_root;
475 wxArrayPtrVoid m_pages;
476 unsigned int m_currentPage;
477 bool m_useRawStream;
478
479 bool m_encrypted;
480 wxPdfEncrypt* m_decryptor;
481 wxPdfDictionary* m_encryption;
482
483 wxPdfObjectQueue* m_objectQueue;
484 wxPdfObjectQueue* m_objectQueueLast;
485 wxPdfObjectMap* m_objectMap;
486 wxPdfObjStmMap* m_objStmCache;
487 bool m_cacheObjects;
488
489 int m_objNum;
490 int m_objGen;
491
492 wxPdfXRef m_xref;
493
494 static wxFileSystem* ms_fileSystem;
495};
496
497#define WXPDF_LZW_STRINGTABLE_SIZE 8192
498
500
504class WXDLLIMPEXP_PDFDOC wxPdfLzwDecoder
505{
506public:
509
511 virtual ~wxPdfLzwDecoder();
512
514
517 int GetNextCode();
518
520
525 bool Decode(wxMemoryInputStream* dataIn, wxMemoryOutputStream* dataOut);
526
528 void InitializeStringTable();
529
531
534 void WriteString(int code);
535
537
541 void AddStringToTable(int oldCode, char newString);
542
543private:
544 wxMemoryInputStream* m_dataIn;
545 wxMemoryOutputStream* m_dataOut;
546 size_t m_dataSize;
547 wxArrayInt m_stringTable[WXPDF_LZW_STRINGTABLE_SIZE];
548
549 int m_tableIndex;
550 int m_bitsToGet;
551 int m_bytePointer;
552 int m_bitPointer;
553 int m_nextData;
554 int m_nextBits;
555
556 static int ms_andTable[4];
557};
558
559#endif
Class representing an array object. (For internal use only)
Definition: pdfobjects.h:361
Class representing a dictionary object. (For internal use only)
Definition: pdfobjects.h:409
Class representing PDF encryption methods. (For internal use only)
Definition: pdfencrypt.h:30
Class representing a PDF document information dictionary.
Definition: pdfinfo.h:20
Class representing an LZW decoder. (For internal use only)
Definition: pdfparser.h:505
Class representing a queue of objects. (For internal use only)
Definition: pdfobjects.h:542
Class representing a base PDF object. (For internal use only)
Definition: pdfobjects.h:35
Class representing a PDF parser. (For internal use only)
Definition: pdfparser.h:239
void SetUseRawStream(bool useRawStream)
Set flag whether a stream should be decoded or not.
Definition: pdfparser.h:365
bool GetUseRawStream() const
Get flag whether a stream should be decoded or not.
Definition: pdfparser.h:371
wxPdfObjectMap * GetObjectMap()
Get the map of referenced objects.
Definition: pdfparser.h:287
wxPdfObjectQueue * GetObjectQueue()
Get the queue of referenced objects.
Definition: pdfparser.h:281
wxString GetPdfVersion() const
Get PDF version of parsed document.
Definition: pdfparser.h:262
Class representing a stream object. (For internal use only)
Definition: pdfobjects.h:456
Class representing a tokenizer for parsing PDF documents.
Definition: pdfparser.h:57
bool IsHexString() const
Check whether the token is a hexadecimal string.
Definition: pdfparser.h:159
Class representing an XRef entry (for internal use only)
Definition: pdfparser.h:217
int m_gen_ref
Generation number (type 1) or object number of the object stream (type 2)
Definition: pdfparser.h:227
int m_type
Type of XRef entry (0: free, 1: normal, 2: in stream)
Definition: pdfparser.h:225
int m_ofs_idx
Byte offset of object (type 1) or index in object stream (type 2)
Definition: pdfparser.h:226
Definition of array of type double.
Compile time switches for the wxPdfDocument component.
Interfaces of the wxPdfObject classes.