forked from rbrito/xpdf-poppler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDFCore.h
315 lines (256 loc) · 10.4 KB
/
PDFCore.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//========================================================================
//
// PDFCore.h
//
// Copyright 2004 Glyph & Cog, LLC
//
//========================================================================
#ifndef PDFCORE_H
#define PDFCORE_H
#include <poppler-config.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <stdlib.h>
#include "poppler/splash/SplashTypes.h"
#include "poppler/CharTypes.h"
class GooString;
class GooList;
class SplashBitmap;
class SplashPattern;
class BaseStream;
class PDFDoc;
class Links;
class LinkDest;
class LinkAction;
class TextPage;
class HighlightFile;
class CoreOutputDev;
class PDFCore;
//------------------------------------------------------------------------
// zoom factor
//------------------------------------------------------------------------
#define zoomPage -1
#define zoomWidth -2
#define defZoom 125
#define EPSILON 1.0e-7 // 32-bit floating point machine precision
//------------------------------------------------------------------------
//------------------------------------------------------------------------
// Number of pixels of matte color between pages in continuous mode.
#define continuousModePageSpacing 3
//------------------------------------------------------------------------
// PDFCorePage
//------------------------------------------------------------------------
class PDFCorePage {
public:
PDFCorePage(int pageA, int wA, int hA, int tileWA, int tileHA);
~PDFCorePage();
int page;
GooList *tiles; // cached tiles [PDFCoreTile]
int xDest, yDest; // position of upper-left corner
// in the drawing area
int w, h; // size of whole page bitmap
int tileW, tileH; // size of tiles
Links *links; // hyperlinks for this page
TextPage *text; // extracted text
};
//------------------------------------------------------------------------
// PDFCoreTile
//------------------------------------------------------------------------
class PDFCoreTile {
public:
PDFCoreTile(int xDestA, int yDestA);
virtual ~PDFCoreTile();
int xMin, yMin, xMax, yMax;
int xDest, yDest;
unsigned edges;
SplashBitmap *bitmap;
double ctm[6]; // coordinate transform matrix:
// default user space -> device space
double ictm[6]; // inverse CTM
};
#define pdfCoreTileTopEdge 0x01
#define pdfCoreTileBottomEdge 0x02
#define pdfCoreTileLeftEdge 0x04
#define pdfCoreTileRightEdge 0x08
#define pdfCoreTileTopSpace 0x10
#define pdfCoreTileBottomSpace 0x20
//------------------------------------------------------------------------
// PDFHistory
//------------------------------------------------------------------------
struct PDFHistory {
GooString *fileName;
int page;
};
#define pdfHistorySize 50
//------------------------------------------------------------------------
// PDFCore
//------------------------------------------------------------------------
class PDFCore {
public:
PDFCore(SplashColorMode colorModeA, int bitmapRowPadA,
bool reverseVideoA, SplashColorPtr paperColorA,
bool incrementalUpdate);
virtual ~PDFCore();
//----- loadFile / displayPage / displayDest
// Load a new file. Returns pdfOk or error code.
virtual int loadFile(GooString *fileName, GooString *ownerPassword = NULL,
GooString *userPassword = NULL);
// Load a new file, via a Stream instead of a file name. Returns
// pdfOk or error code.
virtual int loadFile(BaseStream *stream, GooString *ownerPassword = NULL,
GooString *userPassword = NULL);
// Load an already-created PDFDoc object.
virtual void loadDoc(PDFDoc *docA);
// Clear out the current document, if any.
virtual void clear();
// Same as clear(), but returns the PDFDoc object instead of
// deleting it.
virtual PDFDoc *takeDoc(bool redraw);
// Display (or redisplay) the specified page. If <scrollToTop> is
// set, the window is vertically scrolled to the top; otherwise, no
// scrolling is done. If <addToHist> is set, this page change is
// added to the history list.
virtual void displayPage(int topPageA, double zoomA, int rotateA,
bool scrollToTop, bool addToHist);
// Display a link destination.
virtual void displayDest(LinkDest *dest, double zoomA, int rotateA,
bool addToHist);
// Update the display, given the specified parameters.
virtual void update(int topPageA, int scrollXA, int scrollYA,
double zoomA, int rotateA, bool force, bool addToHist);
//----- page/position changes
virtual bool gotoNextPage(int inc, bool top);
virtual bool gotoPrevPage(int dec, bool top, bool bottom);
virtual bool gotoNamedDestination(GooString *dest);
virtual bool goForward();
virtual bool goBackward();
virtual void scrollLeft(int nCols = 16);
virtual void scrollRight(int nCols = 16);
virtual void scrollUp(int nLines = 16);
virtual void scrollUpPrevPage(int nLines = 16);
virtual void scrollDown(int nLines = 16);
virtual void scrollDownNextPage(int nLines = 16);
virtual void scrollPageUp();
virtual void scrollPageDown();
virtual void scrollTo(int x, int y);
virtual void scrollToLeftEdge();
virtual void scrollToRightEdge();
virtual void scrollToTopEdge();
virtual void scrollToBottomEdge();
virtual void scrollToTopLeft();
virtual void scrollToBottomRight();
virtual void zoomToRect(int pg, double ulx, double uly,
double lrx, double lry);
virtual void zoomCentered(double zoomA);
virtual void zoomToCurrentWidth();
virtual void setContinuousMode(bool cm);
//----- selection
// Current selected region.
void setSelection(int newSelectPage,
int newSelectULX, int newSelectULY,
int newSelectLRX, int newSelectLRY);
void moveSelection(int pg, int x, int y);
bool getSelection(int *pg, double *ulx, double *uly,
double *lrx, double *lry);
// Text extraction.
GooString *extractText(int pg, double xMin, double yMin,
double xMax, double yMax);
//----- find
virtual bool find(char *s, bool caseSensitive, bool next, bool backward,
bool onePageOnly);
virtual bool findU(Unicode *u, int len, bool caseSensitive,
bool next, bool backward, bool onePageOnly);
//----- coordinate conversion
// user space: per-pace, as defined by PDF file; unit = point
// device space: (0,0) is upper-left corner of a page; unit = pixel
// window space: (0,0) is upper-left corner of drawing area; unit = pixel
bool cvtWindowToUser(int xw, int yw, int *pg, double *xu, double *yu);
bool cvtWindowToDev(int xw, int yw, int *pg, int *xd, int *yd);
void cvtUserToWindow(int pg, double xy, double yu, int *xw, int *yw);
void cvtUserToDev(int pg, double xu, double yu, int *xd, int *yd);
void cvtDevToWindow(int pg, int xd, int yd, int *xw, int *yw);
void cvtDevToUser(int pg, int xd, int yd, double *xu, double *yu);
//----- misc access
PDFDoc *getDoc() { return doc; }
int getPageNum() { return topPage; }
double getZoom() { return zoom; }
double getZoomDPI() { return dpi; }
int getRotate() { return rotate; }
bool getContinuousMode() { return continuousMode; }
virtual void setReverseVideo(bool reverseVideoA);
bool canGoBack() { return historyBLen > 1; }
bool canGoForward() { return historyFLen > 0; }
int getScrollX() { return scrollX; }
int getScrollY() { return scrollY; }
int getDrawAreaWidth() { return drawAreaWidth; }
int getDrawAreaHeight() { return drawAreaHeight; }
virtual void setBusyCursor(bool busy) = 0;
LinkAction *findLink(int pg, double x, double y);
protected:
int loadFile2(PDFDoc *newDoc);
void addPage(int pg, int rot);
void needTile(PDFCorePage *page, int x, int y);
void xorRectangle(int pg, int x0, int y0, int x1, int y1,
SplashPattern *pattern, PDFCoreTile *oneTile = NULL);
int loadHighlightFile(HighlightFile *hf, SplashColorPtr color,
SplashColorPtr selectColor, bool selectable);
PDFCorePage *findPage(int pg);
static void redrawCbk(void *data, int x0, int y0, int x1, int y1,
bool composited);
void redrawWindow(int x, int y, int width, int height,
bool needUpdate);
virtual PDFCoreTile *newTile(int xDestA, int yDestA);
virtual void updateTileData(PDFCoreTile *tileA, int xSrc, int ySrc,
int width, int height, bool composited);
virtual void redrawRect(PDFCoreTile *tileA, int xSrc, int ySrc,
int xDest, int yDest, int width, int height,
bool composited) = 0;
void clippedRedrawRect(PDFCoreTile *tile, int xSrc, int ySrc,
int xDest, int yDest, int width, int height,
int xClip, int yClip, int wClip, int hClip,
bool needUpdate, bool composited = true);
virtual void updateScrollbars() = 0;
virtual bool checkForNewFile() { return false; }
PDFDoc *doc; // current PDF file
bool continuousMode; // false for single-page mode, true for
// continuous mode
int drawAreaWidth, // size of the PDF display area
drawAreaHeight;
double maxUnscaledPageW, // maximum unscaled page size
maxUnscaledPageH;
int maxPageW; // maximum page width (only used in
// continuous mode)
int totalDocH; // total document height (only used in
// continuous mode)
int *pageY; // top coordinates for each page (only used
// in continuous mode)
int topPage; // page at top of window
int scrollX, scrollY; // offset from top left corner of topPage
// to top left corner of window
double zoom; // current zoom level, in percent of 72 dpi
double dpi; // current zoom level, in DPI
int rotate; // current page rotation
int selectPage; // page number of current selection
int selectULX, // coordinates of current selection,
selectULY, // in device space -- (ULX==LRX || ULY==LRY)
selectLRX, // means there is no selection
selectLRY;
bool dragging; // set while selection is being dragged
bool lastDragLeft; // last dragged selection edge was left/right
bool lastDragTop; // last dragged selection edge was top/bottom
PDFHistory // page history queue
history[pdfHistorySize];
int historyCur; // currently displayed page
int historyBLen; // number of valid entries backward from
// current entry
int historyFLen; // number of valid entries forward from
// current entry
GooList *pages; // cached pages [PDFCorePage]
PDFCoreTile *curTile; // tile currently being rasterized
PDFCorePage *curPage; // page to which curTile belongs
SplashColor paperColor;
CoreOutputDev *out;
friend class PDFCoreTile;
};
#endif