Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graft: fix invisible text appearing after strip_invisible_text #1448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pajowu
Copy link

@pajowu pajowu commented Dec 11, 2024

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.

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.
@pajowu pajowu force-pushed the pajowu/invisible_text branch from e8ea642 to 636623a Compare December 11, 2024 17:01
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.17%. Comparing base (02d85ff) to head (636623a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1448      +/-   ##
==========================================
- Coverage   90.18%   90.17%   -0.02%     
==========================================
  Files          95       95              
  Lines        7073     7093      +20     
  Branches      722      724       +2     
==========================================
+ Hits         6379     6396      +17     
- Misses        491      493       +2     
- Partials      203      204       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jbarlow83
Copy link
Collaborator

Again: This is great work - I just want to take some time to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants