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.
Properties
trimsFirstLineTop
public val trimsFirstLineTop: Boolean
Returns true if this Trim configuration trims the space at the top of the first line.
trimsLastLineBottom
public val trimsLastLineBottom: 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)
Determines how line height is calculated across lines in a paragraph.
Fixed, Minimum, and Tight measure font metrics on the first line only and apply that single calculated height to every line in the paragraph. If subsequent lines are taller than the first line (such as lines with larger font sizes or taller scripts), they will still use the first line's height and may clip.
Text with mixed font sizes or mixed scripts should use PerLine, which measures each line independently.
Members
Companion
public companion object
Properties
Fixed
public val Fixed: Mode
Sets the same line height for each line, calculated from the font metrics of the first line only.
If the requested line height is smaller than the first line's font metrics, adds padding outside the first line top and last line bottom to prevent clipping at the paragraph boundaries. Middle lines are not padded and will clip if they overflow.
If later lines are taller than the first line, they do not expand and may clip.
This is the default mode in LineHeightStyle.Default.
Minimum
public val Minimum: Mode
Sets the same line height for each line, calculated from the font metrics of the first line only.
If the requested line height is smaller than the first line's font metrics, uses the first line's natural height for all lines instead of shrinking them. If the requested line height is larger, behaves the same as Fixed.
If later lines are taller than the first line, they do not expand and may clip.
Tight
public val Tight: Mode
Sets the requested line height on every line based on the first line only, without adding top or bottom padding.
If the requested line height is smaller than the font metrics of any line, that line will clip.
PerLine
public val PerLine: Mode
Calculates line height independently for each line.
Unlike Fixed, Minimum, and Tight (which only measure the first line), PerLine measures every line. If a line's natural font height exceeds the requested line height, that line expands to its natural height.
Use PerLine when text contains mixed font sizes or mixed scripts so that tall lines do not clip and short lines do not leave extra gaps:
Mode.Fixed / Mode.Minimum (Only measures Line 1; Line 2 may clip):
+----------------------------------------------+
| Line 1 (Small font, measures line height) |
+----------------------------------------------+
| Line 2 (TALL SCRIPT - clips or overlaps!) |
+----------------------------------------------+
| Line 3 (Small font) |
+----------------------------------------------+
Mode.PerLine (Measures each line independently):
+----------------------------------------------+
| Line 1 (Small font, compact line height) |
+----------------------------------------------+
| Line 2 (TALL SCRIPT - expands to fit) |
+----------------------------------------------+
| Line 3 (Small font, compact line height) |
+----------------------------------------------+