class
Eagle::TrueType
- Eagle::TrueType
- Reference
- Object
Overview
A TrueType font file, parsed in pure Crystal: glyph lookup, metrics, kerning and outlines.
Most games use Font.load, which wraps this in a TrueTypeFont. Use TrueType
directly for tools, such as inspecting a font or rasterizing glyphs into your own atlas.
ttf = TrueType.load("res://fonts/Inter.ttf")
g_index = ttf.glyph_index('A')
bitmap = ttf.rasterize(g_index, 32.0_f32 / ttf.units_per_em)
image = bitmap.to_image
Supports glyf outlines, cmap formats 4, 6 and 12, composite glyphs and kern table
format 0. OpenType CFF fonts (.otf) aren't supported.
Defined in:
eagle/graphics/truetype.crConstructors
-
.load(path : String) : TrueType
Reads and parses a font file.
-
.new(data : Bytes)
Parses a font from raw bytes.
Instance Method Summary
-
#advance(glyph : Int32) : Int32
Horizontal advance of a glyph, in font units.
-
#ascent : Int32
Height above the baseline, in font units.
-
#descent : Int32
Depth below the baseline, in font units (negative).
-
#family_name : String
The family name from the font's name table, such as "Inter".
-
#glyph_count : Int32
Number of glyphs in the font.
-
#glyph_index(char : Char) : Int32
--- public metrics --- The glyph index for char, or 0 (the missing-glyph box) if the font lacks it.
-
#has_glyph?(char : Char) : Bool
True when the font has a glyph for char.
-
#kern_pairs : Int32
Number of kerning pairs in the font.
-
#kerning(left : Int32, right : Int32) : Int32
Kerning between two glyph indices, in font units.
-
#left_side_bearing(glyph : Int32) : Int32
Left side bearing of a glyph, in font units.
-
#line_gap : Int32
Extra gap between lines, in font units.
-
#outline(glyph : Int32) : GlyphOutline
--- outlines --- The contours of a glyph.
-
#rasterize(glyph : Int32, scale : Float32, pad : Int32 = 1) : Bitmap
Rasterizes a glyph with anti-aliasing.
-
#units_per_em : Int32
Font units per em.
Constructor Detail
Parses a font from raw bytes. Raises AssetError if it isn't a supported TrueType file.
Instance Method Detail
--- public metrics --- The glyph index for char, or 0 (the missing-glyph box) if the font lacks it.
Kerning between two glyph indices, in font units.
Rasterizes a glyph with anti-aliasing. scale is pixels per font unit.
Font units per em. Multiply by pixel_size / units_per_em to convert to pixels.