From 2d2dace0c4b5b00339f10f4a4a432db0664e5314 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro <aperez@igalia.com> Date: Wed, 5 Mar 2014 11:19:48 +0200 Subject: [PATCH v2] glib: Use flags argument in poppler_structure_element_get_text() Instead of accepting a boolean argument to enable recursive text extraction, use a flags value. Text extraction may add features in the future (for example, allowing using alternate text as replacement for inline figures), and this will allow to extend the method without introducing ABI or API breakage. --- glib/poppler-structure-element.cc | 12 +++++++----- glib/poppler-structure-element.h | 14 +++++++++++++- glib/reference/poppler-sections.txt | 3 +++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/glib/poppler-structure-element.cc b/glib/poppler-structure-element.cc index 7e57a3d..25edece 100644 --- a/glib/poppler-structure-element.cc +++ b/glib/poppler-structure-element.cc @@ -666,8 +666,8 @@ poppler_structure_element_get_actual_text (PopplerStructureElement *poppler_stru /** * poppler_structure_element_get_text: * @poppler_structure_element: A #PopplerStructureElement - * @recursive: If %TRUE, the text of child elements is gathered recursively - * in logical order and returned as part of the result. + * @flags: A #PopplerStructureGetTextFlags value, or + * %POPPLER_STRUCTURE_GET_TEXT_NONE to disable all the flags. * * Obtains the text enclosed by an element, or the text enclosed by the * elements in the subtree (including the element itself). @@ -677,13 +677,15 @@ poppler_structure_element_get_actual_text (PopplerStructureElement *poppler_stru * Since: 0.26 */ gchar * -poppler_structure_element_get_text (PopplerStructureElement *poppler_structure_element, - gboolean recursive) +poppler_structure_element_get_text (PopplerStructureElement *poppler_structure_element, + PopplerStructureGetTextFlags flags) { g_return_val_if_fail (POPPLER_IS_STRUCTURE_ELEMENT (poppler_structure_element), NULL); g_return_val_if_fail (poppler_structure_element->elem != NULL, NULL); - GooString *string = poppler_structure_element->elem->getText (recursive); + + GooString *string = + poppler_structure_element->elem->getText (flags & POPPLER_STRUCTURE_GET_TEXT_RECURSIVE); gchar *result = string ? _poppler_goo_string_to_utf8 (string) : NULL; delete string; return result; diff --git a/glib/poppler-structure-element.h b/glib/poppler-structure-element.h index 53bdca0..4596a41 100644 --- a/glib/poppler-structure-element.h +++ b/glib/poppler-structure-element.h @@ -87,6 +87,18 @@ typedef enum { } PopplerStructureElementKind; /** + * PopplerStructureGetTextFlags: + * @POPPLER_STRUCTURE_GET_TEXT_NONE: No flags. + * @POPPLER_STRUCTURE_GET_TEXT_RECURSIVE: For non-leaf, non-content + * elements, recursively obtain the text from all the elements + * enclosed in the subtree. + */ +typedef enum { + POPPLER_STRUCTURE_GET_TEXT_NONE = 0, + POPPLER_STRUCTURE_GET_TEXT_RECURSIVE = (1 << 0), +} PopplerStructureGetTextFlags; + +/** * PopplerStructurePlacement: */ typedef enum { @@ -253,7 +265,7 @@ gchar *poppler_structure_element_get_title gchar *poppler_structure_element_get_abbreviation (PopplerStructureElement *poppler_structure_element); gchar *poppler_structure_element_get_language (PopplerStructureElement *poppler_structure_element); gchar *poppler_structure_element_get_text (PopplerStructureElement *poppler_structure_element, - gboolean recursive); + PopplerStructureGetTextFlags flags); gchar *poppler_structure_element_get_alt_text (PopplerStructureElement *poppler_structure_element); gchar *poppler_structure_element_get_actual_text (PopplerStructureElement *poppler_structure_element); PopplerTextSpan **poppler_structure_element_get_text_spans (PopplerStructureElement *poppler_structure_element, diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 38ded4f..742065a 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -590,6 +590,7 @@ poppler_movie_get_type PopplerStructureElement PopplerStructureElementKind PopplerStructureElementIter +PopplerStructureGetTextFlags PopplerStructurePlacement PopplerStructureWritingMode PopplerStructureBorderStyle @@ -681,6 +682,7 @@ POPPLER_IS_STRUCTURE_ELEMENT POPPLER_TYPE_STRUCTURE_ELEMENT POPPLER_TYPE_STRUCTURE_ELEMENT_ITER POPPLER_TYPE_STRUCTURE_ELEMENT_KIND +POPPLER_TYPE_STRUCTURE_GET_TEXT_FLAGS POPPLER_TYPE_STRUCTURE_BLOCK_ALIGN POPPLER_TYPE_STRUCTURE_BORDER_STYLE POPPLER_TYPE_STRUCTURE_GLYPH_ORIENTATION @@ -702,6 +704,7 @@ POPPLER_TYPE_TEXT_SPAN poppler_structure_element_get_type poppler_structure_element_kind_get_type poppler_structure_element_iter_get_type +poppler_structure_get_text_flags_get_type poppler_structure_placement_get_type poppler_structure_writing_mode_get_type poppler_structure_border_style_get_type -- 1.9.0