Measures single-line remote text layout bounds, font metrics, tight paint bounds, and tabular width.

Each measurement method inspects a different aspect of text geometry:

All measurements operate on a single unbroken run without paragraph line breaking; newline characters ('\n') are not split into multiple lines or replaced.

Summary

Public constructors

android

Public functions

RemoteFontMetrics

Measures the font ascent and descent for style and returns RemoteFontMetrics.

android
RemoteFloat
measureMonospaceWidth(
    text: RemoteString,
    style: RemoteTextStyle,
    density: RemoteDensity
)

Measures the tabular width of text in pixels using fixed-width '0' character slots.

android
RemotePaintBounds
measurePaintBounds(
    text: RemoteString,
    style: RemoteTextStyle,
    density: RemoteDensity
)

Measures the tight paint bounds of text and returns RemotePaintBounds.

android
RemoteSingleLineTextBounds
measureSingleLine(
    text: RemoteString,
    style: RemoteTextStyle,
    density: RemoteDensity
)

Measures text as a single unconstrained line and returns RemoteSingleLineTextBounds.

android

Public constructors

RemoteTextMeasurer

RemoteTextMeasurer(
    density: RemoteDensity,
    style: RemoteTextStyle = RemoteTextStyle.Default
)
Parameters
density: RemoteDensity

default RemoteDensity of the measurement environment, used to convert font sizes to pixels when not overridden in a measurement call

style: RemoteTextStyle = RemoteTextStyle.Default

default RemoteTextStyle applied when not overridden in a measurement call

Public functions

measureFontMetrics

fun measureFontMetrics(
    style: RemoteTextStyle = this.style,
    density: RemoteDensity = this.density
): RemoteFontMetrics

Measures the font ascent and descent for style and returns RemoteFontMetrics.

Parameters
style: RemoteTextStyle = this.style

RemoteTextStyle to inspect, defaulting to the measurer's default style

density: RemoteDensity = this.density

RemoteDensity used to convert font sizes to pixels, defaulting to the measurer's default density

measureMonospaceWidth

fun measureMonospaceWidth(
    text: RemoteString,
    style: RemoteTextStyle = this.style,
    density: RemoteDensity = this.density
): RemoteFloat

Measures the tabular width of text in pixels using fixed-width '0' character slots.

  • Approximates measuring tabular numerals (fontFeatureSettings = "tnum" on androidx.compose.ui.text.TextStyle.fontFeatureSettings).

  • text is measured as a single run without paragraph line breaking; newline characters ('\n') are not broken into multiple lines.

  • Font size is resolved in order from style.fontSize, the measurer's default style.fontSize, or 12.rsp.

Parameters
text: RemoteString

remote string whose tabular width to measure

style: RemoteTextStyle = this.style

RemoteTextStyle to apply, defaulting to the measurer's default style

density: RemoteDensity = this.density

RemoteDensity used to convert font sizes to pixels, defaulting to the measurer's default density

Returns
RemoteFloat

tabular width in pixels as a RemoteFloat

measurePaintBounds

fun measurePaintBounds(
    text: RemoteString,
    style: RemoteTextStyle = this.style,
    density: RemoteDensity = this.density
): RemotePaintBounds

Measures the tight paint bounds of text and returns RemotePaintBounds.

  • Corresponds to android.graphics.Paint.getTextBounds with (0, 0) at the start of text on its alphabetic baseline.

  • Unlike measureSingleLine and measureFontMetrics, which span the full advance width (including spaces) and font-wide ascent/descent box, RemotePaintBounds tightly wraps only the inked pixels of text: for example, "ac" has a smaller height and higher bottom than "Ág", and " Hello " has a positive RemotePaintBounds.left starting at the first inked pixel of 'H' and excludes trailing spaces from RemotePaintBounds.right.

  • text is measured as a single run without paragraph line breaking; newline characters ('\n') are not broken into multiple lines.

  • Font size is resolved in order from style.fontSize, the measurer's default style.fontSize, or 12.rsp.

Parameters
text: RemoteString

remote string whose paint bounds to measure

style: RemoteTextStyle = this.style

RemoteTextStyle to apply, defaulting to the measurer's default style

density: RemoteDensity = this.density

RemoteDensity used to convert font sizes to pixels, defaulting to the measurer's default density

Returns
RemotePaintBounds

RemotePaintBounds containing baseline-relative tight paint bounds

measureSingleLine

fun measureSingleLine(
    text: RemoteString,
    style: RemoteTextStyle = this.style,
    density: RemoteDensity = this.density
): RemoteSingleLineTextBounds

Measures text as a single unconstrained line and returns RemoteSingleLineTextBounds.

Mirrors androidx.compose.ui.text.TextMeasurer.measure for single-line text (softWrap = false, maxLines = 1) with includeFontPadding disabled:

Parameters
text: RemoteString

remote string to measure as a single line

style: RemoteTextStyle = this.style

RemoteTextStyle to apply, defaulting to the measurer's default style

density: RemoteDensity = this.density

RemoteDensity used to convert font sizes to pixels, defaulting to the measurer's default density

Returns
RemoteSingleLineTextBounds

RemoteSingleLineTextBounds containing single-line layout RemoteSize and baseline