1 //========================================================================
5 // Copyright 2004 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
19 #include "SplashTypes.h"
20 #include "CharTypes.h"
35 //------------------------------------------------------------------------
37 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
48 // Number of pixels of matte color between pages in continuous mode.
49 #define continuousModePageSpacing 3
51 //------------------------------------------------------------------------
53 //------------------------------------------------------------------------
58 PDFCorePage(int pageA
, int wA
, int hA
, int tileWA
, int tileHA
);
62 GList
*tiles
; // cached tiles [PDFCoreTile]
63 int xDest
, yDest
; // position of upper-left corner
64 // in the drawing area
65 int w
, h
; // size of whole page bitmap
66 int tileW
, tileH
; // size of tiles
67 Links
*links
; // hyperlinks for this page
68 TextPage
*text
; // extracted text
71 //------------------------------------------------------------------------
73 //------------------------------------------------------------------------
78 PDFCoreTile(int xDestA
, int yDestA
);
79 virtual ~PDFCoreTile();
81 int xMin
, yMin
, xMax
, yMax
;
85 double ctm
[6]; // coordinate transform matrix:
86 // default user space -> device space
87 double ictm
[6]; // inverse CTM
90 #define pdfCoreTileTopEdge 0x01
91 #define pdfCoreTileBottomEdge 0x02
92 #define pdfCoreTileLeftEdge 0x04
93 #define pdfCoreTileRightEdge 0x08
94 #define pdfCoreTileTopSpace 0x10
95 #define pdfCoreTileBottomSpace 0x20
97 //------------------------------------------------------------------------
99 //------------------------------------------------------------------------
106 #define pdfHistorySize 50
109 //------------------------------------------------------------------------
111 //------------------------------------------------------------------------
116 PDFCore(SplashColorMode colorModeA
, int bitmapRowPadA
,
117 GBool reverseVideoA
, SplashColorPtr paperColorA
);
120 //----- loadFile / displayPage / displayDest
122 // Load a new file. Returns pdfOk or error code.
123 virtual int loadFile(GString
*fileName
, GString
*ownerPassword
= NULL
,
124 GString
*userPassword
= NULL
);
127 // Load a new file. Returns pdfOk or error code.
128 virtual int loadFile(wchar_t *fileName
, int fileNameLen
,
129 GString
*ownerPassword
= NULL
,
130 GString
*userPassword
= NULL
);
133 // Load a new file, via a Stream instead of a file name. Returns
134 // pdfOk or error code.
135 virtual int loadFile(BaseStream
*stream
, GString
*ownerPassword
= NULL
,
136 GString
*userPassword
= NULL
);
138 // Clear out the current document, if any.
139 virtual void clear();
141 // Display (or redisplay) the specified page. If <scrollToTop> is
142 // set, the window is vertically scrolled to the top; otherwise, no
143 // scrolling is done. If <addToHist> is set, this page change is
144 // added to the history list.
145 virtual void displayPage(int topPageA
, double zoomA
, int rotateA
,
146 GBool scrollToTop
, GBool addToHist
);
148 // Display a link destination.
149 virtual void displayDest(LinkDest
*dest
, double zoomA
, int rotateA
,
152 // Update the display, given the specified parameters.
153 virtual void update(int topPageA
, int scrollXA
, int scrollYA
,
154 double zoomA
, int rotateA
, GBool force
, GBool addToHist
);
156 //----- page/position changes
158 virtual GBool
gotoNextPage(int inc
, GBool top
);
159 virtual GBool
gotoPrevPage(int dec
, GBool top
, GBool bottom
);
160 virtual GBool
gotoNamedDestination(GString
*dest
);
161 virtual GBool
goForward();
162 virtual GBool
goBackward();
163 virtual void scrollLeft(int nCols
= 1);
164 virtual void scrollRight(int nCols
= 1);
165 virtual void scrollUp(int nLines
= 1);
166 virtual void scrollDown(int nLines
= 1);
167 virtual void scrollPageUp();
168 virtual void scrollPageDown();
169 virtual void scrollTo(int x
, int y
);
170 virtual void zoomToRect(int pg
, double ulx
, double uly
,
171 double lrx
, double lry
);
172 virtual void setContinuousMode(GBool cm
);
176 // Current selected region.
177 void setSelection(int newSelectPage
,
178 int newSelectULX
, int newSelectULY
,
179 int newSelectLRX
, int newSelectLRY
);
180 void moveSelection(int pg
, int x
, int y
);
181 GBool
getSelection(int *pg
, double *ulx
, double *uly
,
182 double *lrx
, double *lry
);
185 GString
*extractText(int pg
, double xMin
, double yMin
,
186 double xMax
, double yMax
);
190 virtual GBool
find(char *s
, GBool caseSensitive
, GBool next
, GBool backward
,
192 virtual GBool
findU(Unicode
*u
, int len
, GBool caseSensitive
,
193 GBool next
, GBool backward
, GBool onePageOnly
);
196 //----- coordinate conversion
198 // user space: per-pace, as defined by PDF file; unit = point
199 // device space: (0,0) is upper-left corner of a page; unit = pixel
200 // window space: (0,0) is upper-left corner of drawing area; unit = pixel
202 GBool
cvtWindowToUser(int xw
, int yw
, int *pg
, double *xu
, double *yu
);
203 GBool
cvtWindowToDev(int xw
, int yw
, int *pg
, int *xd
, int *yd
);
204 void cvtUserToWindow(int pg
, double xy
, double yu
, int *xw
, int *yw
);
205 void cvtUserToDev(int pg
, double xu
, double yu
, int *xd
, int *yd
);
206 void cvtDevToWindow(int pg
, int xd
, int yd
, int *xw
, int *yw
);
207 void cvtDevToUser(int pg
, int xd
, int yd
, double *xu
, double *yu
);
211 PDFDoc
*getDoc() { return doc
; }
212 int getPageNum() { return topPage
; }
213 double getZoom() { return zoom
; }
214 double getZoomDPI() { return dpi
; }
215 int getRotate() { return rotate
; }
216 GBool
getContinuousMode() { return continuousMode
; }
217 virtual void setReverseVideo(GBool reverseVideoA
);
218 GBool
canGoBack() { return historyBLen
> 1; }
219 GBool
canGoForward() { return historyFLen
> 0; }
220 int getScrollX() { return scrollX
; }
221 int getScrollY() { return scrollY
; }
222 int getDrawAreaWidth() { return drawAreaWidth
; }
223 int getDrawAreaHeight() { return drawAreaHeight
; }
224 virtual void setBusyCursor(GBool busy
) = 0;
225 LinkAction
*findLink(int pg
, double x
, double y
);
229 int loadFile2(PDFDoc
*newDoc
);
230 void addPage(int pg
, int rot
);
231 void needTile(PDFCorePage
*page
, int x
, int y
);
232 void xorRectangle(int pg
, int x0
, int y0
, int x1
, int y1
,
233 SplashPattern
*pattern
, PDFCoreTile
*oneTile
= NULL
);
234 PDFCorePage
*findPage(int pg
);
235 static void redrawCbk(void *data
, int x0
, int y0
, int x1
, int y1
);
236 void redrawWindow(int x
, int y
, int width
, int height
,
238 virtual PDFCoreTile
*newTile(int xDestA
, int yDestA
);
239 virtual void updateTileData(PDFCoreTile
*tileA
,
240 int xSrc
, int ySrc
, int width
, int height
);
241 virtual void redrawRect(PDFCoreTile
*tileA
, int xSrc
, int ySrc
,
242 int xDest
, int yDest
, int width
, int height
) = 0;
243 void clippedRedrawRect(PDFCoreTile
*tile
, int xSrc
, int ySrc
,
244 int xDest
, int yDest
, int width
, int height
,
245 int xClip
, int yClip
, int wClip
, int hClip
,
247 virtual void updateScrollbars() = 0;
248 virtual GBool
checkForNewFile() { return gFalse
; }
250 PDFDoc
*doc
; // current PDF file
251 GBool continuousMode
; // false for single-page mode, true for
253 int drawAreaWidth
, // size of the PDF display area
255 double maxUnscaledPageW
, // maximum unscaled page size
257 int maxPageW
; // maximum page width (only used in
259 int totalDocH
; // total document height (only used in
261 int *pageY
; // top coordinates for each page (only used
262 // in continuous mode)
263 int topPage
; // page at top of window
264 int scrollX
, scrollY
; // offset from top left corner of topPage
265 // to top left corner of window
266 double zoom
; // current zoom level, in percent of 72 dpi
267 double dpi
; // current zoom level, in DPI
268 int rotate
; // current page rotation
270 int selectPage
; // page number of current selection
271 int selectULX
, // coordinates of current selection,
272 selectULY
, // in device space -- (ULX==LRX || ULY==LRY)
273 selectLRX
, // means there is no selection
275 GBool dragging
; // set while selection is being dragged
276 GBool lastDragLeft
; // last dragged selection edge was left/right
277 GBool lastDragTop
; // last dragged selection edge was top/bottom
279 PDFHistory
// page history queue
280 history
[pdfHistorySize
];
281 int historyCur
; // currently displayed page
282 int historyBLen
; // number of valid entries backward from
284 int historyFLen
; // number of valid entries forward from
288 GList
*pages
; // cached pages [PDFCorePage]
289 PDFCoreTile
*curTile
; // tile currently being rasterized
291 SplashColor paperColor
;
294 friend class PDFCoreTile
;