From cd0d7dccc76a0e3427c45aee7e4500fd29ac477d Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 8 Mar 2021 08:52:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/provider/ZhLayout.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 4ed32e41c..c35c7f730 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 @@ -18,9 +18,10 @@ class ZhLayout( textPaint: TextPaint, width: Int ) : Layout(text, textPaint, width, Alignment.ALIGN_NORMAL, 0f, 0f) { - var lineStart = IntArray(100) - var lineWidth = FloatArray(100) - var lineCompressMod = IntArray(100) + private val defaultCapacity = 10 + var lineStart = IntArray(defaultCapacity) + var lineWidth = FloatArray(defaultCapacity) + var lineCompressMod = IntArray(defaultCapacity) private var lineCount = 0 private val curPaint = textPaint private val cnCharWitch = getDesiredWidth("我", textPaint) @@ -173,10 +174,10 @@ class ZhLayout( } private fun addLineArray(line: Int) { - if (lineStart.size <= line) { - lineStart = lineStart.copyOf(line + 100) - lineWidth = lineWidth.copyOf(line + 100) - lineCompressMod = lineCompressMod.copyOf(line + 100) + if (lineStart.size <= line + 1) { + lineStart = lineStart.copyOf(line + defaultCapacity) + lineWidth = lineWidth.copyOf(line + defaultCapacity) + lineCompressMod = lineCompressMod.copyOf(line + defaultCapacity) } }