From efba7844f845283b6df7887ca849e24280a12ab5 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Thu, 26 Sep 2013 19:21:34 +0300 Subject: [PATCH v19 5/5] glib: Methods to obtain link information from structure elements Implements functions to work with PopplerStructureElement objects of type POPPLER_STRUCTURE_REFERENCE_LINK: - poppler_structure_element_link_get_action() retrieves the PopplerAction associated with the link. - poppler_page_get_link_mapping_for_structure_element() obtains the PopplerLinkMapping associated with the link referenced by a structure element. --- glib/poppler-page.cc | 37 ++++++++ glib/poppler-page.h | 3 + glib/poppler-private.h | 2 + glib/poppler-structure-element.cc | 182 ++++++++++++++++++------------------ glib/poppler-structure-element.h | 2 +- glib/reference/poppler-sections.txt | 2 + 6 files changed, 138 insertions(+), 90 deletions(-) diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index dd1796e..5480532 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1412,6 +1412,43 @@ poppler_page_get_form_field_mapping_for_structure_element (PopplerPage } /** + * poppler_page_get_link_mapping_for_structure_element: + * @page: A #PopplerPage. + * @structure_element: A #PopplerStructureElement. + * + * Obtains the #PopplerLinkMapping for a link associated with a structure + * element of type %POPPLER_STRUCTURE_ELEMENT_LINK. The returned value + * must be freed with poppler_link_mapping_free(). + * + * Return value: (transfer full): A #PopplerLinkMapping; or %NULL if + * the element is not a %POPPLER_STRUCTURE_ELEMENT_LINK or if the + * given structure element does not have content in the page. + */ +PopplerLinkMapping * +poppler_page_get_link_mapping_for_structure_element (PopplerPage *page, + PopplerStructureElement *structure_element) +{ + g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); + g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (structure_element), NULL); + + if (page->index != poppler_structure_element_get_page (structure_element)) + return NULL; + + AnnotLink *annot_link = + _poppler_structure_element_link_get_annot_link (structure_element); + + if (annot_link == NULL) + return NULL; + + PopplerLinkMapping *result = + _poppler_link_mapping_new_from_annot_link (structure_element->document, + page->index, + annot_link); + delete annot_link; + return result; +} + +/** * poppler_page_get_annot_mapping: * @page: A #PopplerPage * diff --git a/glib/poppler-page.h b/glib/poppler-page.h index f611b2d..12727a5 100644 --- a/glib/poppler-page.h +++ b/glib/poppler-page.h @@ -92,6 +92,9 @@ GList *poppler_page_get_form_field_mapping (PopplerPage *pa PopplerFormFieldMapping * poppler_page_get_form_field_mapping_for_structure_element(PopplerPage *page, PopplerStructureElement *structure_element); +PopplerLinkMapping * + poppler_page_get_link_mapping_for_structure_element (PopplerPage *page, + PopplerStructureElement *structure_element); void poppler_page_free_form_field_mapping (GList *list); GList *poppler_page_get_annot_mapping (PopplerPage *page); void poppler_page_free_annot_mapping (GList *list); diff --git a/glib/poppler-private.h b/glib/poppler-private.h index baa58bf..f4db499 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -135,6 +135,8 @@ PopplerAnnot *_poppler_annot_line_new (Annot *annot); PopplerAnnot *_poppler_annot_circle_new (Annot *annot); PopplerAnnot *_poppler_annot_square_new (Annot *annot); +AnnotLink *_poppler_structure_element_link_get_annot_link (PopplerStructureElement* element); + PopplerLinkMapping *_poppler_link_mapping_new_from_annot_link (PopplerDocument *document, gint page_num, AnnotLink *link); diff --git a/glib/poppler-structure-element.cc b/glib/poppler-structure-element.cc index 3888a6d..60d8b4e 100644 --- a/glib/poppler-structure-element.cc +++ b/glib/poppler-structure-element.cc @@ -1103,24 +1103,6 @@ poppler_text_span_is_bold_font (PopplerTextSpan *poppler_text_span) return (poppler_text_span->flags & POPPLER_TEXT_SPAN_BOLD); } -/** - * poppler_structure_element_get_placement: - * @poppler_structure_element: A #PopplerStructureElement - * - * Obtains the placement type of the structure element. - * - * Return value: A #PopplerStructurePlacement value. - * - * Since: 0.26 - */ -PopplerStructurePlacement -poppler_structure_element_get_placement (PopplerStructureElement *poppler_structure_element) -{ - g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (poppler_structure_element), - EnumNameValue::values[0].value); - return attr_to_enum (poppler_structure_element); -} - typedef enum { REFERENCE_UNKNOWN, @@ -1147,54 +1129,13 @@ _element_reference_type (StructElement *element, XRef *xref) reftype = REFERENCE_ANNOT_LINK; subtype.free(); } + + obj.free(); } return reftype; } -/** - * poppler_structure_element_get_writing_mode: - * @poppler_structure_element: A #PopplerStructureElement - * - * Obtains the writing mode (writing direction) of the content associated - * with a structure element. - * - * Return value: A #PopplerStructureWritingMode value. - * - * Since: 0.26 - */ -PopplerStructureWritingMode -poppler_structure_element_get_writing_mode (PopplerStructureElement *poppler_structure_element) -{ - g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (poppler_structure_element), - EnumNameValue::values[0].value); - return attr_to_enum (poppler_structure_element); -} - - -static void -convert_border_style (Object *object, PopplerStructureBorderStyle *values) -{ - g_assert (object != NULL); - g_assert (values != NULL); - - if (object->isArray ()) - { - g_assert (object->arrayGetLength () == 4); - for (guint i = 0; i < 4; i++) - { - Object item; - values[i] = name_to_enum (object->arrayGet (i, &item)); - item.free (); - } - } - else - { - values[0] = values[1] = values[2] = values[3] = - name_to_enum (object); - } -} - AnnotLink * _poppler_structure_element_link_get_annot_link (PopplerStructureElement *element) @@ -1241,6 +1182,97 @@ _poppler_structure_element_link_get_annot_link (PopplerStructureElement *element return annot_link; } +/** + * poppler_structure_element_link_get_action: + * @poppler_structure_element: A #PopplerStructureElement + * + * Return value: (transfer full): The #PopplerAction associated to the + * link, or %NULL if the element is not a link element. + */ +PopplerAction * +poppler_structure_element_link_get_action (PopplerStructureElement *poppler_structure_element) +{ + g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (poppler_structure_element), NULL); + g_return_val_if_fail (poppler_structure_element->elem != NULL, NULL); + + if (poppler_structure_element->elem->getType () != StructElement::Link) + return NULL; + + AnnotLink *annot_link = + _poppler_structure_element_link_get_annot_link (poppler_structure_element); + + if (annot_link == NULL) + return NULL; + + PopplerAction *result = _poppler_action_new (poppler_structure_element->document, + annot_link->getAction (), NULL); + delete annot_link; + return result; +} + +/** + * poppler_structure_element_get_placement: + * @poppler_structure_element: A #PopplerStructureElement + * + * Obtains the placement type of the structure element. + * + * Return value: A #PopplerStructurePlacement value. + * + * Since: 0.26 + */ +PopplerStructurePlacement +poppler_structure_element_get_placement (PopplerStructureElement *poppler_structure_element) +{ + g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (poppler_structure_element), + EnumNameValue::values[0].value); + return attr_to_enum (poppler_structure_element); +} + + +/** + * poppler_structure_element_get_writing_mode: + * @poppler_structure_element: A #PopplerStructureElement + * + * Obtains the writing mode (writing direction) of the content associated + * with a structure element. + * + * Return value: A #PopplerStructureWritingMode value. + * + * Since: 0.26 + */ +PopplerStructureWritingMode +poppler_structure_element_get_writing_mode (PopplerStructureElement *poppler_structure_element) +{ + g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (poppler_structure_element), + EnumNameValue::values[0].value); + return attr_to_enum (poppler_structure_element); +} + + +static void +convert_border_style (Object *object, PopplerStructureBorderStyle *values) +{ + g_assert (object != NULL); + g_assert (values != NULL); + + if (object->isArray ()) + { + g_assert (object->arrayGetLength () == 4); + for (guint i = 0; i < 4; i++) + { + Object item; + values[i] = name_to_enum (object->arrayGet (i, &item)); + item.free (); + } + } + else + { + values[0] = values[1] = values[2] = values[3] = + name_to_enum (object); + } +} + + static void convert_double_or_4_doubles (Object *object, gdouble *value) { @@ -1302,34 +1334,6 @@ convert_color (Object *object, PopplerColor *color) } -/** - * poppler_structure_element_link_get_action: - * @poppler_structure_element: A #PopplerStructureElement - * - * Return value: (transfer full): The #PopplerAction associated to the - * link, or %NULL if the element is not a link element. - */ -PopplerAction * -poppler_structure_element_link_get_action (PopplerStructureElement *poppler_structure_element) -{ - g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (poppler_structure_element), NULL); - g_return_val_if_fail (poppler_structure_element->elem != NULL, NULL); - - if (poppler_structure_element->elem->getType () != StructElement::Link) - return NULL; - - AnnotLink *annot_link = - _poppler_structure_element_link_get_annot_link (poppler_structure_element); - - if (annot_link == NULL) - return NULL; - - PopplerAction *result = _poppler_action_new (poppler_structure_element->document, - annot_link->getAction (), NULL); - delete annot_link; - return result; -} - /* * poppler_structure_element_get_border_style: * @poppler_structure_element: A #PopplerStructureElement diff --git a/glib/poppler-structure-element.h b/glib/poppler-structure-element.h index 920aee4..69abd0d 100644 --- a/glib/poppler-structure-element.h +++ b/glib/poppler-structure-element.h @@ -309,6 +309,7 @@ gdouble *poppler_structure_element_get_column_gaps gdouble *poppler_structure_element_get_column_widths (PopplerStructureElement *poppler_structure_element, guint *n_values); gchar **poppler_structure_element_get_headers (PopplerStructureElement *poppler_structure_element); +PopplerAction *poppler_structure_element_link_get_action (PopplerStructureElement *poppler_structure_element); PopplerStructureFormState poppler_structure_element_form_get_state (PopplerStructureElement *poppler_structure_element); PopplerStructureFormRole poppler_structure_element_form_get_role (PopplerStructureElement *poppler_structure_element); PopplerFormField *poppler_structure_element_form_get_field (PopplerStructureElement *poppler_structure_element); @@ -319,7 +320,6 @@ gboolean poppler_structure_element_table_get_bounding_bo void poppler_structure_element_table_get_border_style (PopplerStructureElement *poppler_structure_element, PopplerStructureBorderStyle *border_styles); ->>>>>>> 7275cee... glib: Accessors for form fields of structure elements #define POPPLER_TYPE_STRUCTURE_ELEMENT_ITER (poppler_structure_element_iter_get_type ()) GType poppler_structure_element_iter_get_type (void) G_GNUC_CONST; diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 873a611..c2726fb 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -74,6 +74,7 @@ poppler_text_attributes_new poppler_text_attributes_copy poppler_text_attributes_free poppler_page_get_form_field_mapping_for_structure_element +poppler_page_get_link_mapping_for_structure_element POPPLER_PAGE @@ -665,6 +666,7 @@ poppler_structure_element_get_headers poppler_structure_element_form_get_role poppler_structure_element_form_get_state poppler_structure_element_form_get_field +poppler_structure_element_link_get_action poppler_structure_element_table_get_padding poppler_structure_element_table_get_border_style poppler_structure_element_table_get_bounding_box -- 1.9.0