Skip to content

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.

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.

ReturnsSignatureSummary
TextInfocreate(IFont font, float fontSize) factoryCreates a style that draws with font at fontSize design pixels, in opaque black, regular weight, upright, with the registered markups.

PropertyTypeDefaultSummary
fontIFontset at creation, by TextInfo.create(font, fontSize)The IFont that draws the text; its text renderer measures and draws it.
fontSizefloatset at creation, by TextInfo.create(font, fontSize)The size of the text, in design pixels: the em size of the font.
weightFontWeightFontWeight.REGULARThe FontWeight of the text; a font without that weight draws its closest one.
letterSpacingfloat0FThe extra space after each character, on 1 of the font size: 0.1F adds a tenth of the size, -0.02F tightens.
lineHeightfloatthe line height of the fontThe height of one line, on 1 of the font size; 0F takes the line height of the font.
colorColorColor.BLACKThe Color of the text, gradient and animated colors included; markup colors replace it when colored is true.
coloredbooleantrueIf 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.
italicbooleanfalseIf true, the text draws with the italic face of the font, or slanted when the font has none.
markupsITextMarkup...the registered markups of TextMarkupThe ITextMarkup tags that the text reads; JOID registers none by default.
effectsITextEffect...noneThe ITextEffect list applied to every glyph, such as a wave or a typewriter; getEffects() returns it as a list you cannot change.
shadowTintFloatnone, 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.

ReturnsSignatureSummary
doublegetWidth(String text)Returns the width of text drawn on one line with this style, in design pixels, markup tags excluded.
doublegetHeight()Returns the height of one line, in design pixels.
doublegetHeight(String text)Returns the height of text drawn with this style, in design pixels.
doubledw(String text, double value)Returns the width of text divided by value.
doubledh(double value)Returns the line height divided by value.
doubledh(String text, double value)Returns the height of text divided by value.
doubleaw(String text, double value)Returns the width of text plus value.
doubleah(double value)Returns the line height plus value.
doubleah(String text, double value)Returns the height of text plus value.
ReturnsSignatureSummary
ColorgetShadowColor()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.
thiswithColor(Color color) fluentReturns a copy with color as its color.
thiswithColored(boolean colored) fluentReturns a copy with colored set.
thiswithShadowTint(Float shadowTint) fluentReturns a copy with shadowTint set.
ReturnsSignatureSummary
doublegetBaseline()Returns the distance from the top of a line to its baseline, in design pixels; the elements of a Text align on it.
TextStylegetStyle()Returns the TextStyle that the markups start from: weight, italic, color and effects of this style.
floatgetShadowX()Returns the horizontal offset of the shadow, in design pixels; by default a 13.5th of the font size.
floatgetShadowY()Returns the vertical offset of the shadow, in design pixels; by default a 13.5th of the font size.
FontBoundsgetBounds(String text)Returns the width and the height of text as a FontBounds.
StringtoString()Returns the font, the size and the color, for logs.
ReturnsSignatureSummary
thisshadow() fluentAdds a shadow in the color of the text darkened by 30 %; it follows a color set later.
thisshadow(Color color) fluentSets the color of the shadow; null removes it.
thisshadow(float x, float y) fluentSets the offset of the shadow, in design pixels; on the pixel grid it rounds to at least one screen pixel.
thiswithFont(IFont font) fluentReturns a copy with font as its font.
thiswithFontSize(float fontSize) fluentReturns a copy with fontSize as its size.
thiswithWeight(FontWeight weight) fluentReturns a copy with weight as its weight.
thiswithLetterSpacing(float letterSpacing) fluentReturns a copy with letterSpacing set.
thiswithLineHeight(float lineHeight) fluentReturns a copy with lineHeight set.
thiswithItalic(boolean italic) fluentReturns a copy with italic set.
thiswithMarkups(ITextMarkup… markups) fluentReturns a copy that reads only markups.
thiswithShadow() fluentReturns a copy with a shadow in the color of the text darkened by 30 %, which follows a color set later.
thiswithShadow(Color color) fluentReturns a copy with a shadow of color.
thiswithShadow(float x, float y) fluentReturns a copy with the shadow offset set.
TextInfocopy()Returns an unlocked copy with every property of this style.
thiswithEffects(ITextEffect… effects) fluentReturns a copy with effects as its effects.
Inherited from LockableValue (2)

lock · isLocked

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.

  • this font(IFont font) fluent
  • IFont getFont()

Default: set at creation, by TextInfo.create(font, fontSize)

The IFont that draws the text; its text renderer measures and draws it.

  • this fontSize(float fontSize) fluent
  • float getFontSize()

Default: set at creation, by TextInfo.create(font, fontSize)

The size of the text, in design pixels: the em size of the font.

  • this weight(FontWeight weight) fluent
  • FontWeight getWeight()

Default: FontWeight.REGULAR

The FontWeight of the text; a font without that weight draws its closest one.

  • this letterSpacing(float letterSpacing) fluent
  • float 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.

  • this lineHeight(float lineHeight) fluent
  • float 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) fluent
  • Color getColor()

Default: Color.BLACK

The Color of the text, gradient and animated colors included; markup colors replace it when colored is true.

  • this colored(boolean colored) fluent
  • boolean 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.

  • this italic(boolean italic) fluent
  • boolean isItalic()

Default: false

If true, the text draws with the italic face of the font, or slanted when the font has none.

  • this markups(ITextMarkup... markups) fluent
  • List<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.

  • this effects(ITextEffect... effects) fluent
  • List<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.

  • this shadowTint(Float shadowTint) fluent
  • Float 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).

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.

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.

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.

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.

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.


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

Report a problem with this page