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