| 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 ) |