/src/poppler/cpp/poppler-destination.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
33 | | using namespace poppler; |
34 | | |
35 | 1.11k | destination_private::destination_private(const LinkDest *ld, PDFDoc *doc) : pdf_doc(doc) |
36 | 1.11k | { |
37 | 1.11k | if (!ld) { |
38 | 0 | type = destination::unknown; |
39 | 0 | return; |
40 | 0 | } |
41 | | |
42 | 1.11k | switch (ld->getKind()) { |
43 | 989 | case ::destXYZ: |
44 | 989 | type = destination::xyz; |
45 | 989 | break; |
46 | 122 | case ::destFit: |
47 | 122 | type = destination::fit; |
48 | 122 | break; |
49 | 0 | case ::destFitH: |
50 | 0 | type = destination::fit_h; |
51 | 0 | break; |
52 | 0 | case ::destFitV: |
53 | 0 | type = destination::fit_v; |
54 | 0 | break; |
55 | 0 | case ::destFitR: |
56 | 0 | type = destination::fit_r; |
57 | 0 | break; |
58 | 0 | case ::destFitB: |
59 | 0 | type = destination::fit_b; |
60 | 0 | break; |
61 | 0 | case ::destFitBH: |
62 | 0 | type = destination::fit_b_h; |
63 | 0 | break; |
64 | 0 | case ::destFitBV: |
65 | 0 | type = destination::fit_b_v; |
66 | 0 | break; |
67 | 0 | default: |
68 | 0 | type = destination::unknown; |
69 | 0 | break; |
70 | 1.11k | } |
71 | | |
72 | 1.11k | if (!ld->isPageRef()) { |
73 | | // The page number has been resolved. |
74 | 9 | page_number_unresolved = false; |
75 | 9 | page_number = ld->getPageNum(); |
76 | 1.10k | } else if (doc) { |
77 | | // It is necessary to resolve the page number by its accessor. |
78 | 1.10k | page_number_unresolved = true; |
79 | 1.10k | page_ref = ld->getPageRef(); |
80 | 1.10k | } else { |
81 | | // The page number cannot be resolved because there is no PDFDoc. |
82 | 0 | page_number_unresolved = false; |
83 | 0 | page_number = 0; |
84 | 0 | } |
85 | | |
86 | 1.11k | left = ld->getLeft(); |
87 | 1.11k | bottom = ld->getBottom(); |
88 | 1.11k | right = ld->getRight(); |
89 | 1.11k | top = ld->getTop(); |
90 | 1.11k | zoom = ld->getZoom(); |
91 | 1.11k | change_left = ld->getChangeLeft(); |
92 | 1.11k | change_top = ld->getChangeTop(); |
93 | 1.11k | change_zoom = ld->getChangeZoom(); |
94 | 1.11k | } |
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 | | |
167 | 1.11k | destination::destination(destination_private *dd) : d(dd) { } |
168 | | |
169 | | /** |
170 | | Move constructor. |
171 | | */ |
172 | | destination::destination(destination &&other) noexcept |
173 | 1.09k | { |
174 | 1.09k | *this = std::move(other); |
175 | 1.09k | } |
176 | | |
177 | | /** |
178 | | \returns the type of the destination |
179 | | */ |
180 | | destination::type_enum destination::type() const |
181 | 0 | { |
182 | 0 | return d->type; |
183 | 0 | } |
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 | | */ |
191 | | int destination::page_number() const |
192 | 0 | { |
193 | 0 | if (d->page_number_unresolved) { |
194 | 0 | d->page_number_unresolved = false; |
195 | 0 | d->page_number = d->pdf_doc->findPage(d->page_ref); |
196 | 0 | } |
197 | |
|
198 | 0 | return d->page_number; |
199 | 0 | } |
200 | | |
201 | | /** |
202 | | \returns the left coordinate of the destination |
203 | | */ |
204 | | double destination::left() const |
205 | 0 | { |
206 | 0 | return d->left; |
207 | 0 | } |
208 | | |
209 | | /** |
210 | | \returns the bottom coordinate of the destination |
211 | | */ |
212 | | double destination::bottom() const |
213 | 0 | { |
214 | 0 | return d->bottom; |
215 | 0 | } |
216 | | |
217 | | /** |
218 | | \returns the right coordinate of the destination |
219 | | */ |
220 | | double destination::right() const |
221 | 0 | { |
222 | 0 | return d->right; |
223 | 0 | } |
224 | | |
225 | | /** |
226 | | \returns the top coordinate of the destination |
227 | | */ |
228 | | double destination::top() const |
229 | 0 | { |
230 | 0 | return d->top; |
231 | 0 | } |
232 | | |
233 | | /** |
234 | | \returns the scale factor of the destination |
235 | | */ |
236 | | double destination::zoom() const |
237 | 0 | { |
238 | 0 | return d->zoom; |
239 | 0 | } |
240 | | |
241 | | /** |
242 | | \returns whether left coordinate should be changed |
243 | | */ |
244 | | bool destination::is_change_left() const |
245 | 0 | { |
246 | 0 | return d->change_left; |
247 | 0 | } |
248 | | |
249 | | /** |
250 | | \returns whether top coordinate should be changed |
251 | | */ |
252 | | bool destination::is_change_top() const |
253 | 0 | { |
254 | 0 | return d->change_top; |
255 | 0 | } |
256 | | |
257 | | /** |
258 | | \returns whether scale factor should be changed |
259 | | */ |
260 | | bool destination::is_change_zoom() const |
261 | 0 | { |
262 | 0 | return d->change_zoom; |
263 | 0 | } |
264 | | |
265 | | /** |
266 | | Move assignment operator. |
267 | | */ |
268 | 1.09k | destination &destination::operator=(destination &&other) noexcept = default; |
269 | | |
270 | | /** |
271 | | Destructor. |
272 | | */ |
273 | 2.20k | destination::~destination() = default; |