This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name | ### textAlign()
Examples |
    PFont font;
    // The font must be located in the current sketch's
    // "data" directory to load successfully
    font = loadFont("LetterGothicStd-32.vlw");
    textFont(font, 20);
    textAlign(RIGHT);
    text("WORD", 50, 30);
    textAlign(CENTER);
    text("WORD", 50, 50);
    textAlign(LEFT);
    text("WORD", 50, 70);
    background(0);
    stroke(153);
    textSize(16);
    textAlign(CENTER, BOTTOM);
    line(0, 30, width, 30);
    text("WORD", 50, 30);
    textAlign(CENTER, CENTER);
    line(0, 50, width, 50);
    text("WORD", 50, 50);
    textAlign(CENTER, TOP);
    line(0, 70, width, 70);
    text("WORD", 50, 70);
Description | Sets the current alignment for drawing text. The parameters LEFT, CENTER, and RIGHT set the display characteristics of the letters in relation to the values for the x and y parameters of the text() function. An optional second parameter can be used to vertically align the text. BASELINE is the default, and the vertical alignment will be reset to BASELINE if the second parameter is not used. The TOP and CENTER parameters are straightforward. The BOTTOM parameter offsets the line based on the current textDescent(). 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 textAscent(), 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 textAscent() or textDescent() so that the hack works even if you change the size of the font.
Syntax |
    textAlign(alignX)
    textAlign(alignX, alignY)
Parameters |
alignX | int: horizontal alignment, either LEFT, CENTER, or RIGHT
alignY | int: vertical alignment, either TOP, BOTTOM, CENTER, or BASELINE
Returns | void
Related | loadFont() PFont text()

Updated on October 26, 2013 08:58:31pm PDT