优化
This commit is contained in:
@@ -171,18 +171,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
|||||||
book,
|
book,
|
||||||
textChar.charData,
|
textChar.charData,
|
||||||
ReadBook.bookSource,
|
ReadBook.bookSource,
|
||||||
true
|
(textChar.end - textChar.start).toInt(),
|
||||||
)?.let {
|
(lineBottom - lineTop).toInt()
|
||||||
|
)?.let { bitmap ->
|
||||||
val rectF = if (isImageLine) {
|
val rectF = if (isImageLine) {
|
||||||
RectF(textChar.start, lineTop, textChar.end, lineBottom)
|
RectF(textChar.start, lineTop, textChar.end, lineBottom)
|
||||||
} else {
|
} else {
|
||||||
/*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/
|
/*以宽度为基准保持图片的原始比例叠加,当div为负数时,允许高度比字符更高*/
|
||||||
val h = (textChar.end - textChar.start) / it.width * it.height
|
val h = (textChar.end - textChar.start) / bitmap.width * bitmap.height
|
||||||
val div = (lineBottom - lineTop - h) / 2
|
val div = (lineBottom - lineTop - h) / 2
|
||||||
RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div)
|
RectF(textChar.start, lineTop + div, textChar.end, lineBottom - div)
|
||||||
}
|
}
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
canvas.drawBitmap(it, null, rectF, null)
|
canvas.drawBitmap(bitmap, null, rectF, null)
|
||||||
}.onFailure { e ->
|
}.onFailure { e ->
|
||||||
context.toastOnUi(e.localizedMessage)
|
context.toastOnUi(e.localizedMessage)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,41 +66,54 @@ object ImageProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getImage(
|
fun getImage(
|
||||||
book: Book,
|
book: Book,
|
||||||
src: String,
|
src: String,
|
||||||
bookSource: BookSource?,
|
bookSource: BookSource?,
|
||||||
onUi: Boolean = false,
|
width: Int,
|
||||||
|
height: Int
|
||||||
): Bitmap? {
|
): Bitmap? {
|
||||||
val vFile = BookHelp.getImage(book, src)
|
val vFile = runBlocking {
|
||||||
if (!vFile.exists()) {
|
cacheImage(book, src, bookSource)
|
||||||
if (book.isEpub()) {
|
}
|
||||||
EpubFile.getImage(book, src)?.use { input ->
|
return try {
|
||||||
val newFile = FileUtils.createFileIfNotExist(vFile.absolutePath)
|
ImageLoader.loadBitmap(appCtx, vFile.absolutePath)
|
||||||
FileOutputStream(newFile).use { output ->
|
.submit(width, height)
|
||||||
input.copyTo(output)
|
.get()
|
||||||
}
|
} catch (e: Exception) {
|
||||||
}
|
Coroutine.async {
|
||||||
} else if (!onUi) {
|
putDebug("${vFile.absolutePath} 解码失败", e)
|
||||||
runBlocking {
|
if (FileUtils.readText(vFile.absolutePath).isXml()) {
|
||||||
BookHelp.saveImage(bookSource, book, src)
|
putDebug("${vFile.absolutePath}为xml,自动删除")
|
||||||
|
vFile.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
errorBitmap
|
||||||
}
|
}
|
||||||
return try {
|
}
|
||||||
|
|
||||||
|
fun getImage(
|
||||||
|
book: Book,
|
||||||
|
src: String,
|
||||||
|
bookSource: BookSource?
|
||||||
|
): Bitmap? {
|
||||||
|
val vFile = runBlocking {
|
||||||
|
cacheImage(book, src, bookSource)
|
||||||
|
}
|
||||||
|
return try {
|
||||||
ImageLoader.loadBitmap(appCtx, vFile.absolutePath)
|
ImageLoader.loadBitmap(appCtx, vFile.absolutePath)
|
||||||
.submit(ChapterProvider.visibleWidth,ChapterProvider.visibleHeight)
|
.submit(ChapterProvider.visibleWidth, ChapterProvider.visibleHeight)
|
||||||
.get()
|
.get()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
putDebug("${vFile.absolutePath} 解码失败", e)
|
putDebug("${vFile.absolutePath} 解码失败", e)
|
||||||
if (FileUtils.readText(vFile.absolutePath).isXml()) {
|
if (FileUtils.readText(vFile.absolutePath).isXml()) {
|
||||||
putDebug("${vFile.absolutePath}为xml,自动删除")
|
putDebug("${vFile.absolutePath}为xml,自动删除")
|
||||||
vFile.delete()
|
vFile.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorBitmap
|
errorBitmap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user