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