@@ -59,7 +59,7 @@ fun rememberStyledTextResource(@StringRes id: Int, vararg formatArgs: Any): Anno
5959
6060/* *
6161 * Converts a html-styled resource text to an [AnnotatedString].
62- * #
62+ *
6363 * Tested with:
6464 * - bold: <b>
6565 * - italic: <i>
@@ -103,24 +103,20 @@ private fun spannableStringToAnnotatedString(text: Spanned, density: Density?):
103103 .forEach { span ->
104104 addStyle(
105105 when (span) {
106- is StyleSpan -> when (span.style) {
107- Typeface .NORMAL -> SpanStyle (
108- fontWeight = FontWeight .Normal ,
109- fontStyle = FontStyle .Normal
110- )
111-
112- Typeface .BOLD -> SpanStyle (
113- fontWeight = FontWeight .Bold ,
114- fontStyle = FontStyle .Normal
115- )
106+ is StyleSpan if span.style == Typeface .NORMAL -> SpanStyle (
107+ fontWeight = FontWeight .Normal ,
108+ fontStyle = FontStyle .Normal
109+ )
116110
117- Typeface .ITALIC -> SpanStyle (
118- fontWeight = FontWeight .Normal ,
119- fontStyle = FontStyle .Italic
120- )
111+ is StyleSpan if span.style == Typeface .BOLD -> SpanStyle (
112+ fontWeight = FontWeight .Bold ,
113+ fontStyle = FontStyle .Normal
114+ )
121115
122- else -> SpanStyle ()
123- }
116+ is StyleSpan if span.style == Typeface .ITALIC -> SpanStyle (
117+ fontWeight = FontWeight .Normal ,
118+ fontStyle = FontStyle .Italic
119+ )
124120
125121 is TypefaceSpan -> SpanStyle (
126122 fontFamily = when (span.family) {
@@ -135,9 +131,7 @@ private fun spannableStringToAnnotatedString(text: Spanned, density: Density?):
135131 is AbsoluteSizeSpan -> {
136132 density
137133 ?.run { SpanStyle (fontSize = if (span.dip) span.size.dp.toSp() else span.size.toSp()) }
138- ? : throw IllegalArgumentException (
139- " Found AbsoluteSizeSpan but passed density null. Pass a Density to convert."
140- )
134+ ? : error(" Found AbsoluteSizeSpan but passed density null. Pass a Density to convert." )
141135 }
142136
143137 is RelativeSizeSpan -> SpanStyle (fontSize = span.sizeChange.em)
0 commit comments