diff --git glib/poppler-page.cc glib/poppler-page.cc index 64a65bd..ed93742 100644 --- glib/poppler-page.cc +++ glib/poppler-page.cc @@ -850,19 +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) - * + * @options: find options + * * 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.20 **/ 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; double xMin, yMin, xMax, yMax; @@ -883,12 +887,30 @@ poppler_page_find_text (PopplerPage *page, xMin = 0; yMin = 0; + gboolean find_start_at_top = + (POPPLER_FIND_START_AT_TOP & options)== POPPLER_FIND_START_AT_TOP; + gboolean find_stop_at_bottom = + (POPPLER_FIND_STOP_AT_BOTTOM & options) == POPPLER_FIND_STOP_AT_BOTTOM; + gboolean find_start_at_last = + (POPPLER_FIND_START_AT_LAST & options) == POPPLER_FIND_START_AT_LAST; + gboolean find_stop_at_last = + (POPPLER_FIND_STOP_AT_LAST & options) == POPPLER_FIND_STOP_AT_LAST; + gboolean find_case_sensitive = + (POPPLER_FIND_CASE_SENSITIVE & options) == POPPLER_FIND_CASE_SENSITIVE; + gboolean find_backwards = + (POPPLER_FIND_BACKWARDS & options) == POPPLER_FIND_BACKWARDS; + gboolean find_whole_word = + (POPPLER_FIND_WHOLE_WORD & options) == POPPLER_FIND_WHOLE_WORD; + 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)) + find_start_at_top, + find_stop_at_bottom, + find_start_at_last, + find_stop_at_last, + find_case_sensitive, + find_backwards, + find_whole_word, + &xMin, &yMin, &xMax, &yMax)) { match = poppler_rectangle_new (); match->x1 = xMin; @@ -903,6 +925,25 @@ 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) + * + * 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 glib/poppler-page.h glib/poppler-page.h index 7b36843..9da5f06 100644 --- glib/poppler-page.h +++ glib/poppler-page.h @@ -60,7 +60,10 @@ PopplerPageTransition *poppler_page_get_transition (PopplerPage *pa gboolean poppler_page_get_thumbnail_size (PopplerPage *page, int *width, int *height); -GList *poppler_page_find_text (PopplerPage *page, +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, PopplerPSFile *ps_file); diff --git glib/poppler.h glib/poppler.h index 6c2eefd..cb97898 100644 --- glib/poppler.h +++ glib/poppler.h @@ -153,6 +153,35 @@ typedef enum /*< flags >*/ POPPLER_PRINT_ALL = POPPLER_PRINT_MARKUP_ANNOTS } PopplerPrintFlags; +/** + * PopplerFindFlags: + * @POPPLER_FIND_START_AT_TOP: start the search at the top of the page + * @POPPLER_FIND_START_AT_LAST: start the search after the last find result + * @POPPLER_FIND_STOP_AT_BOTTOM: stop the at the bottom of the page + * @POPPLER_FIND_STOP_AT_LAST: stop the search just before the last find result + * @POPPLER_FIND_CASE_SENSITIVE: do case sensitive search + * @POPPLER_FIND_BACKWARDS: search backwards + * @POPPLER_FIND_WHOLE_WORD: + * + * If neither POPPLER_FIND_START_AT_TOP nor POPPLER_FIND_START_AT_LAST is set, + * the search starts at xMin,yMin. + * If neither POPPLER_FIND_STOP_AT_BOTTOM nor POPPLER_FIND_STOP_AT_LAST is set, + * the search stops at xMax,yMax. + * + * Since: 0.20 + */ +typedef enum /*< flags >*/ +{ + POPPLER_FIND_START_AT_TOP = 1 << 0, + POPPLER_FIND_STOP_AT_BOTTOM = 1 << 1, + POPPLER_FIND_START_AT_LAST = 1 << 2, + POPPLER_FIND_STOP_AT_LAST = 1 << 3, + POPPLER_FIND_CASE_SENSITIVE = 1 << 4, + POPPLER_FIND_BACKWARDS = 1 << 5, + POPPLER_FIND_WHOLE_WORD = 1 << 6, + POPPLER_FIND_DEFAULT = POPPLER_FIND_STOP_AT_BOTTOM +} PopplerFindFlags; + typedef struct _PopplerDocument PopplerDocument; typedef struct _PopplerIndexIter PopplerIndexIter; typedef struct _PopplerFontsIter PopplerFontsIter; diff --git glib/reference/poppler-sections.txt glib/reference/poppler-sections.txt index 5a6708b..15aee61 100644 --- glib/reference/poppler-sections.txt +++ 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