From 1b81192ff2bb9fae4a7bbc685fafe1718f303a7b Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 28 Jan 2007 15:55:11 +0000 Subject: * glib/poppler-page.cc: Make link mapping coordinates follow page rotation. Patch by Carlos Garcia Campos * glib/poppler-action.cc: Fix link destination coordinates. Patch by Carlos Garcia Campos --- ChangeLog | 4 ++ glib/poppler-action.cc | 15 +++++- glib/poppler-page.cc | 124 +++++++++++++++++++++++++++++++------------------ 3 files changed, 97 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index a83e4b6f..31018648 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ * glib/poppler-document.cc: Plug memory leak in poppler-document. Patch by Carlos Garcia Campos + * glib/poppler-page.cc: Make link mapping coordinates follow page + rotation. Patch by Carlos Garcia Campos + * glib/poppler-action.cc: Fix link destination coordinates. Patch by + Carlos Garcia Campos 2007-01-21 Albert Astals Cid diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index e9f29590..98cf0d46 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -249,7 +249,20 @@ dest_new_goto (PopplerDocument *document, dest->change_left = link_dest->getChangeLeft (); dest->change_top = link_dest->getChangeTop (); dest->change_zoom = link_dest->getChangeZoom (); - + + if (dest->page_num > 0) { + PopplerPage *page; + + page = poppler_document_get_page (document, dest->page_num - 1); + + dest->left -= page->page->getCropBox ()->x1; + dest->bottom -= page->page->getCropBox ()->x1; + dest->right -= page->page->getCropBox ()->y1; + dest->top -= page->page->getCropBox ()->y1; + + g_object_unref (page); + } + return dest; } diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 35c0a76d..8b6d35c8 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -841,7 +841,6 @@ poppler_page_init (PopplerPage *page) { } - /** * poppler_page_get_link_mapping: * @page: A #PopplerPage @@ -855,52 +854,87 @@ poppler_page_init (PopplerPage *page) GList * poppler_page_get_link_mapping (PopplerPage *page) { - GList *map_list = NULL; - gint i; - Links *links; - Object obj; - - g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); - - links = new Links (page->page->getAnnots (&obj), - page->document->doc->getCatalog ()->getBaseURI ()); - obj.free (); - - if (links == NULL) - return NULL; - - for (i = 0; i < links->getNumLinks (); i++) { - PopplerLinkMapping *mapping; - LinkAction *link_action; - Link *link; - - link = links->getLink (i); - link_action = link->getAction (); - - /* Create the mapping */ - mapping = g_new (PopplerLinkMapping, 1); - mapping->action = _poppler_action_new (page->document, link_action, NULL); - link->getRect (&(mapping->area.x1), &(mapping->area.y1), - &(mapping->area.x2), &(mapping->area.y2)); - - mapping->area.x1 -= page->page->getCropBox()->x1; - mapping->area.x2 -= page->page->getCropBox()->x1; - mapping->area.y1 -= page->page->getCropBox()->y1; - mapping->area.y2 -= page->page->getCropBox()->y1; - - map_list = g_list_prepend (map_list, mapping); + GList *map_list = NULL; + gint i; + Links *links; + Object obj; + double width, height; + + g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); + + links = new Links (page->page->getAnnots (&obj), + page->document->doc->getCatalog ()->getBaseURI ()); + obj.free (); + + if (links == NULL) + return NULL; + + poppler_page_get_size (page, &width, &height); + + for (i = 0; i < links->getNumLinks (); i++) + { + PopplerLinkMapping *mapping; + PopplerRectangle rect; + LinkAction *link_action; + Link *link; + + link = links->getLink (i); + link_action = link->getAction (); + + /* Create the mapping */ + mapping = g_new (PopplerLinkMapping, 1); + mapping->action = _poppler_action_new (page->document, link_action, NULL); + + link->getRect (&rect.x1, &rect.y1, &rect.x2, &rect.y2); + + switch (page->page->getRotate ()) + { + case 90: + mapping->area.x1 = rect.y1; + mapping->area.y1 = height - rect.x2; + mapping->area.x2 = mapping->area.x1 + (rect.y2 - rect.y1); + mapping->area.y2 = mapping->area.y1 + (rect.x2 - rect.x1); + + break; + case 180: + mapping->area.x1 = width - rect.x2; + mapping->area.y1 = height - rect.y2; + mapping->area.x2 = mapping->area.x1 + (rect.x2 - rect.x1); + mapping->area.y2 = mapping->area.y1 + (rect.y2 - rect.y1); + + break; + case 270: + mapping->area.x1 = width - rect.y2; + mapping->area.y1 = rect.x1; + mapping->area.x2 = mapping->area.x1 + (rect.y2 - rect.y1); + mapping->area.y2 = mapping->area.y1 + (rect.x2 - rect.x1); + + break; + default: + mapping->area.x1 = rect.x1; + mapping->area.y1 = rect.y1; + mapping->area.x2 = rect.x2; + mapping->area.y2 = rect.y2; } - - delete links; - - return map_list; + + mapping->area.x1 -= page->page->getCropBox()->x1; + mapping->area.x2 -= page->page->getCropBox()->x1; + mapping->area.y1 -= page->page->getCropBox()->y1; + mapping->area.y2 -= page->page->getCropBox()->y1; + + map_list = g_list_prepend (map_list, mapping); + } + + delete links; + + return map_list; } static void poppler_mapping_free (PopplerLinkMapping *mapping) { - poppler_action_free (mapping->action); - g_free (mapping); + poppler_action_free (mapping->action); + g_free (mapping); } /** @@ -915,11 +949,11 @@ poppler_mapping_free (PopplerLinkMapping *mapping) void poppler_page_free_link_mapping (GList *list) { - if (list == NULL) - return; + if (list == NULL) + return; - g_list_foreach (list, (GFunc) (poppler_mapping_free), NULL); - g_list_free (list); + g_list_foreach (list, (GFunc) (poppler_mapping_free), NULL); + g_list_free (list); } /* PopplerRectangle type */ -- cgit v1.2.3