allow small fonts when prefixing text lines with @

This commit is contained in:
Joerg Lehmann 2022-11-09 20:04:24 +01:00
parent 655d50af9e
commit 621597b52b
1 changed files with 23 additions and 1 deletions

View File

@ -73,6 +73,7 @@ const marginTop = 7
const logoTop = 6
const logoHeight = 20
const lineSpacing = 5
const lineSpacingTextsmall = 3
const lineSpacingSmall = 4.5
const lineSpacingPaymentSlipBig = 6
const lineSpacingPaymentSlipBelowHeading = 2.8
@ -147,6 +148,16 @@ func writeText(x float64, y float64, w float64, text string, alignStr ...string)
pdf.CellFormat(w, 11, tr(text), "", 0, align, false, 0, "")
}
func writeTextsmall(x float64, y float64, w float64, text string, alignStr ...string) {
tr := pdf.UnicodeTranslatorFromDescriptor("")
align := "LT"
if len(alignStr) > 0 {
align = alignStr[0]
}
pdf.SetXY(x, y)
pdf.CellFormat(w, 6, tr(text), "", 0, align, false, 0, "")
}
func setupInvoice() {
pdf = gofpdf.New("P", "mm", "A4", "")
pdf.SetMargins(0, 0, 0)
@ -260,7 +271,18 @@ func printItems() {
totalNetAmount = totalNetAmount + itemNetAmount
writeText(tabstopPrice, yPos, widthPrice, floatToString(itemNetAmount, "'"), "TR")
}
if i.Text != "" {
if strings.HasPrefix(i.Text, "@") {
pdf.SetFont("Dejavusans", "", smallFontSize)
textwithoutprefix := i.Text[1:]
lines := pdf.SplitText(textwithoutprefix, widthItemText)
for _, il := range lines {
totalItemLines = totalItemLines + 1
writeTextsmall(tabstopLeft, yPos, 0, strings.ReplaceAll(il, "_", " "))
yPos = yPos + lineSpacingTextsmall
maybeNewPage()
}
pdf.SetFont("Dejavusans", "", defaultFontSize)
} else if i.Text != "" {
lines := pdf.SplitText(i.Text, widthItemText)
for _, il := range lines {
totalItemLines = totalItemLines + 1