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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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