Changeset 196

Show
Ignore:
Timestamp:
05/28/06 11:53:35 (2 years ago)
Author:
jordi
Message:

The old DocumentLink? class is now the IDocumentLink interface and only handles the link's rectangle. The functionality of the old DocumentLink? class is now inside the IDocumentLink derived DocumentLinkGoto? class.

The links are now created inside PDFDocument::createDocumentLink function and can be of DocumentLinkGoto? for internal references or DocumentLinkUri? for internet addresses (not yet implemented).

Location:
trunk/src
Files:
4 added
7 modified
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/DocumentPage.cxx

    r172 r196  
    4646          linkItem = g_list_next (linkItem) ) 
    4747    { 
    48         DocumentLink *link = (DocumentLink *)linkItem->data; 
     48        IDocumentLink *link = (IDocumentLink *)linkItem->data; 
    4949        delete link; 
    5050    } 
     
    6161/// 
    6262void 
    63 DocumentPage::addLink (DocumentLink *link) 
     63DocumentPage::addLink (IDocumentLink *link) 
    6464{ 
    6565    m_LinkList = g_list_prepend (m_LinkList, link); 
     
    111111/// @return The link under the position (x, y) or NULL if no link exists. 
    112112/// 
    113 DocumentLink * 
     113IDocumentLink * 
    114114DocumentPage::getLinkAtPosition (gint x, gint y) 
    115115{ 
    116     DocumentLink *link = NULL; 
     116    IDocumentLink *link = NULL; 
    117117 
    118118    for ( GList *linkItem = g_list_first (m_LinkList) ; 
     
    120120          linkItem = g_list_next (linkItem) ) 
    121121    { 
    122         DocumentLink *tmpLink = (DocumentLink *)linkItem->data; 
     122        IDocumentLink *tmpLink = (IDocumentLink *)linkItem->data; 
    123123        if ( tmpLink->positionIsOver (x, y) ) 
    124124        { 
     
    126126        } 
    127127    } 
    128      
     128 
    129129    return link; 
    130130} 
  • trunk/src/DocumentPage.h

    r163 r196  
    3232            DocumentPage (void); 
    3333            ~DocumentPage (void); 
    34             
    35             void addLink (DocumentLink *link); 
     34 
     35            void addLink (IDocumentLink *link); 
    3636            void clearSelection (void); 
    3737            guchar *getData (void); 
    3838            gint getHeight (void); 
    39             DocumentLink *getLinkAtPosition (gint x, gint y); 
     39            IDocumentLink *getLinkAtPosition (gint x, gint y); 
    4040            gint getRowStride (void); 
    4141            gint getWidth (void); 
  • trunk/src/IDocument.cxx

    r172 r196  
    14761476    if ( NULL != page && 0 == getRotation () ) 
    14771477    { 
    1478         DocumentLink *link = page->getLinkAtPosition (x, y); 
     1478        IDocumentLink *link = page->getLinkAtPosition (x, y); 
    14791479        if ( NULL != link ) 
    14801480        { 
    1481             goToPage (link->getDestinationPage ()); 
     1481            link->activate (this); 
    14821482        } 
    1483     }     
    1484 } 
     1483    } 
     1484} 
  • trunk/src/IDocumentLink.cxx

    r155 r196  
    2222 
    2323/// 
    24 /// @brief Construct a new DocumentLink object. 
     24/// @brief Construct a new IDocumentLink object. 
    2525/// 
    2626/// @param x1 The X coordinate of the link's top-left corner. 
     
    2828/// @param x2 The X coordinate of the link's bottom-right corner. 
    2929/// @param y2 The Y coordinate of the link's bottom-right corner. 
    30 /// @param destinationPage The page number the links points to. 
    3130/// 
    32 DocumentLink::DocumentLink (gdouble x1, gdouble y1, gdouble x2, gdouble y2, 
    33                             gint destinationPage) 
     31IDocumentLink::IDocumentLink (gdouble x1, gdouble y1, gdouble x2, gdouble y2) 
    3432{ 
    35     m_DestinationPage = destinationPage; 
    3633    m_Rect = new DocumentRectangle (x1, y1, x2, y2); 
    3734} 
    3835 
    3936/// 
    40 /// @brief Destroys all dynamically allocated memory by DocumentLink. 
     37/// @brief Destroys all dynamically allocated memory by IDocumentLink. 
    4138/// 
    42 DocumentLink::~DocumentLink () 
     39IDocumentLink::~IDocumentLink () 
    4340{ 
    4441    delete m_Rect; 
    4542} 
    4643 
    47 /// 
    48 /// @brief Gets the destination page number. 
    49 /// 
    50 /// @return The page number the link's points at. 
    51 /// 
    52 gint 
    53 DocumentLink::getDestinationPage () 
    54 { 
    55     return m_DestinationPage; 
    56 } 
    57  
    58 /// 
    5944/// @brief Checks if a position is over the link. 
    6045/// 
     
    6853/// 
    6954gboolean 
    70 DocumentLink::positionIsOver (gint x, gint y) 
     55IDocumentLink::positionIsOver (gint x, gint y) 
    7156{ 
    7257    return ( (gint)m_Rect->getX1 () <= x && (gint)m_Rect->getY1 () <= y && 
  • trunk/src/IDocumentLink.h

    r155 r196  
    1616// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1717 
    18 #if !defined (__DOCUMENT_LINK_H__) 
    19 #define __DOCUMENT_LINK_H__ 
     18#if !defined (__IDOCUMENT_LINK_H__) 
     19#define __IDOCUMENT_LINK_H__ 
    2020 
    2121namespace ePDFView 
    2222{ 
     23    // Forward declarations. 
     24    class IDocument; 
     25 
    2326    /// 
    24     /// @class DocumentLink 
     27    /// @class IDocumentLink 
    2528    /// @brief A single link on a page. 
    2629    /// 
    2730    /// This class is used by ePDFView::DocumentPage to maintain a list 
    28     /// of all links that a single page have. A link, in this version of 
    29     /// ePDFView, is just a rectangle on a page that points to another page. 
     31    /// of all links that a single page have. 
    3032    /// 
    31     class DocumentLink 
     33    class IDocumentLink 
    3234    { 
    3335        public: 
    34             DocumentLink (gdouble x1, gdouble y1, gdouble x2, gdouble y1, 
    35                           gint destinationPage); 
    36             ~DocumentLink (void); 
     36            IDocumentLink (gdouble x1, gdouble y1, gdouble x2, gdouble y1); 
     37            virtual ~IDocumentLink (void); 
    3738 
    38             gint getDestinationPage (void); 
     39            virtual void activate (IDocument *document) = 0; 
    3940            gboolean positionIsOver (gint x, gint y); 
    4041 
    4142        protected: 
    42             /// The number of the link's destination page. 
    43             gint m_DestinationPage; 
    4443            /// The link rectangle. 
    4544            DocumentRectangle *m_Rect; 
     
    4746} 
    4847 
    49 #endif // !__DOCUMENT_LINK_H__ 
     48#endif // !__IDOCUMENT_LINK_H__ 
  • trunk/src/Makefile.am

    r182 r196  
    55 
    66libepdfview_a_SOURCES = \ 
    7     Config.cxx          \ 
    8     Config.h            \ 
    9     DocumentLink.cxx    \ 
    10     DocumentLink.h  \ 
     7    Config.cxx  \ 
     8    Config.h    \ 
     9    DocumentLinkGoto.cxx    \ 
     10    DocumentLinkGoto.h  \ 
     11    DocumentLinkUri.cxx \ 
     12    DocumentLinkUri.h   \ 
    1113    DocumentOutline.cxx \ 
    1214    DocumentOutline.h   \ 
     
    1517    DocumentRectangle.cxx   \ 
    1618    DocumentRectangle.h \ 
    17     epdfview.h          \ 
     19    epdfview.h  \ 
    1820    FindPter.cxx    \ 
    1921    FindPter.h  \ 
    20     gettext.h           \ 
    21     IDocument.cxx       \ 
    22     IDocument.h         \ 
     22    gettext.h   \ 
     23    IDocument.cxx   \ 
     24    IDocument.h     \ 
     25    IDocumentLink.cxx   \ 
     26    IDocumentLink.h \ 
    2327    IDocumentObserver.h \ 
    2428    IFindView.h \ 
     
    2933    JobFind.cxx \ 
    3034    JobFind.h   \ 
    31     JobLoad.cxx         \ 
    32     JobLoad.h           \ 
     35    JobLoad.cxx     \ 
     36    JobLoad.h       \ 
    3337    JobRender.cxx   \ 
    3438    JobRender.h \ 
    35     MainPter.cxx        \ 
    36     MainPter.h          \ 
     39    MainPter.cxx    \ 
     40    MainPter.h      \ 
    3741    PagePter.cxx    \ 
    3842    PagePter.h  \ 
    39     PDFDocument.cxx     \ 
     43    PDFDocument.cxx \ 
    4044    PDFDocument.h 
    4145 
    4246libepdfview_a_CXXFLAGS =    \ 
    43     $(GLIB_CFLAGS)          \ 
     47    $(GLIB_CFLAGS)  \ 
    4448    $(POPPLER_CFLAGS) 
    4549 
  • trunk/src/PDFDocument.cxx

    r183 r196  
    5454} 
    5555 
     56/// 
     57/// @brief Creates a new document link. 
     58/// 
     59/// Based on the passed @a link, this function creates a new document 
     60/// links of the best type for the link's action. 
     61/// 
     62/// @param link The link to create the document link from. 
     63/// @param pageHeight The unscaled size of the page's height. 
     64/// @param scale The scale to calculate the link's coordinates. 
     65/// 
     66/// @return The link best suited for @a link or NULL if no link can be 
     67///         created. 
     68IDocumentLink * 
     69PDFDocument::createDocumentLink (const PopplerLinkMapping *link, 
     70                                 const gdouble pageHeight, 
     71                                 const gdouble scale) 
     72{ 
     73    PopplerAction *action = link->action; 
     74    IDocumentLink *documentLink = NULL; 
     75 
     76    // Calculate the four link's corners. 
     77    gdouble topLeft = link->area.x1 * scale; 
     78    gdouble topRight = link->area.x2 * scale; 
     79    gdouble bottomLeft = (pageHeight - link->area.y2) * scale; 
     80    gdouble bottomRight = (pageHeight - link->area.y1) * scale; 
     81 
     82    switch (action->type) 
     83    { 
     84        // Internal cross-reference link. 
     85        case POPPLER_ACTION_GOTO_DEST: 
     86        { 
     87            PopplerActionGotoDest *actionGoTo = (PopplerActionGotoDest *)action; 
     88            documentLink = new DocumentLinkGoto ( 
     89                    topLeft, bottomLeft, topRight, bottomRight, 
     90                    actionGoTo->dest->page_num); 
     91            break; 
     92        } 
     93        // Internet address. 
     94        case POPPLER_ACTION_URI: 
     95        { 
     96            PopplerActionUri *actionUri = (PopplerActionUri *)action; 
     97            documentLink = new DocumentLinkUri ( 
     98                    topLeft, bottomLeft, topRight, bottomRight, 
     99                    actionUri->uri); 
     100            break; 
     101        } 
     102 
     103        default: 
     104            g_warning ("Poppler's link type %d not handled.", action->type); 
     105            break; 
     106    } 
     107 
     108    return documentLink; 
     109} 
     110 
    56111GList * 
    57112PDFDocument::findTextInPage (gint pageNum, const gchar *textToFind) 
    58113{ 
    59114    GList *results = NULL; 
    60      
     115 
    61116    if ( NULL == m_Document ) 
    62     {     
     117    { 
    63118        return results; 
    64119    } 
     
    161216        return FALSE; 
    162217    } 
    163     
     218 
    164219    // Set the used filename and password to let the user reload the 
    165220    // document. 
    166     setFileName (filename);     
     221    setFileName (filename); 
    167222    setPassword (password); 
    168223    if ( NULL != m_Document ) 
     
    289344    { 
    290345        PopplerLinkMapping *link = (PopplerLinkMapping *)pageLink->data; 
    291         PopplerAction *action = link->action; 
    292         // Only internal links. 
    293         if ( POPPLER_ACTION_GOTO_DEST == action->type ) 
    294         { 
    295             PopplerActionGotoDest *actionGoTo = (PopplerActionGotoDest *)action; 
    296             DocumentLink *documentLink =  
    297                 new DocumentLink (link->area.x1 * scale,  
    298                                   (pageHeight - link->area.y2) * scale, 
    299                                   link->area.x2 * scale, 
    300                                   (pageHeight - link->area.y1) * scale, 
    301                                   actionGoTo->dest->page_num); 
     346        IDocumentLink *documentLink = createDocumentLink (link, pageHeight, scale); 
     347        if ( NULL != documentLink ) 
     348        { 
    302349            renderedPage->addLink (documentLink); 
    303350        } 
  • trunk/src/PDFDocument.h

    r154 r196  
    2121 
    2222/// Forward declarations. 
     23typedef struct _PopplerDocument PopplerDocument; 
    2324typedef struct _PopplerIndexIter PopplerIndexIter; 
    24 typedef struct _PopplerDocument PopplerDocument; 
     25typedef struct _PopplerLinkMapping PopplerLinkMapping; 
    2526typedef struct _PopplerPage PopplerPage; 
    2627 
     
    5152            PopplerDocument *m_Document; 
    5253 
     54            IDocumentLink *createDocumentLink (const PopplerLinkMapping *link, 
     55                                               const gdouble pageHeight, 
     56                                               const gdouble scale); 
    5357            void loadMetadata (void); 
    54             void setOutline (DocumentOutline *outline,  
     58            void setOutline (DocumentOutline *outline, 
    5559                             PopplerIndexIter *childrenList); 
    5660            void setLinks (DocumentPage *renderedPage, 
  • trunk/src/epdfview.h

    r174 r196  
    2626 
    2727#include <DocumentRectangle.h> 
    28 #include <DocumentLink.h> 
     28#include <IDocumentLink.h> 
     29#include <DocumentLinkGoto.h> 
     30#include <DocumentLinkUri.h> 
    2931#include <DocumentOutline.h> 
    3032#include <DocumentPage.h>