Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图片样式新增single,调整为【滑动/覆盖 + single】可实现一页一图,且图片为当前页面能显示的最大化 #4463

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/data/entities/Book.kt
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ data class Book(
const val imgStyleDefault = "DEFAULT"
const val imgStyleFull = "FULL"
const val imgStyleText = "TEXT"
const val imgStyleSingle = "SINGLE"
}

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ class ReadBookActivity : BaseReadBookActivity(),
R.id.menu_set_charset -> showCharsetConfig()
R.id.menu_image_style -> {
val imgStyles =
arrayListOf(Book.imgStyleDefault, Book.imgStyleFull, Book.imgStyleText)
arrayListOf(Book.imgStyleDefault, Book.imgStyleFull, Book.imgStyleText, Book.imgStyleSingle)
selector(
R.string.image_style,
imgStyles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,36 @@ object ChapterProvider {
height = size.height * visibleWidth / size.width
}

Book.imgStyleSingle -> {
width = visibleWidth
height = size.height * visibleWidth / size.width
if (height > visibleHeight) {
width = width * visibleHeight / height
height = visibleHeight
}
if (durY > 0f) {
val textPage = textPages.last()
if (doublePage && absStartX < viewWidth / 2) {
//当前页面左列结束
textPage.leftLineSize = textPage.lineSize
absStartX = viewWidth / 2 + paddingLeft
} else {
//当前页面结束
if (textPage.leftLineSize == 0) {
textPage.leftLineSize = textPage.lineSize
}
textPage.text = stringBuilder.toString().ifEmpty { "本页无文字内容" }
stringBuilder.clear()
textPages.add(TextPage())
}
// 双页的 durY 不正确,可能会小于实际高度
if (textPage.height < durY) {
textPage.height = durY
}
durY = 0f
}
}

else -> {
if (size.width > visibleWidth) {
height = size.height * visibleWidth / size.width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,39 @@ class TextChapterLayout(
height = size.height * visibleWidth / size.width
}

Book.imgStyleSingle -> {
width = ChapterProvider.visibleWidth
height = size.height * ChapterProvider.visibleWidth / size.width
if (height > ChapterProvider.visibleHeight) {
width = width * ChapterProvider.visibleHeight / height
height = ChapterProvider.visibleHeight
}
if (durY > 0f) {
val textPage = pendingTextPage
// 双页的 durY 不正确,可能会小于实际高度
if (textPage.height < durY) {
textPage.height = durY
}
if (doublePage && absStartX < viewWidth / 2) {
//当前页面左列结束
textPage.leftLineSize = textPage.lineSize
absStartX = viewWidth / 2 + paddingLeft
} else {
//当前页面结束
if (textPage.leftLineSize == 0) {
textPage.leftLineSize = textPage.lineSize
}
textPage.text = stringBuilder.toString().ifEmpty { "本页无文字内容" }
stringBuilder.clear()
textPages.add(textPage)
coroutineContext.ensureActive()
onPageCompleted()
pendingTextPage = TextPage()
}
durY = 0f
}
}

else -> {
if (size.width > visibleWidth) {
height = size.height * visibleWidth / size.width
Expand Down
Loading