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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion fpdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2566,7 +2566,58 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr, borderStr string, ln int,
f.ws = 0
f.out("0 Tw")
}
f.AddPageFormat(f.curOrientation, f.curPageSize)
if f.PageNo() == f.PageCount() {
f.AddPageFormat(f.curOrientation, f.curPageSize)
} else {
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
Comment on lines +2572 to +2619
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.

}
if f.err != nil {
return
}
Expand Down
Loading