The designer's data model lives in internal/labels: STOCKS are the physical roll in the printer (geometry in mm, margins, dpi — seeded with the common Brother DK sizes, the QL family being what prompted the feature), TEMPLATES are one design each, of two kinds: the QSO label glued on the card, whose repeating table carries several contacts of the same station, and the address label for the envelope, whose lines collapse when a variable is empty. Everything is measured in millimetres — labels are sold in mm, and an operator lining a design up against a physical sticker thinks in mm; pixels exist only in the renderer, at the stock's dpi. The canvas renderer is shared between the editor's preview and the future print path, so there is no second implementation for the preview to disagree with. The preview is fed with the log's latest contacts rather than lorem ipsum: real data shows a too-narrow column immediately. Printing (PDF, one page per label at exact size) is the next module; nothing here prints yet.
14 lines
455 B
Go
14 lines
455 B
Go
package labels
|
|
|
|
import "encoding/json"
|
|
|
|
// The stock row stores its geometry as JSON so adding a field never needs a
|
|
// migration; the name is duplicated into its own column for listing.
|
|
func parseStock(doc string, s *Stock) error { return json.Unmarshal([]byte(doc), s) }
|
|
|
|
func encodeStock(s Stock) (string, error) {
|
|
s.ID = 0 // the row id is authoritative; never persist a stale copy inside the blob
|
|
b, err := json.Marshal(s)
|
|
return string(b), err
|
|
}
|