ReaderPage: reflow con A-/A+ (font-size via JS con !important, posizione conservata in frazione)

This commit is contained in:
2026-08-12 15:49:19 +02:00
parent a5f469a73f
commit 4930f76e03
+41 -9
View File
@@ -17,6 +17,8 @@ Page {
property int saveCounter: 0 property int saveCounter: 0
property int syncCounter: 0 property int syncCounter: 0
property string errorMessage: "" property string errorMessage: ""
// reflow: scala il font (il testo si ri-avvolge), non lo zoom grafico
property double fontScale: 1.0
allowedOrientations: Orientation.All allowedOrientations: Orientation.All
@@ -53,9 +55,8 @@ Page {
loadWatchdog.stop() loadWatchdog.stop()
if (page.restoring) if (page.restoring)
page.restoring = false page.restoring = false
else
restorePosition()
page.ready = true page.ready = true
applyFontScale()
} }
} }
} }
@@ -110,9 +111,31 @@ Page {
onClicked: gotoChapter(page.currentChapter - 1) onClicked: gotoChapter(page.currentChapter - 1)
} }
Button {
id: fontMinus
anchors.left: prevBtn.right
anchors.verticalCenter: parent.verticalCenter
width: Theme.itemSizeSmall
height: Theme.itemSizeMedium
text: "A"
font.pixelSize: Theme.fontSizeSmall
onClicked: page.changeFontScale(-0.15)
}
Button {
id: fontPlus
anchors.left: fontMinus.right
anchors.verticalCenter: parent.verticalCenter
width: Theme.itemSizeSmall
height: Theme.itemSizeMedium
text: "A+"
font.pixelSize: Theme.fontSizeSmall
onClicked: page.changeFontScale(0.15)
}
Label { Label {
id: chapterLabel id: chapterLabel
anchors.left: prevBtn.right anchors.left: fontPlus.right
anchors.right: nextBtn.left anchors.right: nextBtn.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: (book.chapterCount > 0) text: (book.chapterCount > 0)
@@ -208,13 +231,22 @@ Page {
web.url = "file://" + book.chapterFilePath(index) web.url = "file://" + book.chapterFilePath(index)
} }
function restorePosition() { function changeFontScale(delta) {
if (page.chapterFraction > 0.01) { page.fontScale = Math.max(0.7, Math.min(2.5, page.fontScale + delta))
web.runJavaScript( applyFontScale()
"window.scrollTo(0, " + page.chapterFraction
+ " * Math.max(1, document.documentElement.scrollHeight - window.innerHeight)); true",
function() { })
} }
// reflow: imposta il font-size del documento (il testo si ri-avvolge)
// e ripristina la posizione in frazione sull'altezza ricalcolata
function applyFontScale() {
if (!web.loaded)
return
var px = Math.round(16 * page.fontScale * 100) / 100
var script = "document.documentElement.style.setProperty('font-size', '"
+ px + "px', 'important');"
+ "window.scrollTo(0, " + page.chapterFraction
+ " * Math.max(1, document.documentElement.scrollHeight - window.innerHeight)); true"
web.runJavaScript(script, function() { })
} }
function showChapterList() { function showChapterList() {