Merge pull request #894 from hoodie13/local-gedoor-code

修了几个bug。ChapterProvider.kt和ContentTextView.kt是优化“画”标记大小的,感觉会有兼容性问题,这2个文件或者先不要合了。
pull/898/head
kunfei 4 years ago committed by GitHub
commit 3d114068ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  2. 4
      app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  4. 3
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  5. 21
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt

@ -65,7 +65,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
}
val contents = arrayListOf<String>()
content1.split("\n").forEach {
val str = it.replace("^[\\n\\s\\r]+".toRegex(), "")
val str = it.replace("^[\\n\\r]+".toRegex(), "").trim()
if (contents.isEmpty()) {
contents.add(title)
if (str != title && str.isNotEmpty()) {

@ -317,7 +317,9 @@ class EPUBFile(var book: io.legado.app.data.entities.Book) {
)
).getElementsByTag("title")
title =
if (elements != null && elements.size > 0) elements[0].text() else "--卷首--"
if (elements != null && elements.size > 0 && elements[0].text()
.isNotBlank()
) elements[0].text() else "--卷首--"
}
chapter.bookUrl = book.bookUrl
chapter.title = title

@ -165,9 +165,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
lineBottom: Float,
) {
ReadBook.book?.let { book ->
val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom)
ImageProvider.getImage(book, textPage.chapterIndex, textChar.charData, true)
?.let {
/*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/
val h = (textChar.end - textChar.start) / it.width * it.height
val div = (lineBottom - lineTop - h) / 2
val rectF = RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div)
canvas.drawBitmap(it, null, rectF, null)
}
}

@ -69,7 +69,8 @@ object ChapterProvider {
@JvmStatic
lateinit var contentPaint: TextPaint
private const val srcReplaceChar = "🖼"
/*🖼比汉字宽,跟字一起效果的效果不是很好,用卍取代*/
private const val srcReplaceChar = ""
init {
upStyle()

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

Loading…
Cancel
Save