go-pdf / fpdf

A PDF document generator with high level support for text, drawing and images
MIT License
543 stars 48 forks source link

Rotating a rounded rectangle causes subsequent elements to also be rotated #83

Closed krelinga closed 1 month ago

krelinga commented 2 months ago

I'll attach a PR shortly to demonstrate the bug. I'm far from an expert, but I think the issue might be in roundedRectPath() of fpdf.go. The code puts a q operator into the document, which (according to the pdf specification) pushes the current graphic state settings onto a stack. This is fine, but the problem is that the code never seems to put a Q operator to pop the state off of the stack. The transform operations (like rotation) also seem to rely on this graphic state stack: TransformBegin() pushes and TransformEnd() pops. So, when we rotate a rounded rectangle we have two pushes but only one pop, and the graphic state introduced by the transform also ends up applying to subsequent elements.

krelinga commented 2 months ago

Some more supporting evidence for the above theory: this commit to my forked copy of the repo seems to fix the issue.