From 892fe1b63b9a9f0b7bcdcdcdeb96cb6fe0d0a2bb Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 15 Apr 2018 14:15:23 -0400 Subject: Add SetHeaderFuncMode() method to automatically set position to left and top margin after header function is called. Backward compatibility is preserved. This addresses issue #174. --- fpdf.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'fpdf.go') diff --git a/fpdf.go b/fpdf.go index 4afdb8c..0e7071f 100644 --- a/fpdf.go +++ b/fpdf.go @@ -350,6 +350,15 @@ func (f *Fpdf) SetFontLoader(loader FontLoader) { f.fontLoader = loader } +// SetHeaderFuncMode sets the function that lets the application render the +// page header. See SetHeaderFunc() for more details. The value for homeMode +// should be set to true to have the current position set to the left and top +// margin after the header function is called. +func (f *Fpdf) SetHeaderFuncMode(fnc func(), homeMode bool) { + f.headerFnc = fnc + f.headerHomeMode = homeMode +} + // SetHeaderFunc sets the function that lets the application render the page // header. The specified function is automatically called by AddPage() and // should not be called directly by the application. The implementation in Fpdf @@ -676,6 +685,9 @@ func (f *Fpdf) AddPageFormat(orientationStr string, size SizeType) { f.inHeader = true f.headerFnc() f.inHeader = false + if f.headerHomeMode { + f.SetHomeXY() + } } // Restore line width if f.lineWidth != lw { @@ -2702,6 +2714,13 @@ func (f *Fpdf) SetY(y float64) { } } +// SetHomeXY is a convenience method that sets the current position to the left +// and top margins. +func (f *Fpdf) SetHomeXY() { + f.SetY(f.tMargin) + f.SetX(f.lMargin) +} + // SetXY defines the abscissa and ordinate of the current position. If the // passed values are negative, they are relative respectively to the right and // bottom of the page. -- cgit v1.2.1-24-ge1ad