TP-33802 | Italic font support in TextRenderer (#98)

This commit is contained in:
shreyansu raj
2023-06-26 15:02:13 +05:30
committed by GitHub Enterprise
parent 5690cdb38c
commit 06c0ff7652
2 changed files with 20 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ data class TextProperty(
var fontFamily: String? = null,
var fontWeight: String? = null,
var fontSize: Int? = null,
var fontStyle: String? = null,
var textColor: String? = null,
var textDecoration: String? = null,
var letterSpacing: Float? = null,
@@ -31,6 +32,7 @@ data class TextProperty(
textProperty?.fontFamily?.let { fontFamily = it }
textProperty?.fontWeight?.let { fontWeight = it }
textProperty?.fontSize?.let { fontSize = it }
textProperty?.fontStyle?.let { fontStyle = it }
textProperty?.textColor?.let { textColor = it }
textProperty?.textDecoration?.let { textDecoration = it }
textProperty?.letterSpacing?.let { letterSpacing = it }
@@ -41,4 +43,4 @@ data class TextProperty(
textProperty?.maxLines?.let { maxLines = it }
textProperty?.textBrushData?.let { textBrushData = it }
}
}
}

View File

@@ -16,6 +16,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp
@@ -98,7 +99,10 @@ class TextRenderer : Renderer<TextProperty> {
overflow = getTextOverflow(property.overflow),
softWrap = property.softWrap.orTrue(),
maxLines = property.maxLines ?: Int.MAX_VALUE,
style = TextStyle(brush = property.textBrushData?.let { getBrush(it) }),
style = TextStyle(
brush = property.textBrushData?.let { getBrush(it) },
fontStyle = getFontStyle(property.fontStyle)
),
modifier = (modifier ?: Modifier)
.setWidth(property.width)
.setHeight(property.height)
@@ -121,3 +125,15 @@ class TextRenderer : Renderer<TextProperty> {
}
}
}
enum class TextFontStyle {
NORMAL, ITALIC
}
fun getFontStyle(fontStyle: String?): FontStyle {
return when (fontStyle) {
TextFontStyle.NORMAL.name -> FontStyle.Normal
TextFontStyle.ITALIC.name -> FontStyle.Italic
else -> FontStyle.Normal
}
}