Skip to content

Add word wrap and configurable text sizes to Markdown component#80

Open
Igglybuff wants to merge 6 commits into
eljojo:mainfrom
Igglybuff:feature/markdown-wordwrap
Open

Add word wrap and configurable text sizes to Markdown component#80
Igglybuff wants to merge 6 commits into
eljojo:mainfrom
Igglybuff:feature/markdown-wordwrap

Conversation

@Igglybuff

Copy link
Copy Markdown

Note: this PR builds on #79 (configurable printer width). The interesting diff is the three commits on top of that branch.

Changes

Markdown component (src/document/markdown.rs, types.rs): adds two new fields:

  • size: [u8; 2] — character size multipliers applied to the whole block (height, width; 0 = 1×). Defaults to [0, 0] (normal size, existing behaviour unchanged).
  • chars_per_line: Option<usize> — enables word wrapping at the given column width. Without this the printer wraps mid-word at the hardware level; with it text wraps cleanly at word boundaries. The effective column width is adjusted for the size multiplier.

Receipt handler (src/server/handlers/receipt.rs): exposes title_size and body_size as optional JSON fields on the receipt API, both defaulting to existing values so there's no behaviour change for callers that don't set them. Passes chars_per_line derived from PRINTER_WIDTH into the Markdown component.

🤖 Generated with Claude Code

Igglybuff and others added 6 commits May 23, 2026 10:33
The serve command gains a --width flag (also readable from the
PRINTER_WIDTH env var) specifying the printer's dot width. Defaults to
576 to match the TSP650II. Set to 384 for 58mm printers like the
Star mC-Print2.

All server handlers (photo, patterns, weave, receipt) now derive the
print width from the configured value instead of a hardcoded reference
to PrinterConfig::TSP650II. Dividers in the patterns and weave handlers
derive their character width from the printer dot width so they don't
wrap on narrower paper.

Adds PrinterConfig::MCP21 (384 dots, 58mm) alongside the existing
TSP650II constant, and a PrinterConfig::with_width() constructor for
building a config from an arbitrary dot width.

PRINTER_DEVICE and LISTEN_ADDR env vars are also added to the other
serve options for consistency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Same fix as patterns and weave: derive chars_per_line from printer_width
instead of using Divider::default(), which assumed TSP650II column count.
Also threads printer_width into the preview handler.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The env attribute on #[arg] requires clap's env feature flag.
The PrinterConfig import in receipt.rs was unused after refactoring
build_receipt to take a raw u16 width.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Markdown component gains two new optional fields:

- `size: [u8; 2]`: height and width multipliers for body text (0 = 1×,
  1 = 2×, etc.), defaulting to [0, 0] (no scaling). Heading sizes within
  the document are unaffected; this controls the base font size for
  paragraph text only.
- `chars_per_line: Option<usize>`: when set, body text is word-wrapped
  to this column width at 1× size. The emit logic divides by the width
  multiplier to find the effective wrap column, so the same field works
  correctly at any scale.

Word-wrapping is performed in a new `emit_wrapped` helper that tracks
the current column position and inserts newlines at word boundaries.
Soft breaks are suppressed when word-wrapping is active (they are
handled implicitly as spaces). Hard breaks and paragraph ends reset
the column counter.

Both fields default to their zero/None values, so all existing documents
and API callers are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pass chars_per_line (derived from printer_width) into the Markdown
component so body text word-wraps correctly on narrow paper. Also reduce
the default receipt title from size [3, 2] to [1, 1] — the original
value was calibrated for 80mm paper and produces oversized output on
58mm printers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add `title_size` and `body_size` fields to `ReceiptForm` so callers can
override the character size multipliers per-request without changing any
defaults. Both accept a `[height, width]` array where 0 = 1×, 1 = 2×, etc.

Defaults are unchanged from the original: `title_size` defaults to [3, 2]
and `body_size` defaults to [0, 0] (normal size), so existing API callers
are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant