pull/275/head
gedoor 4 years ago
parent d37cec0822
commit f540e2f2a5
  1. 3
      app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  4. 3
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  5. 16
      app/src/main/java/io/legado/app/utils/StringExtensions.kt
  6. 10
      app/src/main/java/io/legado/app/utils/StringUtils.kt

@ -8,5 +8,6 @@ data class ContentRule(
var content: String? = null,
var nextContentUrl: String? = null,
var webJs: String? = null,
var sourceRegex: String? = null
var sourceRegex: String? = null,
var imageStyle: Int = 0 //0默认大小居中,1最大宽度
) : Parcelable

@ -158,7 +158,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
) {
textLine.textChars.forEach { textChar ->
val rectF = RectF(textChar.start, lineTop, textChar.end, lineBottom)
ImageProvider.getImage(ReadBook.book!!, textChar.charData)?.let {
ImageProvider.getImage(
ReadBook.book!!,
textPage.chapterIndex,
textChar.charData
)?.let {
canvas.drawBitmap(it, null, rectF, null)
}
}

@ -69,7 +69,7 @@ object ChapterProvider {
src?.let {
durY =
setTypeImage(
book, src, durY, textPages
book, bookChapter, src, durY, textPages
)
}
} else {
@ -113,12 +113,13 @@ object ChapterProvider {
private fun setTypeImage(
book: Book,
chapter: BookChapter,
src: String,
y: Float,
textPages: ArrayList<TextPage>
): Float {
var durY = y
ImageProvider.getImage(book, src)?.let {
ImageProvider.getImage(book, chapter.index, src)?.let {
var height = it.height
var width = it.width
if (it.width > visibleWidth) {

@ -13,8 +13,9 @@ import java.io.FileOutputStream
object ImageProvider {
val bitmaps = hashMapOf<String, Bitmap?>()
fun getImage(book: Book, src: String): Bitmap? {
fun getImage(book: Book, chapterIndex: Int, src: String): Bitmap? {
val vFile = FileUtils.getFile(
App.INSTANCE.externalFilesDir,
"${MD5Utils.md5Encode16(src)}.jpg",

@ -1,5 +1,8 @@
package io.legado.app.utils
val removeHtmlRegex =
"</?(?:html|head|div|a|p|b|br|hr|h\\d|article|dd|dl|span|link|title)[^>]*>".toRegex()
fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim()
fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true
@ -32,12 +35,13 @@ fun String?.isJsonArray(): Boolean =
str.startsWith("[") && str.endsWith("]")
} ?: false
fun String?.htmlFormat(): String =
this?.replace("</?(?:div|p|b|br|hr|h\\d|article|dd|dl|span|link|title)[^>]*>".toRegex(), "\n")
?.replace("\\s*\\n+\\s*".toRegex(), "\n  ")
?.replace("^[\\n\\s]+".toRegex(), "  ")
?.replace("[\\n\\s]+$".toRegex(), "")
?: ""
fun String?.htmlFormat(): String {
this ?: return ""
return this.replace(removeHtmlRegex, "\n")
.replace("\\s*\\n+\\s*".toRegex(), "\n  ")
.replace("^[\\n\\s]+".toRegex(), "  ")
.replace("[\\n\\s]+$".toRegex(), "")
}
fun String.splitNotBlank(vararg delimiter: String): Array<String> = run {
this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray()

@ -274,14 +274,4 @@ object StringUtils {
return buf.toString()
}
fun formatHtml(html: String): String {
return if (isEmpty(html)) "" else html.replace(
"(?i)<(br[\\s/]*|/*p.*?|/*div.*?)>".toRegex(),
"\n"
)// 替换特定标签为换行符
.replace("<[script>]*.*?>|&nbsp;".toRegex(), "")// 删除script标签对和空格转义符
.replace("\\s*\\n+\\s*".toRegex(), "\n  ")// 移除空行,并增加段前缩进2个汉字
.replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字
.replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行
}
}

Loading…
Cancel
Save