Delete all Trailing spaces in code.
[reactos.git] / rosapps / smartpdf / src / PdfEngine.h
1 /* Copyright Krzysztof Kowalczyk 2006-2007
2 License: GPLv2 */
3 #ifndef _PDF_ENGINE_H_
4 #define _PDF_ENGINE_H_
5
6 #include "geom_util.h"
7
8 #ifndef _FITZ_H_
9 #include <fitz.h>
10 #include <mupdf.h>
11 #endif
12
13 class WindowInfo;
14
15 class SplashBitmap;
16 class SplashOutputDev;
17 class PDFDoc;
18 class Links;
19
20 extern const char* const LINK_ACTION_GOTO;
21 extern const char* const LINK_ACTION_GOTOR;
22 extern const char* const LINK_ACTION_LAUNCH;
23 extern const char* const LINK_ACTION_URI;
24 extern const char* const LINK_ACTION_NAMED;
25 extern const char* const LINK_ACTION_MOVIE;
26
27 /* For simplicity, all in one file. Would be cleaner if they were
28 in separate files PdfEngineFitz.h and PdfEnginePoppler.h */
29
30 #define INVALID_PAGE_NO -1
31 #define INVALID_ROTATION -1
32 /* It seems that PDF documents are encoded assuming DPI of 72.0 */
33 #define PDF_FILE_DPI 72
34
35 void SplashColorsInit(void);
36
37 /* Abstract class representing cached bitmap. Allows different implementations
38 on different platforms. */
39 class RenderedBitmap {
40 public:
41 virtual ~RenderedBitmap() {};
42 virtual int dx() = 0;
43 virtual int dy() = 0;
44 virtual int rowSize() = 0;
45 virtual unsigned char *data() = 0;
46
47 // TODO: this is for WINDOWS only
48 virtual HBITMAP createDIBitmap(HDC) = 0;
49 virtual void stretchDIBits(HDC, int, int, int, int) = 0;
50 };
51
52 class RenderedBitmapFitz : public RenderedBitmap {
53 public:
54 RenderedBitmapFitz(fz_pixmap *);
55 virtual ~RenderedBitmapFitz();
56
57 virtual int dx() { return _bitmap->w; }
58 virtual int dy() { return _bitmap->h; }
59 virtual int rowSize();
60 virtual unsigned char *data();
61
62 virtual HBITMAP createDIBitmap(HDC);
63 virtual void stretchDIBits(HDC, int, int, int, int);
64 protected:
65 fz_pixmap *_bitmap;
66 };
67
68 class RenderedBitmapSplash : public RenderedBitmap {
69 public:
70 RenderedBitmapSplash(SplashBitmap *);
71 virtual ~RenderedBitmapSplash();
72
73 virtual int dx();
74 virtual int dy();
75 virtual int rowSize();
76 virtual unsigned char *data();
77
78 virtual HBITMAP createDIBitmap(HDC);
79 virtual void stretchDIBits(HDC, int, int, int, int);
80
81 protected:
82 SplashBitmap *_bitmap;
83 };
84
85 class PdfEngine {
86 public:
87 PdfEngine() :
88 _fileName(0)
89 , _pageCount(INVALID_PAGE_NO)
90 { }
91
92 virtual ~PdfEngine() { free((void*)_fileName); }
93
94 const char *fileName(void) const { return _fileName; };
95
96 void setFileName(const char *fileName) {
97 assert(!_fileName);
98 _fileName = (const char*)strdup(fileName);
99 }
100
101 bool validPageNo(int pageNo) const {
102 if ((pageNo >= 1) && (pageNo <= pageCount()))
103 return true;
104 return false;
105 }
106
107 int pageCount(void) const { return _pageCount; }
108
109 virtual bool load(const char *fileName, WindowInfo *windowInfo) = 0;
110 virtual int pageRotation(int pageNo) = 0;
111 virtual SizeD pageSize(int pageNo) = 0;
112 virtual RenderedBitmap *renderBitmap(int pageNo, double zoomReal, int rotation,
113 BOOL (*abortCheckCbkA)(void *data),
114 void *abortCheckCbkDataA) = 0;
115
116 virtual bool printingAllowed() = 0;
117 virtual int linkCount(int pageNo) = 0;
118 virtual const char* linkType(int pageNo, int linkNo) = 0;
119
120 protected:
121 const char *_fileName;
122 int _pageCount;
123 WindowInfo *_windowInfo;
124 };
125
126 class PdfEnginePoppler : public PdfEngine {
127 public:
128 PdfEnginePoppler();
129 virtual ~PdfEnginePoppler();
130 virtual bool load(const char *fileName, WindowInfo* windowInfo);
131 virtual int pageRotation(int pageNo);
132 virtual SizeD pageSize(int pageNo);
133 virtual RenderedBitmap *renderBitmap(int pageNo, double zoomReal, int rotation,
134 BOOL (*abortCheckCbkA)(void *data),
135 void *abortCheckCbkDataA);
136
137 virtual bool printingAllowed();
138 virtual int linkCount(int pageNo);
139 virtual const char* linkType(int pageNo, int linkNo);
140
141 PDFDoc* pdfDoc() { return _pdfDoc; }
142 SplashOutputDev * outputDevice();
143 private:
144 Links* getLinksForPage(int pageNo);
145
146 PDFDoc * _pdfDoc;
147 SplashOutputDev * _outputDev;
148 Links ** _linksForPage;
149 };
150
151 class PdfEngineFitz : public PdfEngine {
152 public:
153 PdfEngineFitz();
154 virtual ~PdfEngineFitz();
155 virtual bool load(const char *fileName, WindowInfo* windowInfo);
156 virtual int pageRotation(int pageNo);
157 virtual SizeD pageSize(int pageNo);
158 virtual RenderedBitmap *renderBitmap(int pageNo, double zoomReal, int rotation,
159 BOOL (*abortCheckCbkA)(void *data),
160 void *abortCheckCbkDataA);
161
162 virtual bool printingAllowed();
163 virtual int linkCount(int pageNo);
164 virtual const char* linkType(int pageNo, int linkNo);
165
166 fz_matrix viewctm (pdf_page *page, float zoom, int rotate);
167
168 pdf_page * getPdfPage(int pageNo);
169
170 private:
171 PdfEnginePoppler* _popplerEngine;
172
173 HANDLE _getPageSem;
174
175 pdf_xref * xref() { return _xref; }
176 pdf_pagetree * pages() { return _pageTree; }
177
178 void dropPdfPage(int pageNo);
179
180 pdf_xref * _xref;
181 pdf_outline * _outline;
182 pdf_pagetree * _pageTree;
183 pdf_page ** _pages;
184 #ifdef FITZ_HEAD
185 fz_graphics * _rast;
186 #else
187 fz_renderer * _rast;
188 #endif
189 };
190
191 #endif