58.4 Text Content and Layout
Use plain-text for a single line, paragraph for line breaks or wrapping, and rich-text for styled spans. These constructors store explicit text properties. Use the role-based constructors in Semantic Text and Typography when properties should inherit from a typography theme.
See also Semantic Text and Typography Styles, Numbers and Units.
58.4.1 Plain, Multiline, and Rich Text Visuals
A text Visual stores immutable Unicode content, inline style runs, and explicit font/layout anchors. plain-text preserves the original one-line API; paragraph adds explicit lines and renderer-measured wrapping; and rich-text adds styled spans. Every form implements gen:visual, gen:affine-visual, and gen:opacity-visual. Its raw structure constructor and internal transform and opacity fields are not public.
The reference position is an anchor selected on the untransformed text box. Horizontal alignment chooses its left edge, center, or right edge. Vertical alignment chooses its top edge, center, font baseline, or bottom edge. For a paragraph the baseline is the first rendered line’s baseline. Scale and rotation are applied around that anchor.
procedure
(text-font-family? value) → boolean?
value : any/c
'default 'decorative 'roman 'script 'swiss 'modern 'symbol 'system
A family is a portable request, not a promise of one particular installed font face. The drawing backend chooses a suitable platform font.
procedure
(text-font-style? value) → boolean?
value : any/c
procedure
(text-font-weight? value) → boolean?
value : any/c
procedure
(text-horizontal-alignment? value) → boolean?
value : any/c
procedure
(text-vertical-alignment? value) → boolean?
value : any/c
procedure
(text-span content [ #:font-size font-size #:font-face font-face #:font-family font-family #:font-style font-style #:font-weight font-weight #:color color]) → text-span? content : string? font-size : (or/c false/c (and/c finite-real? positive?)) = #f font-face : (or/c false/c string?) = #f font-family : (or/c false/c text-font-family?) = #f font-style : (or/c false/c text-font-style?) = #f font-weight : (or/c false/c text-font-weight?) = #f color : any/c = #f
procedure
(text-span? value) → boolean?
value : any/c
procedure
(text-span-content span) → string?
span : text-span?
procedure
(text-span-font-size span)
→ (or/c false/c (and/c finite-real? positive?)) span : text-span?
procedure
(text-span-font-face span) → (or/c false/c string?)
span : text-span?
procedure
(text-span-font-family span) → (or/c false/c text-font-family?)
span : text-span?
procedure
(text-span-font-style span) → (or/c false/c text-font-style?)
span : text-span?
procedure
(text-span-font-weight span) → (or/c false/c text-font-weight?)
span : text-span?
procedure
(text-span-color span) → any/c
span : text-span?
58.4.1.1 Constructing Text Visuals
procedure
(plain-text content #:id id [ #:center center #:rotation rotation #:scale scale #:opacity opacity #:font-size font-size #:font-face font-face #:font-family font-family #:font-style font-style #:font-weight font-weight #:color color #:horizontal-alignment horizontal-alignment #:vertical-alignment vertical-alignment]) → text-visual? content : string? id : symbol? center : vec2? = origin rotation : finite-real? = 0 scale : scale-factor? = 1 opacity : opacity? = 1 font-size : (and/c finite-real? positive?) = 1/2 font-face : (or/c string? #f) = #f font-family : text-font-family? = 'default font-style : text-font-style? = 'normal font-weight : text-font-weight? = 'normal color : any/c = theme-foreground horizontal-alignment : text-horizontal-alignment? = 'center vertical-alignment : text-vertical-alignment? = 'center
content may be empty and may contain arbitrary Unicode characters, but it may not contain a carriage return or newline. The constructor copies the string into immutable storage. A mutable font-face string is copied in the same way. A false font-face asks the backend to select a face from font-family. When both are supplied, the face is preferred and the family remains the fallback classification.
font-size is measured in local world units before the Visual’s scale is applied. The default is one half world unit. Non-uniform scale may stretch the rendered text independently in x and y. Rotation is counter-clockwise in radians.
color is deliberately opaque model data. The built-in Pict renderer passes it to Pict color handling. A different renderer may interpret it differently. opacity is semantic global opacity and is applied to the complete rendered line after renderer dispatch.
The alignment arguments determine which point of the original text box is at center. Alignment is resolved before scale and rotation. This makes a left-baseline label, for example, grow to the right and rotate around the start of its baseline.
procedure
(paragraph content #:id id [ #:center center #:rotation rotation #:scale scale #:opacity opacity #:font-size font-size #:font-face font-face #:font-family font-family #:font-style font-style #:font-weight font-weight #:color color #:horizontal-alignment horizontal-alignment #:vertical-alignment vertical-alignment #:width width #:line-spacing line-spacing #:line-alignment line-alignment]) → text-visual? content : string? id : symbol? center : vec2? = origin rotation : finite-real? = 0 scale : scale-factor? = 1 opacity : opacity? = 1 font-size : (and/c finite-real? positive?) = 1/2 font-face : (or/c string? #f) = #f font-family : text-font-family? = 'default font-style : text-font-style? = 'normal font-weight : text-font-weight? = 'normal color : any/c = theme-foreground horizontal-alignment : text-horizontal-alignment? = 'center vertical-alignment : text-vertical-alignment? = 'center width : (or/c false/c (and/c finite-real? positive?)) = #f line-spacing : (and/c finite-real? positive?) = 1 line-alignment : text-horizontal-alignment? = 'left
line-spacing multiplies the largest natural line height in the paragraph. line-alignment aligns every resolved line inside the widest resolved line, while horizontal-alignment selects the anchor of that complete paragraph. The first line supplies a 'baseline anchor.
procedure
(rich-text #:id id [ #:center center #:rotation rotation #:scale scale #:opacity opacity #:font-size font-size #:font-face font-face #:font-family font-family #:font-style font-style #:font-weight font-weight #:color color #:horizontal-alignment horizontal-alignment #:vertical-alignment vertical-alignment #:width width #:line-spacing line-spacing #:line-alignment line-alignment] piece ...) → text-visual? id : symbol? center : vec2? = origin rotation : finite-real? = 0 scale : scale-factor? = 1 opacity : opacity? = 1 font-size : (and/c finite-real? positive?) = 1/2 font-face : (or/c string? #f) = #f font-family : text-font-family? = 'default font-style : text-font-style? = 'normal font-weight : text-font-weight? = 'normal color : any/c = theme-foreground horizontal-alignment : text-horizontal-alignment? = 'center vertical-alignment : text-vertical-alignment? = 'center width : (or/c false/c (and/c finite-real? positive?)) = #f line-spacing : (and/c finite-real? positive?) = 1 line-alignment : text-horizontal-alignment? = 'left piece : (or/c string? text-span?)
Spans retain one combined source string.
> (define label (rich-text #:id 'label "x = " (text-span "2" #:font-weight 'bold))) > (text-visual-content label) "x = 2"
58.4.1.2 Inspecting and Updating Text
procedure
(text-visual? value) → boolean?
value : any/c
procedure
(text-visual-content visual) → string?
visual : text-visual?
procedure
(text-visual-spans visual) → (listof text-span?)
visual : text-visual?
procedure
(text-visual-font-size visual) → (and/c finite-real? positive?)
visual : text-visual?
procedure
(text-visual-font-face visual) → (or/c string? #f)
visual : text-visual?
procedure
(text-visual-font-family visual) → text-font-family?
visual : text-visual?
procedure
(text-visual-font-style visual) → text-font-style?
visual : text-visual?
procedure
(text-visual-font-weight visual) → text-font-weight?
visual : text-visual?
procedure
(text-visual-color visual) → any/c
visual : text-visual?
procedure
(text-visual-horizontal-alignment visual)
→ text-horizontal-alignment? visual : text-visual?
procedure
(text-visual-vertical-alignment visual)
→ text-vertical-alignment? visual : text-visual?
procedure
(text-visual-width visual)
→ (or/c false/c (and/c finite-real? positive?)) visual : text-visual?
procedure
(text-visual-line-spacing visual)
→ (and/c finite-real? positive?) visual : text-visual?
procedure
(text-visual-line-alignment visual)
→ text-horizontal-alignment? visual : text-visual?
procedure
(text-visual-with-content visual content) → text-visual?
visual : text-visual? content : string?
Changing content returns a new value.
> (define before (plain-text "x = 2" #:id 'value)) > (define after (text-visual-with-content before "x = 3")) > (text-visual-content before) "x = 2"
> (text-visual-content after) "x = 3"
procedure
(text-visual-with-spans visual spans) → text-visual?
visual : text-visual? spans : (listof text-span?)