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.
(q/fill 0) (q/stroke 255 0 0) (q/stroke-weight 5) (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/point x y)) ; 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/point x y)))try example
Sets the spacing between lines of text in units of pixels. This setting will be used in all subsequent calls to the text function.
(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
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.
(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)try example
Sets the current font size. This size will be used in all subsequent calls to the text fn. Font size is measured in units of pixels.
(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
Calculates and returns the width of any text string.
(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