ReaderPage: reflow con A-/A+ (font-size via JS con !important, posizione conservata in frazione)
This commit is contained in:
+42
-10
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user