summaryrefslogtreecommitdiff
path: root/glib/poppler-page.cc
diff options
context:
space:
mode:
Diffstat (limited to 'glib/poppler-page.cc')
-rw-r--r--glib/poppler-page.cc124
1 files changed, 79 insertions, 45 deletions
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 */