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 
LinkDestination(const LinkDestinationData & data)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 
LinkDestination(const QString & description)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 
kind() const98 	LinkDestination::Kind LinkDestination::kind() const
99 	{
100 		return m_kind;
101 	}
102 
pageNumber() const103 	int LinkDestination::pageNumber() const
104 	{
105 		return m_pageNum;
106 	}
107 
left() const108 	double LinkDestination::left() const
109 	{
110 		return m_left;
111 	}
112 
bottom() const113 	double LinkDestination::bottom() const
114 	{
115 		return m_bottom;
116 	}
117 
right() const118 	double LinkDestination::right() const
119 	{
120 		return m_right;
121 	}
122 
top() const123 	double LinkDestination::top() const
124 	{
125 		return m_top;
126 	}
127 
zoom() const128 	double LinkDestination::zoom() const
129 	{
130 		return m_zoom;
131 	}
132 
isChangeLeft() const133 	bool LinkDestination::isChangeLeft() const
134 	{
135 		return m_changeLeft;
136 	}
137 
isChangeTop() const138 	bool LinkDestination::isChangeTop() const
139 	{
140 		return m_changeTop;
141 	}
142 
isChangeZoom() const143 	bool LinkDestination::isChangeZoom() const
144 	{
145 		return m_changeZoom;
146 	}
147 
toString() const148 	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
~Link()165 	Link::~Link()
166 	{
167 	}
168 
Link(const QRect & linkArea)169 	Link::Link(const QRect &linkArea) : m_linkArea(linkArea)
170 	{
171 	}
172 
linkType() const173 	Link::LinkType Link::linkType() const
174 	{
175 		return None;
176 	}
177 
linkArea() const178 	QRect Link::linkArea() const
179 	{
180 		return m_linkArea;
181 	}
182 
183 	// LinkGoto
LinkGoto(const QRect & linkArea,QString extFileName,const LinkDestination & destination)184 	LinkGoto::LinkGoto( const QRect &linkArea, QString extFileName, const LinkDestination & destination ) : Link(linkArea), m_extFileName(extFileName), m_destination(destination)
185 	{
186 	}
187 
isExternal() const188 	bool LinkGoto::isExternal() const
189 	{
190 		return !m_extFileName.isEmpty();
191 	}
192 
fileName() const193 	const QString &LinkGoto::fileName() const
194 	{
195 		return m_extFileName;
196 	}
197 
destination() const198 	const LinkDestination &LinkGoto::destination() const
199 	{
200 		return m_destination;
201 	}
202 
linkType() const203 	Link::LinkType LinkGoto::linkType() const
204 	{
205 		return Goto;
206 	}
207 
208 	// LinkExecute
LinkExecute(const QRect & linkArea,const QString & file,const QString & params)209 	LinkExecute::LinkExecute( const QRect &linkArea, const QString & file, const QString & params ) : Link(linkArea), m_fileName(file), m_parameters(params)
210 	{
211 	}
212 
fileName() const213 	const QString & LinkExecute::fileName() const
214 	{
215 		return m_fileName;
216 	}
parameters() const217 	const QString & LinkExecute::parameters() const
218 	{
219 		return m_parameters;
220 	}
221 
linkType() const222 	Link::LinkType LinkExecute::linkType() const
223 	{
224 		return Execute;
225 	}
226 
227 	// LinkBrowse
LinkBrowse(const QRect & linkArea,const QString & url)228 	LinkBrowse::LinkBrowse( const QRect &linkArea, const QString &url ) : Link(linkArea), m_url(url)
229 	{
230 	}
231 
url() const232 	const QString & LinkBrowse::url() const
233 	{
234 		return m_url;
235 	}
236 
linkType() const237 	Link::LinkType LinkBrowse::linkType() const
238 	{
239 		return Browse;
240 	}
241 
242 	// LinkAction
LinkAction(const QRect & linkArea,ActionType actionType)243 	LinkAction::LinkAction( const QRect &linkArea, ActionType actionType ) : Link(linkArea), m_type(actionType)
244 	{
245 	}
246 
actionType() const247 	LinkAction::ActionType LinkAction::actionType() const
248 	{
249 		return m_type;
250 	}
251 
linkType() const252 	Link::LinkType LinkAction::linkType() const
253 	{
254 		return Action;
255 	}
256 
257 	// LinkMovie
LinkMovie(const QRect & linkArea)258 	LinkMovie::LinkMovie( const QRect &linkArea ) : Link(linkArea)
259 	{
260 	}
261 
linkType() const262 	Link::LinkType LinkMovie::linkType() const
263 	{
264 		return Movie;
265 	}
266 
267 }
268