root/trunk/src/IDocument.h
| Revision 277, 15.8 kB (checked in by jordi, 15 months ago) |
|---|
| Line | |
|---|---|
| 1 | // ePDFView - A lightweight PDF Viewer. |
| 2 | // Copyright (C) 2006 Emma's Software. |
| 3 | // |
| 4 | // This program is free software; you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation; either version 2 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program; if not, write to the Free Software |
| 16 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | |
| 18 | #if !defined (__IDOCUMENT_H__) |
| 19 | #define __IDOCUMENT_H__ |
| 20 | |
| 21 | /// This is the definition of the GQuark used for Document's errors. |
| 22 | #define EPDFVIEW_DOCUMENT_ERROR ePDFView::IDocument::getErrorQuark () |
| 23 | |
| 24 | typedef struct _GdkRegion GdkRegion; |
| 25 | |
| 26 | namespace ePDFView |
| 27 | { |
| 28 | // Forward declarations. |
| 29 | class DocumentIndex; |
| 30 | class IDocumentObserver; |
| 31 | class DocumentPage; |
| 32 | |
| 33 | /// |
| 34 | /// @brief Defines the possible errors loading a document. |
| 35 | /// |
| 36 | /// This enumeration matches the definitions at ErrorCodes.h of Poppler. |
| 37 | /// |
| 38 | typedef enum |
| 39 | { |
| 40 | /// No error. |
| 41 | DocumentErrorNone = 0, |
| 42 | /// Couldn't open the PDF file. |
| 43 | DocumentErrorOpenFile = 1, |
| 44 | /// Couldn't read the page catalog. |
| 45 | DocumentErrorBadCatalog = 2, |
| 46 | /// PDF file is damaged and couldn't be repaired. |
| 47 | DocumentErrorDamaged = 3, |
| 48 | /// The file is encrypted and the password was incorrect |
| 49 | /// or not supplied. |
| 50 | DocumentErrorEncrypted = 4, |
| 51 | /// Nonexistent or invalid highlight file. |
| 52 | DocumentErrorHighlightFile = 5, |
| 53 | /// Invalid printer. |
| 54 | DocumentErrorBadPrinter = 6, |
| 55 | /// Error during printing. |
| 56 | DocumentErrorPrinting = 7, |
| 57 | /// PDF File doesn't allow that operation. |
| 58 | DocumentErrorPermission = 8, |
| 59 | /// Invalid page number. |
| 60 | DocumentErrorBadPageNumber = 9, |
| 61 | /// File I/O Error. |
| 62 | DocumentErrorFileIO = 10 |
| 63 | } DocumentError; |
| 64 | |
| 65 | /// |
| 66 | /// @brief Defines the document's page mode when opened. |
| 67 | /// |
| 68 | typedef enum |
| 69 | { |
| 70 | /// Document outline visible. |
| 71 | PageModeOutlines, |
| 72 | /// Thumbnail images visible. |
| 73 | PageModeThumbs, |
| 74 | /// Full-screen mode, with no menu bar, window controls or any |
| 75 | /// other window visible. |
| 76 | PageModeFullScreen, |
| 77 | /// Optional content group panel visible. |
| 78 | PageModeOC, |
| 79 | /// Attachments panel visible. |
| 80 | PageModeAttach, |
| 81 | /// Not set and neither outline nor thumbnail images visible. |
| 82 | PageModeUnset |
| 83 | } PageMode; |
| 84 | |
| 85 | /// |
| 86 | /// @brief Defines the document's page layout when opened. |
| 87 | /// |
| 88 | typedef enum |
| 89 | { |
| 90 | /// Display one page at a time. |
| 91 | PageLayoutSinglePage, |
| 92 | /// Display the pages on one column. |
| 93 | PageLayoutOneColumn, |
| 94 | /// Display the pages in two columns, with odd-numbered pages |
| 95 | /// on the left. |
| 96 | PageLayoutTwoColumnLeft, |
| 97 | /// Display the pages in two columns, with odd-numbered pages |
| 98 | /// on the right. |
| 99 | PageLayoutTwoColumnRight, |
| 100 | /// Display the pages two at a time, with odd-numbered pages |
| 101 | /// on the left. |
| 102 | PageLayoutTwoPageLeft, |
| 103 | /// Display the pages two at a time, with odd-numbered pages |
| 104 | /// on the right. |
| 105 | PageLayoutTwoPageRight, |
| 106 | /// The page layout was not set yet. |
| 107 | PageLayoutUnset |
| 108 | } PageLayout; |
| 109 | |
| 110 | /// |
| 111 | /// @brief A cached page. |
| 112 | /// |
| 113 | typedef struct |
| 114 | { |
| 115 | /// The page's age in the cache. |
| 116 | guint32 age; |
| 117 | /// The page's number. |
| 118 | gint pageNumber; |
| 119 | /// The rendered page image. |
| 120 | DocumentPage *pageImage; |
| 121 | } PageCache; |
| 122 | |
| 123 | /// |
| 124 | /// @class IDocument |
| 125 | /// @brief Interface for documents. |
| 126 | /// |
| 127 | /// Every document type that the application can handle must be |
| 128 | /// created from this base class. |
| 129 | /// Besides the abstracts methods for open a document, this class also |
| 130 | /// handles the rotation and zoom levels for any IDocument's child class. |
| 131 | /// |
| 132 | class IDocument |
| 133 | { |
| 134 | public: |
| 135 | virtual ~IDocument (void); |
| 136 | |
| 137 | /// |
| 138 | /// @brief Makes a copy of the document. |
| 139 | /// |
| 140 | /// This function must make a deep copy of the current document |
| 141 | /// and return the result. |
| 142 | /// |
| 143 | /// @return A new document class with the same content than the |
| 144 | /// caller document. |
| 145 | /// |
| 146 | virtual IDocument *copy (void) const = 0; |
| 147 | |
| 148 | /// |
| 149 | /// @brief Finds text on a single page. |
| 150 | /// |
| 151 | /// The document must find the given text in the indicated page |
| 152 | /// number. |
| 153 | /// |
| 154 | /// @param pageNum The number of the page to find the text in. |
| 155 | /// @param textToFind The text to find in the page. |
| 156 | /// |
| 157 | /// @return The list of positions on the page that the text |
| 158 | /// was found. If the text is not found on the page, |
| 159 | /// then it must result NULL. |
| 160 | /// |
| 161 | virtual GList *findTextInPage (gint pageNum, |
| 162 | const gchar *textToFind) = 0; |
| 163 | |
| 164 | /// |
| 165 | /// @brief Checks if the document has been loaded. |
| 166 | /// |
| 167 | /// @return TRUE if the document has been loaded or FALSE otherwise. |
| 168 | /// |
| 169 | virtual gboolean isLoaded (void) = 0; |
| 170 | |
| 171 | /// |
| 172 | /// @brief Load a document file. |
| 173 | /// |
| 174 | /// Tries to open the document file @a filename using @a password |
| 175 | /// as a password to decrypt the document. |
| 176 | /// |
| 177 | /// The rotation degree is reset to 0 and the scale level to 1.0f |
| 178 | /// |
| 179 | /// @param filename The path, absolute or relative, to the file name |
| 180 | /// to open. |
| 181 | /// @param password The password to use to decrypt @a filename. If |
| 182 | /// the file is not encrypted, you can set it to |
| 183 | /// NULL. |
| 184 | /// @param error Location to store any error that could happen or |
| 185 | /// set to NULL to ignore errors. |
| 186 | /// |
| 187 | /// @return TRUE if the file could be opened. FALSE otherwise. |
| 188 | /// |
| 189 | virtual gboolean loadFile (const gchar *filename, |
| 190 | const gchar *password, |
| 191 | GError **error) = 0; |
| 192 | |
| 193 | /// |
| 194 | /// @brief Gets a document's page's unscaled size. |
| 195 | /// |
| 196 | /// Retrieves the width and height of a document's page before |
| 197 | /// scaling, but after rotate it. |
| 198 | /// |
| 199 | /// @param pageNum The page to get its size. |
| 200 | /// @param width The location to save the page's width. |
| 201 | /// @param height The location to save the page's height. |
| 202 | /// |
| 203 | virtual void getPageSizeForPage (gint pageNum, gdouble *width, |
| 204 | gdouble *height) = 0; |
| 205 | |
| 206 | /// |
| 207 | /// @brief Starts the output to PostScript. |
| 208 | /// |
| 209 | /// This starts a new PostScript file with name @a fileName and |
| 210 | /// with @a numPages pages of @a width x @a height. |
| 211 | /// |
| 212 | /// @param fileName The file name to output the postscript code. |
| 213 | /// @param numOfPages The number of pages to output. |
| 214 | /// @param pageWidth The width of each page. |
| 215 | /// @param pageHeight The height of each page. |
| 216 | /// |
| 217 | virtual void outputPostscriptBegin (const gchar *fileName, |
| 218 | guint numOfPages, |
| 219 | gfloat pageWidth, |
| 220 | gfloat pageHeight) = 0; |
| 221 | |
| 222 | /// |
| 223 | /// @brief Ends the output to PostScript. |
| 224 | /// |
| 225 | /// Ends any started output to PostScript by calling |
| 226 | /// outputPostscriptBegin (). |
| 227 | /// |
| 228 | virtual void outputPostscriptEnd (void) = 0; |
| 229 | |
| 230 | /// |
| 231 | /// @brief Renders a single page to PostScript. |
| 232 | /// |
| 233 | /// Renders the page @a pageNum To the PostScript started |
| 234 | /// at outputPostscriptBegin (). |
| 235 | /// |
| 236 | /// @param pageNum The number of the page to render. |
| 237 | /// |
| 238 | virtual void outputPostscriptPage (guint pageNum) = 0; |
| 239 | |
| 240 | /// |
| 241 | /// @brief Renders a document's page. |
| 242 | /// |
| 243 | /// Rendering a document's page means to get the pixels for the |
| 244 | /// page image given the current rotation and scale level. |
| 245 | /// |
| 246 | /// @param pageNum The page number to render. |
| 247 | /// |
| 248 | /// @return A DocumentPage with the image. The returned page must |
| 249 | /// be freed by calling delete when done with it. |
| 250 | /// |
| 251 | virtual DocumentPage *renderPage (gint pageNum) = 0; |
| 252 | |
| 253 | /// |
| 254 | /// @brief Saves a document's copy to a file. |
| 255 | /// |
| 256 | /// Tries to save the document to file @a filename. |
| 257 | /// |
| 258 | /// @param filename The path, absolute or relative, to the file name |
| 259 | /// to save the copy to. |
| 260 | /// @param error Location to store any error that could happen or |
| 261 | /// set to NULL to ignore errors. |
| 262 | /// |
| 263 | /// @return TRUE if the file could be saved. FALSE otherwise. |
| 264 | /// |
| 265 | virtual gboolean saveFile (const gchar *filename, |
| 266 | GError **error) = 0; |
| 267 | |
| 268 | virtual GdkRegion* getTextRegion (DocumentRectangle *rect) = 0; |
| 269 | virtual void setTextSelection (DocumentRectangle *rect) = 0; |
| 270 | |
| 271 | void attach (const IDocumentObserver *observer); |
| 272 | void detach (const IDocumentObserver *observer); |
| 273 | |
| 274 | void notifyFindChanged (gint pageNum, DocumentRectangle *matchRect); |
| 275 | void notifyFindFinished (void); |
| 276 | void notifyFindStarted (void); |
| 277 | void notifyLoad (void); |
| 278 | void notifyLoadError (const GError *error); |
| 279 | void notifyLoadPassword (const gchar *fileName, gboolean reload, |
| 280 | const GError *error); |
| 281 | void notifyPageChanged (void); |
| 282 | void notifyPageRendered (gint pageNumber, |
| 283 | guint32 age, DocumentPage *pageImage); |
| 284 | void notifyPageRotated (void); |
| 285 | void notifyPageZoomed (void); |
| 286 | void notifyReload (void); |
| 287 | void notifySave (void); |
| 288 | void notifySaveError (const GError *error); |
| 289 | |
| 290 | const gchar *getTitle (void); |
| 291 | void setTitle (gchar *title); |
| 292 | const gchar *getAuthor (void); |
| 293 | void setAuthor (gchar *author); |
| 294 | const gchar *getSubject (void); |
| 295 | void setSubject (gchar *subject); |
| 296 | const gchar *getKeywords (void); |
| 297 | void setKeywords (gchar *keywords); |
| 298 | const gchar *getCreator (void); |
| 299 | void setCreator (gchar *creator); |
| 300 | const gchar *getPassword (void) const; |
| 301 | void setPassword (const gchar *password); |
| 302 | const gchar *getProducer (void); |
| 303 | void setProducer (gchar *producer); |
| 304 | const gchar *getFileName (void) const; |
| 305 | void setFileName (const gchar *fileName); |
| 306 | const gchar *getFormat (void); |
| 307 | void setFormat (gchar *format); |
| 308 | const gchar *getLinearized (void); |
| 309 | void setLinearized (gchar *linearized); |
| 310 | const gchar *getCreationDate (void); |
| 311 | void setCreationDate (gchar *date); |
| 312 | const gchar *getModifiedDate (void); |
| 313 | void setModifiedDate (gchar *date); |
| 314 | PageMode getPageMode (void); |
| 315 | void setPageMode (PageMode mode); |
| 316 | PageLayout getPageLayout (void); |
| 317 | void setPageLayout (PageLayout layout); |
| 318 | void getPageSize (gdouble *width, gdouble *height); |
| 319 | gint getNumPages (void); |
| 320 | void setNumPages (gint numPages); |
| 321 | DocumentPage *getCurrentPage (void); |
| 322 | DocumentPage *getEmptyPage (void); |
| 323 | gint getCurrentPageNum (void); |
| 324 | DocumentOutline *getOutline (void); |
| 325 | |
| 326 | void clearCache (void); |
| 327 | |
| 328 | void load (const gchar *fileName, const gchar *password); |
| 329 | void reload (void); |
| 330 | void save (const gchar *fileName); |
| 331 | |
| 332 | void goToFirstPage (void); |
| 333 | void goToLastPage (void); |
| 334 | void goToNextPage (void); |
| 335 | void goToPage (gint pageNum); |
| 336 | void goToPreviousPage (void); |
| 337 | |
| 338 | gint getRotation (void); |
| 339 | void setRotation (gint rotation); |
| 340 | void rotateLeft (void); |
| 341 | void rotateRight (void); |
| 342 | |
| 343 | gboolean canZoomIn (void); |
| 344 | gboolean canZoomOut (void); |
| 345 | gdouble getZoom (void); |
| 346 | void setZoom (gdouble zoom); |
| 347 | void zoomIn (void); |
| 348 | void zoomOut (void); |
| 349 | void zoomToFit (gint width, gint height); |
| 350 | void zoomToWidth (gint width); |
| 351 | |
| 352 | gboolean hasLinkAtPosition (gint x, gint y); |
| 353 | void activateLinkAtPosition (gint x, gint y); |
| 354 | |
| 355 | static GQuark getErrorQuark (void); |
| 356 | static gchar *getErrorMessage (DocumentError errorCode); |
| 357 | |
| 358 | protected: |
| 359 | static GQuark errorQuark; |
| 360 | |
| 361 | IDocument (void); |
| 362 | void addPageToCache (gint pageNum); |
| 363 | PageCache *getCachedPage (gint pageNum); |
| 364 | void refreshCache (void); |
| 365 | |
| 366 | /// The document's author. |
| 367 | gchar *m_Author; |
| 368 | /// The document's creation date and time. |
| 369 | gchar *m_CreationDate; |
| 370 | /// The document's software creator. |
| 371 | gchar *m_Creator; |
| 372 | /// The document's currently shown page. |
| 373 | gint m_CurrentPage; |
| 374 | /// The currently selected result from a search. |
| 375 | DocumentRectangle *m_FindRect; |
| 376 | /// The page number where IDocument::m_FindRect belongs to. |
| 377 | gint m_FindPage; |
| 378 | /// The document's format. |
| 379 | gchar *m_Format; |
| 380 | /// The document's password. |
| 381 | gchar *m_FileName; |
| 382 | /// The document's keyword. |
| 383 | gchar *m_Keywords; |
| 384 | /// Tells if the document is linearized or not. |
| 385 | gchar *m_Linearized; |
| 386 | /// The document's modification date and time. |
| 387 | gchar *m_ModifiedDate; |
| 388 | /// @brief The list of classes that will receive notifications |
| 389 | /// when the document changes. |
| 390 | GList *m_Observers; |
| 391 | /// The document's outline or index. |
| 392 | DocumentOutline *m_Outline; |
| 393 | /// The cache of already rendered document's pages. |
| 394 | GList *m_PageCache; |
| 395 | /// The age that will get the next page of the cache. |
| 396 | gint m_PageCacheAge; |
| 397 | /// The document's page layout. |
| 398 | PageLayout m_PageLayout; |
| 399 | /// The document's page mode. |
| 400 | PageMode m_PageMode; |
| 401 | /// The number of pages the document has. |
| 402 | gint m_PageNumber; |
| 403 | /// The last password used to open the document. |
| 404 | gchar *m_Password; |
| 405 | /// The document's software producer. |
| 406 | gchar *m_Producer; |
| 407 | /// The document's current rotation in degrees. |
| 408 | gint m_Rotation; |
| 409 | /// The document's current zoom or scale level. |
| 410 | gdouble m_Scale; |
| 411 | /// The document's subject. |
| 412 | gchar *m_Subject; |
| 413 | /// The document's title. |
| 414 | gchar *m_Title; |
| 415 | }; |
| 416 | } |
| 417 | |
| 418 | #endif // !__IDOCUMENT_H__ |
Note: See TracBrowser
for help on using the browser.
