Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .agents/skills/badge-printer-emulator/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: badge-printer-emulator
description: Emulate a Brother QL-820NWB AirPrint label printer with macOS's ippeveprinter and print badges to it from Safari in the iOS Simulator, to see exactly what a real badge printer receives. Use when changing badge layout, print CSS or door and kiosk printing.
---

# Badge printer emulator

Check-in vendors most often recommend the Brother QL-820NWB, and it's the model they support for iPads (AirPrint). `brother-ql820nwb.conf` reproduces its AirPrint attributes from a real Brother QL dump: URF raster only, 300 dpi 8-bit grey, black only, Brother DK label sizes with the 62 × 100 mm DK-1202 badge label loaded.

## Run it

Use bash (zsh doesn't split arguments) and run it in the background:

```bash
S=<scratch dir>; mkdir -p "$S/spool" "$S/out"
ippeveprinter -vvv -k -d "$S/spool" -p 8631 -r _universal -a .agents/skills/badge-printer-emulator/brother-ql820nwb.conf "Brother QL-820NWB" > "$S/printer.log" 2>&1
```

The iOS Simulator finds it over Bonjour. Stop it by killing the process.

## Print to it

1. On a booted iPad simulator, open a check-in list with badge printing on in Safari (`https://localhost:8443/check-in/<short_id>`).
2. Scan by typing the ticket code followed by Return (USB scanner mode), then tap Print my badge (kiosk) or Print badge (attendee sheet).
3. In the print sheet pick Brother QL-820NWB and paper 62 x 100 mm, then Print.
4. Decode the job: `python3 -I .agents/skills/badge-printer-emulator/urf2png.py "$S/spool/<N>-<name>.urf" "$S/out/badge"`. It prints the page size and writes `-gray.png` (what iOS sent) and `-thermal.png` (dithered to dots, as the print head prints it).

## What to check

- The page is 62.0 × 100.0 mm and nothing is cropped (Safari's own margins, `getIosPrintScale`).
- The footer shows only the site origin, never `/check-in/…`.
- With This printer only prints black on, ribbons are solid black with readable white text.
- QR modules are at least 3 dots wide if the QR code has to scan.

## Gotchas

- `-a` can't be combined with `-f`, `-M` or `-m`; everything lives in the conf file.
- Jobs fail with "Unsupported media-col collection value" unless `media-size-supported` lists the size iOS sends.
- iOS caches printers by name. After stopping the emulator, cancel the retrying job on the iPad.
- Desktop Chrome kiosk printing needs the emulator as a macOS printer (`lpadmin -p BadgeEmulator -E -v ipp://localhost:8631/ipp/print -m everywhere`). That changes system settings, so ask before running it.
131 changes: 131 additions & 0 deletions .agents/skills/badge-printer-emulator/brother-ql820nwb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
ATTR text printer-make-and-model "Brother QL-820NWB (emulated)"
ATTR mimeMediaType document-format-supported application/octet-stream,image/urf
ATTR mimeMediaType document-format-default application/octet-stream
ATTR keyword urf-supported V1.3,W8,CP1,IS1,MT1-8-11,OB10,PQ4-5,RS300,FN3-11-60-63
ATTR boolean color-supported false
ATTR keyword print-color-mode-supported monochrome,auto,auto-monochrome
ATTR keyword print-color-mode-default auto
ATTR keyword output-mode-supported monochrome,auto,auto-monochrome
ATTR resolution printer-resolution-supported 300dpi
ATTR resolution printer-resolution-default 300dpi
ATTR keyword sides-supported one-sided
ATTR keyword media-type-supported labels,roll
ATTR keyword media-source-supported main
ATTR keyword media-col-supported media-type,media-size,media-top-margin,media-left-margin,media-right-margin,media-bottom-margin,media-source
ATTR keyword media-supported om_brother-label-62x100mm_62x100mm,om_brother-label-29x90mm_29x90mm,om_brother-label-38x90mm_38x90mm,om_brother-label-62x29mm_62x29mm,om_brother-label-60x86mm_60x86mm,om_brother-label-58x58mm_58x58mm,roll_min_12x12.7mm,roll_max_62x1000mm
ATTR keyword media-default om_brother-label-62x100mm_62x100mm
ATTR keyword media-ready om_brother-label-62x100mm_62x100mm
ATTR integer media-bottom-margin-supported 303,154,288,202,262
ATTR integer media-top-margin-supported 303,154,288,202,262
ATTR integer media-left-margin-supported 154,303,288,202
ATTR integer media-right-margin-supported 154,303,288,202
ATTR collection media-size-supported {
MEMBER integer x-dimension 6200
MEMBER integer y-dimension 10000
},{
MEMBER integer x-dimension 2900
MEMBER integer y-dimension 9000
},{
MEMBER integer x-dimension 3800
MEMBER integer y-dimension 9000
},{
MEMBER integer x-dimension 6200
MEMBER integer y-dimension 2900
},{
MEMBER integer x-dimension 6000
MEMBER integer y-dimension 8600
},{
MEMBER integer x-dimension 5800
MEMBER integer y-dimension 5800
}
ATTR collection media-col-database {
MEMBER collection media-size {
MEMBER integer x-dimension 6200
MEMBER integer y-dimension 10000
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
},{
MEMBER collection media-size {
MEMBER integer x-dimension 2900
MEMBER integer y-dimension 9000
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
},{
MEMBER collection media-size {
MEMBER integer x-dimension 3800
MEMBER integer y-dimension 9000
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
},{
MEMBER collection media-size {
MEMBER integer x-dimension 6200
MEMBER integer y-dimension 2900
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
},{
MEMBER collection media-size {
MEMBER integer x-dimension 6000
MEMBER integer y-dimension 8600
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
},{
MEMBER collection media-size {
MEMBER integer x-dimension 5800
MEMBER integer y-dimension 5800
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
}
ATTR collection media-col-default {
MEMBER collection media-size {
MEMBER integer x-dimension 6200
MEMBER integer y-dimension 10000
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
}
ATTR collection media-col-ready {
MEMBER collection media-size {
MEMBER integer x-dimension 6200
MEMBER integer y-dimension 10000
}
MEMBER integer media-bottom-margin 303
MEMBER integer media-left-margin 154
MEMBER integer media-right-margin 154
MEMBER integer media-top-margin 303
MEMBER keyword media-type labels
MEMBER keyword media-source main
}
61 changes: 61 additions & 0 deletions .agents/skills/badge-printer-emulator/urf2png.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sys, struct, zlib

def decode_urf(data):
assert data[:8] == b'UNIRAST\x00', data[:8]
pages = struct.unpack('>I', data[8:12])[0]
pos, out = 12, []
for _ in range(pages):
bpp, cs, duplex, quality = data[pos], data[pos+1], data[pos+2], data[pos+3]
width, height, dpi = struct.unpack('>III', data[pos+12:pos+24])
pos += 32
bytes_pp = bpp // 8
white = b'\xff' * bytes_pp
rows = []
while len(rows) < height:
repeat = data[pos] + 1; pos += 1
line = bytearray()
while len(line) < width * bytes_pp:
n = data[pos]; pos += 1
if n == 0x80:
line += white * (width - len(line) // bytes_pp)
elif n < 0x80:
line += data[pos:pos+bytes_pp] * (n + 1); pos += bytes_pp
else:
count = 257 - n
line += data[pos:pos+count*bytes_pp]; pos += count*bytes_pp
rows.extend([bytes(line)] * repeat)
out.append((width, height, dpi, bpp, rows[:height]))
return out

def to_gray(row, bpp):
if bpp == 8:
return row
step = bpp // 8
return bytes((row[i]*299 + row[i+1]*587 + row[i+2]*114)//1000 for i in range(0, len(row), step))

def dither(rows, width):
buf = [list(r) for r in rows]
for y in range(len(buf)):
r = buf[y]
for x in range(width):
old = r[x]; new = 255 if old >= 128 else 0; r[x] = new; err = old - new
if x + 1 < width: r[x+1] += err * 7 // 16
if y + 1 < len(buf):
n = buf[y+1]
if x > 0: n[x-1] += err * 3 // 16
n[x] += err * 5 // 16
if x + 1 < width: n[x+1] += err // 16
return [bytes(max(0, min(255, v)) for v in r) for r in buf]

def write_png(path, width, rows):
raw = b''.join(b'\x00' + r for r in rows)
def chunk(t, d): return struct.pack('>I', len(d)) + t + d + struct.pack('>I', zlib.crc32(t + d) & 0xffffffff)
png = b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', width, len(rows), 8, 0, 0, 0, 0)) + chunk(b'IDAT', zlib.compress(raw, 9)) + chunk(b'IEND', b'')
open(path, 'wb').write(png)

src, prefix = sys.argv[1], sys.argv[2]
for i, (w, h, dpi, bpp, rows) in enumerate(decode_urf(open(src, 'rb').read())):
gray = [to_gray(r, bpp) for r in rows]
write_png(f'{prefix}-p{i+1}-gray.png', w, gray)
write_png(f'{prefix}-p{i+1}-thermal.png', w, dither(gray, w))
print(f'page {i+1}: {w}x{h}px @ {dpi}dpi = {w*25.4/dpi:.1f} x {h*25.4/dpi:.1f} mm, {bpp}bpp')
35 changes: 35 additions & 0 deletions .claude/rules/features/badges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
paths:
- "backend/app/**/Badge/**"
- "backend/app/**/*Badge*.php"
- "backend/tests/**/Badges/**"
- "frontend/src/components/common/NameBadge/**"
- "frontend/src/components/routes/event/Badges/**"
- "frontend/src/components/modals/PrintBadgesModal/**"
- "frontend/src/components/layouts/CheckIn/**"
- "frontend/src/hooks/useBadgePrinter.ts"
- "frontend/src/hooks/useCheckInController.tsx"
- "frontend/src/utilites/badge*.ts"
- "e2e/tests/badges/**"
---

# Name badges

- `BadgeDataService` resolves every badge line (names, ticket type, question answers) on the server. The frontend only renders `Badge` payloads; never resolve answers in the browser. The designer preview uses `buildSampleBadge` sample data, not real attendees.
- The design lives in `event_settings.badge_design_settings`; `null` means "use defaults", which `BadgeDesignService` builds from the event (currency picks A4 or Letter, brand colour and font come from the ticket and homepage designs, company/job title/pronoun questions are bound by title).
- Print status is derived (`AttendeeDomainObject::getBadgePrintStatus`) from `badge_print_count` and `badge_printed_at`. Anything that changes what is printed (name, ticket, seat, an answer on the badge, or the QR value: `public_id` is replaced on every email change and accepted transfer) clears `badge_printed_at` through `BadgeReprintService`; don't add jobs or sweepers that write it.
- Question and ticket ids inside the design are validated against the event on save and remapped by `BadgeDesignCloneService` when an event is duplicated.
- Badges are an opt-in event feature: `EventFeature::BADGES` in `event_settings.enabled_features` (Event Settings → Features), off by default. Off hides every badge control in the UI and switches off door printing (`CheckInListDomainObject::isBadgePrintingActive`); the staff badge endpoints stay available. Seating and box office deliberately stay out of this switch: they show whenever their licence and Cloud flag allow.
- Door printing goes through the public check-in list endpoints and only works on lists with `badge_printing_enabled`; the public layout (`BadgeDesignLayoutResource`) leaves out question and ticket ids. Kiosk lists refuse the attendee list and detail endpoints so attendees can't browse each other. The only search on a kiosk is the ticket lookup (`kiosk_lookup_enabled`, on by default): an exact, case-insensitive email and last name match, scoped like a scan, returning only `public_id`, first name and ticket title, with its own `kiosk-ticket-lookup` throttle. The kiosk then checks the ticket in through the normal scan path.
- Backs print one of three ways (`getDesignBackPrinting`): duplex pages mirror each row for a long-edge flip, fold-over units (`fold_over`) put the back beside a portrait badge or below a landscape one turned 180°, or no back. Door devices choose their own back mode in `useBadgePrinter` settings, defaulting to the design's fold-over or front only.
- Badges render at physical size (`mm` plus container query units) and text shrinks to fit with `FitText`; `FitBody` scales a template's main area down when the lines are taller than the space left. `FitText` fits every line from a render in one batch (reset all, read all, write all per step); fitting one element at a time forces a layout per line and froze a 1,000-badge print page for 20 s.
- Badges print through the browser (`window.print()` with an `@page` size). Door printing goes through `printBadgeSheets`, which swaps the address to `/` for the call, because iOS Safari prints the page URL in the margins and the check-in URL is a bearer link. E2E specs stub `window.print` with `stubBrowserPrinting`, which records the printed path and whether the call came from a click.
- iPad and iPhone (`printsOnlyFromATap`) block `print()` outside a tap and fire `afterprint` while the print sheet is still open. There `useBadgePrinter` prepares the badge first (attendee sheet open, kiosk check-in, setup modal open), prints synchronously from the tap and marks it printed at that moment; auto-print is off and the kiosk shows Print my badge and Print again. Never call `print()` after an `await` on that path. The badge-only print layout stays on while a badge is prepared, because iOS re-renders the live page when the printer or paper changes in its sheet.
- iOS Safari ignores `@page` size and margins, keeps its own (12.7 mm sides and top, about 21 mm bottom for the URL/date footer), and evaluates print media queries against the screen. So on those devices `BadgePrintSheets` zooms the pages by `getIosPrintScale` to fit inside those margins; without it badges on badge-sized paper are cropped.
- `blackInkOnly` (per device) prints accent, ribbon and text as pure black and white and images in greyscale. The most common badge printer (Brother QL-820NWB over AirPrint) prints black only, so colour ribbons dither to unreadable grey without it.
- Kiosk staff controls (Set up, scanner mode) appear only after pressing and holding the list name. The kiosk keeps the screen awake and starts touch devices on the camera unless the device already chose a scanner.
- Device setup instructions live only in `DeviceSetupGuide` (the staffed Badge printing modal and the kiosk's Set up modal), with a copyable Chrome command per platform. Facts it relies on, checked in Chromium source: `--kiosk-printing` confirms print preview automatically and prints to the destination last used in that Chrome profile with its last settings (not the OS default printer unless the `PrintPreviewUseSystemDefaultPrinter` policy is set), so staff print one test badge first; if that destination was Save as PDF, badges save silently to Downloads. Switches only apply when Chrome starts, so the guide has staff quit Chrome first. The `SilentPrintingEnabled` policy (Chrome 144+) is the managed-device equivalent. `--kiosk` is only full screen (⌘Q or Alt+F4 still exit); iPads lock to the page with Guided Access.
- Public check-in routes skip the shared `throttle:api` bucket and use their own per-IP allowance, because every door device at a venue shares one IP (`CheckInRateLimitTest`).
- A door badge includes the answers bound to the design even when the list hides question answers from unauthenticated staff: the organizer chose to print them.
- Door printing queues jobs in `useBadgePrinter`; never replace the job being printed.
- Check print CSS changes against an emulated Brother QL-820NWB with the `badge-printer-emulator` skill.
6 changes: 6 additions & 0 deletions .claude/skills/badge-printer-emulator/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: badge-printer-emulator
description: Emulate a Brother QL-820NWB AirPrint label printer with macOS's ippeveprinter and print badges to it from Safari in the iOS Simulator, to see exactly what a real badge printer receives. Use when changing badge layout, print CSS or door and kiosk printing.
---

Read `.agents/skills/badge-printer-emulator/SKILL.md` and follow it.
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ Feature rules live in `.claude/rules/`; Claude Code loads each file automaticall
| Reserved seating | `.claude/rules/ee/seating.md` |
| Audience (CRM) | `.claude/rules/ee/crm.md` |
| Lineup & schedule | `.claude/rules/features/lineup.md` |
| Name badges | `.claude/rules/features/badges.md` |
| Homepage sections | `.claude/rules/features/homepage-sections.md` |
| Embeddable widget | `.claude/rules/features/widget.md` |
| Registration questions | `.claude/rules/features/questions.md` |
| Ticket transfer, resale, verified self-service | `.claude/rules/features/ticket-transfer-resale.md` |
| Frontend UI patterns | `.claude/rules/frontend/ui.md` |
| E2E specs | `.claude/rules/e2e.md` |

Procedures are skills in `.agents/skills/`: `translations`, `api-smoke-test`, `e2e-dev-stack`.
Procedures are skills in `.agents/skills/`: `translations`, `api-smoke-test`, `e2e-dev-stack`, `badge-printer-emulator`.

## Maintaining these docs

Expand Down
12 changes: 12 additions & 0 deletions backend/app/DomainObjects/AttendeeDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use HiEvents\DomainObjects\Interfaces\IsFilterable;
use HiEvents\DomainObjects\Interfaces\IsSortable;
use HiEvents\DomainObjects\SortingAndFiltering\AllowedSorts;
use HiEvents\DomainObjects\Status\BadgePrintStatus;
use HiEvents\Services\Domain\TicketResale\DTO\TicketResaleStateDTO;
use HiEvents\Services\Domain\TicketResale\DTO\TicketResaleSummaryDTO;
use HiEvents\Services\Domain\TicketTransfer\DTO\TicketTransferStateDTO;
Expand Down Expand Up @@ -142,6 +143,17 @@ public function getFullName(): string
return $this->first_name.' '.$this->last_name;
}

public function getBadgePrintStatus(): BadgePrintStatus
{
if ($this->getBadgePrintCount() === 0) {
return BadgePrintStatus::NOT_PRINTED;
}

return $this->getBadgePrintedAt() === null
? BadgePrintStatus::NEEDS_REPRINT
: BadgePrintStatus::PRINTED;
}

public function getProduct(): ?ProductDomainObject
{
return $this->product;
Expand Down
Loading
Loading