X11 core font loading, querying, metrics, measurement, and caching for Linux.
Uses Xlib's built-in font functions (XLoadQueryFont, XLoadFont,
XSetFont, XTextWidth, XFreeFont, etc.) to provide an Oak-friendly
font API on Linux.
sys,writes,linux-core,linux-loader
Loads and queries an X11 core font by name (XLFD or alias).
Returns { type: :ok, fontStruct: <ptr> }.
Loads an X11 font and returns its Font XID.
Returns { type: :ok, fontId }.
Sets the font for a graphics context.
Releases an XFontStruct.
Unloads a font loaded via loadFont.
Pixel width via XTextWidth. Returns { type: :ok, width }.
Loads a font and returns its metrics:
{ type: :ok, fontStruct, fontId, ascent, descent, height }
Loads a font, measures the text, and returns:
{ type: :ok, fontStruct, width, height, ascent, descent }
The font remains loaded — call freeFont when done.
Returns a cached XFontStruct, loading on first access.
Frees all cached fonts for a given display.
Frees every cached font entry globally.
| Constant | Value |
|---|---|
FONT_FIXED |
'fixed' |
FONT_CURSOR |
'cursor' |
FONT_6X13 |
'6x13' |
FONT_9X15 |
'9x15' |
FONT_10X20 |
'10x20' |
FONT_COURIER_14 |
'-*-courier-medium-r-normal--14-*-...-iso8859-1' |
FONT_HELV_12 |
'-*-helvetica-medium-r-normal--12-*-...-iso8859-1' |
FONT_TIMES_14 |
'-*-times-medium-r-normal--14-*-...-iso8859-1' |
Constructs an X Logical Font Description from a spec:
xlfd := lf.buildXLFD({
family: 'courier'
weight: 'bold'
slant: 'r'
pixelSize: 14
registry: 'iso8859'
encoding: '1'
})
// -> '-*-courier-bold-r-*-*-14-*-*-*-*-*-iso8859-1'
lf := import('linux-fonts')
// Load a font and measure text
metrics := lf.fontMetrics(display, '9x15')
if metrics.type = :ok -> {
w := lf.textWidth(metrics.fontStruct, 'Hello, world!')
// w.width is the pixel width
lf.freeFont(display, metrics.fontStruct)
}
// Using the cache
cached := lf.cachedFont(display, 'fixed')
if cached.type = :ok -> {
lf.setFont(display, gc, lf.fontStructFid(cached.fontStruct))
}
lf.releaseCachedFonts(display)