epub: Improve TableOfContents for some files

The link can be percent encoded so try it like that if not found in the
normal way, also if the text overflows the page, it's in the next page

BUGS: 458289
remotes/origin/release/22.08
Albert Astals Cid 4 years ago
parent 818e1445f7
commit 656587ca63
  1. 8
      core/textdocumentgenerator_p.h
  2. 5
      generators/epub/converter.cpp

@ -136,8 +136,12 @@ static Okular::DocumentViewport calculateViewport(QTextDocument *document, const
const QSizeF pageSize = document->pageSize();
const QRectF rect = document->documentLayout()->blockBoundingRect(block);
const int page = qRound(rect.y()) / qRound(pageSize.height());
const int offset = qRound(rect.y()) % qRound(pageSize.height());
int page = qRound(rect.y()) / qRound(pageSize.height());
int offset = qRound(rect.y()) % qRound(pageSize.height());
if (rect.y() + rect.height() > pageSize.height()) {
page = page + 1;
offset = 0;
}
Okular::DocumentViewport viewport(page);
viewport.rePos.normalizedX = (double)rect.x() / (double)pageSize.width();

@ -380,6 +380,10 @@ QTextDocument *Converter::convert(const QString &fileName)
if (mSectionMap.contains(link)) {
block = mSectionMap.value(link);
} else {
const QString percentDecodedLink = QUrl::fromPercentEncoding(link.toUtf8());
if (mSectionMap.contains(percentDecodedLink)) {
block = mSectionMap.value(percentDecodedLink);
} else { // load missing resource
char *data = nullptr;
// epub_get_data can't handle whitespace url encodings
@ -412,6 +416,7 @@ QTextDocument *Converter::convert(const QString &fileName)
free(data);
}
}
if (block.isValid()) { // be sure we actually got a block
Q_EMIT addTitle(epub_tit_get_curr_depth(tit), QString::fromUtf8(label), block);

Loading…
Cancel
Save