Fix fit height to in new renderer and bump webgpuviewer (#3801)

This commit is contained in:
w
2026-08-17 10:08:09 -07:00
committed by GitHub
parent c613b52503
commit f75f2598a3
2 changed files with 65 additions and 1 deletions
@@ -884,6 +884,7 @@ open class WebGpuViewer(
oldImagePage.cleanup() oldImagePage.cleanup()
} }
applyWideZoomIfNeeded(page) applyWideZoomIfNeeded(page)
applyFitModeAnchor(page.imagePage)
pager.state.invalidate() pager.state.invalidate()
} else { } else {
if (pageInCache(page)) page.state = PageState.IDLE if (pageInCache(page)) page.state = PageState.IDLE
@@ -1018,6 +1019,69 @@ open class WebGpuViewer(
} }
} }
private fun applyFitModeAnchor(page: ImagePage) {
if (page.homeScaleOverride != null) return
val scaleType = config.imageScaleType
if (scaleType != 3 && scaleType != 4 && scaleType != 5) return
val image = page.image ?: return
if (image.position != Image.Position.SINGLE) return
val screenW = pager.state.width
val screenH = pager.state.height
if (screenW <= 0 || screenH <= 0) return
val w = page.trimWidth.toFloat()
val h = page.trimHeight.toFloat()
if (w <= 0f || h <= 0f) return
val cutoutTopPx = pager.state.cutoutTopPx
val contentW = screenW.toFloat()
val contentH = if (pager.state.avoidCutout && cutoutTopPx > 0f) screenH - cutoutTopPx else screenH.toFloat()
val homeScale = when (scaleType) {
3 -> contentW / w
4 -> contentH / h
else -> 1f // original size
}.coerceAtLeast(0.01f)
page.homeScaleOverride = homeScale
if (scaleType == 5) { // original size
val minScaleComputed = minOf(contentW / page.width, contentH / page.height).coerceAtLeast(0.01f)
if (homeScale < minScaleComputed) {
page.minScale = homeScale
}
}
// zoom start for fit height/original size
page.homeXOverride = if (scaleType == 4 || scaleType == 5) {
val maxX = maxOf(0f, (page.width.toFloat() / screenW - 1f / homeScale) / 2f)
when (config.imageZoomType) {
ZoomStartPosition.LEFT -> maxX
ZoomStartPosition.RIGHT -> -maxX
ZoomStartPosition.CENTER -> 0f
}
} else {
null
}
// push below cutout for fit width/original size
val trimTop = image.trim?.top ?: 0
val imageTopY = (screenH - page.height * homeScale) / 2f
val trimTopY = imageTopY + trimTop * homeScale
page.homeYOverride = if ((scaleType == 3 || scaleType == 5) && h * homeScale > screenH) {
val target = if (pager.state.avoidCutout && cutoutTopPx > 0f) {
if (pager.state.alwaysAvoidCutout) cutoutTopPx / 2f else cutoutTopPx
} else {
0f
}
maxOf(0f, (target - trimTopY) / (homeScale * screenH))
} else {
null
}
}
/** /**
* Queue a page for decoding. If prioritize=true, moves existing queued page to front. * Queue a page for decoding. If prioritize=true, moves existing queued page to front.
*/ */
+1 -1
View File
@@ -76,7 +76,7 @@ swipe = "1.3.0"
tapmoc = "0.4.2" tapmoc = "0.4.2"
unifile = "08f224c8f9" unifile = "08f224c8f9"
voyager = "2.2.21-1.10.3" voyager = "2.2.21-1.10.3"
webgpuviewer = "25" webgpuviewer = "28"
xmlutil = "1.0.2" xmlutil = "1.0.2"
[libraries] [libraries]