Commit ed0c761c authored by Thomas Schenker's avatar Thomas Schenker Committed by Carlos Garcia Campos

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
parent 126b55c9
......@@ -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),
......
......@@ -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,
......
......@@ -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;
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment