Skip to content

set_font: raise a clear error for a negative font size - #2083

Merged
andersonhc merged 3 commits into
py-pdf:masterfrom
RavSinghChandan:font-size-negative
Oct 30, 2026
Merged

andersonhc merged 3 commits into
py-pdf:masterfrom
RavSinghChandan:font-size-negative

Conversation

@RavSinghChandan

Copy link
Copy Markdown

set_font(size=-12) and set_font_size(-12) wrote a negative font size: the text was mirrored and each line of multi_cell() moved up the page, above the top margin. Both now raise ValueError: Font size must be zero or a positive number, like set_line_width() does for a negative width. A size of 0 still means "keep the current size" in set_font().

So that write_html() does not start raising, it ignores a negative <font size> or CSS font-size, like browsers, and keeps the current size.

  • A unit test is covering the code added / modified by this PR
  • A mention of the change is present in CHANGELOG.md
  • This PR is ready to be merged

@andersonhc
andersonhc merged commit e1093ac into py-pdf:master Oct 30, 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