public class LineHeightStyle(
public val alignment: Alignment,
public val trim: Trim,
public val mode: Mode,
)
Configures line height behavior, including alignment and trimming of extra space.
Applies only when a line height is defined on the text.
Parameters
| alignment | alignment of the line within the allocated line height. |
| trim | trimming behavior for the top of the first line and bottom of the last line. Requires PlatformParagraphStyle.includeFontPadding to be false. |
| mode | behavior when the specified line height is smaller than the system default (see Mode). |
Functions
copy
public fun copy(
alignment: Alignment = this.alignment,
trim: Trim = this.trim,
mode: Mode = this.mode,
): LineHeightStyle
Returns a copy of this LineHeightStyle, optionally overriding some of the values.
Members
Companion
public companion object
Properties
Default
public val Default: LineHeightStyle =
LineHeightStyle(alignment = Alignment.Proportional, trim = Trim.Both, mode = Mode.Fixed)
The default configuration for LineHeightStyle:
- alignment =
Alignment.Proportional - trim =
Trim.Both - mode =
Mode.Fixed
Trim
public class Trim internal constructor(internal val value: Int)
Controls trimming of extra space from the first line top and last line bottom.
Requires PlatformParagraphStyle.includeFontPadding to be false to take effect.
Trimming behavior depends on the selected Mode:
Mode.Fixed/Mode.Minimum: Trims extra space only when the configured line height isMode.Tight: Trims space even when the configured line height is shorter than the font
taller than the font default (prevents clipping).
default.
Warning: Use Mode.Tight with caution to avoid cutting off tall characters or accents. Test your text layout with tall scripts (e.g., Arabic "العَرَبِيَّةُ", Tibetan "དབུ་ཅན་", or Burmese "မြန်မာဘာသာ") before using in production.
Functions
isTrimFirstLineTop
public fun isTrimFirstLineTop(): Boolean
Returns true if this Trim configuration trims the space at the top of the first line.
isTrimLastLineBottom
public fun isTrimLastLineBottom(): Boolean
Returns true if this Trim configuration trims the space at the bottom of the last line.
Members
Companion
public companion object
Properties
FirstLineTop
public val FirstLineTop: Trim
Trim the space that would be added to the top of the first line as a result of the line height. Single line text is both the first and last line. This feature is available only when PlatformParagraphStyle.includeFontPadding is false.
For example, when line height is 3.em, and Alignment is Alignment.Center, the first line has 2.em height and the height from first line baseline to second line baseline is still 3.em:
+--------+ | Line1 | | | |--------| | | | Line2 | | | +--------+
LastLineBottom
public val LastLineBottom: Trim
Trim the space that would be added to the bottom of the last line as a result of the line height. Single line text is both the first and last line. This feature is available only when PlatformParagraphStyle.includeFontPadding is false.
For example, when line height is 3.em, and Alignment is Alignment.Center, the last line has 2.em height and the height from first line baseline to second line baseline is still 3.em:
+--------+ | | | Line1 | | | |--------| | | | Line2 | +--------+
Both
public val Both: Trim
Trim the space that would be added to the top of the first line and bottom of the last line as a result of the line height. This feature is available only when PlatformParagraphStyle.includeFontPadding is false.
For example, when line height is 3.em, and Alignment is Alignment.Center, the first and last line has 2.em height and the height from first line baseline to second line baseline is still 3.em:
+--------+ | Line1 | | | |--------| | | | Line2 | +--------+
None
public val None: Trim
Do not trim first line top or last line bottom.
For example, when line height is 3.em, and Alignment is Alignment.Center, the first line height, last line height and the height from first line baseline to second line baseline are 3.em:
+--------+ | | | Line1 | | | |--------| | | | Line2 | | | +--------+
Alignment
public class Alignment(public val topRatio: Float)
Aligns the line within the space provided by the line height.
Members
Companion
public companion object
Properties
Top
public val Top: Alignment
Align the line to the top of the space reserved for that line. This means that all extra space as a result of line height is applied to the bottom of the line. When the provided line height value is smaller than the actual line height, the line will still be aligned to the top, therefore the required difference will be subtracted from the bottom of the line.
For example, when line height is 3.em, the lines are aligned to the top of 3.em height:
+--------+ | Line1 | | | | | |--------| | Line2 | | | | | +--------+
Center
public val Center: Alignment
Align the line to the center of the space reserved for the line. This configuration distributes additional space evenly between top and bottom of the line.
For example, when line height is 3.em, the lines are aligned to the center of 3.em height:
+--------+ | | | Line1 | | | |--------| | | | Line2 | | | +--------+
Proportional
public val Proportional: Alignment
Align the line proportional to the ascent and descent values of the line. For example if ascent is 8 units of length, and descent is 2 units; an additional space of 10 units will be distributed as 8 units to top, and 2 units to the bottom of the line. This is the default behavior.
Bottom
public val Bottom: Alignment
Align the line to the bottom of the space reserved for that line. This means that all extra space as a result of line height is applied to the top of the line. When the provided line height value is smaller than the actual line height, the line will still be aligned to the bottom, therefore the required difference will be subtracted from the top of the line.
For example, when line height is 3.em, the lines are aligned to the bottom of 3.em height:
+--------+ | | | | | Line1 | |--------| | | | | | Line2 | +--------+
Mode
public class Mode internal constructor(internal val value: Int)
Controls whether to enforce the specified line height.
Font metrics determine the default line height. When the specified line height is too tight for the font, use Mode.Minimum to fall back to system-provided heights. This prevents clipping in languages with tall glyphs (e.g., Arabic, Burmese).
Members
Companion
public companion object
Properties
Fixed
public val Fixed: Mode
Always use the specified line height on every line but add the necessary paddings on text layout's top and bottom when the system preferred line height is larger. This guarantees that taller glyphs won't be trimmed at the boundaries. On the other hand, middle lines respect the specified line height at all times and tall glyphs can overflow to upper or lower lines.
Minimum
public val Minimum: Mode
By specifying Mode.Minimum, when the specified line height is smaller than the system preferred value, the system preferred one is used instead on all lines. Top and bottom paddings are also added. This prevents the overflow of tall glyphs in middle lines.
Tight
public val Tight: Mode
Be able to use the specified line height at all lines, including the first and last. This configuration basically gets rid of the safety rails that are added by Mode.Fixed. Tall glyphs might get trimmed at top, bottom, or both when used in conjunction with the corresponding Trim value.