diff options
-rw-r--r-- | include/mupdf/fitz/structured-text.h | 1 | ||||
-rw-r--r-- | source/fitz/stext-device.c | 21 | ||||
-rw-r--r-- | source/fitz/stext-output.c | 6 |
3 files changed, 13 insertions, 15 deletions
diff --git a/include/mupdf/fitz/structured-text.h b/include/mupdf/fitz/structured-text.h index 0f3364b3..922b8c84 100644 --- a/include/mupdf/fitz/structured-text.h +++ b/include/mupdf/fitz/structured-text.h @@ -81,6 +81,7 @@ struct fz_stext_block_s struct fz_stext_line_s { int wmode; /* 0 for horizontal, 1 for vertical */ + fz_point dir; /* normalized direction of baseline */ fz_rect bbox; fz_stext_char *first_char, *last_char; fz_stext_line *next; diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c index 166f5aa0..87009f03 100644 --- a/source/fitz/stext-device.c +++ b/source/fitz/stext-device.c @@ -113,7 +113,7 @@ add_image_block_to_page(fz_context *ctx, fz_stext_page *page, const fz_matrix *c } static fz_stext_line * -add_line_to_block(fz_context *ctx, fz_stext_page *page, fz_stext_block *block, int wmode) +add_line_to_block(fz_context *ctx, fz_stext_page *page, fz_stext_block *block, const fz_point *dir, int wmode) { fz_stext_line *line = fz_pool_alloc(ctx, page->pool, sizeof *block->u.t.first_line); if (!block->u.t.first_line) @@ -124,6 +124,7 @@ add_line_to_block(fz_context *ctx, fz_stext_page *page, fz_stext_block *block, i block->u.t.last_line = line; } + line->dir = *dir; line->wmode = wmode; return line; @@ -229,15 +230,9 @@ direction_from_bidi_class(int bidiclass, int curdir) } static int -sign_eq(float x, float y) +vec_dot(const fz_point *a, const fz_point *b) { - return (x < 0 && y < 0) || (x > 0 && y > 0) || (x == 0 && y == 0); -} - -static int -mat_sign_eq(const fz_matrix *x, const fz_matrix *y) -{ - return sign_eq(x->a, y->a) && sign_eq(x->b, y->b) && sign_eq(x->c, y->c) && sign_eq(x->d, y->d); + return a->x * b->x + a->y * b->y; } static void @@ -320,7 +315,7 @@ fz_add_stext_char_imp(fz_context *ctx, fz_stext_device *dev, fz_font *font, int return; } - if (cur_line == NULL || !mat_sign_eq(trm, &dev->trm) || cur_line->wmode != wmode) + if (cur_line == NULL || cur_line->wmode != wmode || vec_dot(&ndir, &cur_line->dir) < 0.999f) { /* If the matrix has changed rotation, or the wmode is different (or if we don't have a line at all), * then we can't append to the current block/line. */ @@ -330,8 +325,8 @@ fz_add_stext_char_imp(fz_context *ctx, fz_stext_device *dev, fz_font *font, int else { /* Detect fake bold where text is printed twice in the same place. */ - delta.x = q.x - dev->pen.x; - delta.y = q.y - dev->pen.y; + delta.x = fabsf(q.x - dev->pen.x); + delta.y = fabsf(q.y - dev->pen.y); if (delta.x < FLT_EPSILON && delta.y < FLT_EPSILON && c == dev->lastchar) return; @@ -410,7 +405,7 @@ fz_add_stext_char_imp(fz_context *ctx, fz_stext_device *dev, fz_font *font, int /* Start a new line */ if (new_line || !cur_line) { - cur_line = add_line_to_block(ctx, page, cur_block, wmode); + cur_line = add_line_to_block(ctx, page, cur_block, &ndir, wmode); dev->start = p; } diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c index f5f72412..78136c16 100644 --- a/source/fitz/stext-output.c +++ b/source/fitz/stext-output.c @@ -311,8 +311,10 @@ fz_print_stext_page_as_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) const char *s; fz_rect rect; - fz_write_printf(ctx, out, "<line bbox=\"%g %g %g %g\">\n", - line->bbox.x0, line->bbox.y0, line->bbox.x1, line->bbox.y1); + fz_write_printf(ctx, out, "<line bbox=\"%g %g %g %g\" wmode=\"%d\" dir=\"%g %g\">\n", + line->bbox.x0, line->bbox.y0, line->bbox.x1, line->bbox.y1, + line->wmode, + line->dir.x, line->dir.y); for (ch = line->first_char; ch; ch = ch->next) { |