Skip to content

write() API #1642

Open
Open
@adrianVmariano

Description

@adrianVmariano

text = can be a string or an array of strings. The string can have newline characters, in which case it is treated as an array of strings

width = (maximum) width the text can occupy. If no font size is given then the size is chosen to fit this width in one line. If a font size is given the text is wrapped to fit in this width.

height = (maximum) height the text can occupy. If no font size is given, the text size is chosen to fit this height. If a font size is given the text is wrapped to produce the shortest width constrained by this height

box=[width,height], alternative parameter for passing width and height more compactly.

If width and height are given together with no font size then the text is fit into the specified box with wrapping at the largest possible font size. If font size is given then the text is

font_size = Size of the font in conventional font size, adjusted by the 0.72 factor. (So 0.72*font_size gets passed to OpenSCAD.)

Msize (Mheight?) = The font size is chosen so an upper case M has the specified size.

align= Set this to "left", "right", "center" or "justify". Note that prototype uses "justify=" but it seems that proper typographic terminology (and the way I've always heard it) was that "justify" means simultaneous right and left alignment. (practicaltypography.com says "justified text is spaced so the left and right sides...both have a clean edge. The alternative...is left-aligned text.") I also noticed that the book says not to use justification without hyphenation. Should align also accept LEFT, RIGHT and CENTER?

align_last= alignment of last line in multiline text. Defaults same as align except when align is "justify" in which case defaults to "left". If there is only one line then this method applies.

valign= "top", "center", "bottom". Vertical alignment to use when text doesn't fully fill a box in the vertical direction. Default: center. (As above, should TOP, CENTER, BOT, BACK, FWD work?)

vcenter_mode = control how Roman text, at least, is centered vertically. As noted by Jordan, at least for small texts with 1-2 lines, it matters if the actual text has ascenders or descenders, so there are different centering choices here. I'm not sure what exactly the modes should be. Actually this concept also connects to the question of margins and indeed how much room you think there is to fit the text, so maybe the name is wrong. That is, does the text end at its actual top or nominal top, and at the actual bottom? Or descender bottom? It seems like some possible choices for how to define the text extent are: nominal text box dimension, actual text size, actual text size ignoring descenders

letter_space= gives a space to add between letters. practicaltypography.com suggests that this be given in relative units, like 5%-12% of the font size, when applying to ALL CAPS. That would suggest accepting a fraction or percentage value. On the other hand, if the goal is to spread letters for 3d printability, maybe an absolute letter space is better? This has to be handled manually in the code by breaking up letters and inserting the space due to the broken letter spacing method used in OpenSCAD. If letterspacing is zero, do NOT break up words and insert zero, instead feed whole words to ensure that ligatures and kerning work optimally. Of course, letterspacing can be a negative value to squish letters together.

line_spacing = a multiplier that controls line spacing.

margin= (is this needed) specifies a margin based on the text somehow. The notes say (interline-ascender)/2. The point here is that an absolute margin is easily created by just changing the box size, so this parameter is needed only if it does something relative to the text.

  1. Wrapping of text will apply only to horizontal text. Text written in the vertical direction does not get wrapped.
  2. If text is an array (or contains explicit newlines) then no automatic wrapping will be done. (Including a length1 array.)
  3. If text is at a specified size and doesn't fit in its width/height constraint then that's an error, ideally with a note on how much the text needs to shrink.
  4. Jordan noticed an issue about spacing and balance having to do with the ascenders and descenders in texts which I tried to capture with the vcenter_mode concept above, but maybe it should be something about vboundary---how the boundary of text is defined vertically? I'm not sure. I've also somewhat forgotten the details of the examples, but it was really applicable to things with only 1-2 lines of text and probably not relevant to long texts. There's an example in the wiki for text() where "Foobar" is centered vertically and it looks wrong, presumably because it's centering on the abstract box which has a bunch of extra space above the text.

For anchoring the obvious simple thing is to anchor on the bounding box of the text. There is one point of uncertainty, which is, so you anchor on the actual bounding box of the realized text, or on the nominal requested bounding box. I guess there could be an anchor mode for that.

There is a second question about anchoring to the baseline. This is complicated because (1) there are multiple baselines in multiline text and (2) after saying "baseline" you still have to specify if you mean left, right, or center on the baseline, and for write3d you'd have 6 more directions to manage. My best idea for how to manage this is that we have a function like LINE(dir,n=0) that gives you the named anchor text string for a particular line (or the first line by default) located at the baseline in the direction given by dir. So LINE would produce some text that might look like "baseline_[1,0,0]_4" for LINE(RIGHT,4) and named anchors could be created for all those text strings. This would be easy to do if we had an array of coordinate values providing the baseline locations for each line and the left, right and center for each line (which would depend on whether we're doing actual text extent or bounding box).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions