public class TextStyle internal constructor(
internal val spanStyle: SpanStyle,
internal val paragraphStyle: ParagraphStyle,
public val platformStyle: PlatformTextStyle? = null,
)
Properties
brush
public val brush: Brush?
The brush to use when drawing text. If not null, overrides color.
color
public val color: Color
The text color.
alpha
public val alpha: Float
Opacity of text. This value is either provided along side Brush, or via alpha channel in color.
fontSize
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
public val fontWeight: FontWeight?
The typeface thickness to use when painting the text (e.g., bold).
fontStyle
public val fontStyle: FontStyle?
The typeface variant to use when drawing the letters (e.g., italic).
fontSynthesis
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
public val fontFamily: FontFamily?
The font family to be used when rendering the text.
fontFeatureSettings
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
public val letterSpacing: TextUnit
The amount of space to add between each letter.
baselineShift
public val baselineShift: BaselineShift?
The amount by which the text is shifted up from the current baseline.
textGeometricTransform
public val textGeometricTransform: TextGeometricTransform?
The geometric transformation applied the text.
localeList
public val localeList: LocaleList?
The locale list used to select region-specific glyphs.
background
public val background: Color
The background color for the text.
textDecoration
public val textDecoration: TextDecoration?
The decorations to paint on the text (e.g., an underline).
shadow
public val shadow: Shadow?
The shadow effect applied on the text.
drawStyle
public val drawStyle: DrawStyle?
Drawing style of text, whether fill in the text while drawing or stroke around the edges.
textAlign
public val textAlign: TextAlign
The alignment of the text within the lines of the paragraph.
deprecatedboxingtextAlign
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
@get:JvmName("getTextAlign-buA522U") // b/320819734
public val deprecated_boxing_textAlign: TextAlign?
textDirection
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
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
@get:JvmName("getTextDirection-mmuk1to") // b/320819734
public val deprecated_boxing_textDirection: TextDirection?
lineHeight
public val lineHeight: TextUnit
Line height for the Paragraph in TextUnit unit, e.g. SP or EM.
textIndent
public val textIndent: TextIndent?
The indentation of the paragraph.
lineHeightStyle
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
public val hyphens: Hyphens
The hyphens configuration of the paragraph.
deprecatedboxinghyphens
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
@get:JvmName("getHyphens-EaSxIns") // b/320819734
public val deprecated_boxing_hyphens: Hyphens?
lineBreak
public val lineBreak: LineBreak
The line breaking configuration of the paragraph.
deprecatedboxinglineBreak
@Deprecated("Kept for backwards compatibility.", level = DeprecationLevel.WARNING)
@get:JvmName("getLineBreak-LgCVezo") // b/320819734
public val deprecated_boxing_lineBreak: LineBreak?
textMotion
public val textMotion: TextMotion?
Text character placement configuration, whether to optimize for animated or static text.
Functions
toSpanStyle
@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
@Stable public fun toParagraphStyle(): ParagraphStyle
merge
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
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, paramcolor=Color.Red-> resultColor.Redthis.color=Color.Red, paramcolor=Color.Unspecified-> resultColor.Redthis.color=Color.Red, paramcolor=Color.Blue-> resultColor.Blue
merge
@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
public fun merge(other: SpanStyle): TextStyle
Returns a new text style that is a combination of this style and the given other style.
merge
public fun merge(other: ParagraphStyle): TextStyle
Returns a new text style that is a combination of this style and the given other style.
plus
@Stable public operator fun plus(other: TextStyle): TextStyle
Plus operator overload that applies a merge.
plus
@Stable public operator fun plus(other: ParagraphStyle): TextStyle
Plus operator overload that applies a merge.
plus
@Stable public operator fun plus(other: SpanStyle): TextStyle
Plus operator overload that applies a merge.
copy
@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
@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
@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
@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
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
@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
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
override fun equals(other: Any?): Boolean
hasSameLayoutAffectingAttributes
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
public fun hasSameDrawAffectingAttributes(other: TextStyle): Boolean
hashCode
override fun hashCode(): Int
toString
override fun toString(): String
Members
Companion
public companion object
Properties
Default
@Stable public val Default: TextStyle = TextStyle()
Constant for default text style.