From 31b20a69a0764d17336196d4087d8f068bd231aa Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Thu, 26 Sep 2013 20:01:36 +0300 Subject: [PATCH v10 07/12] glib: Private function _poppler_link_mapping_new_from_form_field() Move the code that creates a PopplerFormFieldMapping to its own function, and add it as private API. This will avoid duplication of the code when creation a PopplerFormFieldMapping from a PopplerStructureElement. --- glib/poppler-page.cc | 45 ++++++++++++++++++++++++++++++++------------- glib/poppler-private.h | 3 +++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index abe13ac..67669ce 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1271,6 +1271,34 @@ poppler_page_free_link_mapping (GList *list) g_list_free (list); } + +PopplerFormFieldMapping * +_poppler_form_field_mapping_new_from_form_field (PopplerFormField *form_field, + gint page_num) +{ + PopplerFormFieldMapping *mapping; + Page *page; + + g_assert (POPPLER_IS_FORM_FIELD (form_field)); + g_assert (page_num >= 0); + g_assert (page_num < poppler_document_get_n_pages (form_field->document)); + + mapping = poppler_form_field_mapping_new (); + mapping->field = form_field; + + form_field->widget->getRect (&mapping->area.x1, &mapping->area.y1, + &mapping->area.x2, &mapping->area.y2); + + page = form_field->document->doc->getPage (page_num + 1); + + mapping->area.x1 -= page->getCropBox ()->x1; + mapping->area.x2 -= page->getCropBox ()->x1; + mapping->area.y1 -= page->getCropBox ()->y1; + mapping->area.y2 -= page->getCropBox ()->y1; + + return mapping; +} + /** * poppler_page_get_form_field_mapping: * @page: A #PopplerPage @@ -1297,21 +1325,12 @@ poppler_page_get_form_field_mapping (PopplerPage *page) for (i = 0; i < forms->getNumWidgets (); i++) { PopplerFormFieldMapping *mapping; - FormWidget *field; + PopplerFormField *field = _poppler_form_field_new (page->document, + forms->getWidget (i)); - mapping = poppler_form_field_mapping_new (); - - field = forms->getWidget (i); + mapping = _poppler_form_field_mapping_new_from_form_field (field, + page->index); - mapping->field = _poppler_form_field_new (page->document, field); - field->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); } diff --git a/glib/poppler-private.h b/glib/poppler-private.h index 5584a03..d8be2cb 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -135,6 +135,9 @@ PopplerLinkMapping *_poppler_link_mapping_new_from_annot_link (PopplerDocument * gint page_num, AnnotLink *link); +PopplerFormFieldMapping *_poppler_form_field_mapping_new_from_form_field (PopplerFormField *form_field, + gint page_num); + char *_poppler_goo_string_to_utf8(GooString *s); gboolean _poppler_convert_pdf_date_to_gtime (GooString *date, time_t *gdate); -- 1.8.4.2