]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/pdf-document.cc
Add a way to open bookmarks
[evince.git] / pdf / xpdf / pdf-document.cc
index d3f4ea68375ef4df60af99837c0c2a28f6e02261..6e077162c59e138e45eefe1246006e94255171bd 100644 (file)
@@ -740,83 +740,70 @@ pdf_document_bookmarks_begin_read (EvDocumentBookmarks *document_bookmarks)
        return (EvDocumentBookmarksIter *) iter;
 }
 
        return (EvDocumentBookmarksIter *) iter;
 }
 
-static gboolean
-pdf_document_bookmarks_get_values (EvDocumentBookmarks      *document_bookmarks,
-                                  EvDocumentBookmarksIter  *bookmarks_iter,
-                                  char                    **title,
-                                  EvDocumentBookmarksType  *type,
-                                  gint                     *page)
+static EvBookmark *
+pdf_document_bookmarks_get_bookmark (EvDocumentBookmarks      *document_bookmarks,
+                                    EvDocumentBookmarksIter  *bookmarks_iter)
 {
        PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
 {
        PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks);
+       EvBookmark *bookmark = NULL;
        BookmarksIter *iter = (BookmarksIter *)bookmarks_iter;
        OutlineItem *anItem;
        LinkAction *link_action;
        BookmarksIter *iter = (BookmarksIter *)bookmarks_iter;
        OutlineItem *anItem;
        LinkAction *link_action;
-       LinkDest *link_dest = NULL;
-       LinkURI *link_uri = NULL;
-       LinkGoTo *link_goto = NULL;
-       GString *named_dest;
        Unicode *link_title;
        Unicode *link_title;
-       Ref page_ref;
-       gint page_num = -1;
+       const char *title;
 
        g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
        g_return_val_if_fail (iter != NULL, FALSE);
 
        g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE);
        g_return_val_if_fail (iter != NULL, FALSE);
-       g_return_val_if_fail (title != NULL, FALSE);
-       g_return_val_if_fail (type != NULL, FALSE);
-       g_return_val_if_fail (page != NULL, FALSE);
 
        anItem = (OutlineItem *)iter->items->get(iter->index);
        link_action = anItem->getAction ();
        link_title = anItem->getTitle ();
 
        anItem = (OutlineItem *)iter->items->get(iter->index);
        link_action = anItem->getAction ();
        link_title = anItem->getTitle ();
-
-       if (link_action) {
-               switch (link_action->getKind ()) {
-
-               case actionGoTo:
-                       link_goto = dynamic_cast <LinkGoTo *> (link_action);
-                       link_dest = link_goto->getDest ();
-                       named_dest = link_goto->getNamedDest ();
-
-                       /* Wow!  This seems excessively slow on large
-                        * documents. I need to investigate more... -jrb */
-                       if (link_dest != NULL) {
-                               link_dest = link_dest->copy ();
-                       } else if (named_dest != NULL) {
-                               named_dest = named_dest->copy ();
-                               link_dest = pdf_document->doc->findDest (named_dest);
-                               delete named_dest;
-                       }
-                       if (link_dest != NULL) {
-                               if (link_dest->isPageRef ()) {
-                                       page_ref = link_dest->getPageRef ();
-                                       page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen);
-                               } else {
-                                       page_num = link_dest->getPageNum ();
-                               }
-
-                               delete link_dest;
+       title = unicode_to_char (anItem, pdf_document->umap);
+
+       if (link_action == NULL) {
+               bookmark = ev_bookmark_new_title (title);
+       } else if (link_action->getKind () == actionGoTo) {
+               LinkDest *link_dest;
+               LinkGoTo *link_goto;
+               Ref page_ref;
+               gint page_num = 0;
+               GString *named_dest;
+
+               link_goto = dynamic_cast <LinkGoTo *> (link_action);
+               link_dest = link_goto->getDest ();
+               named_dest = link_goto->getNamedDest ();
+
+               /* Wow!  This seems excessively slow on large
+                * documents. I need to investigate more... -jrb */
+               if (link_dest != NULL) {
+                       link_dest = link_dest->copy ();
+               } else if (named_dest != NULL) {
+                       named_dest = named_dest->copy ();
+                       link_dest = pdf_document->doc->findDest (named_dest);
+                       delete named_dest;
+               }
+               if (link_dest != NULL) {
+                       if (link_dest->isPageRef ()) {
+                               page_ref = link_dest->getPageRef ();
+                               page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen);
+                       } else {
+                               page_num = link_dest->getPageNum ();
                        }
                        }
+                       delete link_dest;
+               }
 
 
-                       break;
-               case actionURI:
-                       link_uri = dynamic_cast <LinkURI *> (link_action);
-                       break;
+               bookmark = ev_bookmark_new_link (title, page_num);
+       } else if (link_action->getKind () == actionURI) {
+               LinkURI *link_uri;
 
 
-               case actionNamed:
+               link_uri = dynamic_cast <LinkURI *> (link_action);
+               bookmark = ev_bookmark_new_external
+                       (title, link_uri->getURI()->getCString());
+       } else if (link_action->getKind () == actionNamed) {
                        /*Skip, for now */
                        /*Skip, for now */
-               default:
-                       g_warning ("Unknown link action type: %d", link_action->getKind ());
-               }
-
-               *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
-       } else if (link_title) {
-               *title = g_strdup (unicode_to_char (anItem, pdf_document->umap));
        }
 
        }
 
-       *type = EV_DOCUMENT_BOOKMARKS_TYPE_LINK;
-       *page = page_num;
-
-       return TRUE;
+       return bookmark;
 }
 
 static EvDocumentBookmarksIter *
 }
 
 static EvDocumentBookmarksIter *
@@ -1047,7 +1034,7 @@ pdf_document_document_bookmarks_iface_init (EvDocumentBookmarksIface *iface)
 {
        iface->has_document_bookmarks = pdf_document_bookmarks_has_document_bookmarks;
        iface->begin_read = pdf_document_bookmarks_begin_read;
 {
        iface->has_document_bookmarks = pdf_document_bookmarks_has_document_bookmarks;
        iface->begin_read = pdf_document_bookmarks_begin_read;
-       iface->get_values = pdf_document_bookmarks_get_values;
+       iface->get_bookmark = pdf_document_bookmarks_get_bookmark;
        iface->get_child = pdf_document_bookmarks_get_child;
        iface->next = pdf_document_bookmarks_next;
        iface->free_iter = pdf_document_bookmarks_free_iter;
        iface->get_child = pdf_document_bookmarks_get_child;
        iface->next = pdf_document_bookmarks_next;
        iface->free_iter = pdf_document_bookmarks_free_iter;
@@ -1138,6 +1125,39 @@ pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
        return pixbuf;
 }
 
        return pixbuf;
 }
 
+static void
+pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
+                                       gint                  page,
+                                       gint                  suggested_width,
+                                       gint                 *width,
+                                       gint                 *height)
+{
+       PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
+       Page *the_page;
+       Object the_thumb;
+       Thumb *thumb = NULL;
+       gdouble page_ratio;
+
+       /* getPage seems to want page + 1 for some reason; */
+       the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
+       the_page->getThumb (&the_thumb);
+
+
+
+       if (!(the_thumb.isNull () || the_thumb.isNone())) {
+               /* Build the thumbnail object */
+               thumb = new Thumb(pdf_document->doc->getXRef (),
+                                 &the_thumb);
+
+               *width = thumb->getWidth ();
+               *height = thumb->getHeight ();
+       } else {
+               page_ratio = the_page->getHeight () / the_page->getWidth ();
+               *width = suggested_width;
+               *height = (gint) (suggested_width * page_ratio);
+       }
+}
+
 static GdkPixbuf *
 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
                                       gint                  page,
 static GdkPixbuf *
 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
                                       gint                  page,
@@ -1202,6 +1222,7 @@ static void
 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
 {
        iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
 {
        iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
+       iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
 }
 
 
 }