Skip to content

text: raise a clear error for a NaN or infinite position - #2141

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:text-finite-position
Nov 10, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:text-finite-position

Conversation

@RavSinghChandan

Copy link
Copy Markdown

FPDF.text(x, y, ...) writes a NaN or infinite position straight into the content stream, which is not a valid PDF number:

pdf.text(float("nan"), 10, "Hello")   # writes: BT nan 813.54 Td (Hello) Tj ET

set_x(), set_y() and set_xy() already reject these with _check_coordinate() (#2121), so text() now calls the same helper for x and y, before anything is written. Finite positions, including negative ones, are unchanged.

This does not overlap with #2139, which covers line(), polyline(), polygon(), ellipse() and circle().

Added test_text_not_finite_position (NaN, inf and -inf, for x and for y); it fails on master. The full test suite passes except test_image_with_explicit_dimensions, which also fails on master in my environment

@andersonhc
andersonhc merged commit 52dd1e2 into py-pdf:master Nov 10, 2026
23 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