正文规则添加字体

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. 16
      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
)
@ -82,7 +90,13 @@ object BookContent {
.body?.let {
contentData =
analyzeContent(
book, item.nextUrl, it, contentRule, bookChapter, bookSource, false
book,
item.nextUrl,
it,
contentRule,
bookChapter,
bookSource,
false
)
item.content = contentData.content
}

Loading…
Cancel
Save