From 16aeb9588b60ad4df716ef9782493f57ee5d9797 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 8 Aug 2017 14:07:51 +0200 Subject: Add direction of writing vector to fz_stext_line struct. For non-rotated text, this vector will always be [1 0]. --- source/fitz/stext-device.c | 21 ++++++++------------- source/fitz/stext-output.c | 6 ++++-- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'source') 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, "\n", - line->bbox.x0, line->bbox.y0, line->bbox.x1, line->bbox.y1); + fz_write_printf(ctx, out, "\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) { -- cgit v1.2.3