Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / xpdf / PDFCore.h
blob7fea6dfb555cd56391176b92a2fbfa703b73da8f
1 //========================================================================
2 //
3 // PDFCore.h
4 //
5 // Copyright 2004 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef PDFCORE_H
10 #define PDFCORE_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include <stdlib.h>
19 #include "SplashTypes.h"
20 #include "CharTypes.h"
22 class GString;
23 class GList;
24 class SplashBitmap;
25 class SplashPattern;
26 class BaseStream;
27 class PDFDoc;
28 class Links;
29 class LinkDest;
30 class LinkAction;
31 class TextPage;
32 class CoreOutputDev;
33 class PDFCore;
35 //------------------------------------------------------------------------
36 // zoom factor
37 //------------------------------------------------------------------------
39 #define zoomPage -1
40 #define zoomWidth -2
41 #define defZoom 125
43 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
48 // Number of pixels of matte color between pages in continuous mode.
49 #define continuousModePageSpacing 3
51 //------------------------------------------------------------------------
52 // PDFCorePage
53 //------------------------------------------------------------------------
55 class PDFCorePage {
56 public:
58 PDFCorePage(int pageA, int wA, int hA, int tileWA, int tileHA);
59 ~PDFCorePage();
61 int page;
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 //------------------------------------------------------------------------
72 // PDFCoreTile
73 //------------------------------------------------------------------------
75 class PDFCoreTile {
76 public:
78 PDFCoreTile(int xDestA, int yDestA);
79 virtual ~PDFCoreTile();
81 int xMin, yMin, xMax, yMax;
82 int xDest, yDest;
83 Guint edges;
84 SplashBitmap *bitmap;
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 //------------------------------------------------------------------------
98 // PDFHistory
99 //------------------------------------------------------------------------
101 struct PDFHistory {
102 GString *fileName;
103 int page;
106 #define pdfHistorySize 50
109 //------------------------------------------------------------------------
110 // PDFCore
111 //------------------------------------------------------------------------
113 class PDFCore {
114 public:
116 PDFCore(SplashColorMode colorModeA, int bitmapRowPadA,
117 GBool reverseVideoA, SplashColorPtr paperColorA);
118 virtual ~PDFCore();
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);
126 #ifdef WIN32
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);
131 #endif
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,
150 GBool addToHist);
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);
174 //----- selection
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);
184 // Text extraction.
185 GString *extractText(int pg, double xMin, double yMin,
186 double xMax, double yMax);
188 //----- find
190 virtual GBool find(char *s, GBool caseSensitive, GBool next, GBool backward,
191 GBool onePageOnly);
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);
209 //----- misc access
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);
227 protected:
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,
237 GBool needUpdate);
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,
246 GBool needUpdate);
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
252 // continuous mode
253 int drawAreaWidth, // size of the PDF display area
254 drawAreaHeight;
255 double maxUnscaledPageW, // maximum unscaled page size
256 maxUnscaledPageH;
257 int maxPageW; // maximum page width (only used in
258 // continuous mode)
259 int totalDocH; // total document height (only used in
260 // continuous mode)
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
274 selectLRY;
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
283 // current entry
284 int historyFLen; // number of valid entries forward from
285 // current entry
288 GList *pages; // cached pages [PDFCorePage]
289 PDFCoreTile *curTile; // tile currently being rasterized
291 SplashColor paperColor;
292 CoreOutputDev *out;
294 friend class PDFCoreTile;
297 #endif