class Eagle::TrueTypeFont

Overview

A Font backed by a TrueType file at one pixel size. Glyphs are rasterized on first use. Create one with Font.load, which also caches it.

font = Font.load("res://fonts/Inter.ttf", 24)
g.print("Hello", 10, 10, font: font)

Defined in:

eagle/graphics/truetype.cr

Constructors

Instance Method Summary

Instance methods inherited from class Eagle::Font

glyph(char : Char) : Glyph | Nil glyph, height : Float32 height, kerning(a : Char, b : Char) : Float32 kerning, letter_spacing : Float32 letter_spacing, letter_spacing=(letter_spacing : Float32) letter_spacing=, line_height : Float32 line_height, measure(text : String) : Vec2 measure, scale : Float32 scale, scale=(scale : Float32) scale=, texture : Texture texture, width(text : String) : Float32 width, wrap(text : String, max_width : Number) : Array(String) wrap

Constructor methods inherited from class Eagle::Font

default : Font default, load(path : String, size : Number, filter : GPU::Filter = GPU::Filter::Linear) : Font load

Constructor Detail

def self.load(path : String, size : Number, filter : GPU::Filter = GPU::Filter::Linear) : TrueTypeFont #

Loads a font file at size pixels, without caching. Prefer Font.load.


def self.new(data : Bytes, size : Number, filter : GPU::Filter = GPU::Filter::Linear) #

Creates a font from raw TrueType bytes at size pixels.


Instance Method Detail

def ascent : Float32 #

Height above the baseline, in pixels.


def descent : Float32 #

Depth below the baseline, in pixels.


def family_name : String #

The font's family name.


def glyph(char : Char) : Glyph | Nil #

The glyph for char, rasterizing it on first use. Returns nil if the font lacks it.


def kerning(a : Char, b : Char) : Float32 #

Kerning between two characters, in pixels.


def line_height : Float32 #

Distance between baselines, in pixels.


def preload(chars : Enumerable(Char) = (32..126).map(&.chr)) : self #

Rasterizes glyphs up front so the first frame that uses them doesn't hitch. Covers printable ASCII by default.


def size : Float32 #

Pixel size the font was loaded at.


def texture : Texture #

The first atlas texture.


def ttf : TrueType #

The parsed font file.