WIP
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -4,5 +4,8 @@
|
||||
"fpdf",
|
||||
"qrcode",
|
||||
"yeqown"
|
||||
],
|
||||
"cSpell.ignoreWords": [
|
||||
"Hjqy"
|
||||
]
|
||||
}
|
||||
36
main.go
36
main.go
@@ -11,13 +11,16 @@ import (
|
||||
|
||||
var cols = 4
|
||||
var rows = 4
|
||||
var qrSize = 50.0
|
||||
var fontSize = 32.0 // pts
|
||||
var qrSize = 48.0
|
||||
var fontSize = 25.0 // pts
|
||||
var fontSizeMM = fontSize / 72 * 25.4
|
||||
var text = "meow!"
|
||||
var text = "Á[Hjqy]|"
|
||||
var font = "Courier"
|
||||
|
||||
var textTopPadding = 5.0
|
||||
var qrTopPadding = 5.0
|
||||
var textTopPadding = 0.0 // typically none is required
|
||||
var qrTopPadding = 5.0 // below the baseline of the text, remember the descenders like 'y', 'q'
|
||||
|
||||
var requiredCellPadding = 3.0 // half on each side, effectively
|
||||
|
||||
// var probably some padding instead of offsets for qr/font placement
|
||||
|
||||
@@ -79,19 +82,25 @@ func main() {
|
||||
// panic(info.Height())
|
||||
|
||||
pdf.AddPage()
|
||||
pdf.SetFont("Arial", "B", float64(fontSize))
|
||||
pdf.SetFont(font, "B", float64(fontSize))
|
||||
|
||||
textWidth := pdf.GetStringWidth(text)
|
||||
|
||||
colWidth := pageWidth / float64(cols)
|
||||
rowHeight := pageHeight / float64(rows)
|
||||
|
||||
if textTopPadding+fontSizeMM+qrTopPadding+qrSize > rowHeight {
|
||||
slog.Warn("qr is too big for row")
|
||||
cellHeight := textTopPadding + fontSizeMM + qrTopPadding + qrSize
|
||||
cellWidth := qrSize
|
||||
|
||||
if cellHeight > rowHeight-requiredCellPadding {
|
||||
|
||||
slog.Warn("qr is too big for row", "cell_height", cellHeight, "row_height", rowHeight)
|
||||
}
|
||||
|
||||
if qrSize > colWidth {
|
||||
slog.Warn("qr is too big for column")
|
||||
slog.Info("check width", "cell_width", cellWidth, "col_width", colWidth)
|
||||
|
||||
if cellWidth > colWidth-requiredCellPadding {
|
||||
slog.Warn("qr is too big for column", "cell_width", cellWidth, "col_width", colWidth)
|
||||
}
|
||||
|
||||
if textWidth > colWidth {
|
||||
@@ -103,10 +112,15 @@ func main() {
|
||||
topLeftX := colWidth * float64(colIdx)
|
||||
topLeftY := rowHeight * float64(rowIdx)
|
||||
|
||||
// draw box
|
||||
pdf.SetDashPattern([]float64{1, 1}, 0)
|
||||
pdf.Rect(topLeftX, topLeftY, colWidth, rowHeight, "D")
|
||||
pdf.SetDashPattern([]float64{}, 0)
|
||||
|
||||
// label at the top
|
||||
pdf.Text(
|
||||
topLeftX+colWidth/2-textWidth/2,
|
||||
topLeftY+textTopPadding+fontSizeMM,
|
||||
topLeftY+fontSizeMM+textTopPadding,
|
||||
text, // +fmt.Sprintf("%d/%d", rowIdx, colIdx)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user