Changeset 61
- Timestamp:
- 04/14/06 12:36:20 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 4 modified
-
DocumentOutline.cxx (modified) (8 diffs)
-
DocumentOutline.h (modified) (3 diffs)
-
PDFDocument.cxx (modified) (4 diffs)
-
PDFDocument.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/DocumentOutline.cxx
r60 r61 17 17 18 18 #include <config.h> 19 20 // Poppler headers21 #include <goo/GooList.h>22 #include <Outline.h>23 #include <PDFDoc.h>24 #include <Link.h>25 26 19 #include "epdfview.h" 27 20 … … 34 27 /// @brief Constructs a new DocumentOutline. 35 28 /// 36 DocumentOutline::DocumentOutline ( PDFDoc *document)29 DocumentOutline::DocumentOutline () 37 30 { 38 31 m_Destination = 1; 39 m_Document = document;40 32 m_Children = NULL; 41 33 m_LastReturnedChild = NULL; … … 49 41 DocumentOutline::~DocumentOutline () 50 42 { 51 m_Document = NULL;52 43 m_Parent = NULL; 53 44 g_free (m_Title); … … 58 49 59 50 /// 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 /// 55 void 56 DocumentOutline::addChild (DocumentOutline *child) 57 { 58 m_Children = g_list_append (m_Children, child); 59 } 60 61 /// 62 /// @brief Gets the outline's destination page. 61 63 /// 62 64 /// I'm only using the outlines as a way to go to an specific page, although … … 138 140 } 139 141 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 /// 140 150 void 141 151 DocumentOutline::setDestination (gint destination) … … 144 154 } 145 155 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 /// 217 163 void 218 164 DocumentOutline::setParent (DocumentOutline *parent) … … 221 167 } 222 168 169 /// 170 /// @brief Sets the outline item's title. 171 /// 172 /// @param title The title to set to the outline. 173 /// 223 174 void 224 175 DocumentOutline::setTitle (const char *title) … … 230 181 } 231 182 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 /// 232 193 void 233 194 deleteChild (gpointer child, gpointer userData) -
trunk/src/DocumentOutline.h
r60 r61 19 19 #define __DOCUMENT_OUTLINE_H__ 20 20 21 // Forward declarations.22 class PDFDoc;23 class Outline;24 class GooList;25 26 21 namespace ePDFView 27 22 { … … 42 37 { 43 38 public: 44 DocumentOutline ( PDFDoc *document);39 DocumentOutline (void); 45 40 ~DocumentOutline (void); 46 41 42 void addChild (DocumentOutline *child); 47 43 gint getDestinationPage (void); 48 44 DocumentOutline *getFirstChild (void); … … 50 46 gint getNumChildren (void); 51 47 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); 53 51 54 52 private: 55 53 GList *m_Children; 56 54 gint m_Destination; 57 PDFDoc *m_Document;58 55 GList *m_LastReturnedChild; 59 56 DocumentOutline *m_Parent; 60 57 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);66 58 }; 67 59 } -
trunk/src/PDFDocument.cxx
r60 r61 19 19 20 20 // Poppler headers. 21 #include <goo/GooList.h> 21 22 #include <PDFDoc.h> 22 23 #include <CairoOutputDev.h> … … 24 25 #include <GlobalParams.h> 25 26 #include <PDFDocEncoding.h> 27 #include <Outline.h> 28 #include <Link.h> 26 29 27 30 #include "epdfview.h" … … 126 129 // Load the document's information and outline. 127 130 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; 130 137 // Set the output device. 131 138 delete m_OutputDevice; … … 203 210 setNumPages (m_Document->getNumPages ()); 204 211 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 /// 226 void 227 PDFDocument::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 ) 209 277 } 210 278 -
trunk/src/PDFDocument.h
r58 r61 21 21 22 22 /// Forward declarations. 23 class GooList; 23 24 class PDFDoc; 24 25 class CairoOutputDev; … … 49 50 50 51 void loadMetadata (void); 52 void setOutline (DocumentOutline *outline, GooList *childrenList); 51 53 }; 52 54 }
