mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 02:45:38 +00:00
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
This commit is contained in:
parent
0fed884424
commit
b696d6dbfb
|
@ -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");
|
||||
|
|
12
part.cpp
12
part.cpp
|
@ -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 ¶meter : 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;
|
||||
|
|
Loading…
Reference in a new issue