mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -16,7 +16,6 @@ import me.ag2s.epublib.domain.EpubBook
|
||||
import me.ag2s.epublib.domain.Resource
|
||||
import me.ag2s.epublib.domain.TOCReference
|
||||
import me.ag2s.epublib.epub.EpubReader
|
||||
import me.ag2s.epublib.util.StringUtil
|
||||
import me.ag2s.epublib.util.zip.AndroidZipFile
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Element
|
||||
@@ -25,6 +24,7 @@ import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.URI
|
||||
import java.net.URLDecoder
|
||||
import java.nio.charset.Charset
|
||||
|
||||
@@ -245,11 +245,7 @@ class EpubFile(var book: Book) {
|
||||
}
|
||||
bodyElement.select("img").forEach {
|
||||
val src = it.attr("src")
|
||||
val path = res.href.substringBeforeLast("/", "")
|
||||
if (path.isNotEmpty()) {
|
||||
val absSrc = StringUtil.collapsePathDots("$path/$src")
|
||||
it.attr("src", absSrc)
|
||||
}
|
||||
it.attr("src", URI(res.href).resolve(src).toString())
|
||||
}
|
||||
return bodyElement
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.legado.app.ui.book.read.page.entities.TextPage
|
||||
import io.legado.app.ui.book.read.page.entities.column.ImageColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.ReviewColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.TextColumn
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.RealPathUtil
|
||||
import io.legado.app.utils.dpToPx
|
||||
import io.legado.app.utils.fastSum
|
||||
@@ -816,6 +817,9 @@ object ChapterProvider {
|
||||
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
|
||||
val bodyIndent = ReadBookConfig.paragraphIndent
|
||||
indentCharWidth = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length
|
||||
LogUtils.d("ChapterProvider") {
|
||||
"bodyIndentLength:${bodyIndent.length} indentCharWidth:$indentCharWidth"
|
||||
}
|
||||
titlePaintTextHeight = titlePaint.textHeight
|
||||
contentPaintTextHeight = contentPaint.textHeight
|
||||
titlePaintFontMetrics = titlePaint.fontMetrics
|
||||
@@ -885,9 +889,17 @@ object ChapterProvider {
|
||||
//正文
|
||||
val cPaint = TextPaint()
|
||||
cPaint.color = ReadBookConfig.textColor
|
||||
cPaint.letterSpacing = ReadBookConfig.letterSpacing
|
||||
cPaint.letterSpacing = ReadBookConfig.letterSpacing.also {
|
||||
LogUtils.d("ChapterProvider") {
|
||||
"ReadBookConfig.letterSpacing:$it"
|
||||
}
|
||||
}
|
||||
cPaint.typeface = textFont
|
||||
cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx()
|
||||
cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx().also {
|
||||
LogUtils.d("ChapterProvider") {
|
||||
"ReadBookConfig.textSize:$it"
|
||||
}
|
||||
}
|
||||
cPaint.isAntiAlias = true
|
||||
cPaint.isLinearText = true
|
||||
return Pair(tPaint, cPaint)
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.legado.app.ui.book.read.page.entities.TextPage
|
||||
import io.legado.app.ui.book.read.page.entities.column.ImageColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.ReviewColumn
|
||||
import io.legado.app.ui.book.read.page.entities.column.TextColumn
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.dpToPx
|
||||
import io.legado.app.utils.fastSum
|
||||
import io.legado.app.utils.splitNotBlank
|
||||
@@ -29,6 +30,8 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import java.util.LinkedList
|
||||
import java.util.Locale
|
||||
import kotlin.coroutines.coroutineContext
|
||||
@@ -81,13 +84,19 @@ class TextChapterLayout(
|
||||
|
||||
var channel = Channel<TextPage>(Int.MAX_VALUE)
|
||||
|
||||
companion object {
|
||||
val lock = Mutex()
|
||||
}
|
||||
|
||||
init {
|
||||
job = Coroutine.async(scope) {
|
||||
launch {
|
||||
val bookSource = book.getBookSource() ?: return@launch
|
||||
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
|
||||
}
|
||||
getTextChapter(book, bookChapter, displayTitle, bookContent)
|
||||
lock.withLock {
|
||||
getTextChapter(book, bookChapter, displayTitle, bookContent)
|
||||
}
|
||||
}.onError {
|
||||
exception = it
|
||||
onException(it)
|
||||
@@ -650,7 +659,20 @@ class TextChapterLayout(
|
||||
val gapCount: Int = words.lastIndex
|
||||
val d = residualWidth / gapCount
|
||||
textLine.extraLetterSpacingOffsetX = -d / 2
|
||||
textLine.extraLetterSpacing = d / textPaint.textSize
|
||||
val textSize = textPaint.textSize
|
||||
textLine.extraLetterSpacing = d / textSize
|
||||
LogUtils.d("TextChapterLayout") {
|
||||
"words:$words"
|
||||
}
|
||||
LogUtils.d("TextChapterLayout") {
|
||||
"textWidths:$textWidths"
|
||||
}
|
||||
LogUtils.d("TextChapterLayout") {
|
||||
"textSize:$textSize desiredWidth:$desiredWidth residualWidth:$residualWidth " +
|
||||
"gapCount:$gapCount d:$d " +
|
||||
"extraLetterSpacingOffsetX:${textLine.extraLetterSpacingOffsetX} " +
|
||||
"extraLetterSpacing:${textLine.extraLetterSpacing}"
|
||||
}
|
||||
var x = startX
|
||||
for (index in words.indices) {
|
||||
val char = words[index]
|
||||
|
||||
Reference in New Issue
Block a user