From 83a272b13561436b924a30a61691f6e11928a662 Mon Sep 17 00:00:00 2001 From: Ken Sharp Date: Mon, 4 Apr 2022 13:49:58 +0100 Subject: GhostPDF - fix text rendering mode 3 and pdfwrite Bug #705187 "Ghostscript 9.56 removes hidden (e.g. OCR) text layers when refrying with NEWPDF=true" Due to an oversight in the code to preserve text rendering modes pdfwrite was falling back to rendering text to bitmaps in some cases. This was especially a problem with text in text rendering mode 3 because that doesn't make any marks on the page, snd so we ended up discarding the text altogether. This commit adds the TEXT_RETURN_WIDTH flag to the text operation which means pdfwrite will properly process the text. This shows two differences in our automated tests. Firstly a file which has an invalid sized glyph (point size > 1,000,000) which worked with the old code simply because we did not embed the font. The new PDF interpreter does embed the font (which is a separate bug) and that causes an error to be thrown. Because our testing runs with -dPDFSTOPONERROR that means content goes missing. If we don't set that flag then it all renders correctly. I'm choosing to ignore the problem for those reasons and the fact that the original PDF ifle is broken. Secondly a file that had stopped throwing an error with the new PDF interpreter goes back to throwing an error, now that we are not discarding the text. Again, this is a separate bug (which I will open a report for shortly) and is not a change in behaviour wrt the old PDF interpreter so I'm choosing to ignore it with this commit. --- pdf/pdf_text.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pdf/pdf_text.c b/pdf/pdf_text.c index e6345d0f0..e22f0c0ef 100644 --- a/pdf/pdf_text.c +++ b/pdf/pdf_text.c @@ -821,12 +821,12 @@ static int pdfi_show_Tr_preserve(pdf_context *ctx, gs_text_params_t *text) Trmode = gs_currenttextrenderingmode(ctx->pgs); if (Trmode == 3) { if (current_font->pdfi_font_type == e_pdf_font_type3) - text->operation = TEXT_FROM_CHARS | TEXT_DO_NONE | TEXT_RENDER_MODE_3; + text->operation = TEXT_RETURN_WIDTH | TEXT_FROM_CHARS | TEXT_DO_NONE | TEXT_RENDER_MODE_3; else - text->operation = TEXT_FROM_BYTES | TEXT_DO_NONE | TEXT_RENDER_MODE_3; + text->operation = TEXT_RETURN_WIDTH | TEXT_FROM_BYTES | TEXT_DO_NONE | TEXT_RENDER_MODE_3; } else - text->operation |= TEXT_DO_DRAW; + text->operation |= TEXT_RETURN_WIDTH | TEXT_DO_DRAW; /* If we're preserving the text rendering mode, then we don't run a separate * stroke operation, we do effectively run a fill. The fill setup loads the -- cgit v1.2.1