• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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_STRUCTTREE_H_
8 #define PUBLIC_FPDF_STRUCTTREE_H_
9 
10 // clang-format off
11 // NOLINTNEXTLINE(build/include)
12 #include "fpdfview.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 // Function: FPDF_StructTree_GetForPage
19 //          Get the structure tree for a page.
20 // Parameters:
21 //          page        -   Handle to the page, as returned by FPDF_LoadPage().
22 // Return value:
23 //          A handle to the structure tree or NULL on error. The caller owns the
24 //          returned handle and must use FPDF_StructTree_Close() to release it.
25 //          The handle should be released before |page| gets released.
26 FPDF_EXPORT FPDF_STRUCTTREE FPDF_CALLCONV
27 FPDF_StructTree_GetForPage(FPDF_PAGE page);
28 
29 // Function: FPDF_StructTree_Close
30 //          Release a resource allocated by FPDF_StructTree_GetForPage().
31 // Parameters:
32 //          struct_tree -   Handle to the structure tree, as returned by
33 //                          FPDF_StructTree_LoadPage().
34 // Return value:
35 //          None.
36 FPDF_EXPORT void FPDF_CALLCONV
37 FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree);
38 
39 // Function: FPDF_StructTree_CountChildren
40 //          Count the number of children for the structure tree.
41 // Parameters:
42 //          struct_tree -   Handle to the structure tree, as returned by
43 //                          FPDF_StructTree_LoadPage().
44 // Return value:
45 //          The number of children, or -1 on error.
46 FPDF_EXPORT int FPDF_CALLCONV
47 FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree);
48 
49 // Function: FPDF_StructTree_GetChildAtIndex
50 //          Get a child in the structure tree.
51 // Parameters:
52 //          struct_tree -   Handle to the structure tree, as returned by
53 //                          FPDF_StructTree_LoadPage().
54 //          index       -   The index for the child, 0-based.
55 // Return value:
56 //          The child at the n-th index or NULL on error. The caller does not
57 //          own the handle. The handle remains valid as long as |struct_tree|
58 //          remains valid.
59 // Comments:
60 //          The |index| must be less than the FPDF_StructTree_CountChildren()
61 //          return value.
62 FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV
63 FPDF_StructTree_GetChildAtIndex(FPDF_STRUCTTREE struct_tree, int index);
64 
65 // Function: FPDF_StructElement_GetAltText
66 //          Get the alt text for a given element.
67 // Parameters:
68 //          struct_element -   Handle to the struct element.
69 //          buffer         -   A buffer for output the alt text. May be NULL.
70 //          buflen         -   The length of the buffer, in bytes. May be 0.
71 // Return value:
72 //          The number of bytes in the alt text, including the terminating NUL
73 //          character. The number of bytes is returned regardless of the
74 //          |buffer| and |buflen| parameters.
75 // Comments:
76 //          Regardless of the platform, the |buffer| is always in UTF-16LE
77 //          encoding. The string is terminated by a UTF16 NUL character. If
78 //          |buflen| is less than the required length, or |buffer| is NULL,
79 //          |buffer| will not be modified.
80 FPDF_EXPORT unsigned long FPDF_CALLCONV
81 FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element,
82                               void* buffer,
83                               unsigned long buflen);
84 
85 // Experimental API.
86 // Function: FPDF_StructElement_GetActualText
87 //          Get the actual text for a given element.
88 // Parameters:
89 //          struct_element -   Handle to the struct element.
90 //          buffer         -   A buffer for output the actual text. May be NULL.
91 //          buflen         -   The length of the buffer, in bytes. May be 0.
92 // Return value:
93 //          The number of bytes in the actual text, including the terminating
94 //          NUL character. The number of bytes is returned regardless of the
95 //          |buffer| and |buflen| parameters.
96 // Comments:
97 //          Regardless of the platform, the |buffer| is always in UTF-16LE
98 //          encoding. The string is terminated by a UTF16 NUL character. If
99 //          |buflen| is less than the required length, or |buffer| is NULL,
100 //          |buffer| will not be modified.
101 FPDF_EXPORT unsigned long FPDF_CALLCONV
102 FPDF_StructElement_GetActualText(FPDF_STRUCTELEMENT struct_element,
103                                  void* buffer,
104                                  unsigned long buflen);
105 
106 // Function: FPDF_StructElement_GetID
107 //          Get the ID for a given element.
108 // Parameters:
109 //          struct_element -   Handle to the struct element.
110 //          buffer         -   A buffer for output the ID string. May be NULL.
111 //          buflen         -   The length of the buffer, in bytes. May be 0.
112 // Return value:
113 //          The number of bytes in the ID string, including the terminating NUL
114 //          character. The number of bytes is returned regardless of the
115 //          |buffer| and |buflen| parameters.
116 // Comments:
117 //          Regardless of the platform, the |buffer| is always in UTF-16LE
118 //          encoding. The string is terminated by a UTF16 NUL character. If
119 //          |buflen| is less than the required length, or |buffer| is NULL,
120 //          |buffer| will not be modified.
121 FPDF_EXPORT unsigned long FPDF_CALLCONV
122 FPDF_StructElement_GetID(FPDF_STRUCTELEMENT struct_element,
123                          void* buffer,
124                          unsigned long buflen);
125 
126 // Experimental API.
127 // Function: FPDF_StructElement_GetLang
128 //          Get the case-insensitive IETF BCP 47 language code for an element.
129 // Parameters:
130 //          struct_element -   Handle to the struct element.
131 //          buffer         -   A buffer for output the lang string. May be NULL.
132 //          buflen         -   The length of the buffer, in bytes. May be 0.
133 // Return value:
134 //          The number of bytes in the ID string, including the terminating NUL
135 //          character. The number of bytes is returned regardless of the
136 //          |buffer| and |buflen| parameters.
137 // Comments:
138 //          Regardless of the platform, the |buffer| is always in UTF-16LE
139 //          encoding. The string is terminated by a UTF16 NUL character. If
140 //          |buflen| is less than the required length, or |buffer| is NULL,
141 //          |buffer| will not be modified.
142 FPDF_EXPORT unsigned long FPDF_CALLCONV
143 FPDF_StructElement_GetLang(FPDF_STRUCTELEMENT struct_element,
144                            void* buffer,
145                            unsigned long buflen);
146 
147 // Experimental API.
148 // Function: FPDF_StructElement_GetStringAttribute
149 //          Get a struct element attribute of type "name" or "string".
150 // Parameters:
151 //          struct_element -   Handle to the struct element.
152 //          attr_name      -   The name of the attribute to retrieve.
153 //          buffer         -   A buffer for output. May be NULL.
154 //          buflen         -   The length of the buffer, in bytes. May be 0.
155 // Return value:
156 //          The number of bytes in the attribute value, including the
157 //          terminating NUL character. The number of bytes is returned
158 //          regardless of the |buffer| and |buflen| parameters.
159 // Comments:
160 //          Regardless of the platform, the |buffer| is always in UTF-16LE
161 //          encoding. The string is terminated by a UTF16 NUL character. If
162 //          |buflen| is less than the required length, or |buffer| is NULL,
163 //          |buffer| will not be modified.
164 FPDF_EXPORT unsigned long FPDF_CALLCONV
165 FPDF_StructElement_GetStringAttribute(FPDF_STRUCTELEMENT struct_element,
166                                       FPDF_BYTESTRING attr_name,
167                                       void* buffer,
168                                       unsigned long buflen);
169 
170 // Function: FPDF_StructElement_GetMarkedContentID
171 //          Get the marked content ID for a given element.
172 // Parameters:
173 //          struct_element -   Handle to the struct element.
174 // Return value:
175 //          The marked content ID of the element. If no ID exists, returns
176 //          -1.
177 // Comments:
178 //          FPDF_StructElement_GetMarkedContentIdAtIndex() may be able to
179 //          extract more marked content IDs out of |struct_element|. This API
180 //          may be deprecated in the future.
181 FPDF_EXPORT int FPDF_CALLCONV
182 FPDF_StructElement_GetMarkedContentID(FPDF_STRUCTELEMENT struct_element);
183 
184 // Function: FPDF_StructElement_GetType
185 //           Get the type (/S) for a given element.
186 // Parameters:
187 //           struct_element - Handle to the struct element.
188 //           buffer         - A buffer for output. May be NULL.
189 //           buflen         - The length of the buffer, in bytes. May be 0.
190 // Return value:
191 //           The number of bytes in the type, including the terminating NUL
192 //           character. The number of bytes is returned regardless of the
193 //           |buffer| and |buflen| parameters.
194 // Comments:
195 //           Regardless of the platform, the |buffer| is always in UTF-16LE
196 //           encoding. The string is terminated by a UTF16 NUL character. If
197 //           |buflen| is less than the required length, or |buffer| is NULL,
198 //           |buffer| will not be modified.
199 FPDF_EXPORT unsigned long FPDF_CALLCONV
200 FPDF_StructElement_GetType(FPDF_STRUCTELEMENT struct_element,
201                            void* buffer,
202                            unsigned long buflen);
203 
204 // Experimental API.
205 // Function: FPDF_StructElement_GetObjType
206 //           Get the object type (/Type) for a given element.
207 // Parameters:
208 //           struct_element - Handle to the struct element.
209 //           buffer         - A buffer for output. May be NULL.
210 //           buflen         - The length of the buffer, in bytes. May be 0.
211 // Return value:
212 //           The number of bytes in the object type, including the terminating
213 //           NUL character. The number of bytes is returned regardless of the
214 //           |buffer| and |buflen| parameters.
215 // Comments:
216 //           Regardless of the platform, the |buffer| is always in UTF-16LE
217 //           encoding. The string is terminated by a UTF16 NUL character. If
218 //           |buflen| is less than the required length, or |buffer| is NULL,
219 //           |buffer| will not be modified.
220 FPDF_EXPORT unsigned long FPDF_CALLCONV
221 FPDF_StructElement_GetObjType(FPDF_STRUCTELEMENT struct_element,
222                               void* buffer,
223                               unsigned long buflen);
224 
225 // Function: FPDF_StructElement_GetTitle
226 //           Get the title (/T) for a given element.
227 // Parameters:
228 //           struct_element - Handle to the struct element.
229 //           buffer         - A buffer for output. May be NULL.
230 //           buflen         - The length of the buffer, in bytes. May be 0.
231 // Return value:
232 //           The number of bytes in the title, including the terminating NUL
233 //           character. The number of bytes is returned regardless of the
234 //           |buffer| and |buflen| parameters.
235 // Comments:
236 //           Regardless of the platform, the |buffer| is always in UTF-16LE
237 //           encoding. The string is terminated by a UTF16 NUL character. If
238 //           |buflen| is less than the required length, or |buffer| is NULL,
239 //           |buffer| will not be modified.
240 FPDF_EXPORT unsigned long FPDF_CALLCONV
241 FPDF_StructElement_GetTitle(FPDF_STRUCTELEMENT struct_element,
242                             void* buffer,
243                             unsigned long buflen);
244 
245 // Function: FPDF_StructElement_CountChildren
246 //          Count the number of children for the structure element.
247 // Parameters:
248 //          struct_element -   Handle to the struct element.
249 // Return value:
250 //          The number of children, or -1 on error.
251 FPDF_EXPORT int FPDF_CALLCONV
252 FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element);
253 
254 // Function: FPDF_StructElement_GetChildAtIndex
255 //          Get a child in the structure element.
256 // Parameters:
257 //          struct_element -   Handle to the struct element.
258 //          index          -   The index for the child, 0-based.
259 // Return value:
260 //          The child at the n-th index or NULL on error.
261 // Comments:
262 //          If the child exists but is not an element, then this function will
263 //          return NULL. This will also return NULL for out of bounds indices.
264 //          The |index| must be less than the FPDF_StructElement_CountChildren()
265 //          return value.
266 FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV
267 FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element,
268                                    int index);
269 
270 // Experimental API.
271 // Function: FPDF_StructElement_GetChildMarkedContentID
272 //          Get the child's content id
273 // Parameters:
274 //          struct_element -   Handle to the struct element.
275 //          index          -   The index for the child, 0-based.
276 // Return value:
277 //          The marked content ID of the child. If no ID exists, returns -1.
278 // Comments:
279 //          If the child exists but is not a stream or object, then this
280 //          function will return -1. This will also return -1 for out of bounds
281 //          indices. Compared to FPDF_StructElement_GetMarkedContentIdAtIndex,
282 //          it is scoped to the current page.
283 //          The |index| must be less than the FPDF_StructElement_CountChildren()
284 //          return value.
285 FPDF_EXPORT int FPDF_CALLCONV
286 FPDF_StructElement_GetChildMarkedContentID(FPDF_STRUCTELEMENT struct_element,
287                                            int index);
288 
289 // Experimental API.
290 // Function: FPDF_StructElement_GetParent
291 //          Get the parent of the structure element.
292 // Parameters:
293 //          struct_element -   Handle to the struct element.
294 // Return value:
295 //          The parent structure element or NULL on error.
296 // Comments:
297 //          If structure element is StructTreeRoot, then this function will
298 //          return NULL.
299 FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV
300 FPDF_StructElement_GetParent(FPDF_STRUCTELEMENT struct_element);
301 
302 // Function: FPDF_StructElement_GetAttributeCount
303 //          Count the number of attributes for the structure element.
304 // Parameters:
305 //          struct_element -   Handle to the struct element.
306 // Return value:
307 //          The number of attributes, or -1 on error.
308 FPDF_EXPORT int FPDF_CALLCONV
309 FPDF_StructElement_GetAttributeCount(FPDF_STRUCTELEMENT struct_element);
310 
311 // Experimental API.
312 // Function: FPDF_StructElement_GetAttributeAtIndex
313 //          Get an attribute object in the structure element.
314 // Parameters:
315 //          struct_element -   Handle to the struct element.
316 //          index          -   The index for the attribute object, 0-based.
317 // Return value:
318 //          The attribute object at the n-th index or NULL on error.
319 // Comments:
320 //          If the attribute object exists but is not a dict, then this
321 //          function will return NULL. This will also return NULL for out of
322 //          bounds indices. The caller does not own the handle. The handle
323 //          remains valid as long as |struct_element| remains valid.
324 //          The |index| must be less than the
325 //          FPDF_StructElement_GetAttributeCount() return value.
326 FPDF_EXPORT FPDF_STRUCTELEMENT_ATTR FPDF_CALLCONV
327 FPDF_StructElement_GetAttributeAtIndex(FPDF_STRUCTELEMENT struct_element, int index);
328 
329 // Experimental API.
330 // Function: FPDF_StructElement_Attr_GetCount
331 //          Count the number of attributes in a structure element attribute map.
332 // Parameters:
333 //          struct_attribute - Handle to the struct element attribute.
334 // Return value:
335 //          The number of attributes, or -1 on error.
336 FPDF_EXPORT int FPDF_CALLCONV
337 FPDF_StructElement_Attr_GetCount(FPDF_STRUCTELEMENT_ATTR struct_attribute);
338 
339 
340 // Experimental API.
341 // Function: FPDF_StructElement_Attr_GetName
342 //          Get the name of an attribute in a structure element attribute map.
343 // Parameters:
344 //          struct_attribute   - Handle to the struct element attribute.
345 //          index              - The index of attribute in the map.
346 //          buffer             - A buffer for output. May be NULL. This is only
347 //                               modified if |buflen| is longer than the length
348 //                               of the key. Optional, pass null to just
349 //                               retrieve the size of the buffer needed.
350 //          buflen             - The length of the buffer.
351 //          out_buflen         - A pointer to variable that will receive the
352 //                               minimum buffer size to contain the key. Not
353 //                               filled if FALSE is returned.
354 // Return value:
355 //          TRUE if the operation was successful, FALSE otherwise.
356 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
357 FPDF_StructElement_Attr_GetName(FPDF_STRUCTELEMENT_ATTR struct_attribute,
358                                 int index,
359                                 void* buffer,
360                                 unsigned long buflen,
361                                 unsigned long* out_buflen);
362 // Experimental API.
363 // Function: FPDF_StructElement_Attr_GetValue
364 //           Get a handle to a value for an attribute in a structure element
365 //           attribute map.
366 // Parameters:
367 //           struct_attribute   - Handle to the struct element attribute.
368 //           name               - The attribute name.
369 // Return value:
370 //           Returns a handle to the value associated with the input, if any.
371 //           Returns NULL on failure. The caller does not own the handle.
372 //           The handle remains valid as long as |struct_attribute| remains
373 //           valid.
374 FPDF_EXPORT FPDF_STRUCTELEMENT_ATTR_VALUE FPDF_CALLCONV
375 FPDF_StructElement_Attr_GetValue(FPDF_STRUCTELEMENT_ATTR struct_attribute,
376                                  FPDF_BYTESTRING name);
377 
378 // Experimental API.
379 // Function: FPDF_StructElement_Attr_GetType
380 //           Get the type of an attribute in a structure element attribute map.
381 // Parameters:
382 //           value - Handle to the value.
383 // Return value:
384 //           Returns the type of the value, or FPDF_OBJECT_UNKNOWN in case of
385 //           failure. Note that this will never return FPDF_OBJECT_REFERENCE, as
386 //           references are always dereferenced.
387 FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV
388 FPDF_StructElement_Attr_GetType(FPDF_STRUCTELEMENT_ATTR_VALUE value);
389 
390 // Experimental API.
391 // Function: FPDF_StructElement_Attr_GetBooleanValue
392 //           Get the value of a boolean attribute in an attribute map as
393 //           FPDF_BOOL. FPDF_StructElement_Attr_GetType() should have returned
394 //           FPDF_OBJECT_BOOLEAN for this property.
395 // Parameters:
396 //           value     - Handle to the value.
397 //           out_value - A pointer to variable that will receive the value. Not
398 //                       filled if false is returned.
399 // Return value:
400 //           Returns TRUE if the attribute maps to a boolean value, FALSE
401 //           otherwise.
402 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
403 FPDF_StructElement_Attr_GetBooleanValue(FPDF_STRUCTELEMENT_ATTR_VALUE value,
404                                         FPDF_BOOL* out_value);
405 
406 // Experimental API.
407 // Function: FPDF_StructElement_Attr_GetNumberValue
408 //           Get the value of a number attribute in an attribute map as float.
409 //           FPDF_StructElement_Attr_GetType() should have returned
410 //           FPDF_OBJECT_NUMBER for this property.
411 // Parameters:
412 //           value     - Handle to the value.
413 //           out_value - A pointer to variable that will receive the value. Not
414 //                       filled if false is returned.
415 // Return value:
416 //           Returns TRUE if the attribute maps to a number value, FALSE
417 //           otherwise.
418 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
419 FPDF_StructElement_Attr_GetNumberValue(FPDF_STRUCTELEMENT_ATTR_VALUE value,
420                                        float* out_value);
421 
422 // Experimental API.
423 // Function: FPDF_StructElement_Attr_GetStringValue
424 //           Get the value of a string attribute in an attribute map as string.
425 //           FPDF_StructElement_Attr_GetType() should have returned
426 //           FPDF_OBJECT_STRING or FPDF_OBJECT_NAME for this property.
427 // Parameters:
428 //           value      - Handle to the value.
429 //           buffer     - A buffer for holding the returned key in UTF-16LE.
430 //                        This is only modified if |buflen| is longer than the
431 //                        length of the key. Optional, pass null to just
432 //                        retrieve the size of the buffer needed.
433 //           buflen     - The length of the buffer.
434 //           out_buflen - A pointer to variable that will receive the minimum
435 //                        buffer size to contain the key. Not filled if FALSE is
436 //                        returned.
437 // Return value:
438 //           Returns TRUE if the attribute maps to a string value, FALSE
439 //           otherwise.
440 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
441 FPDF_StructElement_Attr_GetStringValue(FPDF_STRUCTELEMENT_ATTR_VALUE value,
442                                        void* buffer,
443                                        unsigned long buflen,
444                                        unsigned long* out_buflen);
445 
446 // Experimental API.
447 // Function: FPDF_StructElement_Attr_GetBlobValue
448 //           Get the value of a blob attribute in an attribute map as string.
449 // Parameters:
450 //           value      - Handle to the value.
451 //           buffer     - A buffer for holding the returned value. This is only
452 //                        modified if |buflen| is at least as long as the length
453 //                        of the value. Optional, pass null to just retrieve the
454 //                        size of the buffer needed.
455 //           buflen     - The length of the buffer.
456 //           out_buflen - A pointer to variable that will receive the minimum
457 //                        buffer size to contain the key. Not filled if FALSE is
458 //                        returned.
459 // Return value:
460 //           Returns TRUE if the attribute maps to a string value, FALSE
461 //           otherwise.
462 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
463 FPDF_StructElement_Attr_GetBlobValue(FPDF_STRUCTELEMENT_ATTR_VALUE value,
464                                      void* buffer,
465                                      unsigned long buflen,
466                                      unsigned long* out_buflen);
467 
468 // Experimental API.
469 // Function: FPDF_StructElement_Attr_CountChildren
470 //           Count the number of children values in an attribute.
471 // Parameters:
472 //           value - Handle to the value.
473 // Return value:
474 //           The number of children, or -1 on error.
475 FPDF_EXPORT int FPDF_CALLCONV
476 FPDF_StructElement_Attr_CountChildren(FPDF_STRUCTELEMENT_ATTR_VALUE value);
477 
478 // Experimental API.
479 // Function: FPDF_StructElement_Attr_GetChildAtIndex
480 //           Get a child from an attribute.
481 // Parameters:
482 //           value - Handle to the value.
483 //           index - The index for the child, 0-based.
484 // Return value:
485 //           The child at the n-th index or NULL on error.
486 // Comments:
487 //           The |index| must be less than the
488 //           FPDF_StructElement_Attr_CountChildren() return value.
489 FPDF_EXPORT FPDF_STRUCTELEMENT_ATTR_VALUE FPDF_CALLCONV
490 FPDF_StructElement_Attr_GetChildAtIndex(FPDF_STRUCTELEMENT_ATTR_VALUE value,
491                                         int index);
492 
493 // Experimental API.
494 // Function: FPDF_StructElement_GetMarkedContentIdCount
495 //          Get the count of marked content ids for a given element.
496 // Parameters:
497 //          struct_element -   Handle to the struct element.
498 // Return value:
499 //          The count of marked content ids or -1 if none exists.
500 FPDF_EXPORT int FPDF_CALLCONV
501 FPDF_StructElement_GetMarkedContentIdCount(FPDF_STRUCTELEMENT struct_element);
502 
503 // Experimental API.
504 // Function: FPDF_StructElement_GetMarkedContentIdAtIndex
505 //          Get the marked content id at a given index for a given element.
506 // Parameters:
507 //          struct_element -   Handle to the struct element.
508 //          index          -   The index of the marked content id, 0-based.
509 // Return value:
510 //          The marked content ID of the element. If no ID exists, returns
511 //          -1.
512 // Comments:
513 //          The |index| must be less than the
514 //          FPDF_StructElement_GetMarkedContentIdCount() return value.
515 //          This will likely supersede FPDF_StructElement_GetMarkedContentID().
516 FPDF_EXPORT int FPDF_CALLCONV
517 FPDF_StructElement_GetMarkedContentIdAtIndex(FPDF_STRUCTELEMENT struct_element,
518                                              int index);
519 
520 #ifdef __cplusplus
521 }  // extern "C"
522 #endif
523 
524 #endif  // PUBLIC_FPDF_STRUCTTREE_H_
525