Skip to content

fix: prevent TextRegion.ln(h) from causing double line break#1803

Closed
Pawansingh3889 wants to merge 1 commit intopy-pdf:masterfrom
Pawansingh3889:fix/textregion-ln-double-linebreak
Closed

fix: prevent TextRegion.ln(h) from causing double line break#1803
Pawansingh3889 wants to merge 1 commit intopy-pdf:masterfrom
Pawansingh3889:fix/textregion-ln-double-linebreak

Conversation

@Pawansingh3889
Copy link
Copy Markdown

Fixes #1786.

Problem

When calling with a custom height inside a region, the next paragraph gets an unwanted extra line break. This happens because sets on the newline fragment, and this inflated font size bleeds into the height calculation of the next line.

Fix

After appending the height-inflated newline fragment, append a second newline fragment with the original (uninflated) font size. This resets the line height context so subsequent content renders at the correct size.

Testing

Tested with the reproduction script from #1786:

Before: Line 2 had an extra blank line above it.
After: Line 2 renders immediately after the 16pt gap, matching the behavior of outside text regions.

When ln() is called with a custom h value inside a text region,
the inflated font_size_pt on the newline fragment bleeds into the
next line's height calculation, producing an unwanted double line
break.

This fix appends a reset fragment with the original font size
after the height-inflated newline fragment, preventing the size
from carrying over to subsequent content.
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.

TextRegion.ln() not working properly when h is provided

1 participant