mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-31 05:28:09 -06:00
place_tagged wrapped the page's content in q/Q only when no Wrap stream existed yet. Content appended after an earlier wrapper (by another tool, or an older OCR layer) that left a cm, a clip or text state set then moved, hid or distorted every later header, Bates number, watermark, added text, flattened annotation and redaction cover. Placing a mark on top now reads the page's actual operators instead of the /PCMark tags. When the content parses cleanly with balanced q/Q and closed text objects and paths, the stretch from the first stream that leaves state set is wrapped, once, at a stream boundary no comment runs into. Content that is already self-contained gets no new wrapper, so repeated marks don't pile up. Content that can't be read that precisely (stray bytes, unbalanced q/Q, an unfinished text object or path, too large) is wrapped whole as before, rather than refusing: redaction stamps its covers after removing the text and can't back out. A q that content leaves open is closed after it, where closing it changes nothing already drawn. The wrapper's close now starts with a newline, so a comment at the end of the content before it can't swallow the Q. Removing marks strips only wrapper pairs that end the list, keeping one that later content still relies on, and recognises the older close bytes too.