Class MsdfFont
java.lang.Object
lol.trq.helios.text.MsdfFont
- All Implemented Interfaces:
AutoCloseable
A multi-channel signed distance field font: glyph metrics, kerning and an RGB atlas, read from an
.hfnt
file that the fontgen module writes.
Metrics are in em units, y pointing down from the baseline. The atlas texture is uploaded on first use and lives
until close().
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionfloatascent()Distance from the baseline up to the top of the tallest glyphs, in em.intAtlas height in texels.Returns the atlas pixels: tightly packed RGB bytes, rows top to bottom.intAtlas width in texels.voidclose()Deletes the atlas texture, if uploaded.floatdescent()Distance from the baseline down to the bottom of descenders, in em.floatemSize()Texels per em in the atlas.glyph(int codepoint) Returns a glyph, or the replacement glyph when the font lacks it.glyphOrNull(int codepoint) Returns a glyph without falling back.floatkerning(int left, int right) Returns the kerning between two characters.floatDistance from one baseline to the next, in em.name()Returns the font name.floatpxRange()The distance range of the atlas in texels.static MsdfFontread(InputStream in) Reads a font.static MsdfFontresource(ClassLoader loader, String resource) Reads a font from the class path.intReturns the atlas texture, uploading it on first use.
-
Method Details
-
read
Reads a font.- Parameters:
in- the.hfntbytes; not closed- Returns:
- the font
- Throws:
IOException- if the data is not a valid font
-
resource
Reads a font from the class path.- Parameters:
loader- the class loaderresource- the resource name- Returns:
- the font
- Throws:
UncheckedIOException- if it is missing or invalid
-
name
-
ascent
public float ascent()Distance from the baseline up to the top of the tallest glyphs, in em.- Returns:
- the ascent
-
descent
public float descent()Distance from the baseline down to the bottom of descenders, in em.- Returns:
- the descent
-
lineHeight
public float lineHeight()Distance from one baseline to the next, in em.- Returns:
- the line height
-
pxRange
public float pxRange()The distance range of the atlas in texels.- Returns:
- the range
-
emSize
public float emSize()Texels per em in the atlas.- Returns:
- the em size
-
atlasWidth
public int atlasWidth()Atlas width in texels.- Returns:
- the width
-
atlasHeight
public int atlasHeight()Atlas height in texels.- Returns:
- the height
-
glyph
Returns a glyph, or the replacement glyph when the font lacks it.- Parameters:
codepoint- the character- Returns:
- the glyph; never null when the font has a replacement or
?
-
glyphOrNull
Returns a glyph without falling back.- Parameters:
codepoint- the character- Returns:
- the glyph, or null
-
kerning
public float kerning(int left, int right) Returns the kerning between two characters.- Parameters:
left- the first characterright- the second character- Returns:
- the adjustment in em, usually negative
-
atlasPixels
Returns the atlas pixels: tightly packed RGB bytes, rows top to bottom.- Returns:
- a read-only view
-
texture
Returns the atlas texture, uploading it on first use.- Parameters:
gl- the backend of the current context- Returns:
- the texture id
-
close
public void close()Deletes the atlas texture, if uploaded. The font can upload it again.- Specified by:
closein interfaceAutoCloseable
-