From 2f47b3f5da0ae9588d16d4b010402906111fd559 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Thu, 25 Apr 2019 21:30:15 +0200 Subject: label-tool: make it possible to print free form text Also commit the label subpackage that we forgot to. --- cmd/label-tool/main.go | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'cmd') diff --git a/cmd/label-tool/main.go b/cmd/label-tool/main.go index 15fb68d..1e5ab4a 100644 --- a/cmd/label-tool/main.go +++ b/cmd/label-tool/main.go @@ -38,7 +38,7 @@ var tmplForm = template.Must(template.New("form").Parse(` - +
{{ if .Printer }} @@ -71,18 +71,26 @@ var tmplForm = template.Must(template.New("form").Parse(` {{ end }}
-

Font: {{ .Font.Name }} Change -

-
- -

- - + Font +

{{ .Font.Name }} Change + +

+

+
+ Label +

+

Kind: + + + +

-

- + + `)) @@ -130,7 +138,9 @@ func handle(w http.ResponseWriter, r *http.Request) { font = fonts[fontIndex] } else { w.Header().Set("Content-Type", "text/html") - tmplFont.Execute(w, fonts) + if err := tmplFont.Execute(w, fonts); err != nil { + http.Error(w, err.Error(), 500) + } return } @@ -170,6 +180,7 @@ func handle(w http.ResponseWriter, r *http.Request) { FontIndex int Text string Scale int + Kind string }{ Printer: printer, PrinterErr: printerErr, @@ -178,17 +189,26 @@ func handle(w http.ResponseWriter, r *http.Request) { Font: font.Font, FontIndex: fontIndex, Text: r.FormValue("text"), + Kind: r.FormValue("kind"), } params.Scale, err = strconv.Atoi(r.FormValue("scale")) if err != nil { params.Scale = 3 } + if params.Kind == "" { + params.Kind = "text" + } var img image.Image if mediaInfo != nil { - img = &imgutil.LeftRotate{Image: label.GenLabelForHeight( - font.Font, params.Text, mediaInfo.PrintAreaPins, params.Scale)} + if params.Kind == "qr" { + img = &imgutil.LeftRotate{Image: label.GenLabelForHeight( + font.Font, params.Text, mediaInfo.PrintAreaPins, params.Scale)} + } else { + img = label.GenLabelForWidth( + font.Font, params.Text, mediaInfo.PrintAreaPins, params.Scale) + } if r.FormValue("print") != "" { if err := printer.Print(img); err != nil { log.Println("print error:", err) @@ -198,7 +218,9 @@ func handle(w http.ResponseWriter, r *http.Request) { if _, ok := r.Form["render"]; !ok { w.Header().Set("Content-Type", "text/html") - tmplForm.Execute(w, ¶ms) + if err := tmplForm.Execute(w, ¶ms); err != nil { + http.Error(w, err.Error(), 500) + } return } -- cgit v1.2.3-70-g09d2