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
Contributor

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
@adrianVmariano
Copy link
Copy Markdown
Collaborator

Presumably we don't want to use this given that @amatulic has mostly written a write() module.

@amatulic
Copy link
Copy Markdown
Contributor

amatulic commented Apr 30, 2026

Doesn't address all of #1642 but looks interesting. I never tried Claude for coding.

The wrapping doesn't appear to handle proportional fonts.

I need to finish this. It's nearly all done (auto-size wrapping to fit a vertical bound still not tested, and the anchoring stuff is not there yet). Right now I'm busy trying to update a model for a $500 contest on Thingiverse, which will take me until Monday, and after that I should be able to work on the write() module.

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.

3 participants