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.
Description
Section titled “Description”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.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| GlyphTextRenderer(CoreShader source) protected | Creates the renderer with the core shader that draws its glyphs. |
Methods
Section titled “Methods”Position and size
Section titled “Position and size”| Returns | Signature | Summary |
|---|---|---|
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. |
Drawing
Section titled “Drawing”| Returns | Signature | Summary |
|---|---|---|
FontBounds | drawText(double x, double y, String text, TextInfo info) | Draws the string with its top-left corner at x, y. |
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. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
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. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
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. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
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. |
void | end() hook protected | JOID calls it after the glyphs of a pass, even when a glyph throws: it unbinds the shader. |
void | drawGlyph(TextGlyph | JOID calls it for each glyph of a pass, between begin() and end(). |
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(). |
Creation details
Section titled “Creation details”GlyphTextRenderer
Section titled “GlyphTextRenderer”GlyphTextRenderer(CoreShader source) protected
Creates the renderer with the core shader that draws its glyphs.
Method details
Section titled “Method details”getWidth
Section titled “getWidth”double getWidth(String text, TextInfo info)
Returns the width of the laid-out string.
getHeight
Section titled “getHeight”double getHeight(String text, TextInfo info)
Returns the line height: a glyph font draws one line.
drawText
Section titled “drawText”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.
getLineHeight
Section titled “getLineHeight”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.
getBaseline
Section titled “getBaseline”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.
layout
Section titled “layout”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().
drawGlyph
Section titled “drawGlyph”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.
isGridAligned
Section titled “isGridAligned”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.
bindColor
Section titled “bindColor”void bindColor(Color color) protected
Sends color to the shader, a gradient spread over the run included; an unchanged color instance sends nothing.
bindPixel
Section titled “bindPixel”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.
getShader
Section titled “getShader”IShader getShader() protected
Returns the shader of the renderer, null before the first draw.
getGrid
Section titled “getGrid”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
