From 6ba115ebd6be0f9e7573d316c6cdb5ee50f94f6e Mon Sep 17 00:00:00 2001 From: hoodie13 <74173949+hoodie13@users.noreply.github.com> Date: Sat, 13 Mar 2021 00:01:11 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=AE=B5=E5=B0=BE?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC=EF=BC=8C=E9=81=BF=E5=85=8D=E5=88=86=E8=A1=8C?= =?UTF-8?q?=E5=90=8E=E5=87=BA=E7=8E=B0=E7=A9=BA=E7=99=BD=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/ContentProcessor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index ab3a60f04..b8787242b 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -65,7 +65,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str } val contents = arrayListOf() 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()) { From 0586dd17aa021c0973625d5ea7ced8a6b4363b50 Mon Sep 17 00:00:00 2001 From: hoodie13 <74173949+hoodie13@users.noreply.github.com> Date: Sat, 13 Mar 2021 01:24:46 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87text?= =?UTF-8?q?=E7=9A=84=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 5 ++++- .../legado/app/ui/book/read/page/provider/ChapterProvider.kt | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 3fba231a4..9c696b89d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 54fec4b6e..786050eab 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -69,7 +69,8 @@ object ChapterProvider { @JvmStatic lateinit var contentPaint: TextPaint - private const val srcReplaceChar = "🖼" + /*🖼字符长度是2,做自定义排版等一些处理时会异常,用卍取代*/ + private const val srcReplaceChar = "卍" init { upStyle() From 7884736e9ac26f68b32cdd65fcb06d330be88e2a Mon Sep 17 00:00:00 2001 From: hoodie13 <74173949+hoodie13@users.noreply.github.com> Date: Sat, 13 Mar 2021 08:20:38 +0800 Subject: [PATCH 3/5] =?UTF-8?q?length=E4=B8=BA2=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E9=9C=80=E8=A6=81Zhlayout=E5=A4=84=E7=90=86=E6=8E=89=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E6=98=AF=F0=9F=96=BC=E6=9C=89=E7=82=B9=E5=A4=AA?= =?UTF-8?q?=E5=AE=BD=E4=BA=86=EF=BC=8C=E4=B8=8D=E5=A5=BD=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/provider/ChapterProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 786050eab..62a9c67f3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -69,7 +69,7 @@ object ChapterProvider { @JvmStatic lateinit var contentPaint: TextPaint - /*🖼字符长度是2,做自定义排版等一些处理时会异常,用卍取代*/ + /*🖼比汉字宽,跟字一起效果的效果不是很好,用卍取代*/ private const val srcReplaceChar = "卍" init { From 2712f0eb18840afeb330c3a5bf272a2ee1afd4f7 Mon Sep 17 00:00:00 2001 From: hoodie13 <74173949+hoodie13@users.noreply.github.com> Date: Sat, 13 Mar 2021 08:53:53 +0800 Subject: [PATCH 4/5] =?UTF-8?q?lineStart=E9=9C=80=E8=A6=81=E8=80=83?= =?UTF-8?q?=E8=99=91=E5=AD=97=E7=AC=A6length?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/page/provider/ZhLayout.kt | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt index 1972f93ef..45d059479 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ZhLayout.kt @@ -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 } From 4ad1fd9c868d9e8a0329a759a704d15ecc27fe29 Mon Sep 17 00:00:00 2001 From: hoodie13 <74173949+hoodie13@users.noreply.github.com> Date: Sat, 13 Mar 2021 09:09:18 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86epub?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt index 77246e20b..a209cf533 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt @@ -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