TextStyle

Class

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

Styling configuration for a Text.

Parameters

platformStylePlatform specific TextStyle parameters.

Secondary Constructors

internal constructor(
    spanStyle: SpanStyle,
    paragraphStyle: ParagraphStyle,
) : this(
    spanStyle = spanStyle,
    paragraphStyle = paragraphStyle,
    platformStyle =
        createPlatformTextStyleInternal(spanStyle.platformStyle, paragraphStyle.platformStyle),
)
constructor(
    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,
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
) : this(
    SpanStyle(
        color = color,
        fontSize = fontSize,
        fontWeight = fontWeight,
        fontStyle = fontStyle,
        fontSynthesis = fontSynthesis,
        fontFamily = fontFamily,
        fontFeatureSettings = fontFeatureSettings,
        letterSpacing = letterSpacing,
        baselineShift = baselineShift,
        textGeometricTransform = textGeometricTransform,
        localeList = localeList,
        background = background,
        textDecoration = textDecoration,
        shadow = shadow,
        platformStyle = null,
        drawStyle = null,
    ),
    ParagraphStyle(
        textAlign = textAlign ?: TextAlign.Unspecified,
        textDirection = textDirection ?: TextDirection.Unspecified,
        lineHeight = lineHeight,
        textIndent = textIndent,
        platformStyle = null,
        lineHeightStyle = null,
        lineBreak = LineBreak.Unspecified,
        hyphens = Hyphens.Unspecified,
        textMotion = null,
    ),
    platformStyle = null,
)
constructor(
    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,
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
    platformStyle: PlatformTextStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
) : this(
    SpanStyle(
        color = color,
        fontSize = fontSize,
        fontWeight = fontWeight,
        fontStyle = fontStyle,
        fontSynthesis = fontSynthesis,
        fontFamily = fontFamily,
        fontFeatureSettings = fontFeatureSettings,
        letterSpacing = letterSpacing,
        baselineShift = baselineShift,
        textGeometricTransform = textGeometricTransform,
        localeList = localeList,
        background = background,
        textDecoration = textDecoration,
        shadow = shadow,
        platformStyle = platformStyle?.spanStyle,
        drawStyle = null,
    ),
    ParagraphStyle(
        textAlign = textAlign ?: TextAlign.Unspecified,
        textDirection = textDirection ?: TextDirection.Unspecified,
        lineHeight = lineHeight,
        textIndent = textIndent,
        platformStyle = platformStyle?.paragraphStyle,
        lineHeightStyle = lineHeightStyle,
        lineBreak = LineBreak.Unspecified,
        hyphens = Hyphens.Unspecified,
        textMotion = null,
    ),
    platformStyle = platformStyle,
)
constructor(
    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,
    textAlign: TextAlign? = null,
    textDirection: TextDirection? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    textIndent: TextIndent? = null,
    platformStyle: PlatformTextStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak? = null,
    hyphens: Hyphens? = null,
) : this(
    SpanStyle(
        color = color,
        fontSize = fontSize,
        fontWeight = fontWeight,
        fontStyle = fontStyle,
        fontSynthesis = fontSynthesis,
        fontFamily = fontFamily,
        fontFeatureSettings = fontFeatureSettings,
        letterSpacing = letterSpacing,
        baselineShift = baselineShift,
        textGeometricTransform = textGeometricTransform,
        localeList = localeList,
        background = background,
        textDecoration = textDecoration,
        shadow = shadow,
        platformStyle = platformStyle?.spanStyle,
    ),
    ParagraphStyle(
        textAlign = textAlign ?: TextAlign.Unspecified,
        textDirection = textDirection ?: TextDirection.Unspecified,
        lineHeight = lineHeight,
        textIndent = textIndent,
        platformStyle = platformStyle?.paragraphStyle,
        lineHeightStyle = lineHeightStyle,
        lineBreak = lineBreak ?: LineBreak.Unspecified,
        hyphens = hyphens ?: Hyphens.Unspecified,
    ),
    platformStyle = platformStyle,
)

Styling configuration for a Text.

Parameters

colorThe text color.
fontSizeThe size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle.
fontWeightThe typeface thickness to use when painting the text (e.g., bold).
fontStyleThe typeface variant to use when drawing the letters (e.g., italic).
fontSynthesisWhether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family.
fontFamilyThe font family to be used when rendering the text.
fontFeatureSettingsThe 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
letterSpacingThe amount of space to add between each letter.
baselineShiftThe amount by which the text is shifted up from the current baseline.
textGeometricTransformThe geometric transformation applied the text.
localeListThe locale list used to select region-specific glyphs.
backgroundThe background color for the text.
textDecorationThe decorations to paint on the text (e.g., an underline).
shadowThe shadow effect applied on the text.
textAlignThe alignment of the text within the lines of the paragraph.
textDirectionThe 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.
lineHeightLine height for the Paragraph in TextUnit unit, e.g. SP or EM.
textIndentThe indentation of the paragraph.
platformStylePlatform specific TextStyle parameters.
lineHeightStylethe 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.
lineBreakThe line breaking configuration for the text.
hyphensThe configuration of hyphenation.
constructor(
    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,
    platformStyle: PlatformTextStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak? = null,
    hyphens: Hyphens? = null,
    textMotion: TextMotion? = null,
) : this(
    SpanStyle(
        color = color,
        fontSize = fontSize,
        fontWeight = fontWeight,
        fontStyle = fontStyle,
        fontSynthesis = fontSynthesis,
        fontFamily = fontFamily,
        fontFeatureSettings = fontFeatureSettings,
        letterSpacing = letterSpacing,
        baselineShift = baselineShift,
        textGeometricTransform = textGeometricTransform,
        localeList = localeList,
        background = background,
        textDecoration = textDecoration,
        shadow = shadow,
        platformStyle = platformStyle?.spanStyle,
        drawStyle = drawStyle,
    ),
    ParagraphStyle(
        textAlign = textAlign ?: TextAlign.Unspecified,
        textDirection = textDirection ?: TextDirection.Unspecified,
        lineHeight = lineHeight,
        textIndent = textIndent,
        platformStyle = platformStyle?.paragraphStyle,
        lineHeightStyle = lineHeightStyle,
        lineBreak = lineBreak ?: LineBreak.Unspecified,
        hyphens = hyphens ?: Hyphens.Unspecified,
        textMotion = textMotion,
    ),
    platformStyle = platformStyle,
)
constructor(
    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,
    platformStyle: PlatformTextStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak = LineBreak.Unspecified,
    hyphens: Hyphens = Hyphens.Unspecified,
    textMotion: TextMotion? = null,
) : this(
    SpanStyle(
        color = color,
        fontSize = fontSize,
        fontWeight = fontWeight,
        fontStyle = fontStyle,
        fontSynthesis = fontSynthesis,
        fontFamily = fontFamily,
        fontFeatureSettings = fontFeatureSettings,
        letterSpacing = letterSpacing,
        baselineShift = baselineShift,
        textGeometricTransform = textGeometricTransform,
        localeList = localeList,
        background = background,
        textDecoration = textDecoration,
        shadow = shadow,
        platformStyle = platformStyle?.spanStyle,
        drawStyle = drawStyle,
    ),
    ParagraphStyle(
        textAlign = textAlign,
        textDirection = textDirection,
        lineHeight = lineHeight,
        textIndent = textIndent,
        platformStyle = platformStyle?.paragraphStyle,
        lineHeightStyle = lineHeightStyle,
        lineBreak = lineBreak,
        hyphens = hyphens,
        textMotion = textMotion,
    ),
    platformStyle = platformStyle,
)

Styling configuration for a Text.

Parameters

colorThe text color.
fontSizeThe size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle.
fontWeightThe typeface thickness to use when painting the text (e.g., bold).
fontStyleThe typeface variant to use when drawing the letters (e.g., italic).
fontSynthesisWhether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family.
fontFamilyThe font family to be used when rendering the text.
fontFeatureSettingsThe 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
letterSpacingThe amount of space to add between each letter.
baselineShiftThe amount by which the text is shifted up from the current baseline.
textGeometricTransformThe geometric transformation applied the text.
localeListThe locale list used to select region-specific glyphs.
backgroundThe background color for the text.
textDecorationThe decorations to paint on the text (e.g., an underline).
shadowThe shadow effect applied on the text.
drawStyleDrawing style of text, whether fill in the text while drawing or stroke around the edges.
textAlignThe alignment of the text within the lines of the paragraph.
textDirectionThe 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.
lineHeightLine height for the Paragraph in TextUnit unit, e.g. SP or EM.
textIndentThe indentation of the paragraph.
platformStylePlatform specific TextStyle parameters.
lineHeightStylethe 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.
lineBreakThe line breaking configuration for the text.
hyphensThe configuration of hyphenation.
textMotionText character placement, whether to optimize for animated or static text.
constructor(
    brush: Brush?,
    alpha: Float = Float.NaN,
    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,
    platformStyle: PlatformTextStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak = LineBreak.Unspecified,
    hyphens: Hyphens = Hyphens.Unspecified,
    textMotion: TextMotion? = null,
) : this(
    SpanStyle(
        brush = brush,
        alpha = alpha,
        fontSize = fontSize,
        fontWeight = fontWeight,
        fontStyle = fontStyle,
        fontSynthesis = fontSynthesis,
        fontFamily = fontFamily,
        fontFeatureSettings = fontFeatureSettings,
        letterSpacing = letterSpacing,
        baselineShift = baselineShift,
        textGeometricTransform = textGeometricTransform,
        localeList = localeList,
        background = background,
        textDecoration = textDecoration,
        shadow = shadow,
        platformStyle = platformStyle?.spanStyle,
        drawStyle = drawStyle,
    ),
    ParagraphStyle(
        textAlign = textAlign,
        textDirection = textDirection,
        lineHeight = lineHeight,
        textIndent = textIndent,
        platformStyle = platformStyle?.paragraphStyle,
        lineHeightStyle = lineHeightStyle,
        lineBreak = lineBreak,
        hyphens = hyphens,
        textMotion = textMotion,
    ),
    platformStyle = platformStyle,
)

Styling configuration for a Text.

Parameters

brushThe brush to use when painting the text. If brush is given as null, it will be treated as unspecified. It is equivalent to calling the alternative color constructor with Color.Unspecified
alphaOpacity to be applied to brush from 0.0f to 1.0f representing fully transparent to fully opaque respectively.
fontSizeThe size of glyphs to use when painting the text. This may be TextUnit.Unspecified for inheriting from another TextStyle.
fontWeightThe typeface thickness to use when painting the text (e.g., bold).
fontStyleThe typeface variant to use when drawing the letters (e.g., italic).
fontSynthesisWhether to synthesize font weight and/or style when the requested weight or style cannot be found in the provided font family.
fontFamilyThe font family to be used when rendering the text.
fontFeatureSettingsThe 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
letterSpacingThe amount of space to add between each letter.
baselineShiftThe amount by which the text is shifted up from the current baseline.
textGeometricTransformThe geometric transformation applied the text.
localeListThe locale list used to select region-specific glyphs.
backgroundThe background color for the text.
textDecorationThe decorations to paint on the text (e.g., an underline).
shadowThe shadow effect applied on the text.
drawStyleDrawing style of text, whether fill in the text while drawing or stroke around the edges.
textAlignThe alignment of the text within the lines of the paragraph.
textDirectionThe 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.
lineHeightLine height for the Paragraph in TextUnit unit, e.g. SP or EM.
textIndentThe indentation of the paragraph.
platformStylePlatform specific TextStyle parameters.
lineHeightStylethe 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.
lineBreakThe line breaking configuration for the text.
hyphensThe configuration of hyphenation.
textMotionText character placement, whether to optimize for animated or static text.
constructor(
    brush: Brush?,
    alpha: Float = Float.NaN,
    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,
    platformStyle: PlatformTextStyle? = null,
    lineHeightStyle: LineHeightStyle? = null,
    lineBreak: LineBreak? = null,
    hyphens: Hyphens? = null,
    textMotion: TextMotion? = null,
) : this(
    SpanStyle(
        brush = brush,
        alpha = alpha,
        fontSize = fontSize,
        fontWeight = fontWeight,
        fontStyle = fontStyle,
        fontSynthesis = fontSynthesis,
        fontFamily = fontFamily,
        fontFeatureSettings = fontFeatureSettings,
        letterSpacing = letterSpacing,
        baselineShift = baselineShift,
        textGeometricTransform = textGeometricTransform,
        localeList = localeList,
        background = background,
        textDecoration = textDecoration,
        shadow = shadow,
        platformStyle = platformStyle?.spanStyle,
        drawStyle = drawStyle,
    ),
    ParagraphStyle(
        textAlign = textAlign ?: TextAlign.Unspecified,
        textDirection = textDirection ?: TextDirection.Unspecified,
        lineHeight = lineHeight,
        textIndent = textIndent,
        platformStyle = platformStyle?.paragraphStyle,
        lineHeightStyle = lineHeightStyle,
        lineBreak = lineBreak ?: LineBreak.Unspecified,
        hyphens = hyphens ?: Hyphens.Unspecified,
        textMotion = textMotion,
    ),
    platformStyle = platformStyle,
)

Properties

Common
val brush: Brush?

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

Common
val color: Color

The text color.

Common
val alpha: Float

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

Common
val fontSize: TextUnit

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

Common
val fontWeight: FontWeight?

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

Common
val fontStyle: FontStyle?

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

Common
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.

Common
val fontFamily: FontFamily?

The font family to be used when rendering the text.

Common
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

Common
val letterSpacing: TextUnit

The amount of space to add between each letter.

Common
val baselineShift: BaselineShift?

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

Common
val textGeometricTransform: TextGeometricTransform?

The geometric transformation applied the text.

Common
val localeList: LocaleList?

The locale list used to select region-specific glyphs.

Common
val background: Color

The background color for the text.

Common
val textDecoration: TextDecoration?

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

Common
val shadow: Shadow?

The shadow effect applied on the text.

Common
val drawStyle: DrawStyle?

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

Common
val textAlign: TextAlign

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

Common

Deprecated Kept for backwards compatibility.

val deprecated_boxing_textAlign: TextAlign?
Common
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.

Common

Deprecated Kept for backwards compatibility.

val deprecated_boxing_textDirection: TextDirection?
Common
val lineHeight: TextUnit

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

Common
val textIndent: TextIndent?

The indentation of the paragraph.

Common
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.

Common
val hyphens: Hyphens

The hyphens configuration of the paragraph.

Common

Deprecated Kept for backwards compatibility.

val deprecated_boxing_hyphens: Hyphens?
Common
val lineBreak: LineBreak

The line breaking configuration of the paragraph.

Common

Deprecated Kept for backwards compatibility.

val deprecated_boxing_lineBreak: LineBreak?
Common
val textMotion: TextMotion?

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

Functions

fun toSpanStyle(): SpanStyle
fun toParagraphStyle(): ParagraphStyle
fun merge(other: TextStyle? = null): TextStyle

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

other text style's null or inherit properties are replaced with the non-null properties of this text style. Another way to think of it is that the "missing" properties of the other style are filled by the properties of this style.

If the given text style is null, returns this text style.

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

Fast merge non-default values and parameters.

This is the same algorithm as merge but does not require allocating it's parameter and may return this instead of allocating a result when all values are default.

This is a similar algorithm to copy but when either this or a parameter are set to a default value, the other value will take precedent.

To explain better, consider the following examples:

Example 1:

  • this.color = Color.Unspecified
  • color = Color.Red
  • result => Color.Red

Example 2:

  • this.color = Color.Red
  • color = Color.Unspecified
  • result => Color.Red

Example 3:

  • this.color = Color.Red
  • color = Color.Blue
  • result => Color.Blue

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

Returns

this or a new TextLayoutResult with all parameters chosen to the non-default option provided.
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
fun merge(other: SpanStyle): TextStyle

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

fun merge(other: ParagraphStyle): TextStyle

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

operator fun plus(other: TextStyle): TextStyle

Plus operator overload that applies a merge.

operator fun plus(other: ParagraphStyle): TextStyle

Plus operator overload that applies a merge.

operator fun plus(other: SpanStyle): TextStyle

Plus operator overload that applies a merge.

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
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
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
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
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
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
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
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

otherThe TextStyle to compare to.
fun hasSameDrawAffectingAttributes(other: TextStyle): Boolean

Companion Object

Properties

Common
val Default = TextStyle()

Constant for default text style.