|
|
@ -40,7 +40,7 @@ class ZhLayout( |
|
|
|
val words = text.toStringArray() |
|
|
|
val words = text.toStringArray() |
|
|
|
var lineW = 0f |
|
|
|
var lineW = 0f |
|
|
|
var cwPre = 0f |
|
|
|
var cwPre = 0f |
|
|
|
|
|
|
|
var length = 0 |
|
|
|
words.forEachIndexed { index, s -> |
|
|
|
words.forEachIndexed { index, s -> |
|
|
|
val cw = getDesiredWidth(s, curPaint) |
|
|
|
val cw = getDesiredWidth(s, curPaint) |
|
|
|
var breakMod: BreakMod |
|
|
|
var breakMod: BreakMod |
|
|
@ -81,6 +81,7 @@ class ZhLayout( |
|
|
|
) reCheck = true |
|
|
|
) reCheck = true |
|
|
|
|
|
|
|
|
|
|
|
/*特殊标点使用难保证显示效果,所以不考虑间隔,直接查找到能满足条件的分割字*/ |
|
|
|
/*特殊标点使用难保证显示效果,所以不考虑间隔,直接查找到能满足条件的分割字*/ |
|
|
|
|
|
|
|
var breakLength = 0 |
|
|
|
if (reCheck && index > 2) { |
|
|
|
if (reCheck && index > 2) { |
|
|
|
breakMod = BreakMod.NORMAL |
|
|
|
breakMod = BreakMod.NORMAL |
|
|
|
for (i in (index) downTo 1) { |
|
|
|
for (i in (index) downTo 1) { |
|
|
@ -89,7 +90,8 @@ class ZhLayout( |
|
|
|
cwPre = 0f |
|
|
|
cwPre = 0f |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
breakIndex++ |
|
|
|
breakIndex++ |
|
|
|
cwPre += StaticLayout.getDesiredWidth(words[i], textPaint) |
|
|
|
breakLength += words[i].length |
|
|
|
|
|
|
|
cwPre += getDesiredWidth(words[i], textPaint) |
|
|
|
} |
|
|
|
} |
|
|
|
if (!isPostPanc(words[i]) && !isPrePanc(words[i - 1])) { |
|
|
|
if (!isPostPanc(words[i]) && !isPrePanc(words[i - 1])) { |
|
|
|
breakMod = BreakMod.BREAK_MORE_CHAR |
|
|
|
breakMod = BreakMod.BREAK_MORE_CHAR |
|
|
@ -101,32 +103,32 @@ class ZhLayout( |
|
|
|
when (breakMod) { |
|
|
|
when (breakMod) { |
|
|
|
BreakMod.NORMAL -> {//模式0 正常断行 |
|
|
|
BreakMod.NORMAL -> {//模式0 正常断行 |
|
|
|
offset = cw |
|
|
|
offset = cw |
|
|
|
lineStart[line + 1] = index |
|
|
|
lineStart[line + 1] = length |
|
|
|
breakCharCnt = 1 |
|
|
|
breakCharCnt = 1 |
|
|
|
} |
|
|
|
} |
|
|
|
BreakMod.BREAK_ONE_CHAR -> {//模式1 当前行下移一个字 |
|
|
|
BreakMod.BREAK_ONE_CHAR -> {//模式1 当前行下移一个字 |
|
|
|
offset = cw + cwPre |
|
|
|
offset = cw + cwPre |
|
|
|
lineStart[line + 1] = index - 1 |
|
|
|
lineStart[line + 1] = length - words[index - 1].length |
|
|
|
breakCharCnt = 2 |
|
|
|
breakCharCnt = 2 |
|
|
|
} |
|
|
|
} |
|
|
|
BreakMod.BREAK_MORE_CHAR -> {//模式2 当前行下移多个字 |
|
|
|
BreakMod.BREAK_MORE_CHAR -> {//模式2 当前行下移多个字 |
|
|
|
offset = cw + cwPre |
|
|
|
offset = cw + cwPre |
|
|
|
lineStart[line + 1] = index - breakIndex |
|
|
|
lineStart[line + 1] = length - breakLength |
|
|
|
breakCharCnt = breakIndex + 1 |
|
|
|
breakCharCnt = breakIndex + 1 |
|
|
|
} |
|
|
|
} |
|
|
|
BreakMod.CPS_1 -> {//模式3 两个后置标点压缩 |
|
|
|
BreakMod.CPS_1 -> {//模式3 两个后置标点压缩 |
|
|
|
offset = 0f |
|
|
|
offset = 0f |
|
|
|
lineStart[line + 1] = index + 1 |
|
|
|
lineStart[line + 1] = length + s.length |
|
|
|
breakCharCnt = 0 |
|
|
|
breakCharCnt = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
BreakMod.CPS_2 -> { //模式4 前置标点压缩+前置标点压缩+字 |
|
|
|
BreakMod.CPS_2 -> { //模式4 前置标点压缩+前置标点压缩+字 |
|
|
|
offset = 0f |
|
|
|
offset = 0f |
|
|
|
lineStart[line + 1] = index + 1 |
|
|
|
lineStart[line + 1] = length + s.length |
|
|
|
breakCharCnt = 0 |
|
|
|
breakCharCnt = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
BreakMod.CPS_3 -> {//模式5 前置标点压缩+字+后置标点压缩 |
|
|
|
BreakMod.CPS_3 -> {//模式5 前置标点压缩+字+后置标点压缩 |
|
|
|
offset = 0f |
|
|
|
offset = 0f |
|
|
|
lineStart[line + 1] = index + 1 |
|
|
|
lineStart[line + 1] = length + s.length |
|
|
|
breakCharCnt = 0 |
|
|
|
breakCharCnt = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -143,7 +145,7 @@ class ZhLayout( |
|
|
|
if ((words.lastIndex) == index) { |
|
|
|
if ((words.lastIndex) == index) { |
|
|
|
if (!breakLine) { |
|
|
|
if (!breakLine) { |
|
|
|
offset = 0f |
|
|
|
offset = 0f |
|
|
|
lineStart[line + 1] = index + 1 |
|
|
|
lineStart[line + 1] = length + s.length |
|
|
|
lineWidth[line] = lineW - offset |
|
|
|
lineWidth[line] = lineW - offset |
|
|
|
lineW = offset |
|
|
|
lineW = offset |
|
|
|
addLineArray(++line) |
|
|
|
addLineArray(++line) |
|
|
@ -155,6 +157,7 @@ class ZhLayout( |
|
|
|
addLineArray(++line) |
|
|
|
addLineArray(++line) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
length += s.length |
|
|
|
cwPre = cw |
|
|
|
cwPre = cw |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|