1package pdfexport23import (4 "strings"56 "codeberg.org/go-pdf/fpdf"7)89const instructionWrapInsetMM = 0.01011func wrapInstructionLines(pdf *fpdf.Fpdf, width float64, rules []string) []string {12 if pdf == nil || width <= 0 {13 return nil14 }1516 setInstructionStyle(pdf)1718 wrapWidth := width - instructionWrapInsetMM*219 if wrapWidth <= 0 {20 wrapWidth = width21 }2223 lines := make([]string, 0, len(rules))24 for _, rule := range rules {25 rule = strings.TrimSpace(rule)26 if rule == "" {27 continue28 }2930 chunks := pdf.SplitLines([]byte(rule), wrapWidth)31 if len(chunks) == 0 {32 lines = append(lines, rule)33 continue34 }3536 for _, chunk := range chunks {37 line := strings.TrimSpace(string(chunk))38 if line != "" {39 lines = append(lines, line)40 }41 }42 }4344 return lines45}4647func InstructionLineCount(pdf *fpdf.Fpdf, width float64, rules []string) int {48 return len(wrapInstructionLines(pdf, width, rules))49}5051func RenderInstructions(pdf *fpdf.Fpdf, x, y, width float64, rules []string) int {52 lines := wrapInstructionLines(pdf, width, rules)53 if len(lines) == 0 {54 return 055 }5657 setInstructionStyle(pdf)58 for i, line := range lines {59 pdf.SetXY(x, y+float64(i)*InstructionLineHMM)60 pdf.CellFormat(width, InstructionLineHMM, line, "", 0, "C", false, 0, "")61 }6263 return len(lines)64}