正文规则添加字体

pull/475/head
gedoor 4 years ago
parent 50b55076b8
commit b272de377c
  1. 28
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 38
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@ -295,6 +295,34 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
return ArrayList()
}
fun getByteArray(ruleStr: String): ByteArray? {
if (ruleStr.isEmpty()) return null
val ruleList = splitSourceRule(ruleStr)
var result: Any? = null
content?.let { o ->
if (ruleList.isNotEmpty()) result = o
for (sourceRule in ruleList) {
putRule(sourceRule.putMap)
result?.let {
result = when (sourceRule.mode) {
Mode.Regex -> AnalyzeByRegex.getElements(
result.toString(),
sourceRule.rule.splitNotBlank("&&")
)
Mode.Js -> evalJS(sourceRule.rule, result)
Mode.Json -> getAnalyzeByJSonPath(it).getList(sourceRule.rule)
Mode.XPath -> getAnalyzeByXPath(it).getElements(sourceRule.rule)
else -> getAnalyzeByJSoup(it).getElements(sourceRule.rule)
}
if (sourceRule.replaceRegex.isNotEmpty()) {
result = replaceRegex(result.toString(), sourceRule)
}
}
}
}
return result as? ByteArray
}
/**
* 保存变量
*/

@ -33,6 +33,14 @@ object BookContent {
val content = StringBuilder()
val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule()
contentRule.font?.let {
//todo 获取字体
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body).setBaseUrl(baseUrl)
analyzeRule.getByteArray(it)?.let { font ->
}
}
var contentData = analyzeContent(
book, baseUrl, body, contentRule, bookChapter, bookSource
)
@ -56,14 +64,14 @@ object BookContent {
headerMapF = bookSource.getHeaderMap()
).getResponseAwait(bookSource.bookSourceUrl)
.body?.let { nextBody ->
contentData =
analyzeContent(
book, nextUrl, nextBody, contentRule, bookChapter, bookSource, false
)
nextUrl =
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
content.append(contentData.content).append("\n")
}
contentData =
analyzeContent(
book, nextUrl, nextBody, contentRule, bookChapter, bookSource, false
)
nextUrl =
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
content.append(contentData.content).append("\n")
}
}
Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
} else if (contentData.nextUrl.size > 1) {
@ -80,10 +88,16 @@ object BookContent {
headerMapF = bookSource.getHeaderMap()
).getResponseAwait(bookSource.bookSourceUrl)
.body?.let {
contentData =
analyzeContent(
book, item.nextUrl, it, contentRule, bookChapter, bookSource, false
)
contentData =
analyzeContent(
book,
item.nextUrl,
it,
contentRule,
bookChapter,
bookSource,
false
)
item.content = contentData.content
}
}

Loading…
Cancel
Save