mirror of
https://github.com/ocrmypdf/OCRmyPDF.git
synced 2026-04-23 23:52:05 -04:00
strip_invisible_text resets the text render mode on each `BT` (begin text) command. However the text state is not actually reset for each text element, only for each page. The pdf reference says: > The text state operators can appear outside text objects, and the values they set > are retained across text objects in a single content stream. Like other graphics > state parameters, these parameters are initialized to their default values at the > beginning of each page. > > -- https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf#page=397 With the current implementation, a text object is only deleted if it contains a `3 Tr` command (setting the text rendering mode to invalid). However the rendering mode may be set once and then not changed for multiple text objects or set outside of a text object. In that case only the first text object (which contains the `3 Tr`-command) is removed. This not only leaves the other text objects in the pdf, but also makes them visible, since the text object that contained the `3 Tr`-command is removed. This PR updates `strip_invisible_text` to not reset the rendering mode for each object and to keep track of the rendering mode when the graphic state is pushed/popped.