Import std.image.font
Font
class
Public Class Font
A TrueType or OpenType font, whose glyphs a Canvas draws text with.
Examples
Local font = Try Font.Load(Path("fonts/Inter.ttf"))
Local image = Image(400, 60)
Local canvas = Canvas(image)
canvas.FillText("Hello", font, 32, Vec2(10, 40), Color32.White)
Print("{font.Width("Hello", 32)} pixels wide")// Bytes that aren't a font are an IOError, never a read past them.
Local error = ExpectThrows<IOError>(Font.Parse([1, 2, 3, 4] As UInt8[]))
Expect(error?.Kind == IOErrorKind.INVALID_DATA)-
The font in
data, a font file or a collection's first font. Throws an IOError of INVALID_DATA when it isn't one, or is broken, and of OTHER when it's a kind std.image doesn't read, like one of CFF2's outlines. -
The font in the file at
path, which Parse reads from its bytes. Throws the IOError File.ReadBytes does for a file that can't be read, and Parse's, its Path the file's, for one it can't read a font of. -
Load's Async twin, which reads the file on libuv's thread pool while the thread that called it goes on, and parses it there once the Await resumes.
-
The units its glyphs are in, an em of them.
-
How far its glyphs go above the baseline, at
sizepixels an em. Panics when thesizeisn't finite or is negative, as each of its metrics does. -
How far its glyphs go below the baseline, at
sizepixels an em, above 0. -
The gap between one line's descent and the next one's ascent, at
sizepixels an em. -
How far apart its lines' baselines are, at
sizepixels an em: its ascent, descent, and line gap. -
How wide the
textis atsizepixels an em, its widest line's, as FillText lays it out: each glyph's advance and the kerning between them. Panics when thesizeisn't finite or is negative. -
Whether it has a glyph for the code point, rather than its .notdef, which draws in its place.
Report an issue with this page or with FutureBlitz on GitHub.