1/*
2 * Copyright (C) 2019, Masamichi Hosoda <trueroad@trueroad.jp>
3 * Copyright (C) 2019 Albert Astals Cid <aacid@kde.org>
4 * Copyright (C) 2022, Oliver Sander <oliver.sander@tu-dresden.de>
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/**
22 \file poppler-destination.h
23 */
24#include "poppler-destination.h"
25
26#include "poppler-destination-private.h"
27
28#include "PDFDoc.h"
29#include "Link.h"
30
31#include <utility>
32
33using namespace poppler;
34
35destination_private::destination_private(const LinkDest *ld, PDFDoc *doc) : pdf_doc(doc)
36{
37 if (!ld) {
38 type = destination::unknown;
39 return;
40 }
41
42 switch (ld->getKind()) {
43 case ::destXYZ:
44 type = destination::xyz;
45 break;
46 case ::destFit:
47 type = destination::fit;
48 break;
49 case ::destFitH:
50 type = destination::fit_h;
51 break;
52 case ::destFitV:
53 type = destination::fit_v;
54 break;
55 case ::destFitR:
56 type = destination::fit_r;
57 break;
58 case ::destFitB:
59 type = destination::fit_b;
60 break;
61 case ::destFitBH:
62 type = destination::fit_b_h;
63 break;
64 case ::destFitBV:
65 type = destination::fit_b_v;
66 break;
67 default:
68 type = destination::unknown;
69 break;
70 }
71
72 if (!ld->isPageRef()) {
73 // The page number has been resolved.
74 page_number_unresolved = false;
75 page_number = ld->getPageNum();
76 } else if (doc) {
77 // It is necessary to resolve the page number by its accessor.
78 page_number_unresolved = true;
79 page_ref = ld->getPageRef();
80 } else {
81 // The page number cannot be resolved because there is no PDFDoc.
82 page_number_unresolved = false;
83 page_number = 0;
84 }
85
86 left = ld->getLeft();
87 bottom = ld->getBottom();
88 right = ld->getRight();
89 top = ld->getTop();
90 zoom = ld->getZoom();
91 change_left = ld->getChangeLeft();
92 change_top = ld->getChangeTop();
93 change_zoom = ld->getChangeZoom();
94}
95
96/**
97 \class poppler::destination poppler-destination.h "poppler/cpp/poppler-destination.h"
98
99 The information about a destination used in a PDF %document.
100 */
101
102/**
103 \enum poppler::destination::type_enum
104
105 The various types of destinations available in a PDF %document.
106*/
107/**
108 \var poppler::destination::type_enum poppler::destination::unknown
109
110 unknown destination
111*/
112/**
113 \var poppler::destination::type_enum poppler::destination::xyz
114
115 go to page with coordinates (left, top) positioned at the upper-left
116 corner of the window and the contents of the page magnified
117 by the factor zoom
118*/
119/**
120 \var poppler::destination::type_enum poppler::destination::fit
121
122 go to page with its contents magnified just enough to fit the entire page
123 within the window both horizontally and vertically
124*/
125/**
126 \var poppler::destination::type_enum poppler::destination::fit_h
127
128 go to page with the vertical coordinate top positioned at the top edge
129 of the window and the contents of the page magnified just enough to fit
130 the entire width of the page within the window
131*/
132/**
133 \var poppler::destination::type_enum poppler::destination::fit_v
134
135 go to page with the horizontal coordinate left positioned at the left edge
136 of the window and the contents of the page magnified just enough to fit
137 the entire height of the page within the window
138*/
139/**
140 \var poppler::destination::type_enum poppler::destination::fit_r
141
142 go to page with its contents magnified just enough to fit the rectangle
143 specified by the coordinates left, bottom, right, and top entirely
144 within the window both horizontally and vertically
145*/
146/**
147 \var poppler::destination::type_enum poppler::destination::fit_b
148
149 go to page with its contents magnified just enough to fit its bounding box
150 entirely within the window both horizontally and vertically
151*/
152/**
153 \var poppler::destination::type_enum poppler::destination::fit_b_h
154
155 go to page with the vertical coordinate top positioned at the top edge
156 of the window and the contents of the page magnified just enough to fit
157 the entire width of its bounding box within the window
158*/
159/**
160 \var poppler::destination::type_enum poppler::destination::fit_b_v
161
162 go to page with the horizontal coordinate left positioned at the left edge
163 of the window and the contents of the page magnified just enough to fit
164 the entire height of its bounding box within the window
165*/
166
167destination::destination(destination_private *dd) : d(dd) { }
168
169/**
170 Move constructor.
171 */
172destination::destination(destination &&other) noexcept
173{
174 *this = std::move(other);
175}
176
177/**
178 \returns the type of the destination
179 */
180destination::type_enum destination::type() const
181{
182 return d->type;
183}
184
185/**
186 \note It is necessary not to destruct parent poppler::document
187 before calling this function for the first time.
188
189 \returns the page number of the destination
190 */
191int destination::page_number() const
192{
193 if (d->page_number_unresolved) {
194 d->page_number_unresolved = false;
195 d->page_number = d->pdf_doc->findPage(ref: d->page_ref);
196 }
197
198 return d->page_number;
199}
200
201/**
202 \returns the left coordinate of the destination
203 */
204double destination::left() const
205{
206 return d->left;
207}
208
209/**
210 \returns the bottom coordinate of the destination
211 */
212double destination::bottom() const
213{
214 return d->bottom;
215}
216
217/**
218 \returns the right coordinate of the destination
219 */
220double destination::right() const
221{
222 return d->right;
223}
224
225/**
226 \returns the top coordinate of the destination
227 */
228double destination::top() const
229{
230 return d->top;
231}
232
233/**
234 \returns the scale factor of the destination
235 */
236double destination::zoom() const
237{
238 return d->zoom;
239}
240
241/**
242 \returns whether left coordinate should be changed
243 */
244bool destination::is_change_left() const
245{
246 return d->change_left;
247}
248
249/**
250 \returns whether top coordinate should be changed
251 */
252bool destination::is_change_top() const
253{
254 return d->change_top;
255}
256
257/**
258 \returns whether scale factor should be changed
259 */
260bool destination::is_change_zoom() const
261{
262 return d->change_zoom;
263}
264
265/**
266 Move assignment operator.
267 */
268destination &destination::operator=(destination &&other) noexcept = default;
269
270/**
271 Destructor.
272 */
273destination::~destination() = default;
274

source code of poppler/cpp/poppler-destination.cpp