Commit 6e6ea570 authored by Pino Toscano's avatar Pino Toscano

check whether normalized values of viewport targets are in the proper [0,1]...

check whether normalized values of viewport targets are in the proper [0,1] range, and use a default value if not

svn path=/trunk/KDE/kdegraphics/okular/; revision=969017
parent 32ca783b
......@@ -74,6 +74,11 @@ static int pageflags = PagePainter::Accessibility | PagePainter::EnhanceLinks |
PagePainter::EnhanceImages | PagePainter::Highlights |
PagePainter::TextSelection | PagePainter::Annotations;
static inline double normClamp( double value, double def )
{
return ( value < 0.0 || value > 1.0 ) ? def : value;
}
// structure used internally by PageView for data storage
class PageViewPrivate
{
......@@ -914,14 +919,14 @@ void PageView::notifyViewportChanged( bool smoothMove )
{
if ( vp.rePos.pos == Okular::DocumentViewport::Center )
{
newCenterX += (int)( vp.rePos.normalizedX * (double)r.width() );
newCenterY += (int)( vp.rePos.normalizedY * (double)r.height() );
newCenterX += (int)( normClamp( vp.rePos.normalizedX, 0.5 ) * (double)r.width() );
newCenterY += (int)( normClamp( vp.rePos.normalizedY, 0.0 ) * (double)r.height() );
}
else
{
// TopLeft
newCenterX += (int)( vp.rePos.normalizedX * (double)r.width() + viewport()->width() / 2 );
newCenterY += (int)( vp.rePos.normalizedY * (double)r.height() + viewport()->height() / 2 );
newCenterX += (int)( normClamp( vp.rePos.normalizedX, 0.0 ) * (double)r.width() + viewport()->width() / 2 );
newCenterY += (int)( normClamp( vp.rePos.normalizedY, 0.0 ) * (double)r.height() + viewport()->height() / 2 );
}
}
else
......@@ -2982,8 +2987,8 @@ void PageView::slotRelayoutPages()
int prevX = horizontalScrollBar()->value(),
prevY = verticalScrollBar()->value();
const QRect & geometry = d->items[ vp.pageNumber ]->croppedGeometry();
double nX = vp.rePos.enabled ? vp.rePos.normalizedX : 0.5,
nY = vp.rePos.enabled ? vp.rePos.normalizedY : 0.0;
double nX = vp.rePos.enabled ? normClamp( vp.rePos.normalizedX, 0.5 ) : 0.5,
nY = vp.rePos.enabled ? normClamp( vp.rePos.normalizedY, 0.0 ) : 0.0;
center( geometry.left() + qRound( nX * (double)geometry.width() ),
geometry.top() + qRound( nY * (double)geometry.height() ) );
// center() usually moves the viewport, that requests pixmaps too.
......
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