From 4930f76e03acada9486aa1099d412fec934017ea Mon Sep 17 00:00:00 2001 From: Carlo Baratto Date: Wed, 12 Aug 2026 15:49:19 +0200 Subject: [PATCH] ReaderPage: reflow con A-/A+ (font-size via JS con !important, posizione conservata in frazione) --- qml/pages/ReaderPage.qml | 52 ++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/qml/pages/ReaderPage.qml b/qml/pages/ReaderPage.qml index 45843f0..8ba1d9a 100644 --- a/qml/pages/ReaderPage.qml +++ b/qml/pages/ReaderPage.qml @@ -17,6 +17,8 @@ Page { property int saveCounter: 0 property int syncCounter: 0 property string errorMessage: "" + // reflow: scala il font (il testo si ri-avvolge), non lo zoom grafico + property double fontScale: 1.0 allowedOrientations: Orientation.All @@ -53,9 +55,8 @@ Page { loadWatchdog.stop() if (page.restoring) page.restoring = false - else - restorePosition() page.ready = true + applyFontScale() } } } @@ -110,9 +111,31 @@ Page { 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 { id: chapterLabel - anchors.left: prevBtn.right + anchors.left: fontPlus.right anchors.right: nextBtn.left anchors.verticalCenter: parent.verticalCenter text: (book.chapterCount > 0) @@ -208,13 +231,22 @@ Page { web.url = "file://" + book.chapterFilePath(index) } - function restorePosition() { - if (page.chapterFraction > 0.01) { - web.runJavaScript( - "window.scrollTo(0, " + page.chapterFraction - + " * Math.max(1, document.documentElement.scrollHeight - window.innerHeight)); true", - function() { }) - } + function changeFontScale(delta) { + page.fontScale = Math.max(0.7, Math.min(2.5, page.fontScale + delta)) + applyFontScale() + } + + // 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() {