From 621597b52b3fbadaa097d31760eef2d5b19a50de Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Wed, 9 Nov 2022 20:04:24 +0100 Subject: [PATCH] allow small fonts when prefixing text lines with @ --- mkinvoice.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mkinvoice.go b/mkinvoice.go index e22184a..b7f14ab 100644 --- a/mkinvoice.go +++ b/mkinvoice.go @@ -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