Skip to content

ROB: Treat a non-numeric text-state operand as missing in layout mode - #4214

Merged
stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:layout-state-param-non-numeric
Oct 20, 2026
Merged

stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:layout-state-param-non-numeric

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

In layout mode, a text-state or positioning operator whose operand is not a number, such as /X Tz, /X Tc, /X TL T*, /X /Y Td or /X 0 0 1 0 0 Tm, made extract_text(extraction_mode="layout") raise TypeError or ValueError: could not convert string to float: '/X'. Plain mode already treats such an operand as missing since #4175 and keeps the text around it.

Layout mode now does the same: set_state_param() leaves Tc, Tz, Tw, TL and Ts unchanged when the operand is not a number, and raw_transform() uses the default for a matrix value it cannot convert, so the text before and after the operator is still extracted.

Used Claude Code (Claude Sonnet 5 and Claude Opus 5.5) to help find and patch this and to draft this description; I reviewed and tested the change.

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.19%. Comparing base (9f86100) to head (75c7f03).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4214      +/-   ##
==========================================
- Coverage   98.19%   98.19%   -0.01%     
==========================================
  Files          59       59              
  Lines       11740    11830      +90     
  Branches     2209     2226      +17     
==========================================
+ Hits        11528    11616      +88     
- Misses        117      118       +1     
- Partials       95       96       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846 stefan6419846 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How reasonable is it to somehow merge the two nearly identical implementations for the float conversion in your latest code changes?

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Makes sense. set_state_param() now reuses _as_float(), with the parameter's current value as the default, so there's only one float conversion. Behaviour is the same: a non-numeric operand still leaves the parameter unchanged.

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

@stefan6419846
stefan6419846 merged commit cd3e646 into py-pdf:main Oct 20, 2026
21 checks passed
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