Skip to content
Eduard Gushchin edited this page Jun 24, 2026 · 5 revisions

Home | API by Category | Complete API Index | API Compatibility

Field Value
Full name Electron2D.Font
Namespace Electron2D
Kind class
Category UI and Text

Overview

Provides the Electron2D base resource for text layout and drawing.

Syntax

public abstract class Electron2D.Font : Electron2D.Resource

Godot 4.7 C# profile compatibility

Profile: Electron2D 0.1.0 2D
Status: Supported / Parity verified
Out of profile: no
Godot reference: Font

Base font resource with string measurement, glyph availability, fallback layout and internal cache.

Remarks

Font supplies the text metrics used by Electron2D.CanvasItem.DrawString(Electron2D.Font,Electron2D.Vector2,System.String,Electron2D.HorizontalAlignment,System.Single,System.Int32,System.Nullable{Electron2D.Color}) and Electron2D.Label. Electron2D 0.1.0 Preview implements a minimal layout cache, Unicode scalar enumeration through System.Text.Rune and fallback font resolution. Concrete font loading remains a later resource import task.

The public surface follows Electron2D's text resource contract. Native text objects stay internal to the renderer backend.

Thread Safety

This type is not synchronized. Create, mutate and query font resources on the main thread that owns the scene tree.

Since

This type is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem.DrawString(Electron2D.Font,Electron2D.Vector2,System.String,Electron2D.HorizontalAlignment,System.Single,System.Int32,System.Nullable{Electron2D.Color})

Members

Member Kind Summary
Electron2D.Font() Constructor Initializes a new instance of the Font type.
GetAscent(System.Int32) Method Returns the ascent above the text baseline for a font size.
GetDescent(System.Int32) Method Returns the descent below the text baseline for a font size.
GetHeight(System.Int32) Method Returns the line height for a font size.
GetStringSize(System.String, Electron2D.HorizontalAlignment, System.Single, System.Int32) Method Returns the size required to draw a single-line string.
HasChar(System.Int32) Method Checks whether this font contains a glyph for a Unicode codepoint.

Member Details

Electron2D.Font()

Kind: Constructor

public Electron2D.Font()

Summary

Initializes a new instance of the Font type.

Remarks

The new instance follows the lifetime and validation rules of its declaring type.

Thread Safety

This member is not synchronized. Call it from the thread that owns the related object unless the declaring type states otherwise.

Since

This API is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Font

GetAscent(System.Int32)

Kind: Method

public System.Single GetAscent(System.Int32)(System.Int32 fontSize)

Summary

Returns the ascent above the text baseline for a font size.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • fontSize: The requested font size in pixels.

Returns

The ascent in pixels.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when fontSize is less than or equal to zero.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Font

GetDescent(System.Int32)

Kind: Method

public System.Single GetDescent(System.Int32)(System.Int32 fontSize)

Summary

Returns the descent below the text baseline for a font size.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • fontSize: The requested font size in pixels.

Returns

The descent in pixels.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when fontSize is less than or equal to zero.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Font

GetHeight(System.Int32)

Kind: Method

public System.Single GetHeight(System.Int32)(System.Int32 fontSize)

Summary

Returns the line height for a font size.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • fontSize: The requested font size in pixels.

Returns

The line height in pixels.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when fontSize is less than or equal to zero.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Font

GetStringSize(System.String, Electron2D.HorizontalAlignment, System.Single, System.Int32)

Kind: Method

public Electron2D.Vector2 GetStringSize(System.String, Electron2D.HorizontalAlignment, System.Single, System.Int32)(System.String text, Electron2D.HorizontalAlignment alignment, System.Single width, System.Int32 fontSize)

Summary

Returns the size required to draw a single-line string.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • text: The Unicode text to measure.
  • alignment: The horizontal alignment used when width is non-negative.
  • width: The optional alignment width. Negative values measure without a width constraint.
  • fontSize: The requested font size in pixels.

Returns

The measured string size in pixels.

Exceptions

  • System.ArgumentNullException: Thrown when text is null.
  • System.ArgumentOutOfRangeException: Thrown when fontSize is less than or equal to zero.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Font

HasChar(System.Int32)

Kind: Method

public System.Boolean HasChar(System.Int32)(System.Int32 charCode)

Summary

Checks whether this font contains a glyph for a Unicode codepoint.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • charCode: The Unicode scalar value to query.

Returns

true when the font contains the glyph; otherwise, false.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Font

Clone this wiki locally