Skip to content

Add auto-fitting text zone option#77

Merged
flocom merged 1 commit into
mainfrom
claude/elegant-archimedes-2nh79p
Jun 21, 2026
Merged

Add auto-fitting text zone option#77
flocom merged 1 commit into
mainfrom
claude/elegant-archimedes-2nh79p

Conversation

@flocom

@flocom flocom commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a per-screenshot Text zone to the Text tab: an optional rectangle that the headline + subheadline are confined to. When enabled, the font size is reduced automatically so the whole text fits inside the zone — entirely, centered, and without breaking any word across lines.

What's new

  • UI (Text tab): a Text zone (auto-fit) toggle, X / Y / W / H sliders (% of canvas), and a draggable / resizable dashed overlay on the preview (corner handles). The overlay is a DOM element, so it is never part of the exported PNG/ZIP.
  • Auto-shrink: the font scale is computed to fit the zone height (binary search over re-wrapped layout) and shrunk further so the widest single word still fits the zone width on one line (no mid-word break).
  • Placement: text wraps at the zone width and is centered both horizontally and vertically inside the rectangle.

Implementation

  • app.js
    • textZone {enabled, x, y, width, height} added to text defaults + normalizeTextSettings (backwards compatible; copied to panorama panels).
    • New maxWordWidth() and computeZoneFit() helpers; textVerticalExtent() gains a wrap-width override; drawTextToContext() confines wrap width / centre / vertical anchor when a zone is active.
    • UI module: toggle, sliders, and pointer-based drag/resize of the overlay; synced from syncUIWithState / updateTextUI and on tab switch.
  • index.html — zone controls + overlay markup.
  • styles.css — styles for the controls and the dashed rectangle/handles.

Verification

  • node --check app.js passes.
  • Dev server serves all assets (200, no errors).
  • Standalone algorithm tests (7/7): shrinks for a small zone, block fits zone height, every word fits zone width, long single word forced to fit, no shrink when text already fits, headline + subheadline both fit.

Note: like the existing overlap auto-fit, the fitting is computed in the browser; the server-side MCP renderer (which already lacks auto-fit) ignores the zone.

🤖 Generated with Claude Code


Generated by Claude Code

Add a per-screenshot "Text zone" to the Text tab: an optional rectangle the
headline + subheadline are confined to. When enabled, the font size is reduced
automatically so the whole text fits inside the zone — entirely, centered, and
without breaking any word across lines.

- State: textZone {enabled,x,y,width,height} in text defaults + normalization
- Rendering: computeZoneFit/maxWordWidth shrink to fit zone height and keep the
  widest word on one line; drawTextToContext/textVerticalExtent confine wrap
  width and center the block in the zone
- UI: toggle + X/Y/W/H sliders and a draggable/resizable dashed overlay on the
  preview (DOM-only, never part of exports)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5pzx2vkZB8DN2dDy4YRNH
@flocom
flocom merged commit a5d58f3 into main Jun 21, 2026
1 check passed
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.

2 participants