Skip to content

GlyphTextRenderer

abstract class GlyphTextRenderer<F extends IFontFace>
Implements: ITextRenderer
Known subtypes: BitmapTextRenderer, MsdfTextRenderer
Package: dev.joid.lib.font.impl.glyph · Module: core · Source: GlyphTextRenderer.java

Base class of the text renderers of glyph fonts, which lays out, kerns, styles and shadows the text and leaves the drawing of each glyph to you.

MsdfTextRenderer and BitmapTextRenderer extend it. Extend it for a GlyphFont of your own: pass the core shader that draws your glyphs to the constructor and implement drawGlyph. On each draw, the renderer lays out the string with TextMarkup, runs the text effects, draws the shadow then the glyphs between begin() and end(), inside a pushed render state. The shader is created on the first draw; when the backend cannot compile it, the text is skipped with one dev-mode warning and its bounds are still returned.

ReturnsSignatureSummary
GlyphTextRenderer(CoreShader source) protectedCreates the renderer with the core shader that draws its glyphs.

ReturnsSignatureSummary
doublegetWidth(String text, TextInfo info)Returns the width of the laid-out string.
doublegetHeight(String text, TextInfo info)Returns the line height: a glyph font draws one line.
ReturnsSignatureSummary
FontBoundsdrawText(double x, double y, String text, TextInfo info)Draws the string with its top-left corner at x, y.
FontBoundsdrawText(double x, double y, String text, TextInfo info, double runX, double runY, double runWidth, double runHeight)Draws the string as a part of the run runX, runY, runWidth, runHeight, over which a gradient color spreads.
ReturnsSignatureSummary
doublegetLineHeight(TextInfo info)Returns TextInfo.lineHeight times the font size when it is set, otherwise the line height of the face times the font size.
doublegetBaseline(TextInfo info)Returns the distance from the top of the line to the baseline: the face’s own baseline, centered in a line height that differs from the face’s.
ReturnsSignatureSummary
GlyphLayout<F>layout(String text, TextInfo info)Returns the GlyphLayout of the string: markup tags read, faces resolved by weight and style, kerning and letter spacing applied.
ReturnsSignatureSummary
voidbegin() hook protectedJOID calls it before the glyphs of a pass are drawn: it binds the shader, resets the color and reads the pixel grid.
voidend() hook protectedJOID calls it after the glyphs of a pass, even when a glyph throws: it unbinds the shader.
voiddrawGlyph(TextGlyph glyph) hook abstract protectedJOID calls it for each glyph of a pass, between begin() and end().
booleanisGridAligned() hook protectedIf true, the origin, the baseline and the offsets of the glyphs snap to whole screen pixels, for pixel fonts; false by default.
voidbindColor(Color color) protectedSends color to the shader, a gradient spread over the run included; an unchanged color instance sends nothing.
voidbindPixel(float pixelX, float pixelY) protectedSends the size of one screen pixel to the pixel uniform of the shader; an unchanged value sends nothing.
IShadergetShader() protectedReturns the shader of the renderer, null before the first draw.
PixelGridgetGrid() protectedReturns the pixel grid of the render bridge, read in begin().

GlyphTextRenderer(CoreShader source) protected

Creates the renderer with the core shader that draws its glyphs.

double getWidth(String text, TextInfo info)

Returns the width of the laid-out string.

double getHeight(String text, TextInfo info)

Returns the line height: a glyph font draws one line.

FontBounds drawText(double x, double y, String text, TextInfo info)

Draws the string with its top-left corner at x, y. Throws IllegalArgumentException when the font of info is not drawn by this renderer.

FontBounds drawText(double x, double y, String text, TextInfo info, double runX, double runY, double runWidth, double runHeight)

Draws the string as a part of the run runX, runY, runWidth, runHeight, over which a gradient color spreads.

double getLineHeight(TextInfo info)

Returns TextInfo.lineHeight times the font size when it is set, otherwise the line height of the face times the font size.

double getBaseline(TextInfo info)

Returns the distance from the top of the line to the baseline: the face’s own baseline, centered in a line height that differs from the face’s.

GlyphLayout<F> layout(String text, TextInfo info)

Returns the GlyphLayout of the string: markup tags read, faces resolved by weight and style, kerning and letter spacing applied.

void begin() hook protected

JOID calls it before the glyphs of a pass are drawn: it binds the shader, resets the color and reads the pixel grid. An override binds its texture or uniforms and calls super.begin() first.

void end() hook protected

JOID calls it after the glyphs of a pass, even when a glyph throws: it unbinds the shader. An override calls super.end().

void drawGlyph(TextGlyph<F> glyph) hook abstract protected

JOID calls it for each glyph of a pass, between begin() and end(). Draw the glyph at its x plus offset, on its baseline, at its size, in its color through bindColor, and slant it when TextGlyph.isSlanted is true.

boolean isGridAligned() hook protected

If true, the origin, the baseline and the offsets of the glyphs snap to whole screen pixels, for pixel fonts; false by default.

void bindColor(Color color) protected

Sends color to the shader, a gradient spread over the run included; an unchanged color instance sends nothing.

void bindPixel(float pixelX, float pixelY) protected

Sends the size of one screen pixel to the pixel uniform of the shader; an unchanged value sends nothing.

IShader getShader() protected

Returns the shader of the renderer, null before the first draw.

PixelGrid getGrid() protected

Returns the pixel grid of the render bridge, read in begin().


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