summaryrefslogtreecommitdiff
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
parent5947bedcbf684907b003b7088a59f091ca04326a (diff)
downloadmupdf-bdbbea6d8868489391c29a9b2e84902e02e5058b.tar.xz
Remove fz_char_and_box struct.
Use fz_stext_char directly instead.
-rw-r--r--include/mupdf/fitz/structured-text.h25
-rw-r--r--source/fitz/stext-search.c72
2 files changed, 33 insertions, 64 deletions
diff --git a/include/mupdf/fitz/structured-text.h b/include/mupdf/fitz/structured-text.h
index 922b8c84..4386fd31 100644
--- a/include/mupdf/fitz/structured-text.h
+++ b/include/mupdf/fitz/structured-text.h
@@ -101,31 +101,10 @@ struct fz_stext_char_s
fz_stext_char *next;
};
-typedef struct fz_char_and_box_s fz_char_and_box;
-
-struct fz_char_and_box_s
-{
- int c;
- fz_rect bbox;
-};
-
extern const char *fz_stext_options_usage;
-fz_char_and_box *fz_stext_char_at(fz_context *ctx, fz_char_and_box *cab, fz_stext_page *page, int idx);
-
-/*
- fz_stext_char_bbox: Return the bbox of a text char. Calculated from
- the supplied enclosing line.
-
- bbox: A place to store the bbox.
-
- line: The enclosing line.
-
- ch: The character.
-
- Returns bbox (updated).
-*/
-fz_rect *fz_stext_char_bbox(fz_context *ctx, fz_rect *bbox, fz_stext_line *line, fz_stext_char *ch);
+int fz_stext_char_count(fz_context *ctx, fz_stext_page *page);
+const fz_stext_char *fz_stext_char_at(fz_context *ctx, fz_stext_page *page, int idx);
/*
fz_new_stext_page: Create an empty text page.
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)
{