diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2023-03-10 14:35:12 +0000 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2023-03-13 08:55:04 +0000 |
commit | e4ea7e1bd9e29813e273a4ca6d001b4279e8f17c (patch) | |
tree | a29c3bacd1da86a30dc3be547d01ce4fa68cd30b /devices | |
parent | 42c0918f239775be2b1774eb89fadb1577b5df6e (diff) | |
download | ghostpdl-e4ea7e1bd9e29813e273a4ca6d001b4279e8f17c.tar.gz |
Pdfwrite - don't count clipped text for auto rotation
Bug #706443 " AutoRotatePages=/PageByPage can be incorrect when there is text outside the TrimBox"
The bug file has text which lies off the page and so is entirely clipped
out and not passed through to the output file. However, because we count
text in pdf_text_begin, before we determine that the text is clipped,
it is still counted for the purposes of auto-rotation.
In this commit; add a new boolean in the pdf text enumerator to track
whether the text has been entirely clipped out. Initialise the flag in
gdev_pdf_text_begin. Move the counting for the purposes of auto-rotation
from pdf_text_begin to pdf_text_release so that we have a chance to
determine if the text is clipped before counting it. In
pdf_process_string, when we determine the text is clipped out, set the
flag.
I also fixed an annoying compiler warning at the same time, in
gdev_pdf_text_begin.
This causes changes in :
tests_private/comparefiles/541_623.pdf
tests_private/comparefiles/541.pdf
tests_private/comparefiles/Altona_Technical_v20_x4.pdf
tests_private/comparefiles/Clarke-Tate-Manns-Chinese.ai
tests_private/ps/ps3cet/13-29.PS
Because text that is clipped out is no longer considered, which
changes the orientation of these pages. One is a progression, one is
debatable and three are arguably regressions.
So I do not intend to commit this until after the release currently
underway is complete (10.1.0). This will give us some time to see
how it performs internally.
Diffstat (limited to 'devices')
-rw-r--r-- | devices/vector/gdevpdte.c | 3 | ||||
-rw-r--r-- | devices/vector/gdevpdtt.c | 54 | ||||
-rw-r--r-- | devices/vector/gdevpdtt.h | 3 |
3 files changed, 33 insertions, 27 deletions
diff --git a/devices/vector/gdevpdte.c b/devices/vector/gdevpdte.c index 9760094b0..ef171fa3b 100644 --- a/devices/vector/gdevpdte.c +++ b/devices/vector/gdevpdte.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2022 Artifex Software, Inc. +/* Copyright (C) 2001-2023 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -871,6 +871,7 @@ pdf_process_string(pdf_text_enum_t *penum, gs_string *pstr, if (rect.p.x > rect.q.x || rect.p.y > rect.q.y) { penum->index += pstr->size; text->operation &= ~TEXT_DO_DRAW; + penum->text_clipped = true; } } } else { diff --git a/devices/vector/gdevpdtt.c b/devices/vector/gdevpdtt.c index e43dc3819..c25587dbe 100644 --- a/devices/vector/gdevpdtt.c +++ b/devices/vector/gdevpdtt.c @@ -327,6 +327,32 @@ pdf_text_release(gs_text_enum_t *pte, client_name_t cname) gx_device_pdf *pdev = (gx_device_pdf *)penum->dev; ocr_glyph_t *next; + /* Track the dominant text rotation. Ignore text outside the page (text_clipped) and + * any text that isn't drawn, unless it is drawn in text rendering mode 3 (invisible) + */ + if (!penum->text_clipped && (penum->text.operation & TEXT_DO_DRAW || penum->pgs->text_rendering_mode == 3)) + { + gs_matrix tmat; + gs_point p; + int i; + gs_font *font = (gs_font *)penum->current_font; + gs_text_params_t *const text = &pte->text; + + gs_matrix_multiply(&font->FontMatrix, &ctm_only(penum->pgs), &tmat); + gs_distance_transform(1, 0, &tmat, &p); + if (p.x > fabs(p.y)) + i = 0; + else if (p.x < -fabs(p.y)) + i = 2; + else if (p.y > fabs(p.x)) + i = 1; + else if (p.y < -fabs(p.x)) + i = 3; + else + i = 4; + pdf_current_page(pdev)->text_rotation.counts[i] += text->size; + } + if (penum->pte_default) { gs_text_release(NULL, penum->pte_default, cname); penum->pte_default = 0; @@ -569,10 +595,8 @@ gdev_pdf_text_begin(gx_device * dev, gs_gstate * pgs, pdf_text_enum_t *penum; int code, user_defined = 0; gs_memory_t * mem = pgs->memory; - - const gs_font_name *fn = &font->font_name; - byte *chars_ptr = fn->chars; - uint size = fn->size; + byte *chars_ptr = font->font_name.chars; + uint size = font->font_name.size; while (pdf_has_subset_prefix(chars_ptr, size)) { /* Strip off an existing subset prefix. */ @@ -589,27 +613,6 @@ gdev_pdf_text_begin(gx_device * dev, gs_gstate * pgs, pcpath, ppte); } - /* Track the dominant text rotation. */ - { - gs_matrix tmat; - gs_point p; - int i; - - gs_matrix_multiply(&font->FontMatrix, &ctm_only(pgs), &tmat); - gs_distance_transform(1, 0, &tmat, &p); - if (p.x > fabs(p.y)) - i = 0; - else if (p.x < -fabs(p.y)) - i = 2; - else if (p.y > fabs(p.x)) - i = 1; - else if (p.y < -fabs(p.x)) - i = 3; - else - i = 4; - pdf_current_page(pdev)->text_rotation.counts[i] += text->size; - } - pdev->last_charpath_op = 0; if ((text->operation & TEXT_DO_ANY_CHARPATH) && !path0->first_subpath) { if (pdf_compare_text_state_for_charpath(pdev->text->text_state, pdev, pgs, font, text)) @@ -703,6 +706,7 @@ gdev_pdf_text_begin(gx_device * dev, gs_gstate * pgs, penum->charproc_accum = false; pdev->accumulating_charproc = false; penum->cdevproc_callout = false; + penum->text_clipped = false; penum->returned.total_width.x = penum->returned.total_width.y = 0; penum->cgp = NULL; penum->returned.current_glyph = GS_NO_GLYPH; diff --git a/devices/vector/gdevpdtt.h b/devices/vector/gdevpdtt.h index 9d25d48c2..c29b5d46d 100644 --- a/devices/vector/gdevpdtt.h +++ b/devices/vector/gdevpdtt.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2021 Artifex Software, Inc. +/* Copyright (C) 2001-2023 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -100,6 +100,7 @@ typedef struct pdf_text_enum_s { gs_text_enum_t *pte_default; bool charproc_accum; bool cdevproc_callout; + bool text_clipped; double cdevproc_result[10]; pdf_char_glyph_pairs_t *cgp; gs_char output_char_code; |