feature: support line height.

This commit is contained in:
cgspine
2021-02-04 00:25:48 +08:00
parent edc0d7d202
commit f3dc9d31de
4 changed files with 29 additions and 6 deletions
@@ -117,7 +117,7 @@ public class QDQQFaceUsageFragment extends BaseFragment {
lineLayout.setMoreUnderlineHeight(QMUIDisplayHelper.dp2px(getContext(), 2));
lineLayout.setMoreTextColor(Color.RED);
lineLayout.setMoreUnderlineColor(Color.BLUE);
mLineType1.setLineSpace(QMUIDisplayHelper.dp2px(getContext(), 5));
mLineType1.setLineHeight(QMUIDisplayHelper.dp2px(getContext(), 36));
mLineType1.setTextColor(Color.BLACK);
mLineType1.setTextSize(QMUIDisplayHelper.sp2px(getContext(), 15));
mLineType1.setTextParser(textParser);
@@ -63,7 +63,7 @@ class LineLayout {
if (canInterrupt()) {
return
}
y += line.contentHeight + env.paragraphSpace
y += (line.contentHeight + env.paragraphSpace).coerceAtLeast(env.lineHeight)
line = createNewLine(env, y)
} else if (line.contentWidth + element.measureWidth > env.widthLimit) {
if (mLines.size == 0 && line.size == 0) {
@@ -78,7 +78,12 @@ class LineLayout {
handleEllipse(env,true)
return
}
y += line.contentHeight + env.lineSpace
y += if(env.lineHeight != -1){
env.lineHeight.coerceAtLeast(line.contentHeight)
}else{
line.contentHeight + env.lineSpace
}
line = createNewLine(env, y)
if (back != null && !back.isEmpty()) {
for (el in back) {
@@ -351,9 +356,9 @@ class LineLayout {
val line = lines[i]
val prev = lines[i - 1]
if (prev.isMiddleParagraphEndLine) {
line.y = lastEnd + env.paragraphSpace
line.y = lastEnd + env.paragraphSpace.coerceAtLeast(env.lineHeight - handleLine.contentHeight)
} else {
line.y = lastEnd + env.lineSpace
line.y = lastEnd + env.lineSpace.coerceAtLeast(env.lineHeight - handleLine.contentHeight)
}
lastEnd = line.y + line.contentHeight
line.move(env)
@@ -42,6 +42,7 @@ class TypeEnvironment {
const val TYPE_BORDER_LEFT_WIDTH = -14
const val TYPE_BORDER_LEFT_COLOR = -15
const val TYPE_BORDER_PAINT = -16
const val TYPE_LINE_HEIGHT = -17
val DEFAULT_LAST_LINE_JUSTIFY_MAX_WIDTH = (Resources.getSystem().displayMetrics.density * 36).toInt()
}
@@ -73,6 +74,8 @@ class TypeEnvironment {
var lineSpace = 0
var lineHeight = -1
var paragraphSpace: Int = 0
get() = field.coerceAtLeast(lineSpace)
@@ -176,6 +179,7 @@ class TypeEnvironment {
env.setMeasureLimit(widthLimit, heightLimit)
env.alignment = alignment
env.lineSpace = lineSpace
env.lineHeight = lineHeight
env.paragraphSpace = paragraphSpace
env.textSize = textSize
env.typeface = typeface
@@ -210,7 +214,9 @@ class TypeEnvironment {
stack.push(lineSpace)
} else if (type == TYPE_PARAGRAPH_SPACE) {
stack.push(paragraphSpace)
} else {
} else if(type == TYPE_LINE_HEIGHT){
stack.push(lineHeight)
} else{
stack.push(mCustomProp[type])
}
}
@@ -240,6 +246,8 @@ class TypeEnvironment {
lineSpace = v as Int
} else if (type == TYPE_PARAGRAPH_SPACE) {
paragraphSpace = v as Int
}else if (type == TYPE_LINE_HEIGHT) {
lineHeight = v as Int
} else {
setCustomProp(type, v)
}
@@ -67,6 +67,16 @@ open class BaseTypeView(context: Context,
}
}
var lineHeight: Int
get() = environment.lineHeight
set(value){
throwIfRunning("setLineHeight")
if(environment.lineHeight != value){
environment.lineHeight = value
requestLayout()
}
}
var paragraphSpace: Int
get() = environment.paragraphSpace
set(value){