~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/poppler/qt/poppler-link.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* poppler-link.cc: qt interface to poppler
 
2
 * Copyright (C) 2006, 2008 Albert Astals Cid
 
3
 * Adapting code from
 
4
 *   Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#include <poppler-qt.h>
 
22
#include <poppler-private.h>
 
23
 
 
24
#include <qstringlist.h>
 
25
 
 
26
#include <Link.h>
 
27
 
 
28
namespace Poppler {
 
29
 
 
30
        LinkDestination::LinkDestination(const LinkDestinationData &data)
 
31
        {
 
32
                bool deleteDest = false;
 
33
                LinkDest *ld = data.ld;
 
34
                
 
35
                if ( data.namedDest && !ld )
 
36
                {
 
37
                        deleteDest = true;
 
38
                        ld = data.doc->doc.findDest( data.namedDest );
 
39
                }
 
40
                
 
41
                if (!ld) return;
 
42
                
 
43
                if (ld->getKind() == ::destXYZ) m_kind = destXYZ;
 
44
                else if (ld->getKind() == ::destFit) m_kind = destFit;
 
45
                else if (ld->getKind() == ::destFitH) m_kind = destFitH;
 
46
                else if (ld->getKind() == ::destFitV) m_kind = destFitV;
 
47
                else if (ld->getKind() == ::destFitR) m_kind = destFitR;
 
48
                else if (ld->getKind() == ::destFitB) m_kind = destFitB;
 
49
                else if (ld->getKind() == ::destFitBH) m_kind = destFitBH;
 
50
                else if (ld->getKind() == ::destFitBV) m_kind = destFitBV;
 
51
 
 
52
                if ( !ld->isPageRef() ) m_pageNum = ld->getPageNum();
 
53
                else
 
54
                {
 
55
                        Ref ref = ld->getPageRef();
 
56
                        m_pageNum = data.doc->doc.findPage( ref.num, ref.gen );
 
57
                }
 
58
                double left = ld->getLeft();
 
59
                double bottom = ld->getBottom();
 
60
                double right = ld->getRight();
 
61
                double top = ld->getTop();
 
62
                m_zoom = ld->getZoom();
 
63
                m_changeLeft = ld->getChangeLeft();
 
64
                m_changeTop = ld->getChangeTop();
 
65
                m_changeZoom = ld->getChangeZoom();
 
66
                
 
67
                int leftAux = 0, topAux = 0, rightAux = 0, bottomAux = 0;
 
68
                
 
69
#if defined(HAVE_SPLASH)
 
70
                SplashOutputDev *sod = data.doc->getOutputDev();
 
71
                sod->cvtUserToDev( left, top, &leftAux, &topAux );
 
72
                sod->cvtUserToDev( right, bottom, &rightAux, &bottomAux );
 
73
#endif
 
74
                
 
75
                m_left = leftAux;
 
76
                m_top = topAux;
 
77
                m_right = rightAux;
 
78
                m_bottom = bottomAux;
 
79
                
 
80
                if (deleteDest) delete ld;
 
81
        }
 
82
        
 
83
        LinkDestination::LinkDestination(const QString &description)
 
84
        {
 
85
                QStringList tokens = QStringList::split(';', description);
 
86
                m_kind = static_cast<Kind>(tokens[0].toInt());
 
87
                m_pageNum = tokens[1].toInt();
 
88
                m_left = tokens[2].toDouble();
 
89
                m_bottom = tokens[3].toDouble();
 
90
                m_right = tokens[4].toDouble();
 
91
                m_top = tokens[5].toDouble();
 
92
                m_zoom = tokens[6].toDouble();
 
93
                m_changeLeft = static_cast<bool>(tokens[7].toInt());
 
94
                m_changeTop = static_cast<bool>(tokens[8].toInt());
 
95
                m_changeZoom = static_cast<bool>(tokens[9].toInt());
 
96
        }
 
97
        
 
98
        LinkDestination::Kind LinkDestination::kind() const
 
99
        {
 
100
                return m_kind;
 
101
        }
 
102
        
 
103
        int LinkDestination::pageNumber() const
 
104
        {
 
105
                return m_pageNum;
 
106
        }
 
107
        
 
108
        double LinkDestination::left() const
 
109
        {
 
110
                return m_left;
 
111
        }
 
112
        
 
113
        double LinkDestination::bottom() const
 
114
        {
 
115
                return m_bottom;
 
116
        }
 
117
        
 
118
        double LinkDestination::right() const
 
119
        {
 
120
                return m_right;
 
121
        }
 
122
        
 
123
        double LinkDestination::top() const
 
124
        {
 
125
                return m_top;
 
126
        }
 
127
        
 
128
        double LinkDestination::zoom() const
 
129
        {
 
130
                return m_zoom;
 
131
        }
 
132
        
 
133
        bool LinkDestination::isChangeLeft() const
 
134
        {
 
135
                return m_changeLeft;
 
136
        }
 
137
        
 
138
        bool LinkDestination::isChangeTop() const
 
139
        {
 
140
                return m_changeTop;
 
141
        }
 
142
        
 
143
        bool LinkDestination::isChangeZoom() const
 
144
        {
 
145
                return m_changeZoom;
 
146
        }
 
147
        
 
148
        QString LinkDestination::toString() const
 
149
        {
 
150
                QString s = QString::number( (Q_INT8)m_kind );
 
151
                s += ";" + QString::number( m_pageNum );
 
152
                s += ";" + QString::number( m_left );
 
153
                s += ";" + QString::number( m_bottom );
 
154
                s += ";" + QString::number( m_right );
 
155
                s += ";" + QString::number( m_top );
 
156
                s += ";" + QString::number( m_zoom );
 
157
                s += ";" + QString::number( (Q_INT8)m_changeLeft );
 
158
                s += ";" + QString::number( (Q_INT8)m_changeTop );
 
159
                s += ";" + QString::number( (Q_INT8)m_changeZoom );
 
160
                return s;
 
161
        }
 
162
        
 
163
        
 
164
        // Link
 
165
        Link::~Link()
 
166
        {
 
167
        }
 
168
        
 
169
        Link::Link(const QRect &linkArea) : m_linkArea(linkArea)
 
170
        {
 
171
        }
 
172
        
 
173
        Link::LinkType Link::linkType() const
 
174
        {
 
175
                return None;
 
176
        }
 
177
        
 
178
        QRect Link::linkArea() const
 
179
        {
 
180
                return m_linkArea;
 
181
        }
 
182
        
 
183
        // LinkGoto
 
184
        LinkGoto::LinkGoto( const QRect &linkArea, QString extFileName, const LinkDestination & destination ) : Link(linkArea), m_extFileName(extFileName), m_destination(destination)
 
185
        {
 
186
        }
 
187
        
 
188
        bool LinkGoto::isExternal() const
 
189
        {
 
190
                return !m_extFileName.isEmpty();
 
191
        }
 
192
        
 
193
        const QString &LinkGoto::fileName() const
 
194
        {
 
195
                return m_extFileName;
 
196
        }
 
197
        
 
198
        const LinkDestination &LinkGoto::destination() const
 
199
        {
 
200
                return m_destination;
 
201
        }
 
202
        
 
203
        Link::LinkType LinkGoto::linkType() const
 
204
        {
 
205
                return Goto;
 
206
        }
 
207
        
 
208
        // LinkExecute
 
209
        LinkExecute::LinkExecute( const QRect &linkArea, const QString & file, const QString & params ) : Link(linkArea), m_fileName(file), m_parameters(params)
 
210
        {
 
211
        }
 
212
        
 
213
        const QString & LinkExecute::fileName() const
 
214
        {
 
215
                return m_fileName;
 
216
        }
 
217
        const QString & LinkExecute::parameters() const
 
218
        {
 
219
                return m_parameters;
 
220
        }
 
221
 
 
222
        Link::LinkType LinkExecute::linkType() const
 
223
        {
 
224
                return Execute;
 
225
        }
 
226
 
 
227
        // LinkBrowse
 
228
        LinkBrowse::LinkBrowse( const QRect &linkArea, const QString &url ) : Link(linkArea), m_url(url)
 
229
        {
 
230
        }
 
231
        
 
232
        const QString & LinkBrowse::url() const
 
233
        {
 
234
                return m_url;
 
235
        }
 
236
        
 
237
        Link::LinkType LinkBrowse::linkType() const
 
238
        {
 
239
                return Browse;
 
240
        }
 
241
 
 
242
        // LinkAction
 
243
        LinkAction::LinkAction( const QRect &linkArea, ActionType actionType ) : Link(linkArea), m_type(actionType)
 
244
        {
 
245
        }
 
246
                
 
247
        LinkAction::ActionType LinkAction::actionType() const
 
248
        {
 
249
                return m_type;
 
250
        }
 
251
 
 
252
        Link::LinkType LinkAction::linkType() const
 
253
        {
 
254
                return Action;
 
255
        }
 
256
 
 
257
        // LinkMovie
 
258
        LinkMovie::LinkMovie( const QRect &linkArea ) : Link(linkArea)
 
259
        {
 
260
        }
 
261
        
 
262
        Link::LinkType LinkMovie::linkType() const
 
263
        {
 
264
                return Movie;
 
265
        }
 
266
 
 
267
}