Bug Description
When using TextRegion with ln(h), the internal font_size_pt state from a previous paragraph can affect line spacing in the next paragraph. This is the root cause behind #1786 (which I submitted a fix for in PR #1803).
Root Cause Analysis
The issue is deeper than the ln() fix — TextRegion._render_paragraph() modifies self.pdf.font_size_pt during rendering, but does not restore it when the paragraph ends. If the next operation reads font_size_pt (e.g., ln() without an explicit h), it gets the value from the last line of the previous paragraph rather than the current font setting.
Minimal Reproduction
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
with pdf.text_region() as region:
pdf.set_font("Helvetica", size=24)
region.paragraph().write("Large heading")
region.ln() # uses font_size_pt from the 24pt paragraph
pdf.set_font("Helvetica", size=10)
region.paragraph().write("Small body text")
region.ln() # should use 10pt spacing, but may inherit 24pt
Expected Behavior
Each ln() call should use the current font size at the time of the call, not the font size from the last rendered paragraph.
Environment
Bug Description
When using
TextRegionwithln(h), the internalfont_size_ptstate from a previous paragraph can affect line spacing in the next paragraph. This is the root cause behind #1786 (which I submitted a fix for in PR #1803).Root Cause Analysis
The issue is deeper than the
ln()fix —TextRegion._render_paragraph()modifiesself.pdf.font_size_ptduring rendering, but does not restore it when the paragraph ends. If the next operation readsfont_size_pt(e.g.,ln()without an explicith), it gets the value from the last line of the previous paragraph rather than the current font setting.Minimal Reproduction
Expected Behavior
Each
ln()call should use the current font size at the time of the call, not the font size from the last rendered paragraph.Environment