diff --git a/qml/pages/ReaderPage.qml b/qml/pages/ReaderPage.qml index 7d43bb6..1b0a8ad 100644 --- a/qml/pages/ReaderPage.qml +++ b/qml/pages/ReaderPage.qml @@ -53,10 +53,15 @@ Page { if (!loaded) return loadWatchdog.stop() - if (page.restoring) - page.restoring = false page.ready = true - applyFontScale() + // ripristina la posizione in frazione sull'altezza ricalcolata + if (page.chapterFraction > 0.01) { + web.runJavaScript( + "window.scrollTo(0," + page.chapterFraction + + "*Math.max(1,document.documentElement.scrollHeight-window.innerHeight));true", + function() { }) + } + page.restoring = false } } } @@ -224,33 +229,32 @@ Page { page.chapterFraction = 0 } page.currentChapter = index - page.restoring = true - page.ready = false - web.url = "file://" + book.chapterFilePath(index) + loadChapter() } function changeFontScale(delta) { page.fontScale = Math.max(0.7, Math.min(2.5, page.fontScale + delta)) - applyFontScale() + // ricarica il capitolo con la nuova dimensione: il reflow avviene al load + loadChapter() } - // reflow: imposta il font-size del documento (il testo si ri-avvolge) - // e ripristina la posizione in frazione sull'altezza ricalcolata. - // Serve uno ") + .arg(fontSizePx); + const int headEnd = html.indexOf(QStringLiteral(""), 0, Qt::CaseInsensitive); + if (headEnd >= 0) + html.insert(headEnd, style); + else + html.prepend(style); + return html; +} + +QString EpubBook::chapterBaseUrl(int index) const +{ + if (index < 0 || index >= m_chapters.size()) + return QString(); + return QUrl::fromLocalFile( + QFileInfo(m_chapters.at(index).path).absolutePath() + QStringLiteral("/")) + .toString(); +} + QString EpubBook::makeBookmarkKey(int chapterIndex, double fraction) const { return QStringLiteral("cw:v1:%1:%2").arg(chapterIndex).arg(fraction, 0, 'f', 4); diff --git a/src/epub.h b/src/epub.h index 2b9498a..b846c5f 100644 --- a/src/epub.h +++ b/src/epub.h @@ -36,6 +36,10 @@ public: Q_INVOKABLE QString chapterTitle(int index) const; // elenco [{index, title}] per la lista capitoli Q_INVOKABLE QVariantList chapterList() const; + // HTML del capitolo con lo stile di reflow iniettato (font-size in px) + Q_INVOKABLE QString chapterHtml(int index, int fontSizePx) const; + // base URL (file://) per risolvere immagini/CSS relativi del capitolo + Q_INVOKABLE QString chapterBaseUrl(int index) const; // chiave segno locale, es. "cw:v1:3:0.42" (capitolo 3, 42% del capitolo) Q_INVOKABLE QString makeBookmarkKey(int chapterIndex, double fraction) const;