From bdbbea6d8868489391c29a9b2e84902e02e5058b Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 21 Aug 2017 16:54:02 +0200 Subject: Remove fz_char_and_box struct. Use fz_stext_char directly instead. --- source/fitz/stext-search.c | 72 ++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 41 deletions(-) (limited to 'source/fitz') diff --git a/source/fitz/stext-search.c b/source/fitz/stext-search.c index 4bf2882a..d9da2900 100644 --- a/source/fitz/stext-search.c +++ b/source/fitz/stext-search.c @@ -16,8 +16,32 @@ static inline int iswhite(int c) return c == ' ' || c == '\r' || c == '\n' || c == '\t' || c == 0xA0 || c == 0x2028 || c == 0x2029; } -fz_char_and_box *fz_stext_char_at(fz_context *ctx, fz_char_and_box *cab, fz_stext_page *page, int idx) +int fz_stext_char_count(fz_context *ctx, fz_stext_page *page) { + fz_stext_block *block; + fz_stext_line *line; + fz_stext_char *ch; + int len = 0; + + for (block = page->first_block; block; block = block->next) + { + if (block->type != FZ_STEXT_BLOCK_TEXT) + continue; + for (line = block->u.t.first_line; line; line = line->next) + { + for (ch = line->first_char; ch; ch = ch->next) + ++len; + ++len; /* pseudo-newline */ + } + } + + return len; +} + +const fz_stext_char *fz_stext_char_at(fz_context *ctx, fz_stext_page *page, int idx) +{ + static const fz_stext_char space = { ' ', 0, {0,0}, {0,0,0,0}, 0, NULL, NULL }; + static const fz_stext_char zero = { '\0', 0, {0,0}, {0,0,0,0}, 0, NULL, NULL }; fz_stext_block *block; fz_stext_line *line; fz_stext_char *ch; @@ -32,65 +56,31 @@ fz_char_and_box *fz_stext_char_at(fz_context *ctx, fz_char_and_box *cab, fz_stex for (ch = line->first_char; ch; ch = ch->next) { if (ofs == idx) - { - cab->c = ch->c; - cab->bbox = ch->bbox; - return cab; - } + return ch; ++ofs; } /* pseudo-newline */ if (idx == ofs) - { - cab->bbox = fz_empty_rect; - cab->c = ' '; - return cab; - } + return &space; ++ofs; } } - cab->bbox = fz_empty_rect; - cab->c = 0; - return cab; + return &zero; } static inline int charat(fz_context *ctx, fz_stext_page *page, int idx) { - fz_char_and_box cab; - return fz_stext_char_at(ctx, &cab, page, idx)->c; + return fz_stext_char_at(ctx, page, idx)->c; } static fz_rect *bboxat(fz_context *ctx, fz_stext_page *page, int idx, fz_rect *bbox) { - fz_char_and_box cab; /* FIXME: Nasty extra copy */ - *bbox = fz_stext_char_at(ctx, &cab, page, idx)->bbox; + *bbox = fz_stext_char_at(ctx, page, idx)->bbox; return bbox; } -static int textlen_stext(fz_context *ctx, fz_stext_page *page) -{ - fz_stext_block *block; - fz_stext_line *line; - fz_stext_char *ch; - int len = 0; - - for (block = page->first_block; block; block = block->next) - { - if (block->type != FZ_STEXT_BLOCK_TEXT) - continue; - for (line = block->u.t.first_line; line; line = line->next) - { - for (ch = line->first_char; ch; ch = ch->next) - ++len; - ++len; /* pseudo-newline */ - } - } - - return len; -} - static int match_stext(fz_context *ctx, fz_stext_page *page, const char *s, int n) { int orig = n; @@ -130,7 +120,7 @@ fz_search_stext_page(fz_context *ctx, fz_stext_page *text, const char *needle, f return 0; hit_count = 0; - len = textlen_stext(ctx, text); + len = fz_stext_char_count(ctx, text); pos = 0; while (pos < len) { -- cgit v1.2.3