From e8df80eb54d51c9339f7e150e266f21b34945ba0 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 31 Aug 2018 15:09:10 +0200 Subject: Add fz_new_stext_page_from_annot utility function. --- include/mupdf/fitz/util.h | 1 + source/fitz/util.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/mupdf/fitz/util.h b/include/mupdf/fitz/util.h index 1335cf86..87595017 100644 --- a/include/mupdf/fitz/util.h +++ b/include/mupdf/fitz/util.h @@ -41,6 +41,7 @@ fz_pixmap *fz_new_pixmap_from_annot(fz_context *ctx, fz_annot *annot, fz_matrix fz_stext_page *fz_new_stext_page_from_page(fz_context *ctx, fz_page *page, const fz_stext_options *options); fz_stext_page *fz_new_stext_page_from_page_number(fz_context *ctx, fz_document *doc, int number, const fz_stext_options *options); fz_stext_page *fz_new_stext_page_from_display_list(fz_context *ctx, fz_display_list *list, const fz_stext_options *options); +fz_stext_page *fz_new_stext_page_from_annot(fz_context *ctx, fz_annot *annot, const fz_stext_options *options); /* fz_new_buffer_from_stext_page: Convert structured text into plain text. diff --git a/source/fitz/util.c b/source/fitz/util.c index 8f0d9f62..fcf6ca00 100644 --- a/source/fitz/util.c +++ b/source/fitz/util.c @@ -339,6 +339,37 @@ fz_new_stext_page_from_page_number(fz_context *ctx, fz_document *doc, int number return text; } +fz_stext_page * +fz_new_stext_page_from_annot(fz_context *ctx, fz_annot *annot, const fz_stext_options *options) +{ + fz_stext_page *text; + fz_device *dev = NULL; + + fz_var(dev); + + if (annot == NULL) + return NULL; + + text = fz_new_stext_page(ctx, fz_bound_annot(ctx, annot)); + fz_try(ctx) + { + dev = fz_new_stext_device(ctx, text, options); + fz_run_annot(ctx, annot, dev, fz_identity, NULL); + fz_close_device(ctx, dev); + } + fz_always(ctx) + { + fz_drop_device(ctx, dev); + } + fz_catch(ctx) + { + fz_drop_stext_page(ctx, text); + fz_rethrow(ctx); + } + + return text; +} + int fz_search_display_list(fz_context *ctx, fz_display_list *list, const char *needle, fz_quad *hit_bbox, int hit_max) { -- cgit v1.2.3