Changeset 155
- Timestamp:
- 05/09/06 06:55:01 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 modified
-
src/DocumentLink.cxx (modified) (3 diffs)
-
src/DocumentLink.h (modified) (1 diff)
-
src/DocumentRectangle.cxx (added)
-
src/DocumentRectangle.h (added)
-
src/Makefile.am (modified) (1 diff)
-
src/PDFDocument.cxx (modified) (2 diffs)
-
src/epdfview.h (modified) (1 diff)
-
tests/Makefile.am (modified) (2 diffs)
-
tests/PDFDocumentTest.cxx (modified) (2 diffs)
-
tests/PDFDocumentTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/DocumentLink.cxx
r148 r155 34 34 { 35 35 m_DestinationPage = destinationPage; 36 m_X1 = x1; 37 m_X2 = x2; 38 m_Y1 = y1; 39 m_Y2 = y2; 36 m_Rect = new DocumentRectangle (x1, y1, x2, y2); 40 37 } 41 38 … … 45 42 DocumentLink::~DocumentLink () 46 43 { 44 delete m_Rect; 47 45 } 48 46 … … 72 70 DocumentLink::positionIsOver (gint x, gint y) 73 71 { 74 return ( (gint)m_ X1 <= x && (gint)m_Y1<= y &&75 (gint)m_ X2 >= x && (gint)m_Y2>= y );72 return ( (gint)m_Rect->getX1 () <= x && (gint)m_Rect->getY1 () <= y && 73 (gint)m_Rect->getX2 () >= x && (gint)m_Rect->getY2 () >= y ); 76 74 } -
trunk/src/DocumentLink.h
r148 r155 42 42 /// The number of the link's destination page. 43 43 gint m_DestinationPage; 44 /// The X coordinate of the link's top-left corner. 45 gdouble m_X1; 46 /// The X coordinate of the link's bottom-right corner. 47 gdouble m_X2; 48 /// The Y coordinate of the link's top-left corner. 49 gdouble m_Y1; 50 /// The Y coordinate of the link's bottom-right corner. 51 gdouble m_Y2; 44 /// The link rectangle. 45 DocumentRectangle *m_Rect; 52 46 }; 53 47 } -
trunk/src/Makefile.am
r154 r155 13 13 DocumentPage.h \ 14 14 DocumentPage.cxx \ 15 DocumentRectangle.cxx \ 16 DocumentRectangle.h \ 15 17 epdfview.h \ 16 18 FindPter.cxx \ -
trunk/src/PDFDocument.cxx
r154 r155 57 57 PDFDocument::findTextInPage (gint pageNum, const gchar *textToFind) 58 58 { 59 return NULL; 59 GList *results = NULL; 60 61 if ( NULL == m_Document ) 62 { 63 return results; 64 } 65 66 PopplerPage *page = poppler_document_get_page (m_Document, pageNum - 1); 67 if ( NULL != page ) 68 { 69 gdouble height = 1.0; 70 poppler_page_get_size (page, NULL, &height); 71 gdouble scale = getZoom (); 72 GList *matches = poppler_page_find_text (page, textToFind); 73 for ( GList *match = g_list_first (matches) ; 74 NULL != match ; 75 match = g_list_next (match) ) 76 { 77 PopplerRectangle *matchRect = (PopplerRectangle *)match->data; 78 DocumentRectangle *rect = 79 new DocumentRectangle (matchRect->x1 * scale, 80 (height - matchRect->y2) * scale, 81 matchRect->x2 * scale, 82 (height - matchRect->y1) * scale); 83 results = g_list_prepend (results, rect); 84 } 85 } 86 87 return g_list_reverse (results); 60 88 } 61 89 … … 167 195 { 168 196 g_assert (NULL != m_Document && "The document has not been loaded."); 169 170 197 171 198 gchar *author = NULL; -
trunk/src/epdfview.h
r154 r155 24 24 #include <Config.h> 25 25 26 #include <DocumentRectangle.h> 26 27 #include <DocumentLink.h> 27 28 #include <DocumentOutline.h> -
trunk/tests/Makefile.am
r153 r155 25 25 FindPterTest.h \ 26 26 main.cxx \ 27 PDFDocumentTest.cxx \ 28 PDFDocumentTest.h \ 27 29 Utils.cxx \ 28 30 Utils.h … … 32 34 # PagePterTest.cxx 33 35 # PagePterTest.h 34 # PDFDocumentTest.cxx35 # PDFDocumentTest.h36 36 37 37 test_epdfview_CXXFLAGS = \ -
trunk/tests/PDFDocumentTest.cxx
r148 r155 621 621 gchar *testFile = getTestFile ("test1.pdf"); 622 622 m_Document->load (testFile, NULL); 623 g_free (testFile); 623 624 while ( !m_Observer->loadFinished () ) { } 624 625 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); … … 669 670 CPPUNIT_ASSERT_EQUAL (5, m_Document->getCurrentPageNum ()); 670 671 } 672 673 /// 674 /// @brief Tests finding text in a page. 675 /// 676 void 677 PDFDocumentTest::pageFindText () 678 { 679 gchar *testFile = getTestFile ("test1.pdf"); 680 m_Document->load (testFile, NULL); 681 g_free (testFile); 682 while ( !m_Observer->loadFinished () ) { } 683 684 // If a text doesn't exist on a page the list of found text is 685 // empty. 686 CPPUNIT_ASSERT (NULL == m_Document->findTextInPage (4, "nothing")); 687 // On the other hand, if something is found the list is filled with 688 // the rectangles the text is found. 689 GList *results = m_Document->findTextInPage (4, "first"); 690 CPPUNIT_ASSERT (NULL != results); 691 // In this case it should have found 2 results. 692 CPPUNIT_ASSERT_EQUAL ((guint)2, g_list_length (results)); 693 694 GList *firstResult = g_list_first (results); 695 { 696 DocumentRectangle *rect = (DocumentRectangle *)firstResult->data; 697 CPPUNIT_ASSERT_DOUBLES_EQUAL (82.00, rect->getX1 (), 0.0001); 698 CPPUNIT_ASSERT_DOUBLES_EQUAL (137.11, rect->getY1 (), 0.0001); 699 CPPUNIT_ASSERT_DOUBLES_EQUAL (100.34, rect->getX2 (), 0.0001); 700 CPPUNIT_ASSERT_DOUBLES_EQUAL (146.11, rect->getY2 (), 0.0001); 701 } 702 GList *secondResult = g_list_next (firstResult); 703 { 704 DocumentRectangle *rect = (DocumentRectangle *)secondResult->data; 705 CPPUNIT_ASSERT_DOUBLES_EQUAL (96.00, rect->getX1 (), 0.0001); 706 CPPUNIT_ASSERT_DOUBLES_EQUAL (148.11, rect->getY1 (), 0.0001); 707 CPPUNIT_ASSERT_DOUBLES_EQUAL (114.34, rect->getX2 (), 0.0001); 708 CPPUNIT_ASSERT_DOUBLES_EQUAL (157.11, rect->getY2 (), 0.0001); 709 } 710 g_list_free (results); 711 } -
trunk/tests/PDFDocumentTest.h
r147 r155 37 37 CPPUNIT_TEST (pageRender); 38 38 CPPUNIT_TEST (pageLinks); 39 CPPUNIT_TEST (pageFindText); 39 40 CPPUNIT_TEST_SUITE_END (); 40 41 … … 54 55 void pageRender (void); 55 56 void pageLinks (void); 57 void pageFindText (void); 56 58 57 59 private:
