abstract class
Eagle::Font
- Eagle::Font
- Reference
- Object
Overview
A font you can draw text with, through Graphics#print or a Label.
Eagle ships a crisp built-in pixel font, Font.default, so text works with no files.
For anything else, load a TrueType file at a pixel size. Glyphs are rasterized in
Crystal on first use and packed into an atlas texture.
title = Font.load("res://fonts/Inter.ttf", 48)
g.print("Eagle", 20, 20, font: title)
w = Font.default.width("Score: 100") # measure before drawing
lines = Font.default.wrap("A long sentence that needs wrapping.", 120)
Load each size you need separately. Scaling a TrueType font with scale: blurs it,
while the pixel font scales cleanly by whole numbers.
Direct Known Subclasses
Defined in:
eagle/graphics/font.creagle/graphics/truetype.cr
Constructors
-
.default : Font
The built-in pixel font.
-
.load(path : String, size : Number, filter : GPU::Filter = GPU::Filter::Linear) : Font
Loads a TrueType font at a pixel size.
Instance Method Summary
-
#glyph(char : Char) : Glyph | Nil
The glyph for char, or
nilif the font doesn't have it. -
#height : Float32
Line height after
#scale. -
#kerning(a : Char, b : Char) : Float32
Extra horizontal adjustment between the pair a, b, such as pulling "AV" together.
-
#letter_spacing : Float32
Extra space between characters, in pixels.
-
#letter_spacing=(letter_spacing : Float32)
Extra space between characters, in pixels.
-
#line_height : Float32
Distance between baselines, in pixels, before
#scale. -
#measure(text : String) : Vec2
Width and height of text, counting every line.
-
#scale : Float32
Scale applied whenever this font is drawn.
-
#scale=(scale : Float32)
Scale applied whenever this font is drawn.
-
#texture : Texture
The atlas texture holding the glyphs.
-
#width(text : String) : Float32
Width of text in pixels, including kerning and scale.
-
#wrap(text : String, max_width : Number) : Array(String)
Splits text into lines that each fit within max_width pixels, breaking at spaces.
Constructor Detail
The built-in pixel font. It needs no files, so it works everywhere, including the web.
Loads a TrueType font at a pixel size. Cached by path and size, so calling it every frame is cheap.
Instance Method Detail
The glyph for char, or nil if the font doesn't have it.
Extra horizontal adjustment between the pair a, b, such as pulling "AV" together.
Scale applied whenever this font is drawn. The pixel font defaults to 2 so it stays readable.
Scale applied whenever this font is drawn. The pixel font defaults to 2 so it stays readable.
Width of text in pixels, including kerning and scale. Uses the longest line for multi-line text.