Changeset 147
- Timestamp:
- 05/05/06 11:42:43 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 18 modified
-
src/DocumentLink.cxx (added)
-
src/DocumentLink.h (added)
-
src/DocumentPage.cxx (modified) (3 diffs)
-
src/DocumentPage.h (modified) (2 diffs)
-
src/IDocument.cxx (modified) (1 diff)
-
src/IDocument.h (modified) (1 diff)
-
src/IPageView.h (modified) (3 diffs)
-
src/MainPter.cxx (modified) (1 diff)
-
src/MainPter.h (modified) (1 diff)
-
src/Makefile.am (modified) (1 diff)
-
src/PDFDocument.cxx (modified) (3 diffs)
-
src/PDFDocument.h (modified) (2 diffs)
-
src/PagePter.cxx (modified) (3 diffs)
-
src/epdfview.h (modified) (1 diff)
-
src/gtk/PageView.cxx (modified) (2 diffs)
-
src/gtk/PageView.h (modified) (1 diff)
-
tests/DumbPageView.cxx (modified) (1 diff)
-
tests/DumbPageView.h (modified) (1 diff)
-
tests/PDFDocumentTest.cxx (modified) (1 diff)
-
tests/PDFDocumentTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/DocumentPage.cxx
r58 r147 31 31 m_Data = NULL; 32 32 m_Height = 0; 33 m_LinkList = NULL; 33 34 m_Width = 0; 34 35 } … … 40 41 { 41 42 delete[] m_Data; 43 for ( GList *linkItem = g_list_first (m_LinkList) ; 44 NULL != linkItem ; 45 linkItem = g_list_next (linkItem) ) 46 { 47 DocumentLink *link = (DocumentLink *)linkItem->data; 48 delete link; 49 } 50 g_list_free (m_LinkList); 51 } 52 53 void 54 DocumentPage::addLink (DocumentLink *link) 55 { 56 m_LinkList = g_list_prepend (m_LinkList, link); 42 57 } 43 58 … … 58 73 59 74 return m_Data; 75 } 76 77 DocumentLink * 78 DocumentPage::getLinkAtPosition (gint x, gint y) 79 { 80 DocumentLink *link = NULL; 81 82 for ( GList *linkItem = g_list_first (m_LinkList) ; 83 NULL != linkItem && NULL == link; 84 linkItem = g_list_next (linkItem) ) 85 { 86 DocumentLink *tmpLink = (DocumentLink *)linkItem->data; 87 if ( tmpLink->positionIsOver (x, y) ) 88 { 89 link = tmpLink; 90 } 91 } 92 93 return link; 60 94 } 61 95 -
trunk/src/DocumentPage.h
r49 r147 32 32 DocumentPage (void); 33 33 ~DocumentPage (void); 34 34 35 void addLink (DocumentLink *link); 35 36 guchar *getData (void); 36 37 gint getHeight (void); 38 DocumentLink *getLinkAtPosition (gint x, gint y); 37 39 gint getRowStride (void); 38 40 gint getWidth (void); … … 43 45 gint m_Height; 44 46 gint m_Width; 47 GList *m_LinkList; 45 48 }; 46 49 } -
trunk/src/IDocument.cxx
r145 r147 1227 1227 } 1228 1228 1229 gboolean 1230 IDocument::hasLinkAtPosition (gint x, gint y) 1231 { 1232 // XXX For now only non rotated pages. 1233 if ( 0 == getRotation () ) 1234 { 1235 DocumentPage *page = getCurrentPage (); 1236 if ( NULL != page ) 1237 { 1238 return (NULL != page->getLinkAtPosition (x, y)); 1239 } 1240 } 1241 return FALSE; 1242 } 1243 1244 void 1245 IDocument::activateLinkAtPosition (gint x, gint y) 1246 { 1247 DocumentPage *page = getCurrentPage (); 1248 // XXX For now only non rotated pages. 1249 if ( NULL != page && 0 == getRotation () ) 1250 { 1251 DocumentLink *link = page->getLinkAtPosition (x, y); 1252 if ( NULL != link ) 1253 { 1254 goToPage (link->getDestinationPage ()); 1255 } 1256 } 1257 } -
trunk/src/IDocument.h
r136 r147 256 256 void zoomToWidth (gint width); 257 257 258 gboolean hasLinkAtPosition (gint x, gint y); 259 void activateLinkAtPosition (gint x, gint y); 260 258 261 static GQuark getErrorQuark (void); 259 262 static gchar *getErrorMessage (DocumentError errorCode); -
trunk/src/IPageView.h
r146 r147 23 23 // Forward declarations. 24 24 class PagePter; 25 26 enum PageCursor 27 { 28 /// Normal cursor. 29 PAGE_VIEW_CURSOR_NORMAL, 30 /// Drag cursor. 31 PAGE_VIEW_CURSOR_DRAG, 32 /// Link cursor. 33 PAGE_VIEW_CURSOR_LINK 34 }; 25 35 26 36 /// … … 84 94 virtual void scrollPage (gdouble scrollX, gdouble scrollY, 85 95 gint dx, gint dy) = 0; 86 96 97 /// 98 /// @brief Sets the cursor for the page view. 99 /// 100 /// The view must change the cursor for the page image. 101 /// If the cursor to be set is the same as the current cursor, 102 /// the view can ignore the petition. 103 /// 104 /// @param cursorType The cursor to set. 105 /// 106 virtual void setCursor (PageCursor cursorType) = 0; 107 87 108 /// 88 109 /// @brief Shows a document's page. … … 100 121 /// 101 122 virtual void showPage (DocumentPage *page, PageScroll scroll) = 0; 102 103 123 104 124 protected: -
trunk/src/MainPter.cxx
r143 r147 589 589 /// @param error Where to save the error if there's one. 590 590 /// 591 bool 591 gboolean 592 592 MainPter::openDocument (const gchar *fileName, const gchar *oldPassword, 593 593 GError **error) -
trunk/src/MainPter.h
r138 r147 51 51 void goToPageActivated (void); 52 52 void goToPreviousPageActivated (void); 53 bool openDocument (const gchar *fileName, const gchar *oldPassword,54 GError **error);53 gboolean openDocument (const gchar *fileName, 54 const gchar *oldPassword, GError **error); 55 55 void openFileActivated (void); 56 56 void outlineActivated (DocumentOutline *outline); -
trunk/src/Makefile.am
r138 r147 7 7 Config.cxx \ 8 8 Config.h \ 9 DocumentLink.cxx \ 10 DocumentLink.h \ 9 11 DocumentOutline.cxx \ 10 12 DocumentOutline.h \ -
trunk/src/PDFDocument.cxx
r128 r147 233 233 } 234 234 235 void 236 PDFDocument::setLinks (DocumentPage *renderedPage, PopplerPage *popplerPage) 237 { 238 gdouble pageHeight = 1.0; 239 // Get the height, to calculate the Y position as the document's origin 240 // is at the bottom-left corner, not the top-left as the screen does. 241 poppler_page_get_size (popplerPage, NULL, &pageHeight); 242 // We'll already calculate the positions scaled. 243 gdouble scale = getZoom (); 244 GList *pageLinks = poppler_page_get_link_mapping (popplerPage); 245 for (GList *pageLink = g_list_first (pageLinks) ; 246 NULL != pageLink ; 247 pageLink = g_list_next (pageLink) ) 248 { 249 PopplerLinkMapping *link = (PopplerLinkMapping *)pageLink->data; 250 PopplerAction *action = link->action; 251 // Only internal links. 252 if ( POPPLER_ACTION_GOTO_DEST == action->type ) 253 { 254 PopplerActionGotoDest *actionGoTo = (PopplerActionGotoDest *)action; 255 DocumentLink *documentLink = 256 new DocumentLink (link->area.x1 * scale, 257 (pageHeight - link->area.y2) * scale, 258 link->area.x2 * scale, 259 (pageHeight - link->area.y1) * scale, 260 actionGoTo->dest->page_num); 261 renderedPage->addLink (documentLink); 262 } 263 } 264 } 265 235 266 /// 236 267 /// @brief Sets the document's outline. … … 311 342 *width = pageWidth; 312 343 *height = pageHeight; 344 345 g_object_unref (G_OBJECT (page)); 313 346 } 314 347 … … 353 386 getRotation (), pixbuf); 354 387 gdk_pixbuf_unref (pixbuf); 388 setLinks (renderedPage, page); 389 g_object_unref (G_OBJECT (page)); 355 390 356 391 return (renderedPage); -
trunk/src/PDFDocument.h
r120 r147 23 23 typedef struct _PopplerIndexIter PopplerIndexIter; 24 24 typedef struct _PopplerDocument PopplerDocument; 25 typedef struct _PopplerPage PopplerPage; 25 26 26 27 namespace ePDFView … … 51 52 void setOutline (DocumentOutline *outline, 52 53 PopplerIndexIter *childrenList); 54 void setLinks (DocumentPage *renderedPage, 55 PopplerPage *popplerPage); 53 56 }; 54 57 } -
trunk/src/PagePter.cxx
r146 r147 83 83 if ( 1 == button ) 84 84 { 85 m_DragInfo = new DragInfo; 86 m_DragInfo->x = x; 87 m_DragInfo->y = y; 88 m_DragInfo->scrollX = getView ().getHorizontalScroll (); 89 m_DragInfo->scrollY = getView ().getVerticalScroll (); 85 if ( m_Document->hasLinkAtPosition (x, y) ) 86 { 87 m_Document->activateLinkAtPosition (x, y); 88 } 89 else 90 { 91 m_DragInfo = new DragInfo; 92 m_DragInfo->x = x; 93 m_DragInfo->y = y; 94 95 IPageView &view = getView (); 96 m_DragInfo->scrollX = view.getHorizontalScroll (); 97 m_DragInfo->scrollY = view.getVerticalScroll (); 98 view.setCursor (PAGE_VIEW_CURSOR_DRAG); 99 } 90 100 } 91 101 } … … 98 108 delete m_DragInfo; 99 109 m_DragInfo = NULL; 110 getView ().setCursor (PAGE_VIEW_CURSOR_NORMAL); 100 111 } 101 112 } … … 104 115 PagePter::mouseMoved (gint x, gint y) 105 116 { 106 if ( NULL != m_DragInfo ) 107 { 108 getView ().scrollPage (m_DragInfo->scrollX, m_DragInfo->scrollY, 109 x - m_DragInfo->x, y - m_DragInfo->y); 117 IPageView &view = getView (); 118 if ( NULL == m_DragInfo ) 119 { 120 if ( m_Document->hasLinkAtPosition (x, y) ) 121 { 122 view.setCursor (PAGE_VIEW_CURSOR_LINK); 123 } 124 else 125 { 126 view.setCursor (PAGE_VIEW_CURSOR_NORMAL); 127 } 128 } 129 else 130 { 131 view.scrollPage (m_DragInfo->scrollX, m_DragInfo->scrollY, 132 x - m_DragInfo->x, y - m_DragInfo->y); 110 133 } 111 134 } -
trunk/src/epdfview.h
r138 r147 24 24 #include <Config.h> 25 25 26 #include <DocumentLink.h> 26 27 #include <DocumentOutline.h> 27 28 #include <DocumentPage.h> -
trunk/src/gtk/PageView.cxx
r146 r147 44 44 IPageView () 45 45 { 46 // The initial cursor is normal. 47 m_CurrentCursor = PAGE_VIEW_CURSOR_NORMAL; 48 46 49 // Create the scrolled window where the page image will be. 47 50 m_PageScroll = gtk_scrolled_window_new (NULL, NULL); … … 100 103 GTK_SCROLLED_WINDOW (m_PageScroll)); 101 104 return gtk_adjustment_get_value (vAdjustment); 105 } 106 107 void 108 PageView::setCursor (PageCursor cursorType) 109 { 110 if ( cursorType != m_CurrentCursor ) 111 { 112 GdkCursor *cursor = NULL; 113 switch (cursorType) 114 { 115 case PAGE_VIEW_CURSOR_LINK: 116 cursor = gdk_cursor_new (GDK_HAND2); 117 break; 118 case PAGE_VIEW_CURSOR_DRAG: 119 cursor = gdk_cursor_new (GDK_FLEUR); 120 break; 121 default: 122 cursor = NULL; 123 } 124 if ( NULL != m_EventBox && GDK_IS_WINDOW (m_EventBox->window) ) 125 { 126 gdk_window_set_cursor (m_EventBox->window, cursor); 127 } 128 if ( NULL != cursor ) 129 { 130 gdk_cursor_unref (cursor); 131 } 132 gdk_flush (); 133 m_CurrentCursor = cursorType; 134 } 102 135 } 103 136 -
trunk/src/gtk/PageView.h
r146 r147 35 35 void scrollPage (gdouble scrollX, gdouble scrollY, 36 36 gint dx, gint dy); 37 void setCursor (PageCursor cursorType); 37 38 void setPresenter (PagePter *pter); 38 39 void showPage (DocumentPage *page, PageScroll scroll); 39 40 40 41 protected: 42 PageCursor m_CurrentCursor; 41 43 GtkWidget *m_EventBox; 42 44 GtkWidget *m_PageImage; -
trunk/tests/DumbPageView.cxx
r146 r147 59 59 60 60 void 61 DumbPageView::setCursor (PageCursor cursorType) 62 { 63 } 64 65 void 61 66 DumbPageView::showPage (DocumentPage *page, PageScroll scroll) 62 67 { -
trunk/tests/DumbPageView.h
r146 r147 32 32 void scrollPage (gdouble scrollX, gdouble scrollY, 33 33 gint dx, gint dy); 34 void setCursor (PageCursor cursorType); 34 35 void showPage (DocumentPage *page, PageScroll scroll); 35 36 -
trunk/tests/PDFDocumentTest.cxx
r136 r147 604 604 g_free (testFile); 605 605 } 606 607 /// 608 /// @brief Tests the document's link. 609 /// 610 /// If a page has a links, we should be able to ask the document if the 611 /// mouse pointer is over any link (to be able to change the cursor) and to 612 /// tell the document to change the current page for the page a links points 613 /// to. 614 /// 615 /// All this should happen even if the page is resized but will keep things 616 /// simple for now and only for unrotated documents. 617 /// 618 void 619 PDFDocumentTest::pageLinks () 620 { 621 gchar *testFile = getTestFile ("test1.pdf"); 622 m_Document->load (testFile, NULL); 623 while ( !m_Observer->loadFinished () ) { } 624 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 625 CPPUNIT_ASSERT (m_Document->isLoaded ()); 626 627 // In this test PDF document there are two links on page 4. 628 // Both links points to page 5 and are situated at: 629 // ((72.00, 147.11), (134.50, 137.11)) 630 // ((96.00, 158.11), (145.17, 148.11)) 631 // 632 // First try with an unscaled document. 633 m_Document->goToPage (4); 634 DocumentPage *page = NULL; 635 while ( NULL == page || (DocumentPage *)0xdeadbeef == page ) 636 { 637 page = m_Document->getCurrentPage (); 638 } 639 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (70, 140)); 640 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (76, 40)); 641 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (136, 139)); 642 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (130, 160)); 643 CPPUNIT_ASSERT (m_Document->hasLinkAtPosition (76, 139)); 644 CPPUNIT_ASSERT (m_Document->hasLinkAtPosition (100, 150)); 645 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (90, 151)); 646 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (100, 130)); 647 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (110, 160)); 648 CPPUNIT_ASSERT (!m_Document->hasLinkAtPosition (150, 152)); 649 650 // Active a link and let see how the page is changed. 651 m_Document->activateLinkAtPosition (76, 139); 652 CPPUNIT_ASSERT_EQUAL (5, m_Document->getCurrentPageNum ()); 653 654 // Now try the same but with an scaled page. (x1.2) 655 // With this scale the links are now at: 656 // ((86.40, 176.53), (160.80, 164.53)) 657 // ((115.2, 189.73), (174.20, 177.73)) 658 // 659 m_Document->zoomIn (); 660 m_Document->goToPage (4); 661 page = NULL; 662 while ( NULL == page || (DocumentPage *)0xdeadbeef == page ) 663 { 664 page = m_Document->getCurrentPage (); 665 } 666 // Just check the first link and activate the second. 667 CPPUNIT_ASSERT (m_Document->hasLinkAtPosition (87, 175)); 668 m_Document->activateLinkAtPosition (174, 177); 669 CPPUNIT_ASSERT_EQUAL (5, m_Document->getCurrentPageNum ()); 670 } -
trunk/tests/PDFDocumentTest.h
r130 r147 36 36 CPPUNIT_TEST (pageZoom); 37 37 CPPUNIT_TEST (pageRender); 38 CPPUNIT_TEST (pageLinks); 38 39 CPPUNIT_TEST_SUITE_END (); 39 40 … … 52 53 void pageZoom (void); 53 54 void pageRender (void); 55 void pageLinks (void); 54 56 55 57 private:
