text-align

text-leading

text-modeclj

text-size

text-stylecljs

text-width

text-align

Arguments
[align][align-x align-y]
Docstring

Sets the current alignment for drawing text. Available modes are:

horizontal - :left, :center, and :right vertical - :top, :bottom, :center, and :baseline

An optional second parameter specifies the vertical alignment mode. :baseline is the default. The :top and :center parameters are straightforward. The :bottom parameter offsets the line based on the current text-descent. For multiple lines, the final line will be aligned to the bottom, with the previous lines appearing above it.

When using text with width and height parameters, :baseline is ignored, and treated as :top. (Otherwise, text would by default draw outside the box, since :baseline is the default setting. :baseline is not a useful drawing mode for text drawn in a rectangle.)

The vertical alignment is based on the value of text-ascent, which many fonts do not specify correctly. It may be necessary to use a hack and offset by a few pixels by hand so that the offset looks correct. To do this as less of a hack, use some percentage of text-ascent or text-descent so that the hack works even if you change the size of the font.

Works only inside sketch functions?
Yes
Original Processing method
textAlign()
Original p5js method
textAlign()
Example
(q/fill 0)
(let [h-align [:left :center :right]
      v-align [:top :bottom :center :baseline]]
  ; text-align with single argument
  (doseq [ind (range (count h-align))
          :let [x 50
                y (+ 20 (* ind 50))]]
    (q/text-align (h-align ind))
    (q/text (name (h-align ind)) x y)
    (q/push-style)
    (q/stroke 255 0 0)
    (q/stroke-weight 5)
    (q/point x y)
    (q/pop-style))
  ; text-align with multiple arguments
  (doseq [ind-h (range (count h-align))
          ind-v (range (count v-align))
          :let [x (+ 70 (* ind-v 100))
                y (+ 250 (* ind-h 50))
                h-al (h-align ind-h)
                v-al (v-align ind-v)
                txt (str (name h-al) "+" (name v-al))]]
    (q/text-align h-al v-al)
    (q/text txt x y)
    (q/push-style)
    (q/stroke 255 0 0)
    (q/stroke-weight 5)
    (q/point x y)
    (q/pop-style)))
try example

text-leading

Arguments
[leading]
Docstring

Sets the spacing between lines of text in units of pixels. This setting will be used in all subsequent calls to the text function.

Works only inside sketch functions?
Yes
Original Processing method
textLeading()
Original p5js method
textLeading()
Example
(q/fill 0)
(doseq [ind (range 4)
        :let [leading (* ind 10)]]
  (q/text-leading leading)
  (q/text (str "text leading\n" leading) 20 (+ 20 (* ind 100))))
try example

text-modeclj

Arguments
[mode]
Docstring

Sets the way text draws to the screen - available modes are :model and :shape

 In the default configuration (the `:model` mode), it's possible to
 rotate, scale, and place letters in two and three dimensional space.

 The `:shape` mode draws text using the glyph outlines of individual
 characters rather than as textures. This mode is only supported with
 the PDF and OPENGL renderer settings. With the PDF renderer, you
 must specify the `:shape` [[text-mode]] before any other drawing occurs.
 If the outlines are not available, then `:shape` will be ignored and
 `:model` will be used instead.

 The `:shape` option in OPENGL mode can be combined with [[begin-raw]] to
 write vector-accurate text to 2D and 3D output files, for instance
 DXF or PDF. `:shape` is not currently optimized for OPENGL, so if
 recording shape data, use `:model` until you're ready to capture the
 geometry with [[begin-raw]].
Works only inside sketch functions?
Yes
Original Processing method
textMode()
Original p5js method
None.
Example
clojure specific
  • (q/fill 0)
    (q/text-mode :model)
    (q/text "text-mode: model" 20 50)
    (q/text-mode :shape)
    (q/text "text-mode: shape" 20 100)

text-size

Arguments
[size]
Docstring

Sets the current font size. This size will be used in all subsequent calls to the text function. Font size is measured in units of pixels.

Works only inside sketch functions?
Yes
Original Processing method
textSize()
Original p5js method
textSize()
Example
(q/fill 0)
(doseq [ind (range 6)
        :let [size (+ 10 (* ind 5))]]
  (q/text-size size)
  (q/text (str "Text size: " size) 20 (+ 20 (* ind 80))))
try example

text-stylecljs

Arguments
[style]
Docstring

Sets/gets the style of the text for system fonts to :normal, :italic, or :bold. Note: this may be is overridden by CSS styling. For non-system fonts (opentype, truetype, etc.) please load styled fonts instead.

Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
textStyle()
Example
clojurescript specific
  • (q/fill 0)
    (q/text-style :normal)
    (q/text "text-style: normal" 20 50)
    (q/text-style :italic)
    (q/text "text-style: italic" 20 100)
    (q/text-style :bold)
    (q/text "text-style: bold" 20 150)
    try example

text-width

Arguments
[data]
Docstring

Calculates and returns the width of any text string.

Works only inside sketch functions?
Yes
Original Processing method
textWidth()
Original p5js method
textWidth()
Example
(q/fill 0)
(let [txt "Hello, world!"
      width (q/text-width txt)]
  (q/text txt 20 20)
  (q/text (str "Width of text above is " width) 20 40))
try example