Files
LektorenPlan/web/pdf/pdf.go
T
2026-11-12 20:00:33 +01:00

824 lines
23 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package pdf renders printable service plans using only core PDF fonts.
package pdf
import (
"fmt"
"io"
"sort"
"strconv"
"strings"
"time"
"github.com/go-pdf/fpdf"
"lektorenplan/domain"
)
// Options configures the printable document.
type Options struct {
TenantName string
Diocese string
GeneratedAt time.Time
}
func (o Options) tenant() string {
if strings.TrimSpace(o.TenantName) == "" {
return "LektorenPlan"
}
return o.TenantName
}
func (o Options) diocese() string {
if strings.TrimSpace(o.Diocese) == "" {
return "Erzbistum Köln"
}
return o.Diocese
}
func (o Options) generated() time.Time {
if o.GeneratedAt.IsZero() {
return time.Now()
}
return o.GeneratedAt
}
// Palette is shared by both layouts.
type palette struct {
ink [3]int
secondary [3]int
tertiary [3]int
line [3]int
accent [3]int
gold [3]int
burgundy [3]int
sundayWash [3]int
feastWash [3]int
open [3]int
headerWash [3]int
}
var colors = palette{
ink: [3]int{31, 34, 40},
secondary: [3]int{97, 98, 99},
tertiary: [3]int{133, 130, 125},
line: [3]int{215, 210, 201},
accent: [3]int{46, 92, 87},
gold: [3]int{184, 135, 59},
burgundy: [3]int{125, 61, 74},
sundayWash: [3]int{251, 244, 226},
feastWash: [3]int{255, 244, 201},
open: [3]int{179, 107, 33},
headerWash: [3]int{245, 243, 238},
}
func newPDF(orientation string) *fpdf.Fpdf {
pdf := fpdf.New(orientation, "mm", "A4", "")
pdf.SetAutoPageBreak(false, 0)
pdf.SetCreator("LektorenPlan Web", true)
pdf.SetTitle("LektorenPlan – Gottesdienstplan", true)
pdf.SetMargins(8.5, 8.5, 8.5)
return pdf
}
func translator(pdf *fpdf.Fpdf) func(string) string {
return pdf.UnicodeTranslatorFromDescriptor("cp1252")
}
func setColor(pdf *fpdf.Fpdf, c [3]int) {
pdf.SetTextColor(c[0], c[1], c[2])
}
func setFill(pdf *fpdf.Fpdf, c [3]int) {
pdf.SetFillColor(c[0], c[1], c[2])
}
func setDraw(pdf *fpdf.Fpdf, c [3]int) {
pdf.SetDrawColor(c[0], c[1], c[2])
}
func hexColor(value string, fallback [3]int) [3]int {
cleaned := strings.TrimPrefix(strings.TrimSpace(value), "#")
if len(cleaned) != 6 {
return fallback
}
parsed, err := strconv.ParseUint(cleaned, 16, 32)
if err != nil {
return fallback
}
return [3]int{int(parsed >> 16 & 0xFF), int(parsed >> 8 & 0xFF), int(parsed & 0xFF)}
}
func fit(pdf *fpdf.Fpdf, text string, width float64) string {
text = strings.TrimSpace(text)
if text == "" {
return ""
}
if pdf.GetStringWidth(text) <= width {
return text
}
runes := []rune(text)
for len(runes) > 0 {
runes = runes[:len(runes)-1]
candidate := strings.TrimSpace(string(runes)) + "…"
if pdf.GetStringWidth(candidate) <= width {
return candidate
}
}
return ""
}
// wrap splits text into at most maxLines lines fitting width.
func wrap(pdf *fpdf.Fpdf, text string, width float64, maxLines int) []string {
text = strings.TrimSpace(text)
if text == "" || maxLines < 1 {
return nil
}
words := strings.Fields(text)
var lines []string
current := ""
for _, word := range words {
candidate := word
if current != "" {
candidate = current + " " + word
}
if pdf.GetStringWidth(candidate) <= width {
current = candidate
continue
}
if current != "" {
lines = append(lines, current)
if len(lines) == maxLines {
break
}
current = word
} else {
current = fit(pdf, word, width)
}
}
if len(lines) < maxLines && current != "" {
lines = append(lines, current)
} else if len(lines) == maxLines && current != "" {
lines[len(lines)-1] = fit(pdf, lines[len(lines)-1]+" "+current, width)
}
return lines
}
func writeLines(pdf *fpdf.Fpdf, lines []string, x, y, width, lineHeight float64) float64 {
for _, line := range lines {
pdf.SetXY(x, y)
pdf.CellFormat(width, lineHeight, line, "", 0, "L", false, 0, "")
y += lineHeight
}
return y
}
func drawBadge(pdf *fpdf.Fpdf, tr func(string) string, text string, x, y float64, color [3]int) {
pdf.SetFont("Helvetica", "B", 5.4)
width := pdf.GetStringWidth(tr(text)) + 3.2
setFill(pdf, color)
pdf.SetTextColor(255, 255, 255)
pdf.RoundedRect(x, y, width, 3.4, 1, "1234", "F")
pdf.SetXY(x, y+0.55)
pdf.CellFormat(width, 2.4, tr(text), "", 0, "C", false, 0, "")
}
func feastBadge(day *domain.LiturgicalDay) (string, [3]int) {
if day == nil {
return "", colors.accent
}
switch {
case day.IsHighFeast():
return "HOCHFEST", colors.gold
case day.Rank == domain.RankFeast:
return "FEST", colors.burgundy
case day.Rank == domain.RankObligatoryMemorial:
return "GEDENKTAG", colors.accent
case day.IsObligation && !day.IsSunday():
return "GEBOTEN", colors.accent
default:
return "", colors.accent
}
}
func shortWeekday(date time.Time) string {
return strings.ToUpper(domain.ShortWeekdayName(date))
}
func feastHint(day *domain.LiturgicalDay) string {
if day == nil || day.Title == "" {
return "Hochfest"
}
title := day.Title
if index := strings.Index(title, " – "); index >= 0 {
return title[index+len(" – "):]
}
if len([]rune(title)) <= 30 {
return title
}
if strings.Contains(strings.ToLower(title), "hochfest") {
return "Hochfest"
}
runes := []rune(title)
return string(runes[:28]) + "…"
}
func namesFor(service domain.ServiceWithAssignments, role domain.Role, people map[string]domain.Person) (string, int) {
needed := service.Service.RequiredCount(role)
assigned := service.AssignmentsFor(role)
lastNames := make([]string, 0, len(assigned))
for _, assignment := range assigned {
if person, ok := people[assignment.PersonID]; ok {
lastNames = append(lastNames, person.LastName)
}
}
open := needed - len(lastNames)
if open < 0 {
open = 0
}
parts := append([]string{}, lastNames...)
if open > 0 {
parts = append(parts, "offen")
}
if len(parts) == 0 {
return "offen", 0
}
return strings.Join(parts, ", "), open
}
// FullPlan writes the A4 landscape calendar.
func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches []domain.Church, people []domain.Person, opts Options) error {
pdf := newPDF("L")
tr := translator(pdf)
peopleByID := map[string]domain.Person{}
for _, person := range people {
peopleByID[person.ID] = person
}
const (
pageWidth = 297.0
pageHeight = 210.0
margin = 8.5
headerH = 26.0
colH = 8.5
footerH = 7.0
dateW = 17.0
liturgyW = 57.0
gap = 1.35
)
churchWidth := (pageWidth - margin*2 - dateW - liturgyW - gap*5) / 4
contentTop := margin + headerH + colH + 1.5
contentBottom := pageHeight - margin - footerH
columns := churches
if len(columns) > 4 {
columns = columns[:4]
}
drawHeader := func(continuation bool) {
setColor(pdf, colors.accent)
pdf.SetFont("Helvetica", "B", 6.4)
pdf.SetXY(margin, margin)
pdf.CellFormat(150, 3.4, tr("LEKTORENPLAN · "+strings.ToUpper(opts.tenant())), "", 0, "L", false, 0, "")
setColor(pdf, colors.ink)
pdf.SetFont("Times", "B", 18)
title := "Gottesdienstplan"
if continuation {
title = "Gottesdienstplan · Fortsetzung"
}
pdf.SetXY(margin, margin+4.6)
pdf.CellFormat(150, 7, tr(title), "", 0, "L", false, 0, "")
setColor(pdf, colors.secondary)
pdf.SetFont("Helvetica", "", 8.2)
pdf.SetXY(margin, margin+13.2)
pdf.CellFormat(160, 4, tr(r.LongTitle()), "", 0, "L", false, 0, "")
rightX := pageWidth - margin - 82
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "", 6.8)
pdf.SetXY(rightX, margin)
pdf.CellFormat(82, 3.2, tr("Erstellt am "+domain.MediumString(opts.generated())), "", 0, "R", false, 0, "")
pdf.SetXY(rightX, margin+4.4)
pdf.CellFormat(82, 3.2, tr("Liturgischer Kalender: "+opts.diocese()), "", 0, "R", false, 0, "")
pdf.SetXY(rightX, margin+8.8)
pdf.CellFormat(82, 3.2, tr("Daten von www.eucharistiefeier.de"), "", 0, "R", false, 0, "")
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.25)
pdf.Line(margin, margin+headerH-2.2, pageWidth-margin, margin+headerH-2.2)
}
drawColumnHeader := func() {
y := margin + headerH
setFill(pdf, colors.headerWash)
pdf.Rect(margin, y, pageWidth-margin*2, colH, "F")
x := margin + 2
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "B", 5.8)
pdf.SetXY(x, y+2.8)
pdf.CellFormat(dateW-2, 3, tr("TAG"), "", 0, "L", false, 0, "")
x += dateW
pdf.SetXY(x, y+2.8)
pdf.CellFormat(liturgyW, 3, tr("LITURGIE & LESUNGEN"), "", 0, "L", false, 0, "")
x += liturgyW + gap
for _, church := range columns {
color := hexColor(church.ColorHex, colors.accent)
setColor(pdf, color)
pdf.SetFont("Times", "B", 8.2)
pdf.SetXY(x+1.3, y+1.2)
pdf.CellFormat(churchWidth-2.6, 4, tr(fit(pdf, church.Name, churchWidth-2.6)), "", 0, "L", false, 0, "")
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "", 5.2)
pdf.SetXY(x+1.3, y+5.1)
pdf.CellFormat(churchWidth-2.6, 2.6, tr(fit(pdf, church.Address, churchWidth-2.6)), "", 0, "L", false, 0, "")
x += churchWidth + gap
}
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.3)
pdf.Line(margin, y+colH, pageWidth-margin, y+colH)
}
drawFooter := func(page int) {
y := pageHeight - margin - footerH
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.25)
pdf.Line(margin, y+1.5, pageWidth-margin, y+1.5)
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "", 5.8)
pdf.SetXY(margin, y+2.6)
pdf.CellFormat(150, 3, tr("LektorenPlan · "+r.ShortTitle()), "", 0, "L", false, 0, "")
pdf.SetXY(pageWidth-margin-30, y+2.6)
pdf.CellFormat(30, 3, tr(fmt.Sprintf("Seite %d", page)), "", 0, "R", false, 0, "")
}
rowHeight := func(row domain.DayPlanRow) float64 {
height := 15.0
if row.LiturgicalDay != nil {
titles := wrap(pdf, row.LiturgicalDay.DisplayTitle(), liturgyW-4, 3)
readings := []string{}
if !row.LiturgicalDay.Readings.IsEmpty() {
readings = wrap(pdf, row.LiturgicalDay.Readings.ShortLabel(), liturgyW-4, 3)
}
lit := 4.5 + float64(len(titles))*3.4 + float64(len(readings))*2.5
if badge, _ := feastBadge(row.LiturgicalDay); badge != "" {
lit += 4.2
}
if lit+2 > height {
height = lit + 2
}
}
for _, service := range row.Services {
h := 5.0
if service.Service.Location != nil && strings.TrimSpace(*service.Service.Location) != "" {
h += 3.2
}
for _, role := range domain.AllRoles {
if service.Service.RequiredCount(role) > 0 {
h += 3.4
}
}
h += 2.2
if h > height {
height = h
}
}
if height > 53 {
height = 53
}
return height
}
pdf.AddPage()
drawHeader(false)
drawColumnHeader()
page := 1
y := contentTop
if len(rows) == 0 {
setColor(pdf, colors.secondary)
pdf.SetFont("Times", "", 12)
pdf.SetXY(margin, y+4)
pdf.CellFormat(pageWidth-margin*2, 6, tr("Für den gewählten Zeitraum sind keine Gottesdienste hinterlegt."), "", 0, "L", false, 0, "")
}
for index, row := range rows {
height := rowHeight(row)
if y+height > contentBottom {
drawFooter(page)
page++
pdf.AddPage()
drawHeader(true)
drawColumnHeader()
y = contentTop
}
isSunday := row.IsSunday()
isFeast := row.IsHighFeast()
isHoliday := row.IsObligation() && !isSunday
if isFeast {
setFill(pdf, colors.feastWash)
pdf.Rect(margin, y, pageWidth-margin*2, height, "F")
} else if isSunday || isHoliday {
setFill(pdf, colors.sundayWash)
pdf.Rect(margin, y, pageWidth-margin*2, height, "F")
}
x := margin
// Date cell.
setColor(pdf, colors.tertiary)
if isSunday {
setColor(pdf, colors.burgundy)
}
pdf.SetFont("Helvetica", "B", 5.9)
pdf.SetXY(x+1.5, y+1.5)
pdf.CellFormat(dateW-1.5, 3, tr(shortWeekday(row.Date)), "", 0, "L", false, 0, "")
if isFeast {
setColor(pdf, colors.gold)
} else if isSunday {
setColor(pdf, colors.burgundy)
} else {
setColor(pdf, colors.ink)
}
pdf.SetFont("Times", "B", 13.5)
pdf.SetXY(x+1.5, y+4)
pdf.CellFormat(dateW-1.5, 6, tr(fmt.Sprintf("%d.", domain.DayNumber(row.Date))), "", 0, "L", false, 0, "")
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "", 5.9)
pdf.SetXY(x+1.5, y+11)
pdf.CellFormat(dateW-1.5, 3, tr(domain.ShortMonthName(row.Date)), "", 0, "L", false, 0, "")
if isSunday {
setColor(pdf, colors.burgundy)
pdf.SetFont("Helvetica", "B", 4.9)
pdf.SetXY(x+1.5, y+14.5)
pdf.CellFormat(dateW, 2.5, tr("SONNTAG"), "", 0, "L", false, 0, "")
}
x += dateW
// Liturgy.
textY := y + 1.6
if day := row.LiturgicalDay; day != nil {
if badge, color := feastBadge(day); badge != "" {
drawBadge(pdf, tr, badge, x+1.2, textY, color)
textY += 4.2
}
titleColor := colors.ink
if isSunday {
titleColor = colors.burgundy
}
setColor(pdf, titleColor)
fontStyle := "B"
if !day.IsFeast() {
fontStyle = ""
}
pdf.SetFont("Times", fontStyle, 8.2)
titleLines := wrap(pdf, day.DisplayTitle(), liturgyW-4, 3)
textY = writeLines(pdf, titleLines, x+1.2, textY, liturgyW-4, 3.3)
if !day.Readings.IsEmpty() {
setColor(pdf, colors.secondary)
pdf.SetFont("Helvetica", "", 5.6)
readingLines := wrap(pdf, day.Readings.ShortLabel(), liturgyW-4, 3)
writeLines(pdf, readingLines, x+1.2, textY+0.4, liturgyW-4, 2.5)
}
}
x += liturgyW + gap
// Church columns.
for _, church := range columns {
services := row.ServicesForChurch(church.ID)
serviceY := y + 1.4
color := hexColor(church.ColorHex, colors.accent)
for _, service := range services {
setColor(pdf, color)
pdf.SetFont("Helvetica", "B", 6.2)
label := fit(pdf, service.Service.TimeLabel()+" "+service.Service.Title, churchWidth-4)
pdf.SetXY(x+1.2, serviceY)
pdf.CellFormat(churchWidth-2.4, 3.6, tr(label), "", 0, "L", false, 0, "")
serviceY += 3.4
if service.Service.Location != nil && strings.TrimSpace(*service.Service.Location) != "" {
setColor(pdf, colors.burgundy)
pdf.SetFont("Helvetica", "B", 5.4)
pdf.SetXY(x+1.6, serviceY)
pdf.CellFormat(churchWidth-3, 2.8, tr(fit(pdf, *service.Service.Location, churchWidth-3)), "", 0, "L", false, 0, "")
serviceY += 3.0
}
for _, role := range domain.AllRoles {
if service.Service.RequiredCount(role) <= 0 {
continue
}
names, open := namesFor(service, role, peopleByID)
prefix := "L: "
if role == domain.RoleHelper {
prefix = "K: "
}
text := prefix + names
if open > 0 {
setColor(pdf, colors.open)
pdf.SetFont("Helvetica", "B", 5.4)
} else {
setColor(pdf, colors.secondary)
pdf.SetFont("Helvetica", "", 5.4)
}
lines := wrap(pdf, text, churchWidth-3, 2)
serviceY = writeLines(pdf, lines, x+1.6, serviceY, churchWidth-3, 3.0)
}
serviceY += 1.5
if serviceY > y+height-2 {
break
}
}
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.15)
pdf.Line(x, y+1.5, x, y+height-1.5)
x += churchWidth + gap
}
if index < len(rows)-1 {
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.2)
pdf.Line(margin, y+height, pageWidth-margin, y+height)
}
y += height
}
drawFooter(page)
if err := pdf.Output(w); err != nil {
return err
}
return pdf.Error()
}
// CompactPlan writes the A4 portrait service list.
func CompactPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, people []domain.Person, opts Options) error {
pdf := newPDF("P")
tr := translator(pdf)
peopleByID := map[string]domain.Person{}
for _, person := range people {
peopleByID[person.ID] = person
}
const (
pageWidth = 210.0
pageHeight = 297.0
margin = 12.7
headerH = 24.7
colH = 8.1
footerH = 8.5
dateW = 25.0
serviceW = 69.0
lectorW = 41.0
gap = 2.8
)
helperW := pageWidth - margin*2 - dateW - serviceW - lectorW - gap*3
contentTop := margin + headerH + colH + 2
contentBottom := pageHeight - margin - footerH
drawHeader := func(continuation bool) {
setColor(pdf, colors.accent)
pdf.SetFont("Helvetica", "B", 6.2)
pdf.SetXY(margin, margin)
pdf.CellFormat(120, 3.2, tr("LEKTORENPLAN · "+strings.ToUpper(opts.tenant())), "", 0, "L", false, 0, "")
setColor(pdf, colors.ink)
pdf.SetFont("Times", "B", 17)
title := "Gottesdienstliste"
if continuation {
title = "Gottesdienstliste · Fortsetzung"
}
pdf.SetXY(margin, margin+4.4)
pdf.CellFormat(130, 6.5, tr(title), "", 0, "L", false, 0, "")
setColor(pdf, colors.secondary)
pdf.SetFont("Helvetica", "", 7.8)
pdf.SetXY(margin, margin+13)
pdf.CellFormat(120, 4, tr(r.LongTitle()), "", 0, "L", false, 0, "")
rightX := pageWidth - margin - 62
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "B", 6.4)
pdf.SetXY(rightX, margin)
pdf.CellFormat(62, 3.2, tr("A4 hoch · kompakte Liste"), "", 0, "R", false, 0, "")
pdf.SetFont("Helvetica", "", 6.4)
pdf.SetXY(rightX, margin+4.5)
pdf.CellFormat(62, 3.2, tr("Erstellt am "+domain.MediumString(opts.generated())), "", 0, "R", false, 0, "")
pdf.SetXY(rightX, margin+9)
pdf.CellFormat(62, 3.2, tr("Daten von www.eucharistiefeier.de"), "", 0, "R", false, 0, "")
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.25)
pdf.Line(margin, margin+headerH-2.2, pageWidth-margin, margin+headerH-2.2)
}
drawColumnHeader := func() {
y := margin + headerH
setFill(pdf, colors.headerWash)
pdf.Rect(margin, y, pageWidth-margin*2, colH, "F")
x := margin + 2
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "B", 5.8)
headers := []struct {
Text string
Width float64
}{
{"TAG", dateW - 2}, {"GOTTESDIENST", serviceW}, {"LEKTOREN", lectorW}, {"KOMMUNIONHELFER", helperW},
}
for _, header := range headers {
pdf.SetXY(x, y+2.7)
pdf.CellFormat(header.Width, 3, tr(header.Text), "", 0, "L", false, 0, "")
x += header.Width + gap
}
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.3)
pdf.Line(margin, y+colH, pageWidth-margin, y+colH)
}
drawFooter := func(page int) {
y := pageHeight - margin - footerH
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.25)
pdf.Line(margin, y+1.5, pageWidth-margin, y+1.5)
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "", 5.8)
pdf.SetXY(margin, y+2.6)
pdf.CellFormat(150, 3, tr("LektorenPlan · kompakte Liste · "+r.ShortTitle()), "", 0, "L", false, 0, "")
pdf.SetXY(pageWidth-margin-25, y+2.6)
pdf.CellFormat(25, 3, tr(fmt.Sprintf("Seite %d", page)), "", 0, "R", false, 0, "")
}
rowHeight := func(service domain.ServiceWithAssignments) float64 {
height := 7.0
if service.Service.Title != "" {
height += 1.8
}
lectorNames, _ := namesFor(service, domain.RoleLector, peopleByID)
helperNames, _ := namesFor(service, domain.RoleHelper, peopleByID)
lectorLines := len(wrap(pdf, lectorNames, lectorW-2, 2))
helperLines := len(wrap(pdf, helperNames, helperW-2, 2))
if lines := maxInt(lectorLines, helperLines); float64(lines)*3 > height {
height = float64(lines) * 3
}
if len(service.AssignmentsFor(domain.RoleLector)) == 0 && service.Service.RequiredCount(domain.RoleLector) > 0 {
height += 1.2
}
return maxFloat(height, 8.2) + 1.6
}
pdf.AddPage()
drawHeader(false)
drawColumnHeader()
page := 1
y := contentTop
visibleDays := 0
for _, row := range rows {
if len(row.Services) > 0 {
visibleDays++
}
}
if visibleDays == 0 {
setColor(pdf, colors.secondary)
pdf.SetFont("Times", "", 12)
pdf.SetXY(margin, y+5)
pdf.CellFormat(pageWidth-margin*2, 6, tr("Für den gewählten Zeitraum sind keine Gottesdienste hinterlegt."), "", 0, "L", false, 0, "")
}
for dayIndex, row := range rows {
if len(row.Services) == 0 {
continue
}
services := append([]domain.ServiceWithAssignments(nil), row.Services...)
sortServices(services)
for serviceIndex, service := range services {
height := rowHeight(service)
if y+height > contentBottom {
drawFooter(page)
page++
pdf.AddPage()
drawHeader(true)
drawColumnHeader()
y = contentTop
}
if row.IsHighFeast() {
setFill(pdf, colors.feastWash)
pdf.Rect(margin, y, pageWidth-margin*2, height, "F")
} else if row.IsSunday() {
setFill(pdf, colors.sundayWash)
pdf.Rect(margin, y, pageWidth-margin*2, height, "F")
}
if serviceIndex == 0 {
setColor(pdf, colors.tertiary)
if row.IsSunday() || row.IsHighFeast() {
setColor(pdf, colors.burgundy)
}
pdf.SetFont("Helvetica", "B", 5.8)
pdf.SetXY(margin+1.5, y+1.8)
pdf.CellFormat(dateW-2, 3, tr(shortWeekday(row.Date)), "", 0, "L", false, 0, "")
if row.IsHighFeast() {
setColor(pdf, colors.gold)
} else if row.IsSunday() {
setColor(pdf, colors.burgundy)
} else {
setColor(pdf, colors.ink)
}
pdf.SetFont("Times", "B", 12.5)
pdf.SetXY(margin+1.5, y+4.3)
pdf.CellFormat(dateW-2, 5, tr(fmt.Sprintf("%d.%d.", domain.DayNumber(row.Date), domain.Month(row.Date))), "", 0, "L", false, 0, "")
if row.IsHighFeast() {
setColor(pdf, colors.gold)
pdf.SetFont("Helvetica", "B", 5.2)
hint := wrap(pdf, feastHint(row.LiturgicalDay), dateW-4, 3)
writeLines(pdf, hint, margin+1.5, y+10, dateW-4, 2.4)
}
}
x := margin + dateW + gap
churchColor := hexColor(service.Church.ColorHex, colors.accent)
setColor(pdf, churchColor)
pdf.SetFont("Helvetica", "B", 7.2)
place := service.Service.PlaceName(service.Church)
line := fit(pdf, service.Service.TimeLabel()+" · "+place, serviceW-2)
pdf.SetXY(x, y+1.6)
pdf.CellFormat(serviceW-2, 3.4, tr(line), "", 0, "L", false, 0, "")
if service.Service.Title != "" {
setColor(pdf, colors.secondary)
if service.Service.Kind == domain.KindSpecial {
setColor(pdf, colors.burgundy)
}
pdf.SetFont("Helvetica", "", 6.1)
title := service.Service.Title
if service.Service.Kind == domain.KindSpecial {
title += " · Sondergottesdienst"
}
pdf.SetXY(x, y+4.8)
pdf.CellFormat(serviceW-2, 3, tr(fit(pdf, title, serviceW-2)), "", 0, "L", false, 0, "")
}
x += serviceW + gap
drawRole := func(role domain.Role, width float64) {
needed := service.Service.RequiredCount(role)
if needed <= 0 {
setColor(pdf, colors.tertiary)
pdf.SetFont("Helvetica", "", 6.6)
pdf.SetXY(x, y+1.8)
pdf.CellFormat(width, 3, tr("—"), "", 0, "L", false, 0, "")
return
}
names, open := namesFor(service, role, peopleByID)
if open > 0 {
setColor(pdf, colors.open)
pdf.SetFont("Helvetica", "B", 6.6)
} else {
setColor(pdf, colors.ink)
pdf.SetFont("Helvetica", "", 6.6)
}
lines := wrap(pdf, names, width, 2)
writeLines(pdf, lines, x, y+1.8, width, 3)
}
drawRole(domain.RoleLector, lectorW)
x += lectorW + gap
drawRole(domain.RoleHelper, helperW)
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.15)
pdf.Line(margin, y+height, pageWidth-margin, y+height)
y += height
}
if dayIndex < len(rows)-1 {
setDraw(pdf, colors.line)
pdf.SetLineWidth(0.3)
pdf.Line(margin+1, y, pageWidth-margin-1, y)
}
}
drawFooter(page)
if err := pdf.Output(w); err != nil {
return err
}
return pdf.Error()
}
func sortServices(services []domain.ServiceWithAssignments) {
sort.SliceStable(services, func(i, j int) bool {
a, b := services[i].Service, services[j].Service
if a.TimeMinutes != b.TimeMinutes {
return a.TimeMinutes < b.TimeMinutes
}
return services[i].Church.SortIndex < services[j].Church.SortIndex
})
}
func maxInt(a, b int) int {
if a > b {
return a
}
return b
}
func maxFloat(a, b float64) float64 {
if a > b {
return a
}
return b
}