diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt index ed0d482cb..054939d0b 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt @@ -11,5 +11,6 @@ data class ContentRule( var sourceRegex: String? = null, var replaceRegex: String? = null, var imageStyle: String? = null, //默认大小居中,FULL最大宽度 - var font: String? = null //必须返回ByteArray + var font: String? = null, //网页内包含的字体必须返回ByteArray + var correctFont: String? = null, //正确的字体必须返回ByteArray ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index c692be75e..c0161c2a1 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -10,6 +10,7 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* import org.jsoup.Connection import org.jsoup.Jsoup +import java.io.File import java.net.URLEncoder import java.nio.charset.Charset import java.util.* @@ -19,7 +20,7 @@ import java.util.* interface JsExtensions { /** - * js实现跨域访问,不能删 + * 访问网络,返回String */ fun ajax(urlStr: String): String? { return try { @@ -32,6 +33,9 @@ interface JsExtensions { } } + /** + * 访问网络,返回Response + */ fun connect(urlStr: String): Any { return try { val analyzeUrl = AnalyzeUrl(urlStr) @@ -44,7 +48,7 @@ interface JsExtensions { } /** - * js实现文件下载 + * 实现文件下载,返回路径 */ fun downloadFile(content: String, url: String): String { val type = AnalyzeUrl(url).type ?: return "type为空,未下载" @@ -111,6 +115,9 @@ interface JsExtensions { .execute() } + /** + * 网络访问post + */ fun post(urlStr: String, body: String, headers: Map): Connection.Response { return Jsoup.connect(urlStr) .sslSocketFactory(SSLHelper.unsafeSSLSocketFactory) @@ -146,6 +153,20 @@ interface JsExtensions { return EncoderUtils.base64Decode(str, flags) } + fun base64DecodeToByteArray(str: String?): ByteArray? { + if (str.isNullOrBlank()) { + return null + } + return Base64.decode(str, Base64.DEFAULT) + } + + fun base64DecodeToByteArray(str: String?, flags: Int): ByteArray? { + if (str.isNullOrBlank()) { + return null + } + return Base64.decode(str, flags) + } + fun base64Encode(str: String): String? { return EncoderUtils.base64Encode(str, Base64.NO_WRAP) } @@ -162,11 +183,16 @@ interface JsExtensions { return MD5Utils.md5Encode16(str) } + /** + * 时间格式化 + */ fun timeFormat(time: Long): String { return dateFormat.format(Date(time)) } - //utf8编码转gbk编码 + /** + * utf8编码转gbk编码 + */ fun utf8ToGbk(str: String): String { val utf8 = String(str.toByteArray(charset("UTF-8"))) val unicode = String(utf8.toByteArray(), charset("UTF-8")) @@ -193,20 +219,16 @@ interface JsExtensions { return str.htmlFormat() } - fun base64DecodeToByteArray(str: String?): ByteArray? { - if (str.isNullOrBlank()) { - return null - } - return Base64.decode(str, Base64.DEFAULT) - } - - fun base64DecodeToByteArray(str: String?, flags: Int): ByteArray? { - if (str.isNullOrBlank()) { - return null - } - return Base64.decode(str, flags) + /** + * 读取本地文件 + */ + fun readFile(path: String): ByteArray? { + return File(path).readBytes() } + /** + * 输出调试日志 + */ fun log(msg: String) { Debug.log(msg) } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.kt b/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.kt index bb8da0789..02fcb2e3e 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.kt @@ -9,7 +9,7 @@ import kotlin.experimental.and * @see 获取详情 * @see 基于Javascript的TTF解析器 */ -class QueryTTF(var Font: Array) : JsExtensions { +class QueryTTF(var Font: ByteArray) : JsExtensions { private class Header { var majorVersion: UShort = 0u var minorVersion: UShort = 0u @@ -150,7 +150,7 @@ class QueryTTF(var Font: Array) : JsExtensions { lateinit var yCoordinates: ArrayList } - private class ByteArrayReader(var Buffer: Array, var Index: Int) { + private class ByteArrayReader(var Buffer: ByteArray, var Index: Int) { fun ReadUIntX(len: Long): ULong { var result: ULong = 0u; for (i in 0 until len) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 136088f51..bf7a61475 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -234,6 +234,7 @@ class BookSourceEditActivity : add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex)) add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style)) add(EditEntity("font", cr?.font, R.string.rule_font)) + add(EditEntity("correctFont", cr?.font, R.string.rule_correct_font)) } //发现 val er = source?.getExploreRule() @@ -338,6 +339,7 @@ class BookSourceEditActivity : "replaceRegex" -> contentRule.replaceRegex = it.value "imageStyle" -> contentRule.imageStyle = it.value "font" -> contentRule.font = it.value + "correctFont" -> contentRule.font = it.value } } source.ruleSearch = searchRule diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 57f2f452a..44fad2b64 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -412,7 +412,8 @@ 正文下一頁 URL 規則 (nextContentUrl) webJs 資源正則 (sourceRegex) - 字體(font) + 网页内嵌字體(font) + 正确字体(font) 圖標 (sourceIcon) 列表規則 (ruleArticles) diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 438097813..47622207e 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -413,7 +413,8 @@ 正文下一頁URL規則(nextContentUrl) webJs 資源正則(sourceRegex) - 字體(font) + 网页内嵌字體(font) + 正确字体(font) 圖示(sourceIcon) 列表規則(ruleArticles) diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 7e5360666..8c54fd559 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -418,7 +418,8 @@ 正文下一页URL规则(nextContentUrl) webJs 资源正则(sourceRegex) - 字体(font) + 网页内嵌字体(font) + 正确字体(font) 图标(sourceIcon) 列表规则(ruleArticles) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index adb2d20a5..5132b8358 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -422,7 +422,8 @@ 资源正则(sourceRegex) 替换规则(replaceRegex) 图片样式(imageStyle) - 字体(font) + 网页内嵌字体(font) + 正确字体(font) 图标(sourceIcon) 列表规则(ruleArticles)