TextInfo
final class TextInfo
Extends: LockableValue<TextInfo>
Package: dev.joid.lib.font · Module: core · Source: TextInfo.java
The style of a text, with its font, size, weight, color, spacing, shadow, markups and effects, and the measures it gives.
Description
Section titled “Description”Create one per style with create(font, fontSize) and keep it in a field: every text node and DrawText call takes one (Describe a style).
The plain setters (color, fontSize…) change this style in place; the withX methods return a changed copy and leave this one unchanged, which a locked style requires: a plain setter on a locked style throws IllegalStateException.
Sizes are in design pixels; the letter spacing and the line height are on 1 of the font size.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
TextInfo | create(IFont font, float fontSize) factory | Creates a style that draws with font at fontSize design pixels, in opaque black, regular weight, upright, with the registered markups. |
Properties
Section titled “Properties”| Property | Type | Default | Summary |
|---|---|---|---|
| font | IFont | set at creation, by TextInfo.create(font, fontSize) | The IFont that draws the text; its text renderer measures and draws it. |
| fontSize | float | set at creation, by TextInfo.create(font, fontSize) | The size of the text, in design pixels: the em size of the font. |
| weight | FontWeight | FontWeight.REGULAR | The FontWeight of the text; a font without that weight draws its closest one. |
| letterSpacing | float | 0F | The extra space after each character, on 1 of the font size: 0.1F adds a tenth of the size, -0.02F tightens. |
| lineHeight | float | the line height of the font | The height of one line, on 1 of the font size; 0F takes the line height of the font. |
| color | Color | Color.BLACK | The Color of the text, gradient and animated colors included; markup colors replace it when colored is true. |
| colored | boolean | true | If true, the markups that set a color change the color of the text and keep the alpha of color; if false, every character takes color. |
| italic | boolean | false | If true, the text draws with the italic face of the font, or slanted when the font has none. |
| markups | ITextMarkup... | the registered markups of TextMarkup | The ITextMarkup tags that the text reads; JOID registers none by default. |
| effects | ITextEffect... | none | The ITextEffect list applied to every glyph, such as a wave or a typewriter; getEffects() returns it as a list you cannot change. |
| shadowTint | Float | none, the shadow takes the color of shadow(Color) | The tint of a shadow drawn in the color of each glyph multiplied by this factor, alpha kept; null for none. |
Methods
Section titled “Methods”Position and size
Section titled “Position and size”| Returns | Signature | Summary |
|---|---|---|
double | getWidth(String text) | Returns the width of text drawn on one line with this style, in design pixels, markup tags excluded. |
double | getHeight() | Returns the height of one line, in design pixels. |
double | getHeight(String text) | Returns the height of text drawn with this style, in design pixels. |
double | dw(String text, double value) | Returns the width of text divided by value. |
double | dh(double value) | Returns the line height divided by value. |
double | dh(String text, double value) | Returns the height of text divided by value. |
double | aw(String text, double value) | Returns the width of text plus value. |
double | ah(double value) | Returns the line height plus value. |
double | ah(String text, double value) | Returns the height of text plus value. |
Colors
Section titled “Colors”| Returns | Signature | Summary |
|---|---|---|
Color | getShadowColor() | Returns the color of the shadow as it is drawn, the color of the text darkened for shadow(), or null when the text has no shadow of its own color. |
this | withColor(Color color) fluent | Returns a copy with color as its color. |
this | withColored(boolean colored) fluent | Returns a copy with colored set. |
this | withShadowTint(Float shadowTint) fluent | Returns a copy with shadowTint set. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
double | getBaseline() | Returns the distance from the top of a line to its baseline, in design pixels; the elements of a Text align on it. |
TextStyle | getStyle() | Returns the TextStyle that the markups start from: weight, italic, color and effects of this style. |
float | getShadowX() | Returns the horizontal offset of the shadow, in design pixels; by default a 13.5th of the font size. |
float | getShadowY() | Returns the vertical offset of the shadow, in design pixels; by default a 13.5th of the font size. |
FontBounds | getBounds(String text) | Returns the width and the height of text as a FontBounds. |
String | toString() | Returns the font, the size and the color, for logs. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
this | shadow() fluent | Adds a shadow in the color of the text darkened by 30 %; it follows a color set later. |
this | shadow(Color color) fluent | Sets the color of the shadow; null removes it. |
this | shadow(float x, float y) fluent | Sets the offset of the shadow, in design pixels; on the pixel grid it rounds to at least one screen pixel. |
this | withFont(IFont font) fluent | Returns a copy with font as its font. |
this | withFontSize(float fontSize) fluent | Returns a copy with fontSize as its size. |
this | withWeight(FontWeight weight) fluent | Returns a copy with weight as its weight. |
this | withLetterSpacing(float letterSpacing) fluent | Returns a copy with letterSpacing set. |
this | withLineHeight(float lineHeight) fluent | Returns a copy with lineHeight set. |
this | withItalic(boolean italic) fluent | Returns a copy with italic set. |
this | withMarkups(ITextMarkup… markups) fluent | Returns a copy that reads only markups. |
this | withShadow() fluent | Returns a copy with a shadow in the color of the text darkened by 30 %, which follows a color set later. |
this | withShadow(Color color) fluent | Returns a copy with a shadow of color. |
this | withShadow(float x, float y) fluent | Returns a copy with the shadow offset set. |
TextInfo | copy() | Returns an unlocked copy with every property of this style. |
this | withEffects(ITextEffect… effects) fluent | Returns a copy with effects as its effects. |
Inherited from LockableValue (2)
Creation details
Section titled “Creation details”create
Section titled “create”TextInfo create(IFont font, float fontSize) factory
Creates a style that draws with font at fontSize design pixels, in opaque black, regular weight, upright, with the registered markups.
Property details
Section titled “Property details”this font(IFont font)fluentIFont getFont()
Default: set at creation, by TextInfo.create(font, fontSize)
The IFont that draws the text; its text renderer measures and draws it.
fontSize
Section titled “fontSize”this fontSize(float fontSize)fluentfloat getFontSize()
Default: set at creation, by TextInfo.create(font, fontSize)
The size of the text, in design pixels: the em size of the font.
weight
Section titled “weight”this weight(FontWeight weight)fluentFontWeight getWeight()
Default: FontWeight.REGULAR
The FontWeight of the text; a font without that weight draws its closest one.
letterSpacing
Section titled “letterSpacing”this letterSpacing(float letterSpacing)fluentfloat getLetterSpacing()
Default: 0F
The extra space after each character, on 1 of the font size: 0.1F adds a tenth of the size, -0.02F tightens.
lineHeight
Section titled “lineHeight”this lineHeight(float lineHeight)fluentfloat getLineHeight()
Default: the line height of the font
The height of one line, on 1 of the font size; 0F takes the line height of the font.
this color(Color color)fluentColor getColor()
Default: Color.BLACK
The Color of the text, gradient and animated colors included; markup colors replace it when colored is true.
colored
Section titled “colored”this colored(boolean colored)fluentboolean isColored()
Default: true
If true, the markups that set a color change the color of the text and keep the alpha of color; if false, every character takes color.
italic
Section titled “italic”this italic(boolean italic)fluentboolean isItalic()
Default: false
If true, the text draws with the italic face of the font, or slanted when the font has none.
markups
Section titled “markups”this markups(ITextMarkup... markups)fluentList<ITextMarkup> getMarkups()
Default: the registered markups of TextMarkup
The ITextMarkup tags that the text reads; JOID registers none by default.
getMarkups() returns the registered markups of TextMarkup until markups(...) sets a list of your own.
effects
Section titled “effects”this effects(ITextEffect... effects)fluentList<ITextEffect> getEffects()
Default: none
The ITextEffect list applied to every glyph, such as a wave or a typewriter; getEffects() returns it as a list you cannot change.
shadowTint
Section titled “shadowTint”this shadowTint(Float shadowTint)fluentFloat getShadowTint()
Default: none, the shadow takes the color of shadow(Color)
The tint of a shadow drawn in the color of each glyph multiplied by this factor, alpha kept; null for none.
When it is set, it replaces the color of shadow(Color).
Method details
Section titled “Method details”getWidth
Section titled “getWidth”double getWidth(String text)
Returns the width of text drawn on one line with this style, in design pixels, markup tags excluded.
getHeight
Section titled “getHeight”double getHeight()
Returns the height of one line, in design pixels.
double getHeight(String text)
Returns the height of text drawn with this style, in design pixels.
double dw(String text, double value)
Returns the width of text divided by value.
double dh(double value)
Returns the line height divided by value.
double dh(String text, double value)
Returns the height of text divided by value.
double aw(String text, double value)
Returns the width of text plus value.
double ah(double value)
Returns the line height plus value.
double ah(String text, double value)
Returns the height of text plus value.
getShadowColor
Section titled “getShadowColor”Color getShadowColor()
Returns the color of the shadow as it is drawn, the color of the text darkened for shadow(), or null when the text has no shadow of its own color.
withColor
Section titled “withColor”this withColor(Color color) fluent
Returns a copy with color as its color.
withColored
Section titled “withColored”this withColored(boolean colored) fluent
Returns a copy with colored set.
withShadowTint
Section titled “withShadowTint”this withShadowTint(Float shadowTint) fluent
Returns a copy with shadowTint set.
getBaseline
Section titled “getBaseline”double getBaseline()
Returns the distance from the top of a line to its baseline, in design pixels; the elements of a Text align on it.
getStyle
Section titled “getStyle”TextStyle getStyle()
Returns the TextStyle that the markups start from: weight, italic, color and effects of this style.
getShadowX
Section titled “getShadowX”float getShadowX()
Returns the horizontal offset of the shadow, in design pixels; by default a 13.5th of the font size.
getShadowY
Section titled “getShadowY”float getShadowY()
Returns the vertical offset of the shadow, in design pixels; by default a 13.5th of the font size.
getBounds
Section titled “getBounds”FontBounds getBounds(String text)
Returns the width and the height of text as a FontBounds.
toString
Section titled “toString”String toString()
Returns the font, the size and the color, for logs.
shadow
Section titled “shadow”this shadow() fluent
Adds a shadow in the color of the text darkened by 30 %; it follows a color set later.
Throws IllegalStateException on a locked style.
this shadow(Color color) fluent
Sets the color of the shadow; null removes it.
Throws IllegalStateException on a locked style.
this shadow(float x, float y) fluent
Sets the offset of the shadow, in design pixels; on the pixel grid it rounds to at least one screen pixel.
Throws IllegalStateException on a locked style.
withFont
Section titled “withFont”this withFont(IFont font) fluent
Returns a copy with font as its font.
withFontSize
Section titled “withFontSize”this withFontSize(float fontSize) fluent
Returns a copy with fontSize as its size.
withWeight
Section titled “withWeight”this withWeight(FontWeight weight) fluent
Returns a copy with weight as its weight.
withLetterSpacing
Section titled “withLetterSpacing”this withLetterSpacing(float letterSpacing) fluent
Returns a copy with letterSpacing set.
withLineHeight
Section titled “withLineHeight”this withLineHeight(float lineHeight) fluent
Returns a copy with lineHeight set.
withItalic
Section titled “withItalic”this withItalic(boolean italic) fluent
Returns a copy with italic set.
withMarkups
Section titled “withMarkups”this withMarkups(ITextMarkup... markups) fluent
Returns a copy that reads only markups.
withShadow
Section titled “withShadow”this withShadow() fluent
Returns a copy with a shadow in the color of the text darkened by 30 %, which follows a color set later.
this withShadow(Color color) fluent
Returns a copy with a shadow of color.
this withShadow(float x, float y) fluent
Returns a copy with the shadow offset set.
TextInfo copy()
Returns an unlocked copy with every property of this style.
withEffects
Section titled “withEffects”this withEffects(ITextEffect... effects) fluent
Returns a copy with effects as its effects.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
