-
Notifications
You must be signed in to change notification settings - Fork 29
/
adjustedlink.cpp
98 lines (78 loc) · 2.6 KB
/
adjustedlink.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2012 <copyright holder> <email>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "adjustedlink.h"
#include <stdexcept>
#include <boost/numeric/conversion/cast.hpp>
using boost::numeric_cast;
QSharedPointer< Poppler::Link > AdjustedLink::link() const
{
return m_link;
}
QRectF AdjustedLink::linkArea() const
{
QRectF const& orig( link()->linkArea() );
QRectF retval( link()->linkArea() );
switch(ri.pagePart()) {
case PagePart::FullPage:
break;
case PagePart::LeftHalf:
if ( retval.left() > 0.5 ) {
return QRectF();
}
retval.setLeft( orig.left() * 2.0 );
retval.setWidth( orig.width() * 2.0 );
break;
case PagePart::RightHalf:
if ( retval.right() < 0.5 ) {
// no part of the rectangle is in our page
return QRectF();
}
retval.setLeft( (orig.left() - 0.5) * 2.0 );
retval.setWidth( orig.width() * 2.0 );
break;
}
if ( retval.height() < 0 ) {
retval.setHeight( -retval.height() );
retval.moveTop( retval.top() - retval.height());
}
return retval;
}
Poppler::Link::LinkType AdjustedLink::linkType() const
{
return link()->linkType();
}
AdjustedLink::AdjustedLink(const RenderingIdentifier& renderIdent, QSharedPointer< Poppler::Link > link)
: m_link(link), ri(renderIdent)
{
if ( linkArea().isNull() )
throw OutsidePage();
}
AdjustedLink::OutsidePage::OutsidePage(): runtime_error("This link is not inside the current page part")
{
}
uint AdjustedLink::targetPageNumber() const
{
/* Although page numbers in a PDF are non-negative, poppler's pageNumber
* is a signed integer.
*
* numeric_cast checks that the number actually *is* non-negative.
*/
return numeric_cast<unsigned>(lgt().destination().pageNumber()) -1u;
}
Poppler::LinkGoto const& AdjustedLink::lgt() const
{
return dynamic_cast<Poppler::LinkGoto const&>( *m_link );
}