On this page:
Text  Content
t
bold
italic
underline
tt
roman
subscript
superscript
strikethrough
boldly
italicly
ttly
romanly
lines
para
item
subitem
verbatim
current_  font
current_  para_  width
current_  line_  sep
8.12

6 Pict Text Layout🔗ℹ

 import: pict/text package: rhombus-prototype

The text function from pict can draw text, but only in a fixed, given font. The pict/text library provides support for font configuration, nestable styles, and basic paragraph typesetting.

annotation

TextContent

Satisfied by a string, a pict, or a list of values that satisfy TextContent.

function

fun t(content :: TextContent, ...,

      ~font: font :: draw.Font = current_font()) :: Pict

Accepts content as either a string, pict, or list of such content (including, potentially, nested lists) and combines it into into a single pict. Strings are converted to text using text with font, and lists are flattened; the result listing of picts is the combined with beside and #'topline mode.

Support for lists makes t suitable for use with @ notation, as in @t{Hello}.

> t("Hello").scale(2)

image

> @t{Hello}.scale(2)

image

> parameterize { current_font:

                   current_font() with (style = #'italic) }:

    @t{Hello}.scale(2)

image

function

fun bold(content :: TextContent, ...) :: Pict

 

function

fun italic(content :: TextContent, ...) :: Pict

 

function

fun underline(content :: TextContent, ...) :: Pict

 

function

fun tt(content :: TextContent, ...) :: Pict

 

function

fun roman(content :: TextContent, ...) :: Pict

Similar to t, but starts with current_font() and adds boldness, italicness, underlinedness, fixed-widthness, or serifness to obstain the font for converting strings.

> @bold{Hello}.scale(2)

image

> @t{To @bold{boldly}  go}.scale(2)

image

> @roman{x = y + z}.scale(2)

image

function

fun subscript(content :: TextContent, ...) :: Pict

 

function

fun superscript(content :: TextContent, ...) :: Pict

Like t, but the resulting pict’s scale and baseline are adjusted to form subscript or superscript text.

> @t{H@subscript{2}O}.scale(2)

image

> @t{x@superscript{2}}.scale(2)

image

function

fun strikethrough(content :: TextContent, ...,

                  ~line: line :: ColorMode = #'inherit,

                  ~line_width: line_width :: LineWidth = 3,

                  ~dy: dy = 0) :: Pict

Like t, but a horizontal line is added on top of the resulting pict. The line, line_width, and dy arguments affect the striketrough line.

> @strikethrough{wrong}.scale(2)

image

expression

boldly(content_expr, ...)

 

expression

boldly: body; ...

 

expression

italicly(content_expr, ...)

 

expression

italicly: body; ...

 

expression

ttly(content_expr, ...)

 

expression

ttly: body; ...

 

expression

romanly(content_expr, ...)

 

expression

romanly: body; ...

Macros that parameterize content_exprs or bodys to adjust the current_font parameter in the sameway as bold, italic, tt, or romanly. For the forms with content_exprs, the results of the expressions are passed on to t. For the forms with bodys, the result is the result of the body sequence.

> @bold{a @italic{b}  c}.scale(2)

image

> @boldly{a @italic{b}  c}.scale(2)

image

function

fun lines(p :: Pict, ...,

          ~horiz: align :: HorizAlignment = #'left) :: Pict

Like stack, but using current_line_sep() as the separation amount and with a default horiztonal alignment of #'left.

function

fun para(content :: TextContent, ...,

         ~width: width = current_para_width(),

         ~horiz: horiz :: HorizAlignment = #'left,

         ~full: full = #false,

         ~decode: decode = #true) :: Pict

Accepts content similar to t, but combines into multiple lines instead of a single beside combination, and a blank space is added between picts that end up on the same line but could be split across lines.

The rules for spacing and line breaks are designed to work naturally with @ notation, and so they treat strings and list nestings specially:

The width argument determines the maximum width of a line, and if full is true, then the resulting pict is padded to that width. The horiz argument controls both how multiple lines are aligned relative to one another and how padding is added when full is true. Lines are separated by current_line_sep() space.

> @para{Say ``hello'' for me!}

image

> @para(~width: 50){Say ``hello'' for me!}

image

> @para(~width: 50, ~horiz: #'right){Say ``hello'' for me!}

image

> para(& for List (i: 0..50): @t{Echo}.scale((50 - i)/50))

image

> parameterize { current_font:

                   current_font() with (size = 18, kind = #'roman) }:

    para(@{There's a fine line between fishing},

         @{and just standing on the shore like an idiot.},

         @{--- Stephen Wright})

image

function

fun item(content :: TextContent, ...,

         ~bullet: bullet :: maybe(Pict) = #false,

         ~width: width = current_para_width(),

         ~horiz: align :: HorizAlignment = #'left,

         ~full: full = #false) :: Pict

 

function

fun subitem(content :: TextContent, ...,

            ~bullet: bullet :: maybe(Pict) = #false,

            ~width: width = current_para_width(),

            ~horiz: align :: HorizAlignment = #'left,

            ~full: full = #false) :: Pict

Like para, but the paragraph is narrowed to leave room for a bullet and space after the bullet. When bullet is #false, then is used for item or is used for subitem.

> lines(

    @para{Outline},

    @item{Introduction},

    @subitem{short version},

    @subitem{long version},

    @item{Conclusion}

  )

image

function

fun verbatim(content :: TextContent, ...,

             ~font: font :: draw.Font = current_font()) :: Pict

Accepts content similar to tt, but recognizes newline characters as line breaks.

> @verbatim{

    Say ``hello''

    for me!

  }

image

context parameter

Parameter.def current_font :: draw.Font

The default font used by functions from pict/text for formatting text, including by t and para.

The default line width for para and related functions.

The default amount of separate used between lines by lines, para and related functions.