summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-08-21 16:54:02 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-08-21 17:20:10 +0200
commitbdbbea6d8868489391c29a9b2e84902e02e5058b (patch)
tree2666b921515b56f6fcd285a25ea053c76ccd8800 /source
parent5947bedcbf684907b003b7088a59f091ca04326a (diff)
downloadmupdf-bdbbea6d8868489391c29a9b2e84902e02e5058b.tar.xz
Remove fz_char_and_box struct.
Use fz_stext_char directly instead.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/stext-search.c72
1 files changed, 31 insertions, 41 deletions
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,11 +16,35 @@ 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;
int ofs = 0;
for (block = page->first_block; block; block = block->next)
@@ -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)
{