1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef PUBLIC_FPDF_DOC_H_
8 #define PUBLIC_FPDF_DOC_H_
9 
10 // NOLINTNEXTLINE(build/include)
11 #include "fpdfview.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif  // __cplusplus
16 
17 // Unsupported action type.
18 #define PDFACTION_UNSUPPORTED 0
19 // Go to a destination within current document.
20 #define PDFACTION_GOTO 1
21 // Go to a destination within another document.
22 #define PDFACTION_REMOTEGOTO 2
23 // URI, including web pages and other Internet resources.
24 #define PDFACTION_URI 3
25 // Launch an application or open a file.
26 #define PDFACTION_LAUNCH 4
27 
28 // View destination fit types. See pdfmark reference v9, page 48.
29 #define PDFDEST_VIEW_UNKNOWN_MODE 0
30 #define PDFDEST_VIEW_XYZ 1
31 #define PDFDEST_VIEW_FIT 2
32 #define PDFDEST_VIEW_FITH 3
33 #define PDFDEST_VIEW_FITV 4
34 #define PDFDEST_VIEW_FITR 5
35 #define PDFDEST_VIEW_FITB 6
36 #define PDFDEST_VIEW_FITBH 7
37 #define PDFDEST_VIEW_FITBV 8
38 
39 typedef struct _FS_QUADPOINTSF {
40   FS_FLOAT x1;
41   FS_FLOAT y1;
42   FS_FLOAT x2;
43   FS_FLOAT y2;
44   FS_FLOAT x3;
45   FS_FLOAT y3;
46   FS_FLOAT x4;
47   FS_FLOAT y4;
48 } FS_QUADPOINTSF;
49 
50 // Get the first child of |bookmark|, or the first top-level bookmark item.
51 //
52 //   document - handle to the document.
53 //   bookmark - handle to the current bookmark. Pass NULL for the first top
54 //              level item.
55 //
56 // Returns a handle to the first child of |bookmark| or the first top-level
57 // bookmark item. NULL if no child or top-level bookmark found.
58 FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
59 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);
60 
61 // Get the next sibling of |bookmark|.
62 //
63 //   document - handle to the document.
64 //   bookmark - handle to the current bookmark.
65 //
66 // Returns a handle to the next sibling of |bookmark|, or NULL if this is the
67 // last bookmark at this level.
68 FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
69 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);
70 
71 // Get the title of |bookmark|.
72 //
73 //   bookmark - handle to the bookmark.
74 //   buffer   - buffer for the title. May be NULL.
75 //   buflen   - the length of the buffer in bytes. May be 0.
76 //
77 // Returns the number of bytes in the title, including the terminating NUL
78 // character. The number of bytes is returned regardless of the |buffer| and
79 // |buflen| parameters.
80 //
81 // Regardless of the platform, the |buffer| is always in UTF-16LE encoding. The
82 // string is terminated by a UTF16 NUL character. If |buflen| is less than the
83 // required length, or |buffer| is NULL, |buffer| will not be modified.
84 FPDF_EXPORT unsigned long FPDF_CALLCONV
85 FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark,
86                       void* buffer,
87                       unsigned long buflen);
88 
89 // Find the bookmark with |title| in |document|.
90 //
91 //   document - handle to the document.
92 //   title    - the UTF-16LE encoded Unicode title for which to search.
93 //
94 // Returns the handle to the bookmark, or NULL if |title| can't be found.
95 //
96 // FPDFBookmark_Find() will always return the first bookmark found even if
97 // multiple bookmarks have the same |title|.
98 FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
99 FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title);
100 
101 // Get the destination associated with |bookmark|.
102 //
103 //   document - handle to the document.
104 //   bookmark - handle to the bookmark.
105 //
106 // Returns the handle to the destination data,  NULL if no destination is
107 // associated with |bookmark|.
108 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV
109 FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);
110 
111 // Get the action associated with |bookmark|.
112 //
113 //   bookmark - handle to the bookmark.
114 //
115 // Returns the handle to the action data, or NULL if no action is associated
116 // with |bookmark|. When NULL is returned, FPDFBookmark_GetDest() should be
117 // called to get the |bookmark| destination data.
118 FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV
119 FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark);
120 
121 // Get the type of |action|.
122 //
123 //   action - handle to the action.
124 //
125 // Returns one of:
126 //   PDFACTION_UNSUPPORTED
127 //   PDFACTION_GOTO
128 //   PDFACTION_REMOTEGOTO
129 //   PDFACTION_URI
130 //   PDFACTION_LAUNCH
131 FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION action);
132 
133 // Get the destination of |action|.
134 //
135 //   document - handle to the document.
136 //   action   - handle to the action. |action| must be a |PDFACTION_GOTO| or
137 //              |PDFACTION_REMOTEGOTO|.
138 //
139 // Returns a handle to the destination data, or NULL on error, typically
140 // because the arguments were bad or the action was of the wrong type.
141 //
142 // In the case of |PDFACTION_REMOTEGOTO|, you must first call
143 // FPDFAction_GetFilePath(), then load the document at that path, then pass
144 // the document handle from that document as |document| to FPDFAction_GetDest().
145 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document,
146                                                        FPDF_ACTION action);
147 
148 // Get the file path of |action|.
149 //
150 //   action - handle to the action. |action| must be a |PDFACTION_LAUNCH| or
151 //            |PDFACTION_REMOTEGOTO|.
152 //   buffer - a buffer for output the path string. May be NULL.
153 //   buflen - the length of the buffer, in bytes. May be 0.
154 //
155 // Returns the number of bytes in the file path, including the trailing NUL
156 // character, or 0 on error, typically because the arguments were bad or the
157 // action was of the wrong type.
158 //
159 // Regardless of the platform, the |buffer| is always in UTF-8 encoding.
160 // If |buflen| is less than the returned length, or |buffer| is NULL, |buffer|
161 // will not be modified.
162 FPDF_EXPORT unsigned long FPDF_CALLCONV
163 FPDFAction_GetFilePath(FPDF_ACTION action, void* buffer, unsigned long buflen);
164 
165 // Get the URI path of |action|.
166 //
167 //   document - handle to the document.
168 //   action   - handle to the action. Must be a |PDFACTION_URI|.
169 //   buffer   - a buffer for the path string. May be NULL.
170 //   buflen   - the length of the buffer, in bytes. May be 0.
171 //
172 // Returns the number of bytes in the URI path, including the trailing NUL
173 // character, or 0 on error, typically because the arguments were bad or the
174 // action was of the wrong type.
175 //
176 // The |buffer| is always encoded in 7-bit ASCII. If |buflen| is less than the
177 // returned length, or |buffer| is NULL, |buffer| will not be modified.
178 FPDF_EXPORT unsigned long FPDF_CALLCONV
179 FPDFAction_GetURIPath(FPDF_DOCUMENT document,
180                       FPDF_ACTION action,
181                       void* buffer,
182                       unsigned long buflen);
183 
184 // Get the page index of |dest|.
185 //
186 //   document - handle to the document.
187 //   dest     - handle to the destination.
188 //
189 // Returns the 0-based page index containing |dest|. Returns -1 on error.
190 FPDF_EXPORT int FPDF_CALLCONV FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document,
191                                                         FPDF_DEST dest);
192 
193 // Get the view (fit type) specified by |dest|.
194 // Experimental API. Subject to change.
195 //
196 //   dest         - handle to the destination.
197 //   pNumParams   - receives the number of view parameters, which is at most 4.
198 //   pParams      - buffer to write the view parameters. Must be at least 4
199 //                  FS_FLOATs long.
200 // Returns one of the PDFDEST_VIEW_* constants, PDFDEST_VIEW_UNKNOWN_MODE if
201 // |dest| does not specify a view.
202 FPDF_EXPORT unsigned long FPDF_CALLCONV
203 FPDFDest_GetView(FPDF_DEST dest, unsigned long* pNumParams, FS_FLOAT* pParams);
204 
205 // Get the (x, y, zoom) location of |dest| in the destination page, if the
206 // destination is in [page /XYZ x y zoom] syntax.
207 //
208 //   dest       - handle to the destination.
209 //   hasXVal    - out parameter; true if the x value is not null
210 //   hasYVal    - out parameter; true if the y value is not null
211 //   hasZoomVal - out parameter; true if the zoom value is not null
212 //   x          - out parameter; the x coordinate, in page coordinates.
213 //   y          - out parameter; the y coordinate, in page coordinates.
214 //   zoom       - out parameter; the zoom value.
215 // Returns TRUE on successfully reading the /XYZ value.
216 //
217 // Note the [x, y, zoom] values are only set if the corresponding hasXVal,
218 // hasYVal or hasZoomVal flags are true.
219 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
220 FPDFDest_GetLocationInPage(FPDF_DEST dest,
221                            FPDF_BOOL* hasXVal,
222                            FPDF_BOOL* hasYVal,
223                            FPDF_BOOL* hasZoomVal,
224                            FS_FLOAT* x,
225                            FS_FLOAT* y,
226                            FS_FLOAT* zoom);
227 
228 // Find a link at point (|x|,|y|) on |page|.
229 //
230 //   page - handle to the document page.
231 //   x    - the x coordinate, in the page coordinate system.
232 //   y    - the y coordinate, in the page coordinate system.
233 //
234 // Returns a handle to the link, or NULL if no link found at the given point.
235 //
236 // You can convert coordinates from screen coordinates to page coordinates using
237 // FPDF_DeviceToPage().
238 FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFLink_GetLinkAtPoint(FPDF_PAGE page,
239                                                             double x,
240                                                             double y);
241 
242 // Find the Z-order of link at point (|x|,|y|) on |page|.
243 //
244 //   page - handle to the document page.
245 //   x    - the x coordinate, in the page coordinate system.
246 //   y    - the y coordinate, in the page coordinate system.
247 //
248 // Returns the Z-order of the link, or -1 if no link found at the given point.
249 // Larger Z-order numbers are closer to the front.
250 //
251 // You can convert coordinates from screen coordinates to page coordinates using
252 // FPDF_DeviceToPage().
253 FPDF_EXPORT int FPDF_CALLCONV FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page,
254                                                             double x,
255                                                             double y);
256 
257 // Get destination info for |link|.
258 //
259 //   document - handle to the document.
260 //   link     - handle to the link.
261 //
262 // Returns a handle to the destination, or NULL if there is no destination
263 // associated with the link. In this case, you should call FPDFLink_GetAction()
264 // to retrieve the action associated with |link|.
265 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document,
266                                                      FPDF_LINK link);
267 
268 // Get action info for |link|.
269 //
270 //   link - handle to the link.
271 //
272 // Returns a handle to the action associated to |link|, or NULL if no action.
273 FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK link);
274 
275 // Enumerates all the link annotations in |page|.
276 //
277 //   page       - handle to the page.
278 //   start_pos  - the start position, should initially be 0 and is updated with
279 //                the next start position on return.
280 //   link_annot - the link handle for |startPos|.
281 //
282 // Returns TRUE on success.
283 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page,
284                                                        int* start_pos,
285                                                        FPDF_LINK* link_annot);
286 
287 // Get the rectangle for |link_annot|.
288 //
289 //   link_annot - handle to the link annotation.
290 //   rect       - the annotation rectangle.
291 //
292 // Returns true on success.
293 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK link_annot,
294                                                           FS_RECTF* rect);
295 
296 // Get the count of quadrilateral points to the |link_annot|.
297 //
298 //   link_annot - handle to the link annotation.
299 //
300 // Returns the count of quadrilateral points.
301 FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountQuadPoints(FPDF_LINK link_annot);
302 
303 // Get the quadrilateral points for the specified |quad_index| in |link_annot|.
304 //
305 //   link_annot  - handle to the link annotation.
306 //   quad_index  - the specified quad point index.
307 //   quad_points - receives the quadrilateral points.
308 //
309 // Returns true on success.
310 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
311 FPDFLink_GetQuadPoints(FPDF_LINK link_annot,
312                        int quad_index,
313                        FS_QUADPOINTSF* quad_points);
314 
315 // Get meta-data |tag| content from |document|.
316 //
317 //   document - handle to the document.
318 //   tag      - the tag to retrieve. The tag can be one of:
319 //                Title, Author, Subject, Keywords, Creator, Producer,
320 //                CreationDate, or ModDate.
321 //              For detailed explanations of these tags and their respective
322 //              values, please refer to PDF Reference 1.6, section 10.2.1,
323 //              'Document Information Dictionary'.
324 //   buffer   - a buffer for the tag. May be NULL.
325 //   buflen   - the length of the buffer, in bytes. May be 0.
326 //
327 // Returns the number of bytes in the tag, including trailing zeros.
328 //
329 // The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two
330 // bytes of zeros indicating the end of the string.  If |buflen| is less than
331 // the returned length, or |buffer| is NULL, |buffer| will not be modified.
332 //
333 // For linearized files, FPDFAvail_IsFormAvail must be called before this, and
334 // it must have returned PDF_FORM_AVAIL or PDF_FORM_NOTEXIST. Before that, there
335 // is no guarantee the metadata has been loaded.
336 FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetMetaText(FPDF_DOCUMENT document,
337                                                          FPDF_BYTESTRING tag,
338                                                          void* buffer,
339                                                          unsigned long buflen);
340 
341 // Get the page label for |page_index| from |document|.
342 //
343 //   document    - handle to the document.
344 //   page_index  - the 0-based index of the page.
345 //   buffer      - a buffer for the page label. May be NULL.
346 //   buflen      - the length of the buffer, in bytes. May be 0.
347 //
348 // Returns the number of bytes in the page label, including trailing zeros.
349 //
350 // The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two
351 // bytes of zeros indicating the end of the string.  If |buflen| is less than
352 // the returned length, or |buffer| is NULL, |buffer| will not be modified.
353 FPDF_EXPORT unsigned long FPDF_CALLCONV
354 FPDF_GetPageLabel(FPDF_DOCUMENT document,
355                   int page_index,
356                   void* buffer,
357                   unsigned long buflen);
358 
359 #ifdef __cplusplus
360 }  // extern "C"
361 #endif  // __cplusplus
362 
363 #endif  // PUBLIC_FPDF_DOC_H_
364