Changeset 21
- Timestamp:
- 04/11/06 08:14:31 (3 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 5 modified
- 4 moved
-
src/Makefile.am (modified) (2 diffs)
-
src/PDFDocument.cxx (moved) (moved from trunk/src/Document.cxx) (28 diffs)
-
src/PDFDocument.h (moved) (moved from trunk/src/Document.h) (6 diffs)
-
src/epdfview.h (modified) (1 diff)
-
tests/DumbDocument.cxx (added)
-
tests/DumbDocument.h (added)
-
tests/DumbMainView.cxx (added)
-
tests/DumbMainView.h (added)
-
tests/MainPterTest.cxx (modified) (3 diffs)
-
tests/MainPterTest.h (modified) (2 diffs)
-
tests/Makefile.am (modified) (1 diff)
-
tests/PDFDocumentTest.cxx (moved) (moved from trunk/tests/DocumentTest.cxx) (19 diffs)
-
tests/PDFDocumentTest.h (moved) (moved from trunk/tests/DocumentTest.h) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r19 r21 3 3 4 4 libepdfview_a_SOURCES = \ 5 Document.cxx \6 Document.h \7 5 DocumentIndex.cxx \ 8 6 DocumentIndex.h \ … … 10 8 DocumentPage.cxx \ 11 9 epdfview.h \ 12 gettext.h 10 gettext.h \ 11 IDocument.cxx \ 12 IDocument.h \ 13 MainPter.cxx \ 14 MainPter.h \ 15 PDFDocument.cxx \ 16 PDFDocument.h 13 17 14 18 libepdfview_a_CXXFLAGS = \ -
trunk/src/PDFDocument.cxx
r19 r21 26 26 27 27 // Constants. 28 static const gdouble ZoomInFactor = 1.2f; 29 static const gdouble ZoomInMax = 4.0f; 30 static const gdouble ZoomOutFactor = (1.0f / ZoomInFactor); 31 static const gdouble ZoomOutMax = 0.05409; 32 static const gint cairoBytesPerPixel = 4; 28 static const gint CAIRO_BYTES_PER_PIXEL = 4; 33 29 34 30 // Forward declarations. … … 39 35 static PageMode convertPageMode (Catalog::PageMode pageMode); 40 36 41 /// This is the error domain that will be used to report Document's errors.42 GQuark Document::errorQuark = 0;43 44 ///45 /// @brief Gets the Document's error quark.46 ///47 /// The first time it's called will create the new quark value for the48 /// document class. Successive calls will just return the previously created49 /// quark value.50 ///51 /// @return The Document's quark.52 ///53 GQuark54 Document::getErrorQuark ()55 {56 if ( 0 == Document::errorQuark )57 Document::errorQuark = g_quark_from_static_string ("epdfview-document");58 59 return Document::errorQuark;60 }61 62 ///63 /// @brief Gives the error's description.64 ///65 /// This function looks the error at @a errorCode and gives an human66 /// readable error string.67 ///68 /// The error message must be freed using g_free().69 ///70 /// @param errorCode The error code to get the string from.71 ///72 /// @return An human readable error message.73 ///74 gchar *75 Document::getErrorMessage (DocumentError errorCode)76 {77 gchar *errorMessage = NULL;78 switch (errorCode)79 {80 case DocumentErrorNone:81 errorMessage = g_strdup (_("No error"));82 break;83 case DocumentErrorOpenFile:84 errorMessage = g_strdup (_("File not found."));85 break;86 case DocumentErrorBadCatalog:87 errorMessage = g_strdup (_("Couldn't read the page catalog."));88 break;89 case DocumentErrorDamaged:90 errorMessage = g_strdup (_("The PDF file is damaged and can't be repaired."));91 break;92 case DocumentErrorEncrypted:93 errorMessage = g_strdup (_("The file is encrypted and the password was incorrect or not supplied."));94 break;95 case DocumentErrorHighlightFile:96 errorMessage = g_strdup (_("Nonexistent or invlid highlight file."));97 break;98 case DocumentErrorBadPrinter:99 errorMessage = g_strdup (_("Invalid printer."));100 break;101 case DocumentErrorPrinting:102 errorMessage = g_strdup (_("Error during printing."));103 break;104 case DocumentErrorPermission:105 errorMessage = g_strdup (_("The PDF file doesn't allow that operation."));106 break;107 case DocumentErrorBadPageNumber:108 errorMessage = g_strdup (_("Invalid page number."));109 break;110 case DocumentErrorFileIO:111 errorMessage = g_strdup (_("File I/O error."));112 break;113 default:114 errorMessage = g_strdup_printf (_("Unknown error (%d)"), errorCode);115 }116 117 g_assert (NULL != errorMessage && "The error message is NULL");118 return errorMessage;119 }120 121 37 /// 122 38 /// @brief Constructs a new Document object. 123 39 /// 124 Document::Document () 40 PDFDocument::PDFDocument (): 41 IDocument () 125 42 { 126 43 m_Author = NULL; 127 44 m_CreationDate = NULL; 128 45 m_Creator = NULL; 129 m_CurrentPage = 0;130 46 m_Document = NULL; 131 m_DocumentIndex = new DocumentIndex ();132 m_FileName = NULL;133 47 m_Format = NULL; 134 48 m_Keywords = NULL; … … 140 54 m_PageNumber = 0; 141 55 m_Producer = NULL; 142 m_Rotation = 0;143 m_Scale = 0.0f;144 56 m_Subject = NULL; 145 57 m_Title = NULL; … … 149 61 /// @brief Deletes all dynamically created objects of Document. 150 62 /// 151 Document::~Document ()63 PDFDocument::~PDFDocument () 152 64 { 153 65 delete m_Document; 154 delete m_DocumentIndex;155 66 delete m_OutputDevice; 156 67 g_free (m_Author); 157 68 g_free (m_CreationDate); 158 69 g_free (m_Creator); 159 g_free (m_FileName);160 70 g_free (m_Format); 161 71 g_free (m_Keywords); … … 173 83 /// 174 84 gboolean 175 Document::isLoaded ()85 PDFDocument::isLoaded () 176 86 { 177 87 return (NULL != m_Document && m_Document->isOk ()); … … 191 101 /// 192 102 gboolean 193 Document::loadFile (const gchar *filename, const gchar *password,103 PDFDocument::loadFile (const gchar *filename, const gchar *password, 194 104 GError **error) 195 105 { … … 220 130 DocumentError errorCode = (DocumentError)newDocument->getErrorCode (); 221 131 delete newDocument; 222 gchar *errorMessage = Document::getErrorMessage (errorCode);132 gchar *errorMessage = IDocument::getErrorMessage (errorCode); 223 133 g_set_error (error, 224 134 EPDFVIEW_DOCUMENT_ERROR, errorCode, … … 230 140 } 231 141 232 g_free (m_FileName); 233 m_FileName = g_strdup (filename); 142 setFileName (filename); 234 143 delete m_Document; 235 144 m_Document = newDocument; … … 250 159 /// 251 160 const gchar * 252 Document::getTitle ()161 PDFDocument::getTitle () 253 162 { 254 163 if ( NULL == m_Title ) … … 266 175 /// 267 176 const gchar * 268 Document::getAuthor ()177 PDFDocument::getAuthor () 269 178 { 270 179 if ( NULL == m_Author ) … … 282 191 /// 283 192 const gchar * 284 Document::getSubject ()193 PDFDocument::getSubject () 285 194 { 286 195 if ( NULL == m_Subject ) … … 298 207 /// 299 208 const gchar * 300 Document::getKeywords ()209 PDFDocument::getKeywords () 301 210 { 302 211 if ( NULL == m_Keywords ) … … 314 223 /// 315 224 const gchar * 316 Document::getCreator ()225 PDFDocument::getCreator () 317 226 { 318 227 if ( NULL == m_Creator ) … … 330 239 /// 331 240 const gchar * 332 Document::getProducer ()241 PDFDocument::getProducer () 333 242 { 334 243 if ( NULL == m_Producer ) … … 337 246 } 338 247 return m_Producer; 339 }340 341 ///342 /// @brief Get the document's file name.343 ///344 /// @return The file name that contains the document, or an empty string345 /// if the document isn't loeaded yet.346 ///347 const gchar *348 Document::getFileName ()349 {350 if ( NULL == m_FileName )351 {352 return "";353 }354 return m_FileName;355 248 } 356 249 … … 363 256 /// 364 257 const gchar * 365 Document::getFormat ()258 PDFDocument::getFormat () 366 259 { 367 260 if ( NULL == m_Format ) … … 380 273 /// 381 274 const gchar * 382 Document::getLinearized ()275 PDFDocument::getLinearized () 383 276 { 384 277 if ( NULL == m_Linearized ) … … 396 289 /// 397 290 const gchar * 398 Document::getCreationDate ()291 PDFDocument::getCreationDate () 399 292 { 400 293 if ( NULL == m_CreationDate ) … … 412 305 /// 413 306 const gchar * 414 Document::getModifiedDate ()307 PDFDocument::getModifiedDate () 415 308 { 416 309 if ( NULL == m_ModifiedDate ) … … 428 321 /// 429 322 PageMode 430 Document::getPageMode ()323 PDFDocument::getPageMode () 431 324 { 432 325 return m_PageMode; … … 440 333 /// 441 334 PageLayout 442 Document::getPageLayout ()335 PDFDocument::getPageLayout () 443 336 { 444 337 return m_PageLayout; … … 452 345 /// 453 346 gint 454 Document::getNumPages ()347 PDFDocument::getNumPages () 455 348 { 456 349 return m_PageNumber; 457 }458 459 ///460 /// @brief Get the document's current page number.461 ///462 /// @return The number of the current page that we are viewing or 0 if the463 /// document has not been loaded yet.464 ///465 gint466 Document::getCurrentPageNum ()467 {468 return m_CurrentPage;469 }470 471 ///472 /// @brief Get the document's index.473 ///474 /// @return The top level DocumentIndex for this document.475 ///476 DocumentIndex &477 Document::getDocumentIndex ()478 {479 g_assert (NULL != m_DocumentIndex && "The document index is NULL.");480 481 return *(m_DocumentIndex);482 350 } 483 351 … … 490 358 /// 491 359 void 492 Document::loadMetadata (void)360 PDFDocument::loadMetadata (void) 493 361 { 494 362 g_assert (NULL != m_Document && "The document has not been loaded."); … … 534 402 // Get the number of pages and set the current to the first. 535 403 m_PageNumber = m_Document->getNumPages (); 536 m_CurrentPage = 1;404 goToFirstPage (); 537 405 538 406 // Set the current rotation angle and zoom level. … … 782 650 783 651 /// 784 /// @brief Goes to the document's first page.785 ///786 /// Changes the current page to be the first page of the787 /// document.788 ///789 void790 Document::goToFirstPage ()791 {792 goToPage (1);793 }794 795 ///796 /// @brief Goes to the document's last page.797 ///798 /// Changes the current page to be the last page of the799 /// document.800 ///801 void802 Document::goToLastPage ()803 {804 goToPage (getNumPages ());805 }806 807 ///808 /// @brief Goes the the document's next page.809 ///810 /// Changes the current page to be the next page. If the current page is811 /// already the last, then it will not change.812 ///813 void814 Document::goToNextPage ()815 {816 goToPage (getCurrentPageNum() + 1);817 }818 819 ///820 /// @brief Goes to a document page.821 ///822 /// Changes the current page to be the page @a pageNum. If @a pageNum is823 /// greater than the document's last page, then the current page becomes824 /// the last page. If @pageNum is instead less then the first page (i.e.,825 /// <= 0) then the current page becomes the first (i.e., 1).826 ///827 /// @param pageNum The page index to go to.828 ///829 void830 Document::goToPage (gint pageNum)831 {832 if ( pageNum > getNumPages () )833 {834 pageNum = getNumPages ();835 }836 else if ( pageNum < 1 )837 {838 pageNum = 1;839 }840 841 m_CurrentPage = pageNum;842 }843 844 ///845 /// @brief Goes to the document's previous page.846 ///847 /// Changes the current page to be the previous page. If the current page848 /// is already the first page, then it will not change.849 ///850 void851 Document::goToPreviousPage ()852 {853 goToPage (getCurrentPageNum () - 1);854 }855 856 ///857 /// @brief Gets the current rotation degrees.858 ///859 /// @return The current document's rotation degrees.860 ///861 gint862 Document::getRotation ()863 {864 return m_Rotation;865 }866 867 ///868 /// @brief Rotates 90 to the left.869 ///870 /// Substract 90 degress to the document's rotation.871 ///872 void873 Document::rotateLeft ()874 {875 m_Rotation = (m_Rotation - 90) % 360;876 if ( m_Rotation < 0 )877 {878 m_Rotation += 360;879 }880 }881 882 ///883 /// @brief Rotates 90 to the right.884 ///885 /// Adds 90 degress to the document's rotation.886 ///887 void888 Document::rotateRight ()889 {890 m_Rotation = (m_Rotation + 90) % 360;891 }892 893 ///894 /// @brief Checks if is possible to zoom in.895 ///896 /// Checks if after zooming int the zoom level will be below the max level.897 ///898 gboolean899 Document::canZoomIn (void)900 {901 return ( getZoom () * ZoomInFactor <= ZoomInMax );902 }903 904 ///905 /// @brief Checks if is possible to zoom out.906 ///907 /// Checks if after zoomin out the zoom level will be above the min level.908 ///909 gboolean910 Document::canZoomOut (void)911 {912 return ( getZoom () * ZoomOutFactor >= ZoomOutMax );913 }914 915 ///916 /// @brief Gets the current zoom.917 ///918 /// @return The current zoom or scale level.919 ///920 gfloat921 Document::getZoom (void)922 {923 return m_Scale;924 }925 926 ///927 /// @brief Zooms In.928 ///929 /// Adds a fixed ammount to the scale / zoom level.930 ///931 void932 Document::zoomIn (void)933 {934 if (canZoomIn ())935 {936 m_Scale *= ZoomInFactor;937 }938 }939 940 ///941 /// @brief Zooms Out.942 ///943 /// Substracts a fixed amount to the scale / zoom level.944 ///945 void946 Document::zoomOut (void)947 {948 if (canZoomOut ())949 {950 m_Scale *= ZoomOutFactor;951 }952 }953 954 ///955 /// @brief Zooms the document to fit the width and the height.956 ///957 /// It tries to get the best zoom / scale level that will let the958 /// document fit into @a width and @a height.959 ///960 /// @param width The width to fit the document to.961 /// @param height The height to fit the document to.962 ///963 void964 Document::zoomToFit (gint width, gint height)965 {966 gdouble pageWidth;967 gdouble pageHeight;968 969 getPageSize (&pageWidth, &pageHeight);970 // In this case we are interested in the minimum zoom level,971 // as is the one that fits best.972 gdouble widthScale = (gdouble)width / pageWidth;973 gdouble heightScale = (gdouble)height / pageHeight;974 m_Scale = MIN (widthScale, heightScale);975 }976 977 ///978 /// @brief Zooms the document to fit the width.979 ///980 /// It tries to get the best zooms / sclale level that will let the document981 /// fit into @a width, wihtout looking into any height.982 ///983 /// @param width The width to fit the document to.984 ///985 void986 Document::zoomToWidth (gint width)987 {988 gdouble pageWidth;989 gdouble pageHeight;990 991 getPageSize (&pageWidth, &pageHeight);992 m_Scale = (gdouble)width / pageWidth;993 }994 995 ///996 652 /// @brief Gets the current page's unscaled size. 997 653 /// … … 1003 659 /// 1004 660 void 1005 Document::getPageSize (gdouble *width, gdouble *height)661 PDFDocument::getPageSize (gdouble *width, gdouble *height) 1006 662 { 1007 663 g_assert (NULL != m_Document && "Tried to get size of a NULL document."); … … 1042 698 /// 1043 699 DocumentPage * 1044 Document::renderPage ()700 PDFDocument::renderPage () 1045 701 { 1046 702 // First create the document's page. … … 1058 714 1059 715 // Prepare the output device. 1060 gint cairoRowStride = width * cairoBytesPerPixel;716 gint cairoRowStride = width * CAIRO_BYTES_PER_PIXEL; 1061 717 gint cairoSize = cairoRowStride * height; 1062 718 guchar *cairoData = new guchar[cairoSize]; -
trunk/src/PDFDocument.h
r19 r21 16 16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 18 #if !defined (__DOCUMENT_H__) 19 #define __DOCUMENT_H__ 20 21 /// This is the definition of the GQuark used for Document's errors. 22 #define EPDFVIEW_DOCUMENT_ERROR ePDFView::Document::getErrorQuark () 18 #if !defined (__PDF_DOCUMENT_H__) 19 #define __PDF_DOCUMENT_H__ 23 20 24 21 namespace ePDFView 25 22 { 26 23 /// 27 /// @brief Defines the possible errors loading a document. 28 /// 29 /// This enumeration matches the definitions at ErrorCodes.h of Poppler. 30 /// 31 typedef enum 32 { 33 /// No error. 34 DocumentErrorNone = 0, 35 /// Couldn't open the PDF file. 36 DocumentErrorOpenFile = 1, 37 /// Coudln't read the page catalog. 38 DocumentErrorBadCatalog = 2, 39 /// PDF file is damaged and couldn't be repaired. 40 DocumentErrorDamaged = 3, 41 /// The file is encrypted and the password was incorrect 42 /// or not supplied. 43 DocumentErrorEncrypted = 4, 44 /// Nonexistent or invalid highlight file. 45 DocumentErrorHighlightFile = 5, 46 /// Invalid printer. 47 DocumentErrorBadPrinter = 6, 48 /// Error during printing. 49 DocumentErrorPrinting = 7, 50 /// PDF File doesn't allow that operation. 51 DocumentErrorPermission = 8, 52 /// Invalid page number. 53 DocumentErrorBadPageNumber = 9, 54 /// File I/O Error. 55 DocumentErrorFileIO = 10 56 } DocumentError; 57 58 /// 59 /// @brief Defines the document's page mode. 60 /// 61 typedef enum 62 { 63 PageModeOutlines, 64 PageModeThumbs, 65 PageModeFullScreen, 66 PageModeOC, 67 PageModeAttach, 68 // Not yet defined. 69 PageModeUnset 70 } PageMode; 71 72 /// 73 /// @brief Defines the document's page layout. 74 /// 75 typedef enum 76 { 77 PageLayoutSinglePage, 78 PageLayoutOneColumn, 79 PageLayoutTwoColumnLeft, 80 PageLayoutTwoColumnRight, 81 PageLayoutTwoPageLeft, 82 PageLayoutTwoPageRight, 83 // Not yet defined. 84 PageLayoutUnset 85 } PageLayout; 86 87 /// 88 /// @class Document 24 /// @class PDFDocument 89 25 /// @brief Has information about a single document. 90 26 /// … … 93 29 /// page, etc. is inside this class. 94 30 /// 95 class Document31 class PDFDocument: public IDocument 96 32 { 97 33 public: 98 Document (void);99 ~ Document (void);34 PDFDocument (void); 35 ~PDFDocument (void); 100 36 101 37 gboolean isLoaded (void); … … 108 44 const gchar *getCreator (void); 109 45 const gchar *getProducer (void); 110 const gchar *getFileName (void);111 46 const gchar *getFormat (void); 112 47 const gchar *getLinearized (void); … … 116 51 PageLayout getPageLayout (void); 117 52 gint getNumPages (void); 118 gint getCurrentPageNum (void);119 DocumentIndex &getDocumentIndex (void);120 53 121 void goToFirstPage (); 122 void goToLastPage (); 123 void goToNextPage (); 124 void goToPage (gint pageNum); 125 void goToPreviousPage (); 126 127 gint getRotation (void); 128 void rotateLeft (void); 129 void rotateRight (void); 130 131 gboolean canZoomIn (void); 132 gboolean canZoomOut (void); 133 gfloat getZoom (void); 134 void zoomIn (void); 135 void zoomOut (void); 136 void zoomToFit (gint width, gint height); 137 void zoomToWidth (gint width); 138 54 void getPageSize (gdouble *width, gdouble *height); 139 55 DocumentPage *renderPage (void); 140 141 static GQuark getErrorQuark (void);142 static gchar *getErrorMessage (DocumentError errorCode);143 56 144 57 protected:
