Commit b696d6db authored by Michael Weghorn's avatar Michael Weghorn Committed by Albert Astals Cid
Browse files

Support '#page=<pagenum>' fragment to open at page <pagenum>

Support the '#page=<pagenum>' fragment to specify which page
to open the document at, in addition to the existing '#<pagenum>'
syntax.

For PDF, the '#page=<pagenum>' fragment is specified in RFC 8118,
section 3.

BUG: 406831
parent 0fed8844
Pipeline #33792 passed with stage
in 23 minutes and 13 seconds
......@@ -95,6 +95,7 @@ private slots:
void testAdditionalActionTriggers();
void testTypewriterAnnotTool();
void testJumpToPage();
void testOpenAtPage();
void testForwardBackwardNavigation();
void testTabletProximityBehavior();
void testOpenPrintPreview();
......@@ -1794,6 +1795,26 @@ void PartTest::testJumpToPage()
QCOMPARE(part.m_pageView->verticalScrollBar()->value(), pageWithSpaceTop - 4);
}
void PartTest::testOpenAtPage()
{
const QString testFile = QStringLiteral(KDESRCDIR "data/simple-multipage.pdf");
QUrl url = QUrl::fromLocalFile(testFile);
Okular::Part part(nullptr, nullptr, QVariantList());
const uint targetPageNumA = 25;
const uint expectedPageA = targetPageNumA - 1;
url.setFragment(QString::number(targetPageNumA));
part.openUrl(url);
QCOMPARE(part.m_document->currentPage(), expectedPageA);
// 'page=<pagenum>' param as specified in RFC 3778
const uint targetPageNumB = 15;
const uint expectedPageB = targetPageNumB - 1;
url.setFragment("page=" + QString::number(targetPageNumB));
part.openUrl(url);
QCOMPARE(part.m_document->currentPage(), expectedPageB);
}
void PartTest::testForwardBackwardNavigation()
{
const QString testFile = QStringLiteral(KDESRCDIR "data/simple-multipage.pdf");
......
......@@ -1670,7 +1670,17 @@ bool Part::openUrl(const QUrl &_url, bool swapInsteadOfOpening)
if (url.hasFragment()) {
const QString dest = url.fragment(QUrl::FullyDecoded);
bool ok = true;
const int page = dest.toInt(&ok);
int page = dest.toInt(&ok);
if (!ok) {
const QStringList parameters = dest.split(QChar('&'));
for (const QString &parameter : parameters) {
if (parameter.startsWith(QStringLiteral("page="), Qt::CaseInsensitive)) {
page = dest.midRef(5).toInt(&ok);
}
}
}
if (ok) {
Okular::DocumentViewport vp(page - 1);
vp.rePos.enabled = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment