WIP
This commit is contained in:
54
main.go
54
main.go
@@ -12,9 +12,9 @@ import (
|
|||||||
// 1
|
// 1
|
||||||
|
|
||||||
var cols = 4
|
var cols = 4
|
||||||
var rows = 7
|
var rows = 5
|
||||||
var qrSize = 35
|
var qrSize = 40
|
||||||
var offset = qrSize/2 + 5
|
var fontSize = 20
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
qrc, err := qrcode.New("https://nanocat.net")
|
qrc, err := qrcode.New("https://nanocat.net")
|
||||||
@@ -25,6 +25,8 @@ func main() {
|
|||||||
|
|
||||||
b := newBWC()
|
b := newBWC()
|
||||||
qrBytes := standard.NewWithWriter(&b,
|
qrBytes := standard.NewWithWriter(&b,
|
||||||
|
// standard.WithQRWidth(uint8(qrSize)),
|
||||||
|
standard.WithBorderWidth(0),
|
||||||
standard.WithBuiltinImageEncoder(standard.PNG_FORMAT),
|
standard.WithBuiltinImageEncoder(standard.PNG_FORMAT),
|
||||||
standard.WithCircleShape(),
|
standard.WithCircleShape(),
|
||||||
standard.WithFgGradient(&standard.LinearGradient{
|
standard.WithFgGradient(&standard.LinearGradient{
|
||||||
@@ -53,8 +55,10 @@ func main() {
|
|||||||
if err = qrc.Save(qrBytes); err != nil {
|
if err = qrc.Save(qrBytes); err != nil {
|
||||||
fmt.Printf("could not save image: %v", err)
|
fmt.Printf("could not save image: %v", err)
|
||||||
}
|
}
|
||||||
|
// dim := qrc.Dimension()
|
||||||
|
|
||||||
pdf := fpdf.New("P", "mm", "A4", "")
|
pdf := fpdf.New("P", "mm", "A4", "")
|
||||||
|
pdf.SetMargins(0, 0, 0)
|
||||||
pageWidth, pageHeight := pdf.GetPageSize()
|
pageWidth, pageHeight := pdf.GetPageSize()
|
||||||
|
|
||||||
// register the qr
|
// register the qr
|
||||||
@@ -64,8 +68,11 @@ func main() {
|
|||||||
AllowNegativePosition: false,
|
AllowNegativePosition: false,
|
||||||
}, b)
|
}, b)
|
||||||
|
|
||||||
|
info := pdf.GetImageInfo("qr")
|
||||||
|
// panic(info.Height())
|
||||||
|
|
||||||
pdf.AddPage()
|
pdf.AddPage()
|
||||||
pdf.SetFont("Arial", "B", 16)
|
pdf.SetFont("Arial", "B", float64(fontSize))
|
||||||
|
|
||||||
text := "foobar"
|
text := "foobar"
|
||||||
textWidth := pdf.GetStringWidth(text)
|
textWidth := pdf.GetStringWidth(text)
|
||||||
@@ -73,16 +80,39 @@ func main() {
|
|||||||
colWidth := pageWidth / float64(cols)
|
colWidth := pageWidth / float64(cols)
|
||||||
rowHeight := pageHeight / float64(rows)
|
rowHeight := pageHeight / float64(rows)
|
||||||
|
|
||||||
for i := 0; i < rows; i++ {
|
for rowIdx := range rows {
|
||||||
for j := 0; j < cols; j++ {
|
for colIdx := range cols {
|
||||||
pdf.Text(colWidth*float64(j)+colWidth/2-textWidth/2,
|
topLeftX := colWidth * float64(colIdx)
|
||||||
rowHeight*float64(i)+rowHeight/2-float64(offset),
|
topLeftY := rowHeight * float64(rowIdx)
|
||||||
text)
|
|
||||||
|
|
||||||
pdf.Image("qr",
|
// if rowHeight*0.8 < float64(qrSize) {
|
||||||
colWidth*float64(j)+colWidth/2-float64(qrSize)/2, rowHeight*float64(i)+rowHeight/2+float64(offset),
|
// panic("row too small for qr")
|
||||||
|
// }
|
||||||
|
// if colWidth*0.6 < float64(qrSize) {
|
||||||
|
// panic("col too small for qr")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// label at the top
|
||||||
|
pdf.Text(
|
||||||
|
topLeftX+colWidth/2-textWidth/2,
|
||||||
|
topLeftY+float64(fontSize),
|
||||||
|
text, // +fmt.Sprintf("%d/%d", rowIdx, colIdx)
|
||||||
|
)
|
||||||
|
|
||||||
|
info.Height()
|
||||||
|
// pdf at the bottom
|
||||||
|
pdf.ImageOptions("qr",
|
||||||
|
topLeftX+info.Width()-float64(qrSize), //+float64(dim)/2, // centre
|
||||||
|
topLeftY+float64(fontSize)*1.3, // centre
|
||||||
float64(qrSize), float64(qrSize),
|
float64(qrSize), float64(qrSize),
|
||||||
false, "tp", 0, "")
|
false,
|
||||||
|
fpdf.ImageOptions{AllowNegativePosition: true}, 0, "")
|
||||||
|
// pdf.Image("qr",
|
||||||
|
// topLeftX+5, // centre
|
||||||
|
// topLeftY+float64(fontSize)*1.3, // centre
|
||||||
|
// float64(qrSize),
|
||||||
|
// float64(qrSize),
|
||||||
|
// false, "tp", 0, "")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user