# Label printers (TSPL/TSPL2) — experimental

Branch `experimental/tspl2`. Receipt printers (ESC/POS) behave exactly as before;
this only adds a second output language for label printers such as the
Altec ATP-300 Pro (USB 1203:0231, `MFG:Altec;CMD:TSPL2;MDL:ATP-300 Pro;`).

## Protocol detection (automatic)

1. The printer's IEEE 1284 device ID (`CMD:` field): read from Linux sysfs
   (`ieee1284_id`) or with the USB printer-class `GET_DEVICE_ID` request.
   `TSPL*` → TSPL. If ESC/POS is also listed, ESC/POS is used.
2. No device ID but USB vendor 0x1203 (TSC/Altec) → TSPL.
3. Windows queue name containing `TSPL`, `Altec ATP` or `TSC` → TSPL.
4. Otherwise ESC/POS (unchanged default).

## Label format

The print dialog shows a *Label printer* section only for TSPL printers. The
first time a model is used it asks width, height, gap/black mark/continuous,
resolution and rotation, pre-filled from the printer when it answers
`GETSETTING$("CONFIG","TSPL","PAPER WIDTH" / "PAPER SIZE" / "GAP SIZE")` and
`GETSETTING$("SYSTEM","INFORMATION","DPI")` over bidirectional USB (values are
only used when the reply has an explicit unit). The format is stored per model
in `label_formats.json` next to `config.json`. "Let the printer measure the
labels first" sends `GAPDETECT x,y` / `BLINEDETECT x,y` once.

## Output

The page is encoded with the unchanged ESC/POS encoder, rendered to a bitmap
(Font A 12×24 grid, alignment, double size, bold, raster images, barcodes, QR),
scaled to the label resolution (8 → 12 dots/mm at 300 dpi, shrunk to fit the
label width), centred, split over labels (`@cut` = next label, long pages over
several labels) and sent as:

```
SIZE w mm,h mm
GAP g mm,0 mm        (BLINE g mm,0 mm / GAP 0,0)
DIRECTION 0,0
REFERENCE 0,0
CLS
BITMAP x,0,wbytes,h,0,<1-bit data, 0 = black>
PRINT 1,1
```

`cargo run --example tspl_preview -- file.pos out 100 50 3 300` writes PNG
previews and the `.prn` job without a printer.
