Font Class
Package: GHIElectronics.Endpoint.Drawing
Namespace: GHIElectronics.Endpoint.Drawing
A TrueType / OpenType font loaded from raw file bytes. Pass to Canvas.DrawText to render strings at any pixel size.
public sealed class Font : IDisposable
Example
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("MyApp.Resources.Montserrat.ttf");
var bytes = new byte[stream.Length];
stream.ReadExactly(bytes);
using var font = Font.Load(bytes);
canvas.DrawText("Hello Endpoint", font, x: 20, y: 60, sizePx: 32, Color.White);
Methods
Load(byte[] ttfBytes)
public static Font Load(byte[] ttfBytes)
Loads a TTF / OTF font from raw file bytes. The bytes are copied into the native font handle, so the caller's buffer can be released as soon as this returns.
Returns Font
GetMetrics(int sizePx)
public (int Ascent, int Descent, int LineGap) GetMetrics(int sizePx)
Font-wide vertical metrics at the given pixel height. Ascent is the distance from the baseline to the top of the tallest glyph; descent is negative (below the baseline). LineHeight = Ascent - Descent + LineGap.
Returns (int Ascent, int Descent, int LineGap)
Dispose()
public void Dispose()
Releases the native font handle.