From 1eae98fc2704016303ae47169b7d9c853f7500b8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 22 Nov 2020 17:57:50 +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 --- .../legado/app/model/analyzeRule/AnalyzeRule.kt | 4 ++-- .../io/legado/app/model/webBook/BookContent.kt | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index d72dc8f73..22f7e8e13 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -298,7 +298,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { return ArrayList() } - fun getByteArray(ruleStr: String): ByteArray? { + fun getResult(ruleStr: String): Any? { if (ruleStr.isEmpty()) return null val ruleList = splitSourceRule(ruleStr) var result: Any? = null @@ -323,7 +323,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } } - return result as? ByteArray + return result } /** diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 760e8efd1..40597eab7 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -39,16 +39,16 @@ object BookContent { val fontRule = contentRule.font val correctFontRule = contentRule.correctFont var font: ByteArray? = null - var correctFont: ByteArray? = null + var cQueryTTF: QueryTTF? = null fontRule?.let { //todo 获取网页嵌入字体 - font = analyzeRule.getByteArray(it) + font = analyzeRule.getResult(it) as? ByteArray } correctFontRule?.let { //todo 获取正确字体 - correctFont = analyzeRule.getByteArray(it) + cQueryTTF = analyzeRule.getResult(it) as? QueryTTF } - if (correctFont == null && font != null) { + if (cQueryTTF == null && font != null) { BookHelp.saveFont(book, bookChapter, font!!) } var contentData = analyzeContent( @@ -114,13 +114,12 @@ object BookContent { analyzeRule.chapter = bookChapter contentStr = analyzeRule.getString(replaceRegex) } - if (correctFont != null && font != null) { + if (cQueryTTF != null && font != null) { val queryTTF = QueryTTF(font!!) - val cQueryTTF = QueryTTF(correctFont!!) val contentArray = contentStr.toCharArray() contentArray.forEachIndexed { index, s -> - if(s> 58000.toChar()){ - val code = cQueryTTF.GetCodeByGlyf(queryTTF.GetGlyfByCode(s.toInt())) + if (s > 58000.toChar()) { + val code = cQueryTTF!!.GetCodeByGlyf(queryTTF.GetGlyfByCode(s.toInt())) contentArray[index] = code.toChar() } }