Skip to content

rect: round the corners named in round_corners - #2098

Merged
andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:rect-corner-names
Nov 3, 2026
Merged

andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:rect-corner-names

Conversation

@RavSinghChandan

Copy link
Copy Markdown

FPDF.rect() rounds the opposite corner of the one named in round_corners, left and right being swapped:

pdf.rect(50, 50, 100, 100, round_corners=("TOP_LEFT",), corner_radius=20)      # rounds the top right corner
pdf.rect(50, 50, 100, 100, round_corners=("BOTTOM_RIGHT",), corner_radius=20)  # rounds the bottom left corner

The image of the documentation shows it too: its code rounds the BOTTOM_RIGHT corner of the green rectangle and the TOP_LEFT and BOTTOM_LEFT corners of the yellow square, but the image shows the bottom left corner and the right corners rounded. In _draw_rounded_rect, each corner name moved the points and drew the arc of the corner on the other side; the names in the conditions are now swapped back (and the comments of the arcs fixed to match).

  • test_round_corners_rect_corner_position checks, for each corner name, that the arc is drawn in that corner of the rectangle; it fails for all four names before the fix.

  • The three class_round_corners_rect*.pdf reference files are regenerated: in their second row, each rectangle now has the named corner rounded. round_corners=True is unchanged.

  • The documentation example passed round_corners=("BOTTOM_RIGHT"), a string rather than a tuple, which raises ValueError: B is not a valid Corner; it now passes ("BOTTOM_RIGHT",), and round_corners_rectangles.png is regenerated from it.

  • 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 781df6a into py-pdf:master Nov 3, 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