Skip to content

feat: add write() module for advanced 3D text with auto-sizing and wrapping (#1642)#1963

Open
junhinhow wants to merge 1 commit intoBelfrySCAD:masterfrom
junhinhow:feat/write-api-1642
Open

feat: add write() module for advanced 3D text with auto-sizing and wrapping (#1642)#1963
junhinhow wants to merge 1 commit intoBelfrySCAD:masterfrom
junhinhow:feat/write-api-1642

Conversation

@junhinhow
Copy link
Copy Markdown

Summary

New write.scad module (not included in std.scad, requires separate include):

  • write() module: advanced 3D text with:

    • Auto-sizing: omit font_size + provide box/width/height → text scales to fit
    • Word wrapping: provide font_size + width → automatic line breaks at word boundaries
    • Multi-line: accepts array of strings or string with \n newlines
    • Alignment: horizontal (left/center/right) and vertical (top/center/bottom/baseline)
    • Margins: configurable padding inside the bounding box
    • Full attachable() integration with anchor/spin/orient
  • get_font_size() function: converts between typographic units

    • font_size (traditional point-like size)
    • em_size (em square / font design box)
    • cap_height (capital letter height, with configurable ratio)
    • Automatically handles the OpenSCAD 0.72 size factor

Usage: include <BOSL2/std.scad> then include <BOSL2/write.scad>

Test plan

  • get_font_size() returns correct values for all 3 unit types
  • Basic text renders valid 3D geometry
  • Multi-line text (array input) renders correctly
  • Auto-sizing fits text within specified box
  • Word wrapping breaks lines at word boundaries
  • All alignment combinations work (left/center/right × top/center/bottom)
  • Attachment to parent objects works correctly

Addresses #1642

🤖 Generated with Claude Code

…apping (BelfrySCAD#1642)

New write.scad module with advanced 3D text API for BOSL2:

write(text, h, font_size, font, width, height, box, align, valign,
      line_spacing, letter_space, margin, anchor, spin, orient):
  - Auto-sizing: without font_size, scales text to fit box
  - Word wrapping: with font_size + width, breaks at word boundaries
  - Multi-line: accepts array of strings or string with newlines
  - Alignment: horizontal (left/center/right) and vertical (top/center/bottom/baseline)
  - Configurable margin inside box
  - Full integration with BOSL2 attachable() system

get_font_size(font_size, em_size, cap_height, cap_ratio):
  - Converts between typographic units (font_size, em, cap_height)
  - Automatically corrects OpenSCAD 0.72 factor

Helper functions _wrap_line() and _wrap_words() for recursive word
wrapping respecting width limits.

Tests covering: get_font_size with 3 units, basic text, multi-line,
auto-sizing, wrapping, alignments and attachment.

Module not included in std.scad (use: include <BOSL2/write.scad>).
@junhinhow junhinhow force-pushed the feat/write-api-1642 branch from c92dd36 to 43be5a6 Compare April 6, 2026 13:48
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