summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/jni/mupdf.c34
-rw-r--r--fitz/fitz.h2
-rw-r--r--fitz/text_search.c9
3 files changed, 10 insertions, 35 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c
index 47196840..514bdde4 100644
--- a/android/jni/mupdf.c
+++ b/android/jni/mupdf.c
@@ -954,25 +954,6 @@ textlen(fz_text_page *page)
}
static int
-match(fz_text_page *page, const char *s, int n)
-{
- int orig = n;
- int c;
- while (*s) {
- s += fz_chartorune(&c, (char *)s);
- if (c == ' ' && charat(page, n) == ' ') {
- while (charat(page, n) == ' ')
- n++;
- } else {
- if (tolower(c) != tolower(charat(page, n)))
- return 0;
- n++;
- }
- }
- return n - orig;
-}
-
-static int
countOutlineItems(fz_outline *outline)
{
int count = 0;
@@ -1138,20 +1119,7 @@ JNI_FN(MuPDFCore_searchPage)(JNIEnv * env, jobject thiz, jstring jtext)
fz_free_device(dev);
dev = NULL;
- len = textlen(text);
- for (pos = 0; pos < len; pos++)
- {
- fz_rect rr = fz_empty_rect;
- n = match(text, str, pos);
- for (i = 0; i < n; i++)
- {
- fz_rect bbox = bboxcharat(text, pos + i);
- fz_union_rect(&rr, &bbox);
- }
-
- if (!fz_is_empty_rect(&rr) && hit_count < MAX_SEARCH_HITS)
- glo->hit_bbox[hit_count++] = rr;
- }
+ hit_count = fz_search_text_page(ctx, text, str, glo->hit_bbox, MAX_SEARCH_HITS);
}
fz_always(ctx)
{
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 52264d92..8817672d 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -2292,7 +2292,7 @@ void fz_print_text_page(fz_context *ctx, fz_output *out, fz_text_page *page);
NOTE: This is an experimental interface and subject to change without notice.
*/
-int fz_search_text_page(fz_context *ctx, fz_text_page *text, char *needle, fz_rect *hit_bbox, int hit_max);
+int fz_search_text_page(fz_context *ctx, fz_text_page *text, const char *needle, fz_rect *hit_bbox, int hit_max);
/*
fz_highlight_selection: Return a list of rectangles to highlight given a selection rectangle.
diff --git a/fitz/text_search.c b/fitz/text_search.c
index 6631535b..9b0a3acf 100644
--- a/fitz/text_search.c
+++ b/fitz/text_search.c
@@ -103,9 +103,16 @@ static int match(fz_text_page *page, const char *s, int n)
s += fz_chartorune(&c, (char *)s);
if (iswhite(c) && iswhite(charat(page, n)))
{
+ const char *s_next;
+
+ /* Skip over whitespace in the document */
do
n++;
while (iswhite(charat(page, n)));
+
+ /* Skip over multiple whitespace in the search string */
+ while (s_next = s + fz_chartorune(&c, (char *)s), iswhite(c))
+ s = s_next;
}
else
{
@@ -118,7 +125,7 @@ static int match(fz_text_page *page, const char *s, int n)
}
int
-fz_search_text_page(fz_context *ctx, fz_text_page *text, char *needle, fz_rect *hit_bbox, int hit_max)
+fz_search_text_page(fz_context *ctx, fz_text_page *text, const char *needle, fz_rect *hit_bbox, int hit_max)
{
int pos, len, i, n, hit_count;