fix: Paragraph.ln(h) no longer causes a double line break - #1903
Closed
Sanjays2402 wants to merge 1 commit into
Closed
fix: Paragraph.ln(h) no longer causes a double line break#1903Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
Paragraph.ln(h) carries the requested vertical gap by appending a newline fragment whose font_size_pt is set to h. In MultiLineBreak.get_line() the per-fragment font size was folded into current_font_height *before* the check that skips a fragment whose characters are already consumed, so the inflated newline fragment kept driving the height of the following line - producing an extra blank line after the first line of the next paragraph. Moving the exhausted-fragment check ahead of the font-size update leaves the requested gap intact while the next line uses the real font height. Adds a regression test asserting all four lines around an ln(16) share the same height; it fails without the source change. Closes py-pdf#1786
andersonhc
requested changes
Aug 5, 2026
|
|
||
| if character in (NEWLINE, FORM_FEED): | ||
| self.character_index += 1 | ||
| if not current_line.fragments: |
Collaborator
There was a problem hiding this comment.
Suggested change
| if not current_line.fragments or FloatTolerance.greater_than( | |
| current_font_height * self.line_height, current_line.height | |
| ):: |
We should also allow a newline character to increase the line height
| cols.write("A1\nA2") | ||
| cols.ln(16) | ||
| cols.write("B1\nB2") | ||
| heights = [lw.line.height for lw in cols._paragraphs[0].build_lines(False)] |
Collaborator
There was a problem hiding this comment.
Suggested change
| heights = [lw.line.height for lw in cols._paragraphs[0].build_lines(False)] | |
| heights = [ | |
| lw.line.height for lw in cols._paragraphs[0].build_lines(False) | |
| ] # pylint: disable=protected-access |
We need to disable the pylint check here so the lint job can pass
Collaborator
|
I just saw you opened PR #1904 fixing the issue. I'm closing this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1786
Paragraph.ln(h)carries the requested gap by appending a newline fragment whosefont_size_ptis set toh. InMultiLineBreak.get_line()the per-fragment font size was folded intocurrent_font_heightbefore the check that skips a fragment whose characters are already consumed, so the inflated newline fragment kept driving the height of the following line — producing an extra blank line after the first line of the next paragraph. Moving the exhausted-fragment check ahead of the font-size update keeps the requested gap while the next line uses the real font height.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 — N/AA mention of the change is present in
CHANGELOG.mdThis 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.