int fz_search_stext_page(fz_context *ctx, fz_stext_page *text, const char *needle, fz_rect *hit_bbox, int hit_max) { int pos, len, i, n, hit_count; if (strlen(needle) == 0) return 0; hit_count = 0; len = textlen_stext(ctx, text); pos = 0; while (pos < len) { n = match_stext(ctx, text, needle, pos); if (n) { fz_rect linebox = fz_empty_rect; for (i = 0; i < n; i++) { fz_rect charbox; bboxat(ctx, text, pos + i, &charbox); if (!fz_is_empty_rect(&charbox)) { if (charbox.y0 != linebox.y0 || fz_abs(charbox.x0 - linebox.x1) > 5) { if (!fz_is_empty_rect(&linebox) && hit_count < hit_max) hit_bbox[hit_count++] = linebox; linebox = charbox; } else { fz_union_rect(&linebox, &charbox); } } } if (!fz_is_empty_rect(&linebox) && hit_count < hit_max) hit_bbox[hit_count++] = linebox; pos += n; } else { pos += 1; } } return hit_count; }
int fz_search_text_page(fz_context *ctx, fz_text_page *text, char *needle, fz_bbox *hit_bbox, int hit_max) { int pos, len, i, n, hit_count; if (strlen(needle) == 0) return 0; hit_count = 0; len = textlen(text); for (pos = 0; pos < len; pos++) { n = match(text, needle, pos); if (n) { fz_bbox linebox = fz_empty_bbox; for (i = 0; i < n; i++) { fz_bbox charbox = bboxat(text, pos + i); if (!fz_is_empty_bbox(charbox)) { if (charbox.y0 != linebox.y0 || fz_absi(charbox.x0 - linebox.x1) > 5) { if (!fz_is_empty_bbox(linebox) && hit_count < hit_max) hit_bbox[hit_count++] = linebox; linebox = charbox; } else { linebox = fz_union_bbox(linebox, charbox); } } } if (!fz_is_empty_bbox(linebox) && hit_count < hit_max) hit_bbox[hit_count++] = linebox; } } return hit_count; }