pref: 文字行间距
This commit is contained in:
parent
20b9dd5bfa
commit
fed1b0c284
|
|
@ -271,6 +271,7 @@ fun PbContentText(
|
|||
textDecoration = textDecoration,
|
||||
textAlign = textAlign,
|
||||
lineHeight = lineHeight,
|
||||
lineSpacing = 0.8.sp,
|
||||
overflow = overflow,
|
||||
softWrap = softWrap,
|
||||
maxLines = maxLines,
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import androidx.compose.ui.layout.ContentScale
|
|||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.text.ExperimentalTextApi
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
|
|
@ -201,6 +202,7 @@ private fun Badge(
|
|||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTextApi::class)
|
||||
@Composable
|
||||
fun ThreadContent(
|
||||
title: String = "",
|
||||
|
|
@ -228,7 +230,9 @@ fun ThreadContent(
|
|||
append(title)
|
||||
}
|
||||
}
|
||||
if (showTitle && showAbstract) append('\n')
|
||||
if (showTitle && showAbstract) {
|
||||
append('\n')
|
||||
}
|
||||
if (showAbstract) {
|
||||
append(abstractText.emoticonString)
|
||||
}
|
||||
|
|
@ -238,7 +242,7 @@ fun ThreadContent(
|
|||
text = content,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
fontSize = 15.sp,
|
||||
lineHeight = 22.sp,
|
||||
lineSpacing = 0.8.sp,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 5,
|
||||
style = MaterialTheme.typography.body1
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ import com.huanchengfly.tieba.post.spToPxFloat
|
|||
import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme
|
||||
import com.huanchengfly.tieba.post.utils.EmoticonManager
|
||||
import com.huanchengfly.tieba.post.utils.EmoticonUtil.emoticonString
|
||||
import com.huanchengfly.tieba.post.utils.getEmoticonHeightPx
|
||||
import com.huanchengfly.tieba.post.utils.calcLineHeightPx
|
||||
|
||||
@Composable
|
||||
fun EmoticonText(
|
||||
|
|
@ -72,6 +72,7 @@ fun EmoticonText(
|
|||
textDecoration: TextDecoration? = null,
|
||||
textAlign: TextAlign? = null,
|
||||
lineHeight: TextUnit = TextUnit.Unspecified,
|
||||
lineSpacing: TextUnit = 0.sp,
|
||||
overflow: TextOverflow = TextOverflow.Clip,
|
||||
softWrap: Boolean = true,
|
||||
maxLines: Int = Int.MAX_VALUE,
|
||||
|
|
@ -93,6 +94,7 @@ fun EmoticonText(
|
|||
textDecoration,
|
||||
textAlign,
|
||||
lineHeight,
|
||||
lineSpacing,
|
||||
overflow,
|
||||
softWrap,
|
||||
maxLines,
|
||||
|
|
@ -116,6 +118,7 @@ fun EmoticonText(
|
|||
textDecoration: TextDecoration? = null,
|
||||
textAlign: TextAlign? = null,
|
||||
lineHeight: TextUnit = TextUnit.Unspecified,
|
||||
lineSpacing: TextUnit = 0.sp,
|
||||
overflow: TextOverflow = TextOverflow.Clip,
|
||||
softWrap: Boolean = true,
|
||||
maxLines: Int = Int.MAX_VALUE,
|
||||
|
|
@ -143,9 +146,11 @@ fun EmoticonText(
|
|||
letterSpacing = letterSpacing
|
||||
)
|
||||
)
|
||||
val sizePx = getEmoticonHeightPx(mergedStyle) * emoticonSize
|
||||
val sizePx = calcLineHeightPx(mergedStyle)
|
||||
val spacingLineHeight =
|
||||
remember(sizePx) { (sizePx + lineSpacing.value.spToPxFloat()).pxToSpFloat().sp }
|
||||
val emoticonInlineContent =
|
||||
remember(sizePx) { EmoticonManager.getEmoticonInlineContent(sizePx) }
|
||||
remember(sizePx) { EmoticonManager.getEmoticonInlineContent(sizePx * emoticonSize) }
|
||||
IconText(
|
||||
text,
|
||||
modifier,
|
||||
|
|
@ -157,7 +162,7 @@ fun EmoticonText(
|
|||
letterSpacing,
|
||||
textDecoration,
|
||||
textAlign,
|
||||
lineHeight,
|
||||
spacingLineHeight,
|
||||
overflow,
|
||||
softWrap,
|
||||
maxLines,
|
||||
|
|
@ -207,7 +212,7 @@ fun IconText(
|
|||
letterSpacing = letterSpacing
|
||||
)
|
||||
)
|
||||
val sizePx = getEmoticonHeightPx(mergedStyle) * 9 / 10
|
||||
val sizePx = calcLineHeightPx(mergedStyle) * 9 / 10
|
||||
val sizeSp = sizePx.pxToSp(LocalContext.current).sp
|
||||
val sizeDp = sizePx.pxToDp().dp
|
||||
val iconInlineContent =
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ import java.lang.ref.WeakReference
|
|||
|
||||
@OptIn(ExperimentalTextApi::class)
|
||||
@Composable
|
||||
fun getEmoticonHeightPx(style: TextStyle): Int {
|
||||
fun calcLineHeightPx(style: TextStyle): Int {
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
val textLayoutResult = textMeasurer.measure(
|
||||
AnnotatedString(stringResource(id = R.string.emoticon_default)),
|
||||
AnnotatedString(stringResource(id = R.string.single_chinese_char)),
|
||||
style
|
||||
)
|
||||
return textLayoutResult.size.height
|
||||
|
|
|
|||
Loading…
Reference in New Issue