Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
Okular
Commits
0a23d4a0
Commit
0a23d4a0
authored
Mar 31, 2021
by
Gerd Wachsmuth
Browse files
Fix a bug with zoom levels on cropped pages
BUG: 342003
Uses ideas of
https://bugs.kde.org/show_bug.cgi?id=342003#c5
parent
d3b2317a
Changes
2
Hide whitespace changes
Inline
Side-by-side
autotests/parttest.cpp
View file @
0a23d4a0
...
...
@@ -58,6 +58,7 @@ signals:
void
urlHandler
(
const
QUrl
&
url
);
// NOLINT(readability-inconsistent-declaration-parameter-name)
private
slots
:
void
testZoomWithCrop
();
void
testReload
();
void
testCanceledReload
();
void
testTOCReload
();
...
...
@@ -2031,6 +2032,59 @@ void PartTest::testZoomInFacingPages()
QVERIFY
(
QMetaObject
::
invokeMethod
(
part
.
m_pageView
,
"slotZoomIn"
));
QVERIFY
(
QMetaObject
::
invokeMethod
(
part
.
m_pageView
,
"slotZoomIn"
));
QTRY_COMPARE
(
zoomSelectAction
->
currentText
(),
QStringLiteral
(
"66%"
));
// Back to single mode
part
.
m_pageView
->
findChild
<
QAction
*>
(
QStringLiteral
(
"view_render_mode_single"
))
->
trigger
();
}
void
PartTest
::
testZoomWithCrop
()
{
// We test that all zoom levels can be achieved with cropped pages, bug 342003
QVariantList
dummyArgs
;
Okular
::
Part
part
(
nullptr
,
nullptr
,
dummyArgs
);
QVERIFY
(
openDocument
(
&
part
,
QStringLiteral
(
KDESRCDIR
"data/file2.pdf"
)));
KActionMenu
*
cropMenu
=
part
.
m_pageView
->
findChild
<
KActionMenu
*>
(
QStringLiteral
(
"view_trim_mode"
));
KToggleAction
*
cropAction
=
cropMenu
->
menu
()
->
findChild
<
KToggleAction
*>
(
QStringLiteral
(
"view_trim_margins"
));
KSelectAction
*
zoomSelectAction
=
part
.
m_pageView
->
findChild
<
KSelectAction
*>
(
QStringLiteral
(
"zoom_to"
));
part
.
widget
()
->
resize
(
600
,
400
);
part
.
widget
()
->
show
();
QVERIFY
(
QTest
::
qWaitForWindowExposed
(
part
.
widget
()));
// Activate "Trim Margins"
QVERIFY
(
!
Okular
::
Settings
::
trimMargins
());
cropAction
->
trigger
();
QVERIFY
(
Okular
::
Settings
::
trimMargins
());
// Wait for the bounding boxes
QTRY_VERIFY
(
part
.
m_document
->
page
(
0
)
->
isBoundingBoxKnown
());
QTRY_VERIFY
(
part
.
m_document
->
page
(
1
)
->
isBoundingBoxKnown
());
// Zoom out
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
QVERIFY
(
QMetaObject
::
invokeMethod
(
part
.
m_pageView
,
"slotZoomOut"
));
}
QCOMPARE
(
zoomSelectAction
->
currentText
(),
"12%"
);
// Zoom in and out and check that all zoom levels appear
QSet
<
QString
>
zooms_ref
{
"12%"
,
"25%"
,
"33%"
,
"50%"
,
"66%"
,
"75%"
,
"100%"
,
"125%"
,
"150%"
,
"200%"
,
"400%"
,
"800%"
,
"1,600%"
,
"2,500%"
,
"5,000%"
,
"10,000%"
};
for
(
int
j
=
0
;
j
<
2
;
j
++
)
{
QSet
<
QString
>
zooms
;
for
(
int
i
=
0
;
i
<
18
;
i
++
)
{
zooms
<<
zoomSelectAction
->
currentText
();
QVERIFY
(
QMetaObject
::
invokeMethod
(
part
.
m_pageView
,
j
==
0
?
"slotZoomIn"
:
"slotZoomOut"
));
}
QVERIFY
(
zooms
.
contains
(
zooms_ref
));
}
// Deactivate "Trim Margins"
QVERIFY
(
Okular
::
Settings
::
trimMargins
());
cropAction
->
trigger
();
QVERIFY
(
!
Okular
::
Settings
::
trimMargins
());
}
}
// namespace Okular
...
...
part/pageview.cpp
View file @
0a23d4a0
...
...
@@ -3724,8 +3724,12 @@ double PageView::zoomFactorFitMode(ZoomMode mode)
// prevent segmentation fault when opening a new document;
if
(
!
currentItem
)
return
0
;
// We need the real width/height of the cropped page.
const
Okular
::
Page
*
okularPage
=
currentItem
->
page
();
const
double
width
=
okularPage
->
width
(),
height
=
okularPage
->
height
();
const
double
width
=
okularPage
->
width
()
*
currentItem
->
crop
().
width
();
const
double
height
=
okularPage
->
height
()
*
currentItem
->
crop
().
height
();
if
(
mode
==
ZoomFitWidth
)
return
(
double
)
colWidth
/
width
;
if
(
mode
==
ZoomFitPage
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment