Changeset 61

Show
Ignore:
Timestamp:
04/14/06 12:36:20 (3 years ago)
Author:
jordi
Message:

I've removed all Poppler stuff from the DocumentOutline? and put it into the PDFDocument, where it should be. Also the previously protected setters DocumentOutline? methods are set to public.

Added the missing documentation comments.

Location:
trunk/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/DocumentOutline.cxx

    r60 r61  
    1717 
    1818#include <config.h> 
    19  
    20 // Poppler headers 
    21 #include <goo/GooList.h> 
    22 #include <Outline.h> 
    23 #include <PDFDoc.h> 
    24 #include <Link.h> 
    25  
    2619#include "epdfview.h" 
    2720 
     
    3427/// @brief Constructs a new DocumentOutline. 
    3528/// 
    36 DocumentOutline::DocumentOutline (PDFDoc *document) 
     29DocumentOutline::DocumentOutline () 
    3730{ 
    3831    m_Destination = 1; 
    39     m_Document = document; 
    4032    m_Children = NULL; 
    4133    m_LastReturnedChild = NULL; 
     
    4941DocumentOutline::~DocumentOutline () 
    5042{ 
    51     m_Document = NULL; 
    5243    m_Parent = NULL; 
    5344    g_free (m_Title); 
     
    5849 
    5950/// 
    60 /// @brief Get the outline's destination page. 
     51/// @brief Adds a new outline's child. 
     52/// 
     53/// @param child The new child to add. 
     54/// 
     55void 
     56DocumentOutline::addChild (DocumentOutline *child) 
     57{ 
     58    m_Children = g_list_append (m_Children, child); 
     59} 
     60 
     61/// 
     62/// @brief Gets the outline's destination page. 
    6163/// 
    6264/// I'm only using the outlines as a way to go to an specific page, although 
     
    138140} 
    139141 
     142/// 
     143/// @brief Sets the outline item's destination. 
     144/// 
     145/// @see getDestination(). 
     146/// 
     147/// @param destination The page number, starting from 1, that 
     148///                    this outline links to. 
     149/// 
    140150void 
    141151DocumentOutline::setDestination (gint destination) 
     
    144154} 
    145155 
    146 void 
    147 DocumentOutline::setChildren (GooList *childrenList) 
    148 { 
    149     if ( NULL != childrenList ) 
    150     { 
    151         int numChildren = childrenList->getLength (); 
    152         for ( int childIndex = 0; childIndex < numChildren; childIndex++) 
    153         { 
    154             OutlineItem *item = (OutlineItem *)childrenList->get (childIndex); 
    155             // Get the title. 
    156             gchar *title = g_ucs4_to_utf8 (item->getTitle (),  
    157                                            item->getTitleLength (), 
    158                                            NULL, NULL, NULL);             
    159             // The page destination. 
    160             gint destination = 1; 
    161             LinkAction *action = item->getAction (); 
    162             if ( NULL != action ) 
    163             { 
    164                 if ( action->isOk () && actionGoTo == action->getKind () ) 
    165                 { 
    166                     LinkDest *dest = ((LinkGoTo *)action)->getDest (); 
    167                     if ( dest->isOk () && dest->isPageRef () ) 
    168                     { 
    169                         Ref ref = dest->getPageRef (); 
    170                         destination = m_Document->findPage (ref.num, ref.gen); 
    171                     } 
    172                     else if ( dest->isOk () ) 
    173                     { 
    174                         destination = dest->getPageNum (); 
    175                     } 
    176                 } 
    177             } 
    178             // Create the child. 
    179             DocumentOutline *child = new DocumentOutline (m_Document); 
    180             child->setParent (this); 
    181             child->setTitle (title); 
    182             g_free (title); 
    183             child->setDestination (destination); 
    184             // Add to the list of children. 
    185             m_Children = g_list_append (m_Children, child); 
    186             // And add its own children. 
    187             if ( item->hasKids () ) 
    188             { 
    189                 // I need to open the outline because if it's not  
    190                 // open then the getKids() function returns NULL. 
    191                 item->open (); 
    192                 child->setChildren (item->getKids ()); 
    193             } 
    194         } 
    195     } 
    196 } 
    197  
    198 /// 
    199 /// @brief Sets the outline. 
    200 /// 
    201 /// This is only called for the root outline element when loading a document. 
    202 /// Fills in the list of outline items from the document. 
    203 /// 
    204 /// @param outline The outline from the documents. 
    205 /// 
    206 void 
    207 DocumentOutline::setOutline (Outline *outline) 
    208 { 
    209     g_assert (NULL != outline && "Tried to set a NULL outline."); 
    210      
    211     setTitle (""); 
    212     setDestination (1); 
    213          
    214     setChildren (outline->getItems ()); 
    215 } 
    216  
     156/// 
     157/// @brief Sets the item's parent. 
     158/// 
     159/// This is currently not used. 
     160/// 
     161/// @param parent The outline item's parent. 
     162/// 
    217163void 
    218164DocumentOutline::setParent (DocumentOutline *parent) 
     
    221167} 
    222168 
     169/// 
     170/// @brief Sets the outline item's title. 
     171/// 
     172/// @param title The title to set to the outline. 
     173/// 
    223174void 
    224175DocumentOutline::setTitle (const char *title) 
     
    230181} 
    231182 
     183/// 
     184/// @brief Deletes an outline item's child. 
     185/// 
     186/// This function is called by the destructor to delete all childs in 
     187/// the m_Children list. 
     188/// 
     189/// @param child The data element in the list's item. 
     190/// @param userData The data passed to the g_list_foreach() function. 
     191///                 Currently unused. 
     192/// 
    232193void 
    233194deleteChild (gpointer child, gpointer userData) 
  • trunk/src/DocumentOutline.h

    r60 r61  
    1919#define __DOCUMENT_OUTLINE_H__ 
    2020 
    21 // Forward declarations. 
    22 class PDFDoc; 
    23 class Outline; 
    24 class GooList; 
    25  
    2621namespace ePDFView 
    2722{ 
     
    4237    { 
    4338        public: 
    44             DocumentOutline (PDFDoc *document); 
     39            DocumentOutline (void); 
    4540            ~DocumentOutline (void); 
    4641 
     42            void addChild (DocumentOutline *child); 
    4743            gint getDestinationPage (void); 
    4844            DocumentOutline *getFirstChild (void); 
     
    5046            gint getNumChildren (void); 
    5147            const gchar *getTitle (void); 
    52             void setOutline (Outline *outline); 
     48            void setParent (DocumentOutline *parent); 
     49            void setTitle (const gchar *title); 
     50            void setDestination (gint destination); 
    5351 
    5452        private: 
    5553            GList *m_Children; 
    5654            gint m_Destination; 
    57             PDFDoc *m_Document; 
    5855            GList *m_LastReturnedChild; 
    5956            DocumentOutline *m_Parent; 
    6057            gchar *m_Title; 
    61  
    62             void setChildren (GooList *childrenList); 
    63             void setParent (DocumentOutline *parent); 
    64             void setTitle (const gchar *title); 
    65             void setDestination (gint destination); 
    6658    }; 
    6759} 
  • trunk/src/PDFDocument.cxx

    r60 r61  
    1919 
    2020// Poppler headers. 
     21#include <goo/GooList.h> 
    2122#include <PDFDoc.h> 
    2223#include <CairoOutputDev.h> 
     
    2425#include <GlobalParams.h> 
    2526#include <PDFDocEncoding.h> 
     27#include <Outline.h> 
     28#include <Link.h> 
    2629 
    2730#include "epdfview.h" 
     
    126129    // Load the document's information and outline. 
    127130    loadMetadata (); 
    128     m_Outline = new DocumentOutline (m_Document); 
    129     m_Outline->setOutline (m_Document->getOutline ()); 
     131    Outline *outline = m_Document->getOutline (); 
     132    m_Outline = new DocumentOutline (); 
     133    setOutline (m_Outline, outline->getItems ()); 
     134    // Set the current rotation angle and zoom level. 
     135    m_Rotation = 0; 
     136    m_Scale = 1.0f; 
    130137    // Set the output device. 
    131138    delete m_OutputDevice; 
     
    203210    setNumPages (m_Document->getNumPages ()); 
    204211    goToFirstPage (); 
    205  
    206     // Set the current rotation angle and zoom level. 
    207     m_Rotation = 0; 
    208     m_Scale = 1.0f; 
     212} 
     213 
     214/// 
     215/// @brief Sets the document's outline. 
     216/// 
     217/// This is a recursive function that adds child outlines 
     218/// from the PDF's outline to the passed @a outline. 
     219/// 
     220/// @param outline The outline to set the nodes to. The first 
     221///                call must be set to the root DocumentOutline. 
     222/// @param childrenList The list of children for to set to @outline. 
     223///                     The first line must be a call to the getItems() 
     224///                     function from the PDF's outline. 
     225/// 
     226void 
     227PDFDocument::setOutline (DocumentOutline *outline, GooList *childrenList) 
     228{ 
     229    if ( NULL != childrenList ) 
     230    { 
     231        int numChildren = childrenList->getLength (); 
     232        for ( int childIndex = 0 ; childIndex < numChildren ; childIndex++ ) 
     233        { 
     234            OutlineItem *item = (OutlineItem *)childrenList->get (childIndex); 
     235            // Get the title, create the new child outline and set the 
     236            // title to it. 
     237            gchar *title = g_ucs4_to_utf8 (item->getTitle (), 
     238                                           item->getTitleLength (),  
     239                                           NULL, NULL, NULL); 
     240            DocumentOutline *child = new DocumentOutline (); 
     241            child->setParent (outline); 
     242            child->setTitle (title); 
     243            g_free (title); 
     244            /// Get the page destination. 
     245            gint destination = 1; 
     246            LinkAction *action = item->getAction (); 
     247            if ( NULL != action && action->isOk () &&  
     248                 actionGoTo == action->getKind () )  
     249            { 
     250                LinkDest *linkDestination = ((LinkGoTo *)action)->getDest (); 
     251                if ( linkDestination->isOk () ) 
     252                { 
     253                    if ( linkDestination->isPageRef () ) 
     254                    { 
     255                        Ref pageReference = linkDestination->getPageRef (); 
     256                        destination = m_Document->findPage (pageReference.num, 
     257                                                            pageReference.gen); 
     258                    } 
     259                    else 
     260                    { 
     261                        destination = linkDestination->getPageNum (); 
     262                    } 
     263                } // if ( linkDestination->isOk () ) 
     264            } // if ( NULL != action ... ) 
     265            child->setDestination (destination); 
     266            outline->addChild (child); 
     267            // Add the child's children, if any. 
     268            if ( item->hasKids () ) 
     269            { 
     270                // I need to open the outline because if it's not 
     271                // open then the getKids() function would return NULL. 
     272                item->open (); 
     273                setOutline (child, item->getKids ()); 
     274            } 
     275        } // for ( int childIndex = 0 ; ... )        
     276    } // if ( NULL != childrenList ) 
    209277} 
    210278 
  • trunk/src/PDFDocument.h

    r58 r61  
    2121 
    2222/// Forward declarations. 
     23class GooList; 
    2324class PDFDoc; 
    2425class CairoOutputDev; 
     
    4950 
    5051            void loadMetadata (void); 
     52            void setOutline (DocumentOutline *outline, GooList *childrenList); 
    5153    }; 
    5254}