Skip to content

CellMetrics

Namespace: Hex1b.Surfaces

Assembly: Hex1b.dll

Represents the pixel dimensions of a terminal cell.

csharp
public readonly record struct CellMetrics : IEquatable<CellMetrics>

Implements

Constructors

CellMetrics(double, int)

Creates cell metrics with actual (floating-point) width.

Parameters:

csharp
public CellMetrics(double actualPixelWidth, int pixelHeight)

CellMetrics(int, int)

Creates cell metrics with integer dimensions.

Parameters:

csharp
public CellMetrics(int pixelWidth, int pixelHeight)

Properties

ActualPixelWidth

The actual (possibly fractional) width of a cell in pixels. Used for precise sixel sizing in browser-based terminals.

Returns: Double

csharp
public double ActualPixelWidth { get; }

PixelHeight

The integer height of a cell in pixels.

Returns: Int32

csharp
public int PixelHeight { get; }

PixelWidth

The integer width of a cell in pixels (for backward compatibility).

Returns: Int32

csharp
public int PixelWidth { get; }

Methods

CellToPixel(int, int, int, int)

Converts a cell rectangle to pixel coordinates.

Parameters:

Returns: PixelRect

csharp
public PixelRect CellToPixel(int cellX, int cellY, int cellWidth, int cellHeight)

CellToPixel(Rect)

Converts a cell rectangle to pixel coordinates.

Parameters:

Returns: PixelRect

csharp
public PixelRect CellToPixel(Rect cellRect)

GetCellOffsetForPixel(int)

Calculates the cell offset for a given pixel position using actual dimensions.

Parameters:

Returns: Int32

csharp
public int GetCellOffsetForPixel(int pixelX)

GetPixelForCellBoundary(int)

Calculates the pixel position for a cell boundary using actual dimensions.

Parameters:

Returns: Int32

csharp
public int GetPixelForCellBoundary(int cellX)

GetPixelWidthForCells(int)

Calculates the pixel width for a given number of cells using actual dimensions.

Parameters:

Returns: Int32

csharp
public int GetPixelWidthForCells(int cellCount)

PixelToCell(PixelRect)

Converts a pixel rectangle to cell coordinates.

Parameters:

Returns: Rect

csharp
public Rect PixelToCell(PixelRect pixelRect)

PixelToCellSpan(int, int)

Computes the cell span for a pixel dimension (rounds up).

Parameters:

Returns: ValueTuple<Int32, Int32>

csharp
public (int CellWidth, int CellHeight) PixelToCellSpan(int pixelWidth, int pixelHeight)

Fields

Default

Default cell metrics (10×20 pixels).

Returns: CellMetrics

csharp
public static readonly CellMetrics Default

XtermJs

Cell metrics for xterm.js with 14px font (approximately 9×17 pixels).

Returns: CellMetrics

csharp
public static readonly CellMetrics XtermJs

Remarks

Terminal cells have a fixed pixel size determined by the font and terminal emulator. This information is needed for sixel graphics, which are defined in pixels but must be mapped to cell boundaries for proper rendering and clipping.

Note: Cell width may be fractional in browser-based terminals like xterm.js due to font rendering. The property stores the precise value while provides the integer approximation for compatibility.

Released under the MIT License.