Fix rounded rectangle rendering with thick borders and fill artifacts#1634
Merged
Lucas-C merged 5 commits intopy-pdf:masterfrom Oct 23, 2025
Merged
Conversation
andersonhc
reviewed
Oct 21, 2025
andersonhc
requested changes
Oct 21, 2025
Collaborator
andersonhc
left a comment
There was a problem hiding this comment.
Please see comments
Also, the lint job is failing. Please run black and pylint before the next commit.
…update docstrings, run black and pylint
Lucas-C
approved these changes
Oct 21, 2025
Collaborator
|
@allcontributors please add @Ai-Chetan for code |
|
I've put up a pull request to add @Ai-Chetan! 🎉 |
Collaborator
|
@Ai-Chetan please add an entry on the CHANGELOG.md file, something like We should be good to merge after that. |
andersonhc
approved these changes
Oct 21, 2025
Member
|
Merged! Thank you very much @Ai-Chetan for your contribution 👍 |
Member
|
This has just been released in the new published version 2.8.5: |
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.
Fix: Rounded rectangle rendering issues with thick borders and fill artifacts
Fixes #1632
Fixes rendering bugs in rectangles with rounded corners where thick borders caused arc positioning issues and fill colors showed visible line artifacts at corners.
🐛 Problem
When rendering rectangles with rounded corners using
rect(..., round_corners=True), two visual issues occurred:Reproduction code:
🔧 Root Cause
The
_draw_rounded_rect()method drew each corner arc as a separate path operation with independent fill/stroke operations, then added separate lines for edges. This caused:✅ Solution
Rewrote
_draw_rounded_rect()to construct the entire rounded rectangle as a single continuous closed path:_draw_arc_segment()that draws arc segments without starting a new path or applying styles_draw_rounded_rect()to:m(move) commandl(line) andc(curve) commandshand apply the style operator once at the endBenefits:
🧪 Testing
Automated tests:
Manual validation:
# Generate visual validation PDF python scripts/validate_round_corners_fix.pyAdded comprehensive test suite in
test/shapes/test_round_corners_fix.pywith 3 test cases:test_round_corners_thick_border- Verifies thick borders render without positioning issuestest_round_corners_fill_no_artifacts- Verifies filled corners have no visible line artifactstest_round_corners_combined_issue- Tests both issues togetherAll existing rounded corner tests updated and passing ✅
📝 Changes
Modified:
fpdf/fpdf.py- Rewrote_draw_rounded_rect(), added_draw_arc_segment()helper methodtest/shapes/class_round_corners_rect.pdf- Updated reference PDFtest/shapes/class_round_corners_rect_conditionals.pdf- Updated reference PDFtest/shapes/class_round_corners_rect_draw_color.pdf- Updated reference PDFAdded:
test/shapes/test_round_corners_fix.py- New test file with 3 comprehensive teststest/shapes/round_corners_thick_border.pdf- Reference PDF for thick border testtest/shapes/round_corners_fill_no_artifacts.pdf- Reference PDF for fill artifacts testtest/shapes/round_corners_combined_fix.pdf- Reference PDF for combined testscripts/validate_round_corners_fix.py- Visual validation script✔️ Checklist
docs/folder (N/A - bug fix)CHANGELOG.mdVisual comparison:
Before (with bugs):
After (fixed):
Run
python scripts/validate_round_corners_fix.pyto generate a validation PDF demonstrating the fix.By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.