Text Formatting

From C4 Engine Wiki
Jump to navigation Jump to search

Strings displayed by text widgets may contain the embedded formatting directives supported by Slug. A list of formatting directives begins with the two-character sequence {# and ends with the closing brace }. Each directive has the form directive(params), where params can be empty or consist of one or more parameters that apply to the directive. Multiple directives can be included in one list by separating them with semicolons.

The following table lists the formatting directives recognized by the Text Widget.

Directive

Description

size(value)

Set the font size to value in pixels, where value is a floating-point number. This directive is ignored if value is not greater than zero.

stretch(value)

Set the text stretch to value, where value is a floating-point number. Ignored if value is not greater than zero.

track(value)

Set the text tracking to value in em units, where value is a floating-point number.

skew(value)

Set the text skew to value, where value is a floating-point number. Positive values skew to the right, and negative values skew to the left.

scale(x, y)

Set the text scale to (x, y), where x and y are floating-point numbers. The y component may be omitted, in which case it is set equal to the x component. Ignored if either x or y is not greater than zero.

offset(x, y)

Set the text offset to (x, y) in em units, where x and y are floating-point numbers. Positive values offset right and upward, and negative values offset left and downward.

under(value)

Set the underline state to value, where value is either true or false.

strike(value)

Set the strikethrough state to value, where value is either true or false.

script(value)

Set the transform-based script state to value, where value is an integer in the range [−3, 3]. If value is 0, then the text scale and text offset states are set to the identity transform. If value is positive, then the superscript scale and offset are applied value times. If value is negative, then the subscript scale and offset are applied value times. Ignored if value is out of range or the font does not contain transform-based script information.

left()

Set the text alignment to left. The new alignment takes effect at the beginning of the next line.

right()

Set the text alignment to right. The new alignment takes effect at the beginning of the next line.

center()

Set the text alignment to center. The new alignment takes effect at the beginning of the next line.

lead(value)

Set the leading to value in em units, where value is a floating-point number. The new leading takes effect at the beginning of the next line.

pspace(value)

Set the paragraph spacing to value in em units, where value is a floating-point number.

margin(left,right)

Set the left and right paragraph margins to left and right in absolute units. The right margin may be omitted, in which case it is set to the same value as the left margin.

indent(value)

Set the paragraph first-line indent to value in absolute units, where value is a floating-point number.

kern(value)

Set the glyph kerning state to value, where value is either true or false.

mark(value)

Set the combining mark positioning state to value, where value is either true or false.

seq(value)

Set the sequence replacement state to value, where value is either true or false.

alt(value)

Set the alternate substitution state to value, where value is either true or false.

grid(value)

Set the grid positioning state to value, where value is either true or false.

color(red,green,blue,alpha)

Set the primary text color to (red, green, blue, alpha), where each component is an integer in the range [0, 255]. The alpha component may be omitted, in which case it is 255. This directive is ignored if any component is out of range.

color2(red,green,blue,alpha)

Set the secondary text color to (red, green, blue, alpha) using the same format as the primary color. The secondary text color is used only when gradients are enabled.

gcoord(y1,y2)

Set the gradient coordinates to y1 and y2. These are the distances above the baseline at which the gradient is equal to the primary and secondary color, respectively. Negative values are allowed.

grad(value)

Set the gradient state to value, where value is either true or false.

effect_color(red,green,blue,alpha)

Set the primary effect color to (red, green, blue, alpha), where each component is an integer in the range [0, 255]. The alpha component may be omitted, in which case it is 255. This directive is ignored if any component is out of range.

effect_color2(red,green,blue,alpha)

Set the secondary effect color to (red, green, blue, alpha) using the same format as the primary color. The secondary effect color is used only when effect gradients are enabled.

effect_gcoord(y1,y2)

Set the effect gradient coordinates to y1 and y2. These are the distances above the baseline at which the gradient is equal to the primary and secondary color, respectively. Negative values are allowed.

effect_grad(value)

Set the effect gradient state to value, where value is either true or false.

reset()

Reset all formatting state to the initial values given by the text widget. This directive always turns subscript and superscript modes off and resets their parameters to the default values.


When sequence replacement is enabled, the following directives can be used to control what types of sequences are recognized.

Directive

Description

comp(value)

Set the glyph composition state to value, where value is either true or false.

slig(value)

Set the standard ligatures state to value, where value is either true or false.

rlig(value)

Set the required ligatures state to value, where value is either true or false.

dlig(value)

Set the discretionary ligatures state to value, where value is either true or false.

hlig(value)

Set the historical ligatures state to value, where value is either true or false.


When alternate substitution is enabled, the following directives can be used to control what types of alternates are applied.

Directive

Description

style(value)

Set the stylistic alternates state to value, where value is an integer in the range 0–20. If value is nonzero, stylistic alternates are enabled, and they use the set specified by value. If value is zero, stylistic alternates are disabled. Ignored if value is out of range.

historical(value)

Set the historical alternates state to value, where value is either true or false.

smallcap(value)

Set the lowercase small caps state to value, where value is either true or false.

capsmall(value)

Set the uppercase small caps state to value, where value is either true or false.

titling(value)

Set the titling caps state to value, where value is either true or false.

unicase(value)

Set the unicase state to value, where value is either true or false.

caseform(value)

Set the case-sensitive forms state to value, where value is either true or false.

slashzero(value)

Set the slashed zero state to value, where value is either true or false.

hyphenminus(value)

Set the hyphen minus state to value, where value is either true or false.

frac(value)

Set the fraction state to value, where value is either true or false.

lining(value)

Set the lining figures state to value, where value is either true or false. If value is true, then the oldstyle figures state is disabled.

oldstyle(value)

Set the oldstyle figures state to value, where value is either true or false. If value is true, then the lining figures state is disabled.

tabfig(value)

Set the tabular figures state to value, where value is either true or false. If value is true, then the proportional figures state is disabled.

propfig(value)

Set the proportional figures state to value, where value is either true or false. If value is true, then the tabular figures state is disabled.

sub(value)

Set the subscript state to value, where value is either true or false. If value is true, then the superscript, scientific inferiors, and ordinals states are disabled.

sup(value)

Set the superscript state to value, where value is either true or false. If value is true, then the subscript, scientific inferiors, and ordinals states are disabled.

inf(value)

Set the scientific inferiors state to value, where value is either true or false. If value is true, then the subscript, superscript, and ordinals states are disabled.

ord(value)

Set the ordinals state to value, where value is either true or false. If value is true, then the subscript, superscript, and scientific inferiors states are disabled.

Examples

The chemical formula for water would be displayed using the following string.

H{#sub(true)}2{#sub(false)}O

Words can be displayed in different colors with the following string.

{#color(255,0,0)}RED {#color(0,255,0)}GREEN {#color(0,0,255)}BLUE

Text can be displayed at different sizes and with different tracking with the following string.

Normal size {#size(30);track(0.2)} Big and wide

See Also