summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Perez de Castro <aperez@igalia.com>2013-09-26 19:56:23 +0300
committerCarlos Garcia Campos <carlosgc@gnome.org>2013-09-30 10:16:47 +0200
commitc503dd05b071ade141908853fbdcb4ff0e36ffbc (patch)
treec2492c1ea7da2e5833ef2913725455714fdafecc
parent454abc800988d3639ea3d41a419c29410244e427 (diff)
glib: Private function _poppler_link_mapping_new_from_annot_link()
Move the code that creates a PopplerLinkMapping to its own function, and add it as private API. This will avoid duplication of the code when creating a PopplerLinkMapping from a PopplerStructureElement.
-rw-r--r--glib/poppler-page.cc114
-rw-r--r--glib/poppler-private.h4
2 files changed, 70 insertions, 48 deletions
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 9115b786..abe13ac1 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1147,6 +1147,69 @@ poppler_page_init (PopplerPage *page)
{
}
+
+PopplerLinkMapping *
+_poppler_link_mapping_new_from_annot_link (PopplerDocument *document,
+ gint page_num,
+ AnnotLink *link)
+{
+ Page *page;
+ PopplerRectangle rect;
+ PopplerLinkMapping *mapping;
+ double width, height;
+
+ g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (link != NULL, NULL);
+
+ g_assert (page_num >= 0);
+ g_assert (page_num < poppler_document_get_n_pages (document));
+
+ mapping = poppler_link_mapping_new ();
+ mapping->action = _poppler_action_new (document, link->getAction (), NULL);
+
+ page = document->doc->getPage (page_num + 1);
+ width = page->getCropWidth ();
+ height = page->getCropHeight ();
+
+ link->getRect (&rect.x1, &rect.y1, &rect.x2, &rect.y2);
+
+ rect.x1 -= page->getCropBox()->x1;
+ rect.x2 -= page->getCropBox()->x1;
+ rect.y1 -= page->getCropBox()->y1;
+ rect.y2 -= page->getCropBox()->y1;
+
+ switch (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;
+ }
+ return mapping;
+}
+
/**
* poppler_page_get_link_mapping:
* @page: A #PopplerPage
@@ -1176,55 +1239,10 @@ poppler_page_get_link_mapping (PopplerPage *page)
for (i = 0; i < links->getNumLinks (); i++)
{
- PopplerLinkMapping *mapping;
- PopplerRectangle rect;
- LinkAction *link_action;
- AnnotLink *link;
-
- link = links->getLink (i);
- link_action = link->getAction ();
-
/* Create the mapping */
- mapping = poppler_link_mapping_new ();
- mapping->action = _poppler_action_new (page->document, link_action, NULL);
-
- link->getRect (&rect.x1, &rect.y1, &rect.x2, &rect.y2);
-
- rect.x1 -= page->page->getCropBox()->x1;
- rect.x2 -= page->page->getCropBox()->x1;
- rect.y1 -= page->page->getCropBox()->y1;
- rect.y2 -= page->page->getCropBox()->y1;
-
- 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;
- }
-
+ PopplerLinkMapping *mapping = _poppler_link_mapping_new_from_annot_link (page->document,
+ page->index,
+ links->getLink (i));
map_list = g_list_prepend (map_list, mapping);
}
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index fb772403..e7fbea96 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -139,6 +139,10 @@ PopplerAnnot *_poppler_annot_file_attachment_new (Annot *annot);
PopplerAnnot *_poppler_annot_movie_new (Annot *annot);
PopplerAnnot *_poppler_annot_screen_new (Annot *annot);
+PopplerLinkMapping *_poppler_link_mapping_new_from_annot_link (PopplerDocument *document,
+ gint page_num,
+ AnnotLink *link);
+
char *_poppler_goo_string_to_utf8(GooString *s);
gboolean _poppler_convert_pdf_date_to_gtime (GooString *date,
time_t *gdate);