Rac. Text

String, position and format to draw a text.

An instance of this object contains the string and a Point used to determine the location of the drawn text. The Text.Format object determines the font, size, orientation angle, and the alignment relative to point to draw the text.

instance.Text

Instances of Rac contain a convenience rac.Text function to create Text objects with fewer parameters. This function also contains ready-made convenience objects, like rac.Text.hello, listed under instance.Text.

Example
let rac = new Rac()
let point = rac.Point(55, 77)
let format = rac.Text.Format('left', 'baseline')
// new instance with constructor
let text = new Rac.Text(rac, point, 'black quartz', format)
// or convenience function
let otherText = rac.Text(55, 77, 'black quartz', format)
See also:

Constructor

new Text(rac, point, string, format)

Creates a new Text instance.

Parameters:
Name Type Description
rac Rac

Instance to use for drawing and creating other objects

point Rac.Point

The location for the drawn text

string String

The string to draw

format Rac.Text.Format

The format for the drawn text

Classes

Format

Members

format :Rac.Text.Format

The alignment, angle, font, and size to use to draw the text.

point :Rac.Point

The location where the text will be drawn.

The text will be drawn relative to this point based on the alignment and angle configuration of format.

rac :Rac

Instance of Rac used for drawing and passed along to any created object.

string :String

The string to draw.

Methods

equals(otherText) → {Boolean}

Returns true when the string and point of both texts are equal; otherwise returns false.

When otherText is any class other that Rac.Text, returns false.

points are compared using point.equals.

The format objects are ignored in this comparison.

See also:
Parameters:
Name Type Description
otherText Rac.Text

A Text to compare

reverse() → {Rac.Text}

Returns a new Text which is an upside-down equivalent of this and generally in the same location.

The resulting Text is at the same location as this, using a reversed format and oriented towards the inverse of format.angle.

toString(digitsopt) → {String}

Returns a string representation intended for human consumption.

Parameters:
Name Type Attributes Default Description
digits Number <optional>
null

The number of digits to print after the decimal point, when ommited all digits are printed

Example
rac.Text(55, 77, 'sphinx of black quartz').toString()
// returns 'Text((55,77) "sphinx of black quartz")'

upright() → {Rac.Text}

Returns this or a new Text and Format that will always be oriented to be upright and readable.

Returns this when format.angle turn value is between [3/4, 1/4), since this is an upright text already; otheriwse [this.reverse()]}Rac.Text#reverse is returned.

withAngle(newAngle) → {Rac.Text}

Returns a new Text and Format with format.angle set to the Angle derived from newAngle.

Parameters:
Name Type Description
newAngle Rac.Angle | Number

The angle for the new Text and Text.Format

withFont(newFontnullable) → {Rac.Text}

Returns a new Text and Format with format.font set to newFont.

Parameters:
Name Type Attributes Description
newFont String <nullable>

The font name for the new Text and Text.Format; can be set to null.

withPaddings(hPadding, vPaddingopt) → {Rac.Text.Format}

Returns a new Text and Format with paddings set to the given values.

When only hPadding is provided, that value is used for both horizontal and vertical padding.

Parameters:
Name Type Attributes Default Description
hPadding Number

The horizontal padding for the new Text and Text.Format

vPadding Number <optional>
null

The vertical padding for the new Text and Text.Format; when ommited, hPadding is used instead

withSize(newSizenullable) → {Rac.Text}

Returns a new Text and Format with format.size set to newSize.

Parameters:
Name Type Attributes Description
newSize Number <nullable>

The font size for the new Text and Text.Format; can be set to null.