diff options
author | Thomas Schenker <mail.thomas.schenker@googlemail.com> | 2012-06-02 11:54:21 +0200 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2012-06-02 17:35:31 +0200 |
commit | ed0c761c2190a3c1959a60ae9b7961f58a43c939 (patch) | |
tree | cb1cbaa4daec6506cc65c65675d1d098997e0808 /glib | |
parent | 126b55c9a44ccb0dba55e758843e9ee4aa43ee2b (diff) |
glib: Add poppler_page_find_text_with_options
To be able to search text with options like case sensitive, search
backwards and whole words only.
https://bugs.freedesktop.org/show_bug.cgi?id=2951
Diffstat (limited to 'glib')
-rw-r--r-- | glib/poppler-page.cc | 52 | ||||
-rw-r--r-- | glib/poppler-page.h | 3 | ||||
-rw-r--r-- | glib/poppler.h | 18 | ||||
-rw-r--r-- | glib/reference/poppler-sections.txt | 2 |
4 files changed, 62 insertions, 13 deletions
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 90f9a621..8113e9ca 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -850,18 +850,23 @@ poppler_page_get_text (PopplerPage *page) } /** - * poppler_page_find_text: + * poppler_page_find_text_with_options: * @page: a #PopplerPage * @text: the text to search for (UTF-8 encoded) - * - * A #GList of rectangles for each occurance of the text on the page. + * @options: find options + * + * Finds @text in @page with the given #PopplerFindFlags options and + * returns a #GList of rectangles for each occurance of the text on the page. * The coordinates are in PDF points. - * + * * Return value: (element-type PopplerRectangle) (transfer full): a #GList of #PopplerRectangle, + * + * Since: 0.22 **/ GList * -poppler_page_find_text (PopplerPage *page, - const char *text) +poppler_page_find_text_with_options (PopplerPage *page, + const char *text, + PopplerFindFlags options) { PopplerRectangle *match; GList *matches; @@ -870,6 +875,7 @@ poppler_page_find_text (PopplerPage *page, glong ucs4_len; double height; TextPage *text_dev; + gboolean backwards; g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); g_return_val_if_fail (text != NULL, NULL); @@ -878,17 +884,19 @@ poppler_page_find_text (PopplerPage *page, ucs4 = g_utf8_to_ucs4_fast (text, -1, &ucs4_len); poppler_page_get_size (page, NULL, &height); - + + backwards = options & POPPLER_FIND_BACKWARDS; matches = NULL; xMin = 0; - yMin = 0; + yMin = backwards ? height : 0; while (text_dev->findText (ucs4, ucs4_len, - gFalse, gTrue, // startAtTop, stopAtBottom - gFalse, gFalse, // startAtLast, stopAtLast - gFalse, gFalse, // caseSensitive, backwards - gFalse, // wholeWord - &xMin, &yMin, &xMax, &yMax)) + gFalse, gTrue, // startAtTop, stopAtBottom + gTrue, gFalse, // startAtLast, stopAtLast + options & POPPLER_FIND_CASE_SENSITIVE, + backwards, + options & POPPLER_FIND_WHOLE_WORDS_ONLY, + &xMin, &yMin, &xMax, &yMax)) { match = poppler_rectangle_new (); match->x1 = xMin; @@ -903,6 +911,24 @@ poppler_page_find_text (PopplerPage *page, return g_list_reverse (matches); } +/** + * poppler_page_find_text: + * @page: a #PopplerPage + * @text: the text to search for (UTF-8 encoded) + * + * Finds @text in @page with the default options (%POPPLER_FIND_DEFAULT) and + * returns a #GList of rectangles for each occurance of the text on the page. + * The coordinates are in PDF points. + * + * Return value: (element-type PopplerRectangle) (transfer full): a #GList of #PopplerRectangle, + **/ +GList * +poppler_page_find_text (PopplerPage *page, + const char *text) +{ + return poppler_page_find_text_with_options (page, text, POPPLER_FIND_DEFAULT); +} + static CairoImageOutputDev * poppler_page_get_image_output_dev (PopplerPage *page, GBool (*imgDrawDeviceCbk)(int img_id, void *data), diff --git a/glib/poppler-page.h b/glib/poppler-page.h index 6064ac5c..c081b8cc 100644 --- a/glib/poppler-page.h +++ b/glib/poppler-page.h @@ -60,6 +60,9 @@ PopplerPageTransition *poppler_page_get_transition (PopplerPage *pa gboolean poppler_page_get_thumbnail_size (PopplerPage *page, int *width, int *height); +GList *poppler_page_find_text_with_options (PopplerPage *page, + const char *text, + PopplerFindFlags options); GList *poppler_page_find_text (PopplerPage *page, const char *text); void poppler_page_render_to_ps (PopplerPage *page, diff --git a/glib/poppler.h b/glib/poppler.h index 6c2eefd8..2d190f35 100644 --- a/glib/poppler.h +++ b/glib/poppler.h @@ -153,6 +153,24 @@ typedef enum /*< flags >*/ POPPLER_PRINT_ALL = POPPLER_PRINT_MARKUP_ANNOTS } PopplerPrintFlags; +/** + * PopplerFindFlags: + * @POPPLER_FIND_CASE_SENSITIVE: do case sensitive search + * @POPPLER_FIND_BACKWARDS: search backwards + * @POPPLER_FIND_WHOLE_WORDS_ONLY: search only whole words + * + * Flags using while searching text in a page + * + * Since: 0.22 + */ +typedef enum /*< flags >*/ +{ + POPPLER_FIND_DEFAULT = 0, + POPPLER_FIND_CASE_SENSITIVE = 1 << 0, + POPPLER_FIND_BACKWARDS = 1 << 1, + POPPLER_FIND_WHOLE_WORDS_ONLY = 1 << 2 +} PopplerFindFlags; + typedef struct _PopplerDocument PopplerDocument; typedef struct _PopplerIndexIter PopplerIndexIter; typedef struct _PopplerFontsIter PopplerFontsIter; diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 76abf4c7..6fb14bca 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -33,6 +33,7 @@ poppler_page_get_selection_region poppler_page_selection_region_free poppler_page_get_selected_text poppler_page_find_text +poppler_page_find_text_with_options poppler_page_get_text poppler_page_get_text_layout poppler_page_get_text_attributes @@ -338,6 +339,7 @@ PopplerOrientation PopplerBackend PopplerColor PopplerPrintFlags +PopplerFindFlags poppler_get_backend poppler_get_version poppler_date_parse |