From a4c5a90c8bcfe6978e0786682d2d870f31e19595 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Thu, 26 Sep 2013 19:56:23 +0300 Subject: [PATCH 1/2] 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. --- glib/poppler-page.cc | 114 ++++++++++++++++++++++++++++--------------------- glib/poppler-private.h | 4 ++ 2 files changed, 70 insertions(+), 48 deletions(-) diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 4e57201..34db46f 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1169,6 +1169,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 @@ -1198,55 +1261,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 8e96bd4..86ceb6f 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -137,6 +137,10 @@ PopplerAnnot *_poppler_annot_square_new (Annot *annot); PopplerFormFieldMapping *_poppler_form_field_mapping_new_from_form_field (PopplerFormField *form_field, gint page_num); +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, -- 1.9.3