Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fpdf: fix autobreak when next page already exists #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mwoelk
Copy link

@mwoelk mwoelk commented Sep 5, 2024

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

@mwoelk
Copy link
Author

mwoelk commented Sep 5, 2024

@sbinet let me know if I should add any test or provide a reproduction repo.

Copy link
Contributor

@sbinet sbinet left a 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.

Comment on lines +2572 to +2619
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
Copy link
Contributor

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 ?

Copy link
Author

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.

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.

Autobreak creates new pages when there is already a new page
2 participants