58.5 Semantic Text and Typography Styles
A semantic text Visual retains a role and its explicit overrides; a text-style is a complete style, and a typography-theme is an immutable table of styles. text-treatment adds padding, background, and a cosmetic border. The contracts below distinguish an omitted property (inherit or retain) from an explicit #f (clear an optional property).
See also Text Content and Layout, Numbers and Units.
58.5.1 Semantic Text and Typography
Semantic text stores a presentation role instead of a resolved platform font. It lowers to the ordinary text-visual? protocol only when Animate renders or measures it under an explicit typography snapshot. Raw plain-text, paragraph, and rich-text remain independent of typography themes.
58.5.1.1 Backgrounds, Borders, and Padding
procedure
(text-treatment [ #:background background #:border-color border-color #:border-width border-width #:padding-x padding-x #:padding-y padding-y]) → text-treatment? background : (or/c false/c paint?) = #f border-color : (or/c false/c color-spec?) = #f border-width : (and/c finite-real? (>=/c 0)) = 0 padding-x : (and/c finite-real? (>=/c 0)) = 0 padding-y : (and/c finite-real? (>=/c 0)) = 0
A structured background paint uses the same local coordinates as every other Paint: the semantic text anchor is the origin, positive x points right, and positive y points up. Linear and radial gradients follow text placement, scaling, and rotation rather than starting at the treatment box’s top-left corner. The current Pict backend draws a checker-pattern as a device-aligned tile, so checker cells do not yet fully follow scale or rotation.
The built-in text renderer knows that content box exactly. A custom Pict renderer for a semantic text value instead declares its own logical Pict box; the treatment decorates that declared box. Animate does not inspect rendered pixels to guess a tighter ink box for custom renderers. Its treatment anchor is the center of the declared box, independently of the text alignment stored on the Visual. Backgrounds and padding scale with the Pict; a treatment border is added after that scale, so its width stays cosmetic (in device pixels).
procedure
(text-treatment? value) → boolean?
value : any/c
procedure
(text-treatment-background treatment) → (or/c false/c paint?)
treatment : text-treatment? (text-treatment-border-color treatment) → (or/c false/c color-spec?) treatment : text-treatment? (text-treatment-border-width treatment) → (and/c finite-real? (>=/c 0)) treatment : text-treatment? (text-treatment-padding-x treatment) → (and/c finite-real? (>=/c 0)) treatment : text-treatment? (text-treatment-padding-y treatment) → (and/c finite-real? (>=/c 0)) treatment : text-treatment?
procedure
(text-treatment-update treatment #:background background #:border-color border-color #:border-width border-width #:padding-x padding-x #:padding-y padding-y) → text-treatment? treatment : text-treatment? background : (or/c false/c paint?) border-color : (or/c false/c color-spec?) border-width : (and/c finite-real? (>=/c 0)) padding-x : (and/c finite-real? (>=/c 0)) padding-y : (and/c finite-real? (>=/c 0))
An explicit false border color clears it; an omitted padding value is retained.
> (define framed (text-treatment #:border-color "gray" #:border-width 1 #:padding-x 1/2)) > (define unframed (text-treatment-update framed #:border-color #f)) > (text-treatment-border-color unframed) #f
> (text-treatment-padding-x unframed) 1/2
58.5.1.2 Complete Styles
procedure
(text-style #:font-family font-family #:font-size font-size #:font-style font-style #:font-weight font-weight #:color color #:line-spacing line-spacing #:line-alignment line-alignment #:horizontal-alignment horizontal-alignment #:vertical-alignment vertical-alignment [ #:font-face font-face #:treatment treatment]) → text-style? font-family : text-font-family? font-size : (and/c finite-real? positive?) font-style : text-font-style? font-weight : text-font-weight? color : color-spec? line-spacing : (and/c finite-real? positive?) line-alignment : text-horizontal-alignment? horizontal-alignment : text-horizontal-alignment? vertical-alignment : text-vertical-alignment? font-face : (or/c false/c string?) = #f treatment : (or/c false/c text-treatment?) = #f
procedure
(text-style? value) → boolean?
value : any/c
procedure
(text-style-update style #:font-face font-face #:font-family font-family #:font-size font-size #:font-style font-style #:font-weight font-weight #:color color #:line-spacing line-spacing #:line-alignment line-alignment #:horizontal-alignment horizontal-alignment #:vertical-alignment vertical-alignment #:treatment treatment) → text-style? style : text-style? font-face : (or/c false/c string?) font-family : text-font-family? font-size : (and/c finite-real? positive?) font-style : text-font-style? font-weight : text-font-weight? color : color-spec? line-spacing : (and/c finite-real? positive?) line-alignment : text-horizontal-alignment? horizontal-alignment : text-horizontal-alignment? vertical-alignment : text-vertical-alignment? treatment : (or/c false/c text-treatment?)
procedure
(text-style-font-face style) → (or/c false/c string?)
style : text-style? (text-style-font-family style) → text-font-family? style : text-style? (text-style-font-size style) → (and/c finite-real? positive?) style : text-style? (text-style-font-style style) → text-font-style? style : text-style? (text-style-font-weight style) → text-font-weight? style : text-style? (text-style-color style) → color-spec? style : text-style? (text-style-line-spacing style) → (and/c finite-real? positive?) style : text-style? (text-style-line-alignment style) → text-horizontal-alignment? style : text-style? (text-style-horizontal-alignment style) → text-horizontal-alignment? style : text-style? (text-style-vertical-alignment style) → text-vertical-alignment? style : text-style? (text-style-treatment style) → (or/c false/c text-treatment?) style : text-style?
procedure
(text-style->datum style) → any/c
style : text-style?
procedure
(datum->text-style datum) → text-style?
datum : any/c
58.5.1.3 Typography Snapshots
procedure
(typography-theme #:id id [ #:styles styles #:extends parent] #:display-name display-name [ #:provenance provenance]) → typography-theme? id : symbol? styles : (or/c hash? (listof pair?)) = #hash() parent : (or/c false/c typography-theme?) = #f display-name : string? provenance : (or/c false/c string? symbol?) = #f
procedure
(typography-theme? value) → boolean?
value : any/c
procedure
(typography-theme-id theme) → symbol?
theme : typography-theme? (typography-theme-display-name theme) → string? theme : typography-theme? (typography-theme-provenance theme) → (or/c false/c string? symbol?) theme : typography-theme? (typography-style-keys theme) → (listof symbol?) theme : typography-theme? (typography-ref theme style-key) → text-style? theme : typography-theme? style-key : symbol? (typography-theme-fingerprint theme) → bytes? theme : typography-theme? (typography-theme->datum theme) → any/c theme : typography-theme? (datum->typography-theme datum) → typography-theme? datum : any/c
value
58.5.1.4 Role-Based Text
procedure
(title-text content #:id id [ #:center center] #:font-size font-size ...) → semantic-text-visual? content : string? id : symbol? center : vec2? = origin font-size : (and/c finite-real? positive?) (subtitle-text content #:id id ...) → semantic-text-visual? content : string? id : symbol? (section-heading-text content #:id id ...) → semantic-text-visual? content : string? id : symbol? (body-text content #:id id ...) → semantic-text-visual? content : string? id : symbol? (caption-text content #:id id ...) → semantic-text-visual? content : string? id : symbol? (label-text content #:id id ...) → semantic-text-visual? content : string? id : symbol? (quotation-text content #:id id ...) → semantic-text-visual? content : string? id : symbol? (code-text content #:id id ...) → semantic-text-visual? content : string? id : symbol? (annotation-text content #:id id ...) → semantic-text-visual? content : string? id : symbol?
procedure
(styled-text content #:style style-key #:id id ...) → semantic-text-visual? content : string? style-key : symbol? id : symbol?
procedure
(styled-rich-text #:style style-key #:id id [ #:center center #:rotation rotation #:scale scale #:opacity opacity #:width width] piece ...) → semantic-text-visual? style-key : symbol? id : symbol? center : vec2? = origin rotation : finite-real? = 0 scale : scale-factor? = 1 opacity : opacity? = 1 width : (or/c false/c (and/c finite-real? positive?)) = #f piece : (or/c string? text-span?)
procedure
(semantic-text-content visual) → string?
visual : semantic-text-visual? (semantic-text-spans visual) → (listof text-span?) visual : semantic-text-visual? (semantic-text-overrides visual) → semantic-text-overrides? visual : semantic-text-visual? (semantic-text-visual-width visual) → (or/c false/c (and/c finite-real? positive?)) visual : semantic-text-visual?
procedure
(semantic-text-override-inherited? value) → boolean?
value : any/c
procedure
(semantic-text-visual? value) → boolean?
value : any/c
procedure
(semantic-text-overrides? value) → boolean?
value : any/c
procedure
(semantic-text-style-key visual) → symbol?
visual : semantic-text-visual?
A role-based constructor keeps its role in the model.
> (define heading (title-text "Velocity" #:id 'heading)) > (semantic-text-style-key heading) 'title
procedure
(resolve-semantic-text-style visual theme) → text-style?
visual : semantic-text-visual? theme : typography-theme?