Skip to content

fix(text_region): prevent font state leaking out of text_columns rendering#1849

Open
SAY-5 wants to merge 1 commit into
py-pdf:masterfrom
SAY-5:fix-1804-textregion-font-size-leak
Open

fix(text_region): prevent font state leaking out of text_columns rendering#1849
SAY-5 wants to merge 1 commit into
py-pdf:masterfrom
SAY-5:fix-1804-textregion-font-size-leak

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 13, 2026

Fixes #1804

The render path inside _render_styled_text_line mutates self.font_size_pt to match each fragment but never restores it, so text_columns() leaves the FPDF instance with the font size of the last rendered fragment. Snapshot current_font, font_size_pt, and font_style at the start of TextColumns.render() and restore them in a finally block.

Checklist:

  • A unit test is covering the code added / modified by this PR

  • In case of a new feature, docstrings have been added, with also some documentation in the `docs/` folder

  • A mention of the change is present in `CHANGELOG.md`

  • This PR is ready to be merged

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@SAY-5 SAY-5 force-pushed the fix-1804-textregion-font-size-leak branch from ca0c11f to 7b78c17 Compare May 19, 2026 00:02
@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented May 19, 2026

Reworked this: the snapshot/restore now lives in ParagraphCollectorMixin.__exit__ around render() rather than inside TextColumns.render(), so HTML rendering (which calls render() directly without the context manager) keeps its font-state persistence and all of test_html.py stays green. Full test/text_region/ and test/html/ suites pass locally, and the regression test fails on master without the fix.

@SAY-5 SAY-5 force-pushed the fix-1804-textregion-font-size-leak branch from 7b78c17 to ced532a Compare May 19, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

font_size_pt state bleeds across TextRegion boundaries when using ln()

2 participants