-
Notifications
You must be signed in to change notification settings - Fork 57
fpdf: fix autobreak when next page already exists #86
base: main
Are you sure you want to change the base?
Conversation
|
@sbinet let me know if I should add any test or provide a reproduction repo. |
sbinet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apologies for the belated answer (coming back from a long vacation)
see my comment below.
| familyStr := f.fontFamily | ||
| style := f.fontStyle | ||
| if f.underline { | ||
| style += "U" | ||
| } | ||
| if f.strikeout { | ||
| style += "S" | ||
| } | ||
| fontsize := f.fontSizePt | ||
| lw := f.lineWidth | ||
| dc := f.color.draw | ||
| fc := f.color.fill | ||
| tc := f.color.text | ||
| cf := f.colorFlag | ||
|
|
||
| f.page += 1 | ||
| f.y = f.tMargin | ||
|
|
||
| // Set line cap style to current value | ||
| // f.out("2 J") | ||
| f.outf("%d J", f.capStyle) | ||
| // Set line join style to current value | ||
| f.outf("%d j", f.joinStyle) | ||
| // Set line width | ||
| f.lineWidth = lw | ||
| f.outf("%.2f w", lw*f.k) | ||
| // Set dash pattern | ||
| if len(f.dashArray) > 0 { | ||
| f.outputDashPattern() | ||
| } | ||
| // Set font | ||
| if familyStr != "" { | ||
| f.SetFont(familyStr, style, fontsize) | ||
| if f.err != nil { | ||
| return | ||
| } | ||
| } | ||
| // Set colors | ||
| f.color.draw = dc | ||
| if dc.str != "0 G" { | ||
| f.out(dc.str) | ||
| } | ||
| f.color.fill = fc | ||
| if fc.str != "0 g" { | ||
| f.out(fc.str) | ||
| } | ||
| f.color.text = tc | ||
| f.colorFlag = cf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be a copy-paste of some of the content of AddPageFormat, w/o the "page open" prolog and some cleanup "postlog".
perhaps we could refactor AddPageFormat to use a non-exported method that does essentially what you copy-pasted here, and use that new non-exported method there ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! Wanted to keep the PR as short as possible but let's make it clean ;)
I'll be quite busy the next few days but I'll try to make the changes until end of week.
This PR fixes #85.
This is done by only creating a new page if we are currently on the last page.
Otherwise, we just advance the current page by one (use the already existing one) and update the y position to start at the top margin. Additionally we re-set the current font, color, and line styles similar to
AddPageFormat