🌈 Create new beautiful Compose Gradients with our new wesite ->
Class

TextStyle

Source set: Common
public class TextStyle internal constructor(
    internal val spanStyle: SpanStyle,
    internal val paragraphStyle: ParagraphStyle,
    public val platformStyle: PlatformTextStyle? = null,
)

Properties

brush

Source set: Common
public val brush: Brush?

The brush to use when drawing text. If not null, overrides color.

color

Source set: Common
public val color: Color

The text color.

alpha

Source set: Common
public val alpha: Float

Opacity of text. This value is either provided along side Brush, or via alpha channel in color.

fontSize

Source set: Common
public val fontSize: TextUnit

The size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle.

fontWeight

Source set: Common
public val fontWeight: FontWeight?

The typeface thickness to use when painting the text (e.g., bold).

fontStyle

Source set: Common
public val fontStyle: FontStyle?

The typeface variant to use when drawing the letters (e.g., italic).

fontSynthesis

Source set: Common
public val fontSynthesis: FontSynthesis?

Whether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family.

fontFamily

Source set: Common
public val fontFamily: FontFamily?

The font family to be used when rendering the text.

fontFeatureSettings

Source set: Common
public val fontFeatureSettings: String?

The advanced typography settings provided by font. The format is the same as the CSS font-feature-settings attribute: https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop

letterSpacing

Source set: Common
public val letterSpacing: TextUnit

The amount of space to add between each letter.

baselineShift

Source set: Common
public val baselineShift: BaselineShift?

The amount by which the text is shifted up from the current baseline.

textGeometricTransform

Source set: Common
public val textGeometricTransform: TextGeometricTransform?

The geometric transformation applied the text.

localeList

Source set: Common
public val localeList: LocaleList?

The locale list used to select region-specific glyphs.

background

Source set: Common
public val background: Color

The background color for the text.

textDecoration

Source set: Common
public val textDecoration: TextDecoration?

The decorations to paint on the text (e.g., an underline).

shadow

Source set: Common
public val shadow: Shadow?

The shadow effect applied on the text.

drawStyle

Source set: Common
public val drawStyle: DrawStyle?

Drawing style of text, whether fill in the text while drawing or stroke around the edges.

textAlign

Source set: Common
public val textAlign: TextAlign

The alignment of the text within the lines of the paragraph.

deprecatedboxingtextAlign

Source set: Common
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
    @get:JvmName("getTextAlign-buA522U") // b/320819734
    public val deprecated_boxing_textAlign: TextAlign?

textDirection

Source set: Common
public val textDirection: TextDirection

The algorithm to be used to resolve the final text and paragraph direction: Left To Right or Right To Left. If no value is provided the system will use the LayoutDirection as the primary signal.

deprecatedboxingtextDirection

Source set: Common
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
    @get:JvmName("getTextDirection-mmuk1to") // b/320819734
    public val deprecated_boxing_textDirection: TextDirection?

lineHeight

Source set: Common
public val lineHeight: TextUnit

Line height for the Paragraph in TextUnit unit, e.g. SP or EM.

textIndent

Source set: Common
public val textIndent: TextIndent?

The indentation of the paragraph.

lineHeightStyle

Source set: Common
public val lineHeightStyle: LineHeightStyle?

The configuration for line height such as vertical alignment of the line, whether to apply additional space as a result of line height to top of first line top and bottom of last line.

The configuration is applied only when a lineHeight is defined.

When null, LineHeightStyle.Default is used.

hyphens

Source set: Common
public val hyphens: Hyphens

The hyphens configuration of the paragraph.

deprecatedboxinghyphens

Source set: Common
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
    @get:JvmName("getHyphens-EaSxIns") // b/320819734
    public val deprecated_boxing_hyphens: Hyphens?

lineBreak

Source set: Common
public val lineBreak: LineBreak

The line breaking configuration of the paragraph.

deprecatedboxinglineBreak

Source set: Common
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
    @get:JvmName("getLineBreak-LgCVezo") // b/320819734
    public val deprecated_boxing_lineBreak: LineBreak?

textMotion

Source set: Common
public val textMotion: TextMotion?

Text character placement configuration, whether to optimize for animated or static text.

Functions

toSpanStyle

Source set: Common
@Stable public fun toSpanStyle(): SpanStyle

Styling configuration for text.

Parameters

brush Brush for painting text, null for unspecified
alpha opacity applied to brush (0.0 to 1.0)
fontSize glyph size. If TextUnit.Unspecified, inherits size from parent or default style.
fontWeight typeface thickness (e.g., bold)
fontStyle typeface variant (e.g., italic)
fontSynthesis font synthesis rules to fallback to bold/italic if the requested style is missing in fontFamily
fontFamily font family for rendering
fontFeatureSettings advanced font features in CSS format (e.g., "smcp" for small caps)
letterSpacing amount of space (in SP or EM) to add between letters. If TextUnit.Unspecified, inherits from parent.
baselineShift vertical shift amount from the baseline (e.g., for superscript or subscript)
textGeometricTransform geometric transformation to apply
localeList locale list for region-specific glyphs
background color of background rectangle covering entire line height from start to end
textDecoration decorations (e.g., underline)
shadow shadow effect
drawStyle drawing style (fill or stroke)
textAlign alignment of the text within the lines of the paragraph.
textDirection TextDirection direction resolution algorithm, defaults to LayoutDirection signal
lineHeight line height
textIndent paragraph indentation
platformStyle platform-specific parameters
lineHeightStyle line height distribution configuration
lineBreak line breaking rules
hyphens hyphenation configuration.
textMotion TextMotion character placement optimization

toParagraphStyle

Source set: Common
@Stable public fun toParagraphStyle(): ParagraphStyle

merge

Source set: Common
public fun merge(other: TextStyle? = null): TextStyle

Merges this style with other.

Properties of other take precedence when they are not unspecified (e.g. Color.Unspecified). Returns this if other is null or TextStyle.Default.

Parameters

other style to merge

merge

Source set: Common
public fun merge(
        color: Color = Color.Unspecified,
        fontSize: TextUnit = TextUnit.Unspecified,
        fontWeight: FontWeight? = null,
        fontStyle: FontStyle? = null,
        fontSynthesis: FontSynthesis? = null,
        fontFamily: FontFamily? = null,
        fontFeatureSettings: String? = null,
        letterSpacing: TextUnit = TextUnit.Unspecified,
        baselineShift: BaselineShift? = null,
        textGeometricTransform: TextGeometricTransform? = null,
        localeList: LocaleList? = null,
        background: Color = Color.Unspecified,
        textDecoration: TextDecoration? = null,
        shadow: Shadow? = null,
        drawStyle: DrawStyle? = null,
        textAlign: TextAlign = TextAlign.Unspecified,
        textDirection: TextDirection = TextDirection.Unspecified,
        lineHeight: TextUnit = TextUnit.Unspecified,
        textIndent: TextIndent? = null,
        lineHeightStyle: LineHeightStyle? = null,
        lineBreak: LineBreak = LineBreak.Unspecified,
        hyphens: Hyphens = Hyphens.Unspecified,
        platformStyle: PlatformTextStyle? = null,
        textMotion: TextMotion? = null,
    ): TextStyle

Merges this style with individual styling parameters.

Similar to merge but avoids allocation if parameters are default.

Always use this method over the merge (taking TextStyle) overload when you do not already have a TextStyle allocated. Prefer this over copy when building a theming system and applying styling information to a specific usage.

Example:

  • this.color = Color.Unspecified, param color = Color.Red -> result Color.Red
  • this.color = Color.Red, param color = Color.Unspecified -> result Color.Red
  • this.color = Color.Red, param color = Color.Blue -> result Color.Blue

merge

Source set: Common
@Deprecated(
        "merge that takes nullable TextAlign, " +
            "TextDirection, LineBreak, and Hyphens are deprecated. Please use a new constructor " +
            "where these parameters are non-nullable. Null value has been replaced by a special " +
            "Unspecified object for performance reason.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun merge(
        color: Color = Color.Unspecified,
        fontSize: TextUnit = TextUnit.Unspecified,
        fontWeight: FontWeight? = null,
        fontStyle: FontStyle? = null,
        fontSynthesis: FontSynthesis? = null,
        fontFamily: FontFamily? = null,
        fontFeatureSettings: String? = null,
        letterSpacing: TextUnit = TextUnit.Unspecified,
        baselineShift: BaselineShift? = null,
        textGeometricTransform: TextGeometricTransform? = null,
        localeList: LocaleList? = null,
        background: Color = Color.Unspecified,
        textDecoration: TextDecoration? = null,
        shadow: Shadow? = null,
        drawStyle: DrawStyle? = null,
        textAlign: TextAlign? = null,
        textDirection: TextDirection? = null,
        lineHeight: TextUnit = TextUnit.Unspecified,
        textIndent: TextIndent? = null,
        lineHeightStyle: LineHeightStyle? = null,
        lineBreak: LineBreak? = null,
        hyphens: Hyphens? = null,
        platformStyle: PlatformTextStyle? = null,
        textMotion: TextMotion? = null,
    ): TextStyle

merge

Source set: Common
public fun merge(other: SpanStyle): TextStyle

Returns a new text style that is a combination of this style and the given other style.

merge

Source set: Common
public fun merge(other: ParagraphStyle): TextStyle

Returns a new text style that is a combination of this style and the given other style.

plus

Source set: Common
@Stable public operator fun plus(other: TextStyle): TextStyle

Plus operator overload that applies a merge.

plus

Source set: Common
@Stable public operator fun plus(other: ParagraphStyle): TextStyle

Plus operator overload that applies a merge.

plus

Source set: Common
@Stable public operator fun plus(other: SpanStyle): TextStyle

Plus operator overload that applies a merge.

copy

Source set: Common
@Deprecated(
        "TextStyle copy constructors that do not take new stable parameters " +
            "like LineHeightStyle, LineBreak, Hyphens are deprecated. Please use the new stable " +
            "copy constructor.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.spanStyle.color,
        fontSize: TextUnit = this.spanStyle.fontSize,
        fontWeight: FontWeight? = this.spanStyle.fontWeight,
        fontStyle: FontStyle? = this.spanStyle.fontStyle,
        fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
        fontFamily: FontFamily? = this.spanStyle.fontFamily,
        fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
        letterSpacing: TextUnit = this.spanStyle.letterSpacing,
        baselineShift: BaselineShift? = this.spanStyle.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
        localeList: LocaleList? = this.spanStyle.localeList,
        background: Color = this.spanStyle.background,
        textDecoration: TextDecoration? = this.spanStyle.textDecoration,
        shadow: Shadow? = this.spanStyle.shadow,
        textAlign: TextAlign? = this.paragraphStyle.textAlign,
        textDirection: TextDirection? = this.paragraphStyle.textDirection,
        lineHeight: TextUnit = this.paragraphStyle.lineHeight,
        textIndent: TextIndent? = this.paragraphStyle.textIndent,
    ): TextStyle

copy

Source set: Common
@Deprecated(
        "TextStyle copy constructors that do not take new stable parameters " +
            "like LineHeightStyle, LineBreak, Hyphens are deprecated. Please use the new stable " +
            "copy constructor.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.spanStyle.color,
        fontSize: TextUnit = this.spanStyle.fontSize,
        fontWeight: FontWeight? = this.spanStyle.fontWeight,
        fontStyle: FontStyle? = this.spanStyle.fontStyle,
        fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
        fontFamily: FontFamily? = this.spanStyle.fontFamily,
        fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
        letterSpacing: TextUnit = this.spanStyle.letterSpacing,
        baselineShift: BaselineShift? = this.spanStyle.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
        localeList: LocaleList? = this.spanStyle.localeList,
        background: Color = this.spanStyle.background,
        textDecoration: TextDecoration? = this.spanStyle.textDecoration,
        shadow: Shadow? = this.spanStyle.shadow,
        textAlign: TextAlign? = this.paragraphStyle.textAlign,
        textDirection: TextDirection? = this.paragraphStyle.textDirection,
        lineHeight: TextUnit = this.paragraphStyle.lineHeight,
        textIndent: TextIndent? = this.paragraphStyle.textIndent,
        platformStyle: PlatformTextStyle? = this.platformStyle,
        lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
    ): TextStyle

copy

Source set: Common
@Deprecated(
        "TextStyle copy constructors that do not take new stable parameters " +
            "like LineBreak, Hyphens, and TextMotion are deprecated. Please use the new stable " +
            "copy constructor.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.spanStyle.color,
        fontSize: TextUnit = this.spanStyle.fontSize,
        fontWeight: FontWeight? = this.spanStyle.fontWeight,
        fontStyle: FontStyle? = this.spanStyle.fontStyle,
        fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
        fontFamily: FontFamily? = this.spanStyle.fontFamily,
        fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
        letterSpacing: TextUnit = this.spanStyle.letterSpacing,
        baselineShift: BaselineShift? = this.spanStyle.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
        localeList: LocaleList? = this.spanStyle.localeList,
        background: Color = this.spanStyle.background,
        textDecoration: TextDecoration? = this.spanStyle.textDecoration,
        shadow: Shadow? = this.spanStyle.shadow,
        textAlign: TextAlign? = this.paragraphStyle.textAlign,
        textDirection: TextDirection? = this.paragraphStyle.textDirection,
        lineHeight: TextUnit = this.paragraphStyle.lineHeight,
        textIndent: TextIndent? = this.paragraphStyle.textIndent,
        platformStyle: PlatformTextStyle? = this.platformStyle,
        lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
        lineBreak: LineBreak? = this.paragraphStyle.lineBreak,
        hyphens: Hyphens? = this.paragraphStyle.hyphens,
    ): TextStyle

copy

Source set: Common
@Deprecated(
        "copy constructors that take nullable TextAlign, " +
            "TextDirection, LineBreak, and Hyphens are deprecated. Please use a new constructor " +
            "where these parameters are non-nullable. Null value has been replaced by a special " +
            "Unspecified object for performance reason.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.spanStyle.color,
        fontSize: TextUnit = this.spanStyle.fontSize,
        fontWeight: FontWeight? = this.spanStyle.fontWeight,
        fontStyle: FontStyle? = this.spanStyle.fontStyle,
        fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
        fontFamily: FontFamily? = this.spanStyle.fontFamily,
        fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
        letterSpacing: TextUnit = this.spanStyle.letterSpacing,
        baselineShift: BaselineShift? = this.spanStyle.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
        localeList: LocaleList? = this.spanStyle.localeList,
        background: Color = this.spanStyle.background,
        textDecoration: TextDecoration? = this.spanStyle.textDecoration,
        shadow: Shadow? = this.spanStyle.shadow,
        drawStyle: DrawStyle? = this.spanStyle.drawStyle,
        textAlign: TextAlign? = this.paragraphStyle.textAlign,
        textDirection: TextDirection? = this.paragraphStyle.textDirection,
        lineHeight: TextUnit = this.paragraphStyle.lineHeight,
        textIndent: TextIndent? = this.paragraphStyle.textIndent,
        platformStyle: PlatformTextStyle? = this.platformStyle,
        lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
        lineBreak: LineBreak? = this.paragraphStyle.lineBreak,
        hyphens: Hyphens? = this.paragraphStyle.hyphens,
        textMotion: TextMotion? = this.paragraphStyle.textMotion,
    ): TextStyle

copy

Source set: Common
public fun copy(
        color: Color = this.spanStyle.color,
        fontSize: TextUnit = this.spanStyle.fontSize,
        fontWeight: FontWeight? = this.spanStyle.fontWeight,
        fontStyle: FontStyle? = this.spanStyle.fontStyle,
        fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
        fontFamily: FontFamily? = this.spanStyle.fontFamily,
        fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
        letterSpacing: TextUnit = this.spanStyle.letterSpacing,
        baselineShift: BaselineShift? = this.spanStyle.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
        localeList: LocaleList? = this.spanStyle.localeList,
        background: Color = this.spanStyle.background,
        textDecoration: TextDecoration? = this.spanStyle.textDecoration,
        shadow: Shadow? = this.spanStyle.shadow,
        drawStyle: DrawStyle? = this.spanStyle.drawStyle,
        textAlign: TextAlign = this.paragraphStyle.textAlign,
        textDirection: TextDirection = this.paragraphStyle.textDirection,
        lineHeight: TextUnit = this.paragraphStyle.lineHeight,
        textIndent: TextIndent? = this.paragraphStyle.textIndent,
        platformStyle: PlatformTextStyle? = this.platformStyle,
        lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
        lineBreak: LineBreak = this.paragraphStyle.lineBreak,
        hyphens: Hyphens = this.paragraphStyle.hyphens,
        textMotion: TextMotion? = this.paragraphStyle.textMotion,
    ): TextStyle

copy

Source set: Common
@Deprecated(
        "copy constructors that take nullable TextAlign, " +
            "TextDirection, LineBreak, and Hyphens are deprecated. Please use a new constructor " +
            "where these parameters are non-nullable. Null value has been replaced by a special " +
            "Unspecified object for performance reason.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        brush: Brush?,
        alpha: Float = this.spanStyle.alpha,
        fontSize: TextUnit = this.spanStyle.fontSize,
        fontWeight: FontWeight? = this.spanStyle.fontWeight,
        fontStyle: FontStyle? = this.spanStyle.fontStyle,
        fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
        fontFamily: FontFamily? = this.spanStyle.fontFamily,
        fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
        letterSpacing: TextUnit = this.spanStyle.letterSpacing,
        baselineShift: BaselineShift? = this.spanStyle.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
        localeList: LocaleList? = this.spanStyle.localeList,
        background: Color = this.spanStyle.background,
        textDecoration: TextDecoration? = this.spanStyle.textDecoration,
        shadow: Shadow? = this.spanStyle.shadow,
        drawStyle: DrawStyle? = this.spanStyle.drawStyle,
        textAlign: TextAlign? = this.paragraphStyle.textAlign,
        textDirection: TextDirection? = this.paragraphStyle.textDirection,
        lineHeight: TextUnit = this.paragraphStyle.lineHeight,
        textIndent: TextIndent? = this.paragraphStyle.textIndent,
        platformStyle: PlatformTextStyle? = this.platformStyle,
        lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
        lineBreak: LineBreak? = this.paragraphStyle.lineBreak,
        hyphens: Hyphens? = this.paragraphStyle.hyphens,
        textMotion: TextMotion? = this.paragraphStyle.textMotion,
    ): TextStyle

copy

Source set: Common
public fun copy(
        brush: Brush?,
        alpha: Float = this.spanStyle.alpha,
        fontSize: TextUnit = this.spanStyle.fontSize,
        fontWeight: FontWeight? = this.spanStyle.fontWeight,
        fontStyle: FontStyle? = this.spanStyle.fontStyle,
        fontSynthesis: FontSynthesis? = this.spanStyle.fontSynthesis,
        fontFamily: FontFamily? = this.spanStyle.fontFamily,
        fontFeatureSettings: String? = this.spanStyle.fontFeatureSettings,
        letterSpacing: TextUnit = this.spanStyle.letterSpacing,
        baselineShift: BaselineShift? = this.spanStyle.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.spanStyle.textGeometricTransform,
        localeList: LocaleList? = this.spanStyle.localeList,
        background: Color = this.spanStyle.background,
        textDecoration: TextDecoration? = this.spanStyle.textDecoration,
        shadow: Shadow? = this.spanStyle.shadow,
        drawStyle: DrawStyle? = this.spanStyle.drawStyle,
        textAlign: TextAlign = this.paragraphStyle.textAlign,
        textDirection: TextDirection = this.paragraphStyle.textDirection,
        lineHeight: TextUnit = this.paragraphStyle.lineHeight,
        textIndent: TextIndent? = this.paragraphStyle.textIndent,
        platformStyle: PlatformTextStyle? = this.platformStyle,
        lineHeightStyle: LineHeightStyle? = this.paragraphStyle.lineHeightStyle,
        lineBreak: LineBreak = this.paragraphStyle.lineBreak,
        hyphens: Hyphens = this.paragraphStyle.hyphens,
        textMotion: TextMotion? = this.paragraphStyle.textMotion,
    ): TextStyle

equals

Source set: Common
override fun equals(other: Any?): Boolean

hasSameLayoutAffectingAttributes

Source set: Common
public fun hasSameLayoutAffectingAttributes(other: TextStyle): Boolean

Returns true if text layout affecting attributes between this TextStyle and other are the same.

The attributes that do not require a layout change are color, textDecoration and shadow.

Majority of attributes change text layout, and examples are line height, font properties, font size, locale etc.

This function can be used to identify if a new text layout is required for a given TextStyle.

Parameters

other The TextStyle to compare to.

hasSameDrawAffectingAttributes

Source set: Common
public fun hasSameDrawAffectingAttributes(other: TextStyle): Boolean

hashCode

Source set: Common
override fun hashCode(): Int

toString

Source set: Common
override fun toString(): String

Members

Companion

Source set: Common
public companion object

Properties

Default

Source set: Common
@Stable public val Default: TextStyle = TextStyle()

Constant for default text style.