Expose MuPDF's search function#2279
Conversation
|
Minor sidenote (though one can't imagine it changing that much): |
| cdecl_func(mupdf_fz_bound_page) | ||
| cdecl_func(fz_drop_page) | ||
|
|
||
| cdecl_func(mupdf_fz_search_stext_page); |
There was a problem hiding this comment.
Let's keep it in the structured text block a bit further down.
| --[[ | ||
| Get a list of matches for the given text on the page, with their coordinates. | ||
| --]] | ||
| function page_mt.__index:search(needle, hit_max) |
There was a problem hiding this comment.
I'd go for something like searchPageText, both to fit in with getPageText right above and to be clear that it's not searching through the entire document.
| fz_alloc_context *mupdf_get_my_alloc_context(); | ||
| int mupdf_get_cache_size(); | ||
| int mupdf_error_code(fz_context *); | ||
| int mupdf_fz_search_stext_page(fz_context *ctx, fz_stext_page *text, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max); |
There was a problem hiding this comment.
The CI was complaining about this location not matching with the cdefs, but mind like I said I'd like to improve the location in the cdefs. ^_^
| local hit_mark = ffi.new("int[?]", hit_max) -- allocate the hit_mark array | ||
|
|
||
| local count = W.mupdf_fz_search_stext_page(ctx, text_page, needle, hit_mark, hits, hit_max) |
There was a problem hiding this comment.
You should be able to just pass nil: no point in allocating hit_mark if it's not going to be used.
| int mupdf_fz_search_stext_page(fz_context *ctx, fz_stext_page *text, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max) { | ||
| return fz_search_stext_page(ctx, text, needle, hit_mark, hit_bbox, hit_max); | ||
| } |
There was a problem hiding this comment.
The whole point of those wrappers is sandwitching those MuPDF calls between fz_try(ctx) / fz_catch(ctx).
So change the declaration in wrap-mupdf.h to use:
MUPDF_WRAP(mupdf_search_stext_page, int, -1,
ret = fz_search_stext_page(ctx, text, needle, hit_mark, hit_bbox, hit_max),
fz_stext_page *text, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max)There was a problem hiding this comment.
Which means completely dropping this change.
|
hoping I didn't miss anything, excuse my clumsiness around here... unknown surroundings ;) |
| int mupdf_fz_search_stext_page(fz_context *ctx, fz_stext_page *text, const char *needle, int *hit_mark, fz_quad *hit_bbox, int hit_max) { | ||
| return fz_search_stext_page(ctx, text, needle, hit_mark, hit_bbox, hit_max); | ||
| } |
There was a problem hiding this comment.
Which means completely dropping this change.
Co-authored-by: Benoit Pierre <benoit.pierre@gmail.com>
Co-authored-by: Benoit Pierre <benoit.pierre@gmail.com>
- zlib: update to 1.3.2 (koreader/koreader-base#2278) - Expose MuPDF's search function (koreader/koreader-base#2279) - mupdf: add getMarkupAnnotationBoxesFromPage() (koreader/koreader-base#2280) - luajit: update to 2.1.1772148810 (koreader/koreader-base#2281)
- zlib: update to 1.3.2 (koreader/koreader-base#2278) - Expose MuPDF's search function (koreader/koreader-base#2279) - mupdf: add getMarkupAnnotationBoxesFromPage() (koreader/koreader-base#2280) - luajit: update to 2.1.1772148810 (koreader/koreader-base#2281)
- zlib: update to 1.3.2 (koreader/koreader-base#2278) - Expose MuPDF's search function (koreader/koreader-base#2279) - mupdf: add getMarkupAnnotationBoxesFromPage() (koreader/koreader-base#2280) - luajit: update to 2.1.1772148810 (koreader/koreader-base#2281)
what's new
I was originally trying to do this in Lua but it turns out this function was there all along for anyone to C (sorry!)
massively simplifies koreader/koreader#15001
mupdf_fz_search_stext_pagethat exposes the MuPDFfz_search_stext_pageAPI for searching text on a page.searchmethod to thepage_mtmetatable inmupdf.lua, which uses the new C function to find all matches for a given string on a page and returns their bounding box coordinates.my effort ;(
https://github.com/ArtifexSoftware/mupdf/blob/8c39e04a09c74fcc96ebb704bf6d1f59adb9b6fa/source/fitz/stext-search.c#L1254-L1285
This change is