Fix center margin breaking image loading
This commit is contained in:
parent
8bab648b44
commit
11b9a71034
@ -343,13 +343,13 @@ class PagerPageHolder(
|
|||||||
private fun mergePages(imageStream: InputStream, imageStream2: InputStream?): InputStream {
|
private fun mergePages(imageStream: InputStream, imageStream2: InputStream?): InputStream {
|
||||||
// Handle adding a center margin to wide images if requested
|
// Handle adding a center margin to wide images if requested
|
||||||
if (imageStream2 == null) {
|
if (imageStream2 == null) {
|
||||||
if (imageStream is BufferedInputStream && ImageUtil.isWideImage(imageStream) &&
|
return if (imageStream is BufferedInputStream && ImageUtil.isWideImage(imageStream) &&
|
||||||
viewer.config.centerMarginType and PagerConfig.CenterMarginType.WIDE_PAGE_CENTER_MARGIN > 0 &&
|
viewer.config.centerMarginType and PagerConfig.CenterMarginType.WIDE_PAGE_CENTER_MARGIN > 0 &&
|
||||||
!viewer.config.imageCropBorders
|
!viewer.config.imageCropBorders
|
||||||
) {
|
) {
|
||||||
return ImageUtil.AddHorizontalCenterMargin(imageStream, getHeight(), context)
|
ImageUtil.addHorizontalCenterMargin(imageStream, height, context)
|
||||||
} else {
|
} else {
|
||||||
return imageStream
|
imageStream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,10 +424,8 @@ class PagerPageHolder(
|
|||||||
imageStream.close()
|
imageStream.close()
|
||||||
imageStream2.close()
|
imageStream2.close()
|
||||||
|
|
||||||
val centerMargin = if (viewer.config.centerMarginType and PagerConfig.CenterMarginType.DOUBLE_PAGE_CENTER_MARGIN > 0 &&
|
val centerMargin = if (viewer.config.centerMarginType and PagerConfig.CenterMarginType.DOUBLE_PAGE_CENTER_MARGIN > 0 && !viewer.config.imageCropBorders) {
|
||||||
!viewer.config.imageCropBorders
|
96 / (getHeight().coerceAtLeast(1) / max(height, height2).coerceAtLeast(1)).coerceAtLeast(1)
|
||||||
) {
|
|
||||||
96 / (max(1, getHeight()) / max(height, height2))
|
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||||||
*/
|
*/
|
||||||
private fun getPageHolder(page: ReaderPage): PagerPageHolder? =
|
private fun getPageHolder(page: ReaderPage): PagerPageHolder? =
|
||||||
pager.children
|
pager.children
|
||||||
.filterIsInstance(PagerPageHolder::class.java)
|
.filterIsInstance<PagerPageHolder>()
|
||||||
.firstOrNull { it.item.first == page || it.item.second == page }
|
.firstOrNull { it.item.first == page || it.item.second == page }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,7 +195,7 @@ object ImageUtil {
|
|||||||
* to compensate for scaling.
|
* to compensate for scaling.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fun AddHorizontalCenterMargin(imageStream: InputStream, viewHeight: Int, backgroundContext: Context): InputStream {
|
fun addHorizontalCenterMargin(imageStream: InputStream, viewHeight: Int, backgroundContext: Context): InputStream {
|
||||||
val imageBitmap = ImageDecoder.newInstance(imageStream)?.decode()!!
|
val imageBitmap = ImageDecoder.newInstance(imageStream)?.decode()!!
|
||||||
val height = imageBitmap.height
|
val height = imageBitmap.height
|
||||||
val width = imageBitmap.width
|
val width = imageBitmap.width
|
||||||
@ -642,18 +642,18 @@ object ImageUtil {
|
|||||||
canvas.drawColor(background)
|
canvas.drawColor(background)
|
||||||
val upperPart = Rect(
|
val upperPart = Rect(
|
||||||
if (isLTR) 0 else width2 + centerMargin,
|
if (isLTR) 0 else width2 + centerMargin,
|
||||||
(maxHeight - imageBitmap.height) / 2,
|
(maxHeight - height) / 2,
|
||||||
(if (isLTR) 0 else width2 + centerMargin) + imageBitmap.width,
|
(if (isLTR) 0 else width2 + centerMargin) + width,
|
||||||
imageBitmap.height + (maxHeight - imageBitmap.height) / 2,
|
height + (maxHeight - height) / 2,
|
||||||
)
|
)
|
||||||
|
|
||||||
canvas.drawBitmap(imageBitmap, imageBitmap.rect, upperPart, null)
|
canvas.drawBitmap(imageBitmap, imageBitmap.rect, upperPart, null)
|
||||||
progressCallback?.invoke(98)
|
progressCallback?.invoke(98)
|
||||||
val bottomPart = Rect(
|
val bottomPart = Rect(
|
||||||
if (!isLTR) 0 else width + centerMargin,
|
if (!isLTR) 0 else width + centerMargin,
|
||||||
(maxHeight - imageBitmap2.height) / 2,
|
(maxHeight - height2) / 2,
|
||||||
(if (!isLTR) 0 else width + centerMargin) + imageBitmap2.width,
|
(if (!isLTR) 0 else width + centerMargin) + width2,
|
||||||
imageBitmap2.height + (maxHeight - imageBitmap2.height) / 2,
|
height2 + (maxHeight - height2) / 2,
|
||||||
)
|
)
|
||||||
|
|
||||||
canvas.drawBitmap(imageBitmap2, imageBitmap2.rect, bottomPart, null)
|
canvas.drawBitmap(imageBitmap2, imageBitmap2.rect, bottomPart, null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user