Versendung: doppelseitiges Sammel PDF und diverse Verbesserungen
This commit is contained in:
1 parent
4b88aca958
commit
feab6135ff
31 files changed
+1302
-96
No files matched your search
+40
-12
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-pdf/fpdf"
|
||||
|
||||
"lektorenplan/domain"
|
||||
)
|
||||
|
||||
@@ -15,7 +17,7 @@ type DispatchAssignment struct {
|
||||
TimeMinutes int
|
||||
Church string
|
||||
Title string
|
||||
Role domain.Role
|
||||
RoleLabel string
|
||||
}
|
||||
|
||||
// CoverData describes the personal cover sheet of a dispatch packet.
|
||||
@@ -39,7 +41,7 @@ func AssignmentLines(assignments []DispatchAssignment) []string {
|
||||
domain.MediumString(assignment.Date),
|
||||
domain.TimeString(assignment.TimeMinutes),
|
||||
assignment.Church,
|
||||
assignment.Role.Title()))
|
||||
assignment.RoleLabel))
|
||||
}
|
||||
return lines
|
||||
}
|
||||
@@ -48,6 +50,34 @@ func coverOptions(data CoverData) Options {
|
||||
return Options{TenantName: data.TenantName, Diocese: data.Diocese, GeneratedAt: data.GeneratedAt}
|
||||
}
|
||||
|
||||
// writeCoverText writes letter paragraphs with manual page breaks. Cover pages
|
||||
// are laid out with explicit coordinates, so fpdf's own page breaking would
|
||||
// reset the cursor to the default margin and misalign the letter. A long
|
||||
// introduction or greeting must nevertheless appear completely instead of
|
||||
// running off the page.
|
||||
func writeCoverText(pdf *fpdf.Fpdf, tr func(string) string, text string, x, y, width, lineHeight, pageTop, bottom float64) float64 {
|
||||
text = strings.TrimSpace(strings.ReplaceAll(text, "\r\n", "\n"))
|
||||
if text == "" {
|
||||
return y
|
||||
}
|
||||
for _, paragraph := range strings.Split(text, "\n") {
|
||||
if strings.TrimSpace(paragraph) == "" {
|
||||
y += lineHeight
|
||||
continue
|
||||
}
|
||||
for _, line := range pdf.SplitLines([]byte(tr(paragraph)), width) {
|
||||
if y+lineHeight > bottom {
|
||||
pdf.AddPage()
|
||||
y = pageTop
|
||||
}
|
||||
pdf.SetXY(x, y)
|
||||
pdf.CellFormat(width, lineHeight, string(line), "", 0, "L", false, 0, "")
|
||||
y += lineHeight
|
||||
}
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// Cover writes an A4 portrait cover letter with the personal assignment overview.
|
||||
func Cover(w io.Writer, data CoverData) error {
|
||||
pdf := newPDF("P")
|
||||
@@ -109,9 +139,8 @@ func Cover(w io.Writer, data CoverData) error {
|
||||
y += 10
|
||||
setColor(pdf, colors.ink)
|
||||
pdf.SetFont("Times", "", 11.5)
|
||||
pdf.SetXY(margin, y)
|
||||
pdf.MultiCell(contentW, 5.6, tr(strings.TrimSpace(data.Intro)), "", "L", false)
|
||||
y = pdf.GetY() + 8
|
||||
y = writeCoverText(pdf, tr, data.Intro, margin, y, contentW, 5.6, margin, 278)
|
||||
y += 8
|
||||
|
||||
// Assignment table -----------------------------------------------------
|
||||
setColor(pdf, colors.ink)
|
||||
@@ -162,7 +191,7 @@ func Cover(w io.Writer, data CoverData) error {
|
||||
dayLabel,
|
||||
domain.TimeString(assignment.TimeMinutes),
|
||||
assignment.Church,
|
||||
assignment.Role.Title() + " · " + assignment.Title,
|
||||
assignment.RoleLabel + " · " + assignment.Title,
|
||||
}
|
||||
for index, column := range columns {
|
||||
pdf.SetXY(x, y+2.1)
|
||||
@@ -179,16 +208,15 @@ func Cover(w io.Writer, data CoverData) error {
|
||||
|
||||
// Greeting -------------------------------------------------------------
|
||||
if strings.TrimSpace(data.Greeting) != "" {
|
||||
if y > 245 {
|
||||
pdf.AddPage()
|
||||
y = margin
|
||||
}
|
||||
setColor(pdf, colors.ink)
|
||||
pdf.SetFont("Times", "", 11.5)
|
||||
pdf.SetXY(margin, y)
|
||||
pdf.MultiCell(contentW, 5.6, tr(strings.TrimSpace(data.Greeting)), "", "L", false)
|
||||
y = writeCoverText(pdf, tr, data.Greeting, margin, y, contentW, 5.6, margin, 278)
|
||||
y += 8
|
||||
}
|
||||
|
||||
// The recipient is already named explicitly in the address block above,
|
||||
// so the cover does not repeat the name in parentheses at the end.
|
||||
|
||||
// Footer ---------------------------------------------------------------
|
||||
setColor(pdf, colors.tertiary)
|
||||
pdf.SetFont("Helvetica", "", 6.5)
|
||||
|
||||
Reference in new issue
Block a user