Files
OpsLog/internal/pdf/pdf_test.go
T
rouggy 5ee0ade54b feat(labels): print the labels — queue, address review, PDF, log update
The printing session in three steps. The worklist is the paper queue (ADIF
qsl_sent R/Q), grouped by callsign since several QSOs of one station share a
card. Each recipient is reviewed before anything prints: routing first — via
manager when qsl_via says so, direct when an address is known, bureau otherwise
— then the address itself, editable and fetchable from QRZ (the MANAGER's
address when routing says via). What is printed is the reviewed text verbatim,
not a re-resolution that could differ from what was checked.

One PDF per label kind, never one file for all: a roll printer holds one stock
at a time, and a file mixing 29 mm addresses with 62 mm QSO labels could not be
printed at all. Pages are rasterised by the designer's own renderer at the
stock's dpi and carried into the PDF untouched — internal/pdf is a hand-written
image-page writer (DeviceGray + flate: monochrome, lossless, no cgo) because
that is the entire need.

Bureau stations get no address label (no envelope); return labels are printed
one per envelope. Finishing offers the log update: QSL_SENT=Y, the chosen date,
via B or D per routing — through the same BulkUpdateQSL the paper view uses.
2026-08-28 19:58:37 +02:00

55 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package pdf
import (
"bytes"
"image"
"image/color"
"image/png"
"testing"
)
func testPNG(t *testing.T, w, h int) []byte {
t.Helper()
img := image.NewRGBA(image.Rect(0, 0, w, h))
for x := 0; x < w; x++ {
img.Set(x, h/2, color.Black)
}
var buf bytes.Buffer
if err := png.Encode(&buf, img); err != nil {
t.Fatal(err)
}
return buf.Bytes()
}
func TestDocShape(t *testing.T) {
var d Doc
// A 90×29 mm label at 300 dpi is 1063×343 px.
if err := d.AddImagePage(testPNG(t, 1063, 343), 90, 29); err != nil {
t.Fatal(err)
}
if err := d.AddImagePage(testPNG(t, 1063, 343), 90, 29); err != nil {
t.Fatal(err)
}
b, err := d.Bytes()
if err != nil {
t.Fatal(err)
}
// Not a PDF parser — the shape a viewer needs to find its way in.
for _, want := range []string{"%PDF-1.4", "/Count 2", "/DeviceGray", "startxref", "%%EOF"} {
if !bytes.Contains(b, []byte(want)) {
t.Errorf("missing %q in output", want)
}
}
// 90 mm = 255.118 pt — the page size a driver prints 1:1 on the roll.
if !bytes.Contains(b, []byte("/MediaBox [0 0 255.1181 82.2047]")) {
t.Errorf("media box is not the label size")
}
}
func TestEmptyDocRefused(t *testing.T) {
var d Doc
if _, err := d.Bytes(); err == nil {
t.Fatal("an empty document should refuse to render")
}
}