正文规则添加图片样式规则,可以设置为FULL

pull/279/head
gedoor 4 years ago
parent 5f06b4afd6
commit 3436708a94
  1. 26
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 40
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -313,7 +313,13 @@ object ReadBook {
when (chapter.index) { when (chapter.index) {
durChapterIndex -> { durChapterIndex -> {
curTextChapter = curTextChapter =
ChapterProvider.getTextChapter(book, chapter, contents, chapterSize) ChapterProvider.getTextChapter(
book,
chapter,
contents,
chapterSize,
imageStyle
)
if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset) if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset)
callBack?.upView() callBack?.upView()
curPageChanged() curPageChanged()
@ -322,12 +328,24 @@ object ReadBook {
} }
durChapterIndex - 1 -> { durChapterIndex - 1 -> {
prevTextChapter = prevTextChapter =
ChapterProvider.getTextChapter(book, chapter, contents, chapterSize) ChapterProvider.getTextChapter(
book,
chapter,
contents,
chapterSize,
imageStyle
)
if (upContent) callBack?.upContent(-1, resetPageOffset) if (upContent) callBack?.upContent(-1, resetPageOffset)
} }
durChapterIndex + 1 -> { durChapterIndex + 1 -> {
nextTextChapter = nextTextChapter =
ChapterProvider.getTextChapter(book, chapter, contents, chapterSize) ChapterProvider.getTextChapter(
book,
chapter,
contents,
chapterSize,
imageStyle
)
if (upContent) callBack?.upContent(1, resetPageOffset) if (upContent) callBack?.upContent(1, resetPageOffset)
} }
} }
@ -338,6 +356,8 @@ object ReadBook {
} }
} }
private val imageStyle get() = webBook?.bookSource?.ruleContent?.imageStyle
fun saveRead() { fun saveRead() {
Coroutine.async { Coroutine.async {
book?.let { book -> book?.let { book ->

@ -51,7 +51,8 @@ object ChapterProvider {
book: Book, book: Book,
bookChapter: BookChapter, bookChapter: BookChapter,
contents: List<String>, contents: List<String>,
chapterSize: Int chapterSize: Int,
imageStyle: String?
): TextChapter { ): TextChapter {
val textPages = arrayListOf<TextPage>() val textPages = arrayListOf<TextPage>()
val pageLines = arrayListOf<Int>() val pageLines = arrayListOf<Int>()
@ -69,7 +70,7 @@ object ChapterProvider {
src?.let { src?.let {
durY = durY =
setTypeImage( setTypeImage(
book, bookChapter, src, durY, textPages book, bookChapter, src, durY, textPages, imageStyle
) )
} }
} else { } else {
@ -116,25 +117,32 @@ object ChapterProvider {
chapter: BookChapter, chapter: BookChapter,
src: String, src: String,
y: Float, y: Float,
textPages: ArrayList<TextPage> textPages: ArrayList<TextPage>,
imageStyle: String?
): Float { ): Float {
var durY = y var durY = y
ImageProvider.getImage(book, chapter.index, src)?.let { ImageProvider.getImage(book, chapter.index, src)?.let {
var height = it.height var height = it.height
var width = it.width var width = it.width
if (it.width > visibleWidth) { when (imageStyle?.toUpperCase()) {
height = it.height * visibleWidth / it.width "FULL" -> {
width = width = visibleWidth
visibleWidth height = it.width / width * it.height
} }
if (height > visibleHeight) { else -> {
width = width * visibleHeight / height if (it.width > visibleWidth) {
height = height = it.height * visibleWidth / it.width
visibleHeight width = visibleWidth
} }
if (durY + height > visibleHeight) { if (height > visibleHeight) {
textPages.add(TextPage()) width = width * visibleHeight / height
durY = 0f height = visibleHeight
}
if (durY + height > visibleHeight) {
textPages.add(TextPage())
durY = 0f
}
}
} }
val textLine = TextLine(isImage = true) val textLine = TextLine(isImage = true)
textLine.lineTop = durY textLine.lineTop = durY

Loading…
Cancel
Save