Typography
On this page · 11 entries
TextSize · TextFont
TextSize(float size)TextFont(string? path, float? size = null)TextFont(PFont font, float? size = null)
TextFont(null) resets to the default typeface. The string overload loads a font file directly; the PFont overload activates a font previously obtained via CreateFont/LoadFont and reuses its size unless you override it.
TextSizeSnap
TextSizeSnap(float step)
Rounds every text size to a multiple of step pixels (0, the default, turns it off). Skia renders each glyph once per size and reuses it; thousands of characters each at a slightly different size — a 3D field of glyphs, text that zooms — reuse nothing and draw several times slower. TextSizeSnap(1) makes the sizes repeat and looks the same.
CreateFont
CreateFont(string fontFamily, float size) → PFont
Creates a font from an installed system font family, like Processing's createFont(name, size). Unknown family names silently fall back to the system default rather than throwing.
LoadFont
LoadFont(string path, float size = 32) → PFont
Loads a font file (.ttf/.otf/etc.) from disk.
loadFont() loads a pre-baked .vlw bitmap font produced by the PDE's Tools > Create Font. DanaProcessing has no equivalent pipeline, so this loads a real font file directly instead — same practical result, one less step.class PFont
A loaded/created font. Get one from CreateFont()/LoadFont(), then activate it with TextFont(font). Implements IDisposable — dispose it once nothing is drawing with it anymore.
TextAlign
TextAlign(TextAlignH h, TextAlignV v = Baseline)
Sets both axes of alignment.
TextMode
TextMode(TextRenderMode mode)
Accepts Model — the only supported mode, regular text drawn straight to the canvas. Shape throws NotSupportedException, the same treatment as Filter(Erode/Dilate).
TextLeading
TextLeading(float leading)
Line spacing for multi-line strings.
TextWidth · TextAscent · TextDescent
TextWidth(string text)TextAscent()TextDescent() → float
TextWidth returns the widest line in a multi-line string.
Text
Text(string text, x, y)
Draws text at (x, y) per the current alignment.
Runnable example
A complete sketch using this section. Test in Dana opens it in the IDE, or paste it into a new tab and press Run.
// Text, TextSize, TextAlign, TextWidth and a font from the system. public class Typo : Sketch { PFont serif; public override void Setup() { Size(600, 300); serif = CreateFont("Georgia", 48); } public override void Draw() { Background(250, 245, 235); Fill(30); TextFont(serif); TextAlign(TextAlignH.Center, TextAlignV.Center); Text("Hello, type", Width / 2, 80); TextFont((string?)null); // back to the default font TextSize(16); string line = $"x = {MouseX:0}, y = {MouseY:0}"; float w = TextWidth(line); TextAlign(TextAlignH.Left, TextAlignV.Baseline); NoFill(); Stroke(200, 80, 60); Rect(MouseX - 4, MouseY - TextAscent() - 4, w + 8, TextAscent() + TextDescent() + 8); NoStroke(); Fill(30); Text(line, MouseX, MouseY); } }