annot.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. // Copyright (C) 2004-2025 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #ifndef MUPDF_PDF_ANNOT_H
  23. #define MUPDF_PDF_ANNOT_H
  24. #include "mupdf/fitz/display-list.h"
  25. #include "mupdf/fitz/stream.h"
  26. #include "mupdf/fitz/structured-text.h"
  27. #include "mupdf/pdf/object.h"
  28. #include "mupdf/pdf/page.h"
  29. typedef struct pdf_annot pdf_annot;
  30. enum pdf_annot_type
  31. {
  32. PDF_ANNOT_TEXT,
  33. PDF_ANNOT_LINK,
  34. PDF_ANNOT_FREE_TEXT,
  35. PDF_ANNOT_LINE,
  36. PDF_ANNOT_SQUARE,
  37. PDF_ANNOT_CIRCLE,
  38. PDF_ANNOT_POLYGON,
  39. PDF_ANNOT_POLY_LINE,
  40. PDF_ANNOT_HIGHLIGHT,
  41. PDF_ANNOT_UNDERLINE,
  42. PDF_ANNOT_SQUIGGLY,
  43. PDF_ANNOT_STRIKE_OUT,
  44. PDF_ANNOT_REDACT,
  45. PDF_ANNOT_STAMP,
  46. PDF_ANNOT_CARET,
  47. PDF_ANNOT_INK,
  48. PDF_ANNOT_POPUP,
  49. PDF_ANNOT_FILE_ATTACHMENT,
  50. PDF_ANNOT_SOUND,
  51. PDF_ANNOT_MOVIE,
  52. PDF_ANNOT_RICH_MEDIA,
  53. PDF_ANNOT_WIDGET,
  54. PDF_ANNOT_SCREEN,
  55. PDF_ANNOT_PRINTER_MARK,
  56. PDF_ANNOT_TRAP_NET,
  57. PDF_ANNOT_WATERMARK,
  58. PDF_ANNOT_3D,
  59. PDF_ANNOT_PROJECTION,
  60. PDF_ANNOT_UNKNOWN = -1
  61. };
  62. /*
  63. Map an annotation type to a (static) string.
  64. The returned string must not be freed by the caller.
  65. */
  66. const char *pdf_string_from_annot_type(fz_context *ctx, enum pdf_annot_type type);
  67. /*
  68. Map from a (non-NULL, case sensitive) string to an annotation
  69. type.
  70. */
  71. enum pdf_annot_type pdf_annot_type_from_string(fz_context *ctx, const char *subtype);
  72. enum
  73. {
  74. PDF_ANNOT_IS_INVISIBLE = 1 << (1-1),
  75. PDF_ANNOT_IS_HIDDEN = 1 << (2-1),
  76. PDF_ANNOT_IS_PRINT = 1 << (3-1),
  77. PDF_ANNOT_IS_NO_ZOOM = 1 << (4-1),
  78. PDF_ANNOT_IS_NO_ROTATE = 1 << (5-1),
  79. PDF_ANNOT_IS_NO_VIEW = 1 << (6-1),
  80. PDF_ANNOT_IS_READ_ONLY = 1 << (7-1),
  81. PDF_ANNOT_IS_LOCKED = 1 << (8-1),
  82. PDF_ANNOT_IS_TOGGLE_NO_VIEW = 1 << (9-1),
  83. PDF_ANNOT_IS_LOCKED_CONTENTS = 1 << (10-1)
  84. };
  85. enum pdf_line_ending
  86. {
  87. PDF_ANNOT_LE_NONE = 0,
  88. PDF_ANNOT_LE_SQUARE,
  89. PDF_ANNOT_LE_CIRCLE,
  90. PDF_ANNOT_LE_DIAMOND,
  91. PDF_ANNOT_LE_OPEN_ARROW,
  92. PDF_ANNOT_LE_CLOSED_ARROW,
  93. PDF_ANNOT_LE_BUTT,
  94. PDF_ANNOT_LE_R_OPEN_ARROW,
  95. PDF_ANNOT_LE_R_CLOSED_ARROW,
  96. PDF_ANNOT_LE_SLASH
  97. };
  98. enum
  99. {
  100. PDF_ANNOT_Q_LEFT = 0,
  101. PDF_ANNOT_Q_CENTER = 1,
  102. PDF_ANNOT_Q_RIGHT = 2
  103. };
  104. enum pdf_intent
  105. {
  106. PDF_ANNOT_IT_DEFAULT = 0,
  107. PDF_ANNOT_IT_FREETEXT_CALLOUT,
  108. PDF_ANNOT_IT_FREETEXT_TYPEWRITER,
  109. PDF_ANNOT_IT_LINE_ARROW,
  110. PDF_ANNOT_IT_LINE_DIMENSION,
  111. PDF_ANNOT_IT_POLYLINE_DIMENSION,
  112. PDF_ANNOT_IT_POLYGON_CLOUD,
  113. PDF_ANNOT_IT_POLYGON_DIMENSION,
  114. PDF_ANNOT_IT_STAMP_IMAGE,
  115. PDF_ANNOT_IT_STAMP_SNAPSHOT,
  116. PDF_ANNOT_IT_UNKNOWN = 255,
  117. };
  118. const char *pdf_string_from_intent(fz_context *ctx, enum pdf_intent intent);
  119. pdf_obj *pdf_name_from_intent(fz_context *ctx, enum pdf_intent intent);
  120. enum pdf_intent pdf_intent_from_string(fz_context *ctx, const char *str);
  121. enum pdf_intent pdf_intent_from_name(fz_context *ctx, pdf_obj *obj);
  122. /*
  123. Map from a PDF name specifying an annotation line ending
  124. to an enumerated line ending value.
  125. */
  126. enum pdf_line_ending pdf_line_ending_from_name(fz_context *ctx, pdf_obj *end);
  127. /*
  128. Map from a (non-NULL, case sensitive) C string specifying
  129. an annotation line ending to an enumerated line ending value.
  130. */
  131. enum pdf_line_ending pdf_line_ending_from_string(fz_context *ctx, const char *end);
  132. /*
  133. Map from an enumerated line ending to a pdf name object that
  134. specifies it.
  135. */
  136. pdf_obj *pdf_name_from_line_ending(fz_context *ctx, enum pdf_line_ending end);
  137. /*
  138. Map from an enumerated line ending to a C string that specifies
  139. it.
  140. The caller must not free the returned string.
  141. */
  142. const char *pdf_string_from_line_ending(fz_context *ctx, enum pdf_line_ending end);
  143. /*
  144. Increment the reference count for an annotation.
  145. Never throws exceptions. Returns the same pointer.
  146. */
  147. pdf_annot *pdf_keep_annot(fz_context *ctx, pdf_annot *annot);
  148. /*
  149. Drop the reference count for an annotation.
  150. When the reference count reaches zero, the annotation will
  151. be destroyed. Never throws exceptions.
  152. */
  153. void pdf_drop_annot(fz_context *ctx, pdf_annot *annot);
  154. /*
  155. Returns a borrowed reference to the first annotation on
  156. a page, or NULL if none.
  157. The caller should fz_keep this if it intends to hold the
  158. pointer. Unless it fz_keeps it, it must not fz_drop it.
  159. */
  160. pdf_annot *pdf_first_annot(fz_context *ctx, pdf_page *page);
  161. /*
  162. Returns a borrowed reference to the next annotation
  163. on a page, or NULL if none.
  164. The caller should fz_keep this if it intends to hold the
  165. pointer. Unless it fz_keeps it, it must not fz_drop it.
  166. */
  167. pdf_annot *pdf_next_annot(fz_context *ctx, pdf_annot *annot);
  168. /*
  169. Returns a borrowed reference to the object underlying
  170. an annotation.
  171. The caller should fz_keep this if it intends to hold the
  172. pointer. Unless it fz_keeps it, it must not fz_drop it.
  173. */
  174. pdf_obj *pdf_annot_obj(fz_context *ctx, pdf_annot *annot);
  175. /*
  176. Returns a borrowed reference to the page to which
  177. an annotation belongs.
  178. The caller should fz_keep this if it intends to hold the
  179. pointer. Unless it fz_keeps it, it must not fz_drop it.
  180. */
  181. pdf_page *pdf_annot_page(fz_context *ctx, pdf_annot *annot);
  182. /*
  183. Return the rectangle for an annotation on a page.
  184. */
  185. fz_rect pdf_bound_annot(fz_context *ctx, pdf_annot *annot);
  186. enum pdf_annot_type pdf_annot_type(fz_context *ctx, pdf_annot *annot);
  187. /*
  188. Interpret an annotation and render it on a device.
  189. page: A page loaded by pdf_load_page.
  190. annot: an annotation.
  191. dev: Device used for rendering, obtained from fz_new_*_device.
  192. ctm: A transformation matrix applied to the objects on the page,
  193. e.g. to scale or rotate the page contents as desired.
  194. */
  195. void pdf_run_annot(fz_context *ctx, pdf_annot *annot, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
  196. /*
  197. Lookup needle in the nametree of the document given by which.
  198. The returned reference is borrowed, and should not be dropped,
  199. unless it is kept first.
  200. */
  201. pdf_obj *pdf_lookup_name(fz_context *ctx, pdf_document *doc, pdf_obj *which, pdf_obj *needle);
  202. /*
  203. Load a nametree, flattening it into a single dictionary.
  204. The caller is responsible for pdf_dropping the returned
  205. reference.
  206. */
  207. pdf_obj *pdf_load_name_tree(fz_context *ctx, pdf_document *doc, pdf_obj *which);
  208. /*
  209. Lookup needle in the given number tree.
  210. The returned reference is borrowed, and should not be dropped,
  211. unless it is kept first.
  212. */
  213. pdf_obj *pdf_lookup_number(fz_context *ctx, pdf_obj *root, int needle);
  214. /*
  215. Perform a depth first traversal of a tree.
  216. Start at tree, looking for children in the array named
  217. kid_name at each level.
  218. The arrive callback is called when we arrive at a node (i.e.
  219. before all the children are walked), and then the leave callback
  220. is called as we leave it (after all the children have been
  221. walked).
  222. names and values are (matching) null terminated arrays of
  223. names and values to be carried down the tree, to implement
  224. inheritance. NULL is a permissible value.
  225. */
  226. void pdf_walk_tree(fz_context *ctx, pdf_obj *tree, pdf_obj *kid_name,
  227. void (*arrive)(fz_context *, pdf_obj *, void *, pdf_obj **),
  228. void (*leave)(fz_context *, pdf_obj *, void *),
  229. void *arg,
  230. pdf_obj **names,
  231. pdf_obj **values);
  232. /*
  233. Resolve a link within a document.
  234. */
  235. int pdf_resolve_link(fz_context *ctx, pdf_document *doc, const char *uri, float *xp, float *yp);
  236. fz_link_dest pdf_resolve_link_dest(fz_context *ctx, pdf_document *doc, const char *uri);
  237. /*
  238. Create an action object given a link URI. The action will
  239. be a GoTo or URI action depending on whether the link URI
  240. specifies a document internal or external destination.
  241. */
  242. pdf_obj *pdf_new_action_from_link(fz_context *ctx, pdf_document *doc, const char *uri);
  243. /*
  244. Create a destination object given a link URI expected to adhere
  245. to the Adobe specification "Parameters for Opening PDF files"
  246. from the Adobe Acrobat SDK. The resulting destination object
  247. will either be a PDF string, or a PDF array referring to a page
  248. and suitable zoom level settings. In the latter case the page
  249. can be referred to by PDF object number or by page number, this
  250. is controlled by the is_remote argument. For remote destinations
  251. it is not possible to refer to the page by object number, so
  252. page numbers are used instead.
  253. */
  254. pdf_obj *pdf_new_dest_from_link(fz_context *ctx, pdf_document *doc, const char *uri, int is_remote);
  255. /*
  256. Create a link URI string according to the Adobe specification
  257. "Parameters for Opening PDF files" from the Adobe Acrobat SDK,
  258. version 8.1, which can, at the time of writing, be found here:
  259. https://web.archive.org/web/20170921000830/http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
  260. The resulting string must be freed by the caller.
  261. */
  262. char *pdf_new_uri_from_explicit_dest(fz_context *ctx, fz_link_dest dest);
  263. /*
  264. Create a remote link URI string according to the Adobe specification
  265. "Parameters for Opening PDF files" from the Adobe Acrobat SDK,
  266. version 8.1, which can, at the time of writing, be found here:
  267. https://web.archive.org/web/20170921000830/http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
  268. The file: URI scheme is used in the resulting URI if the remote document
  269. is specified by a system independent path (already taking the recommendations
  270. in table 3.40 of the PDF 1.7 specification into account), and either a
  271. destination name or a page number and zoom level are appended:
  272. file:///path/doc.pdf#page=42&view=FitV,100
  273. file:///path/doc.pdf#nameddest=G42.123456
  274. If a URL is used to specify the remote document, then its scheme takes
  275. precedence and either a destination name or a page number and zoom level
  276. are appended:
  277. ftp://example.com/alpha.pdf#page=42&view=Fit
  278. https://example.com/bravo.pdf?query=parameter#page=42&view=Fit
  279. The resulting string must be freed by the caller.
  280. */
  281. char *pdf_append_named_dest_to_uri(fz_context *ctx, const char *url, const char *name);
  282. char *pdf_append_explicit_dest_to_uri(fz_context *ctx, const char *url, fz_link_dest dest);
  283. char *pdf_new_uri_from_path_and_named_dest(fz_context *ctx, const char *path, const char *name);
  284. char *pdf_new_uri_from_path_and_explicit_dest(fz_context *ctx, const char *path, fz_link_dest dest);
  285. /*
  286. Create transform to fit appearance stream to annotation Rect
  287. */
  288. fz_matrix pdf_annot_transform(fz_context *ctx, pdf_annot *annot);
  289. /*
  290. Create a new link object.
  291. */
  292. fz_link *pdf_new_link(fz_context *ctx, pdf_page *page, fz_rect rect, const char *uri, pdf_obj *obj);
  293. /*
  294. create a new annotation of the specified type on the
  295. specified page. The returned pdf_annot structure is owned by the
  296. page and does not need to be freed.
  297. */
  298. pdf_annot *pdf_create_annot_raw(fz_context *ctx, pdf_page *page, enum pdf_annot_type type);
  299. /*
  300. create a new link on the specified page. The returned fz_link
  301. structure is owned by the page and does not need to be freed.
  302. */
  303. fz_link *pdf_create_link(fz_context *ctx, pdf_page *page, fz_rect bbox, const char *uri);
  304. /*
  305. delete an existing link from the specified page.
  306. */
  307. void pdf_delete_link(fz_context *ctx, pdf_page *page, fz_link *link);
  308. enum pdf_border_style
  309. {
  310. PDF_BORDER_STYLE_SOLID = 0,
  311. PDF_BORDER_STYLE_DASHED,
  312. PDF_BORDER_STYLE_BEVELED,
  313. PDF_BORDER_STYLE_INSET,
  314. PDF_BORDER_STYLE_UNDERLINE,
  315. };
  316. enum pdf_border_effect
  317. {
  318. PDF_BORDER_EFFECT_NONE = 0,
  319. PDF_BORDER_EFFECT_CLOUDY,
  320. };
  321. /*
  322. create a new annotation of the specified type on the
  323. specified page. Populate it with sensible defaults per the type.
  324. Currently this returns a reference that the caller owns, and
  325. must drop when finished with it. Up until release 1.18, the
  326. returned reference was owned by the page and did not need to
  327. be freed.
  328. */
  329. pdf_annot *pdf_create_annot(fz_context *ctx, pdf_page *page, enum pdf_annot_type type);
  330. /*
  331. Delete an annotation from the page.
  332. This unlinks the annotation from the page structure and drops
  333. the pages reference to it. Any reference held by the caller
  334. will not be dropped automatically, so this can safely be used
  335. on a borrowed reference.
  336. */
  337. void pdf_delete_annot(fz_context *ctx, pdf_page *page, pdf_annot *annot);
  338. /*
  339. Edit the associated Popup annotation rectangle.
  340. Popup annotations are used to store the size and position of the
  341. popup box that is used to edit the contents of the markup annotation.
  342. */
  343. void pdf_set_annot_popup(fz_context *ctx, pdf_annot *annot, fz_rect rect);
  344. fz_rect pdf_annot_popup(fz_context *ctx, pdf_annot *annot);
  345. /*
  346. Check to see if an annotation has a rect.
  347. */
  348. int pdf_annot_has_rect(fz_context *ctx, pdf_annot *annot);
  349. /*
  350. Check to see if an annotation has an ink list.
  351. */
  352. int pdf_annot_has_ink_list(fz_context *ctx, pdf_annot *annot);
  353. /*
  354. Check to see if an annotation has quad points data.
  355. */
  356. int pdf_annot_has_quad_points(fz_context *ctx, pdf_annot *annot);
  357. /*
  358. Check to see if an annotation has vertex data.
  359. */
  360. int pdf_annot_has_vertices(fz_context *ctx, pdf_annot *annot);
  361. /*
  362. Check to see if an annotation has line data.
  363. */
  364. int pdf_annot_has_line(fz_context *ctx, pdf_annot *annot);
  365. /*
  366. Check to see if an annotation has an interior color.
  367. */
  368. int pdf_annot_has_interior_color(fz_context *ctx, pdf_annot *annot);
  369. /*
  370. Check to see if an annotation has line ending styles.
  371. */
  372. int pdf_annot_has_line_ending_styles(fz_context *ctx, pdf_annot *annot);
  373. /*
  374. Check to see if an annotation has quadding.
  375. */
  376. int pdf_annot_has_quadding(fz_context *ctx, pdf_annot *annot);
  377. /*
  378. Check to see if an annotation has a border.
  379. */
  380. int pdf_annot_has_border(fz_context *ctx, pdf_annot *annot);
  381. /*
  382. Check to see if an annotation has a border effect.
  383. */
  384. int pdf_annot_has_border_effect(fz_context *ctx, pdf_annot *annot);
  385. /*
  386. Check to see if an annotation has an icon name.
  387. */
  388. int pdf_annot_has_icon_name(fz_context *ctx, pdf_annot *annot);
  389. /*
  390. Check to see if an annotation has an open action.
  391. */
  392. int pdf_annot_has_open(fz_context *ctx, pdf_annot *annot);
  393. /*
  394. Check to see if an annotation has a popup annotation.
  395. */
  396. int pdf_annot_has_popup(fz_context *ctx, pdf_annot *annot);
  397. /*
  398. Check to see if an annotation has author data.
  399. */
  400. int pdf_annot_has_author(fz_context *ctx, pdf_annot *annot);
  401. /*
  402. Check to see if an annotation has rich content.
  403. */
  404. int pdf_annot_has_rich_contents(fz_context *ctx, pdf_annot *annot);
  405. /*
  406. Check to see if an annotation has rich default styles.
  407. */
  408. int pdf_annot_has_rich_defaults(fz_context *ctx, pdf_annot *annot);
  409. /*
  410. Retrieve the annotation flags.
  411. */
  412. int pdf_annot_flags(fz_context *ctx, pdf_annot *annot);
  413. /*
  414. Retrieve the annotation design rectangle in doc space.
  415. Note: This is NOT the same as the bounding rectangle.
  416. The design rectangle is the bounding rectangle adjusted
  417. by the RD padding.
  418. */
  419. fz_rect pdf_annot_rect(fz_context *ctx, pdf_annot *annot);
  420. /*
  421. Retrieve the annotation border line width in points.
  422. DEPRECATED: Use pdf_annot_border_width instead.
  423. */
  424. float pdf_annot_border(fz_context *ctx, pdf_annot *annot);
  425. /*
  426. Retrieve the annotation border style.
  427. */
  428. enum pdf_border_style pdf_annot_border_style(fz_context *ctx, pdf_annot *annot);
  429. /*
  430. Retrieve the annotation border width in points.
  431. */
  432. float pdf_annot_border_width(fz_context *ctx, pdf_annot *annot);
  433. /*
  434. How many items does the annotation border dash pattern have?
  435. */
  436. int pdf_annot_border_dash_count(fz_context *ctx, pdf_annot *annot);
  437. /*
  438. How long is dash item i in the annotation border dash pattern?
  439. */
  440. float pdf_annot_border_dash_item(fz_context *ctx, pdf_annot *annot, int i);
  441. /*
  442. Retrieve the annotation border effect.
  443. */
  444. enum pdf_border_effect pdf_annot_border_effect(fz_context *ctx, pdf_annot *annot);
  445. /*
  446. Retrieve the annotation border effect intensity.
  447. */
  448. float pdf_annot_border_effect_intensity(fz_context *ctx, pdf_annot *annot);
  449. /*
  450. Retrieve the annotation opacity. (0 transparent, 1 solid).
  451. */
  452. float pdf_annot_opacity(fz_context *ctx, pdf_annot *annot);
  453. /*
  454. Retrieve the annotation color.
  455. n components, each between 0 and 1.
  456. n = 1 (grey), 3 (rgb) or 4 (cmyk).
  457. */
  458. void pdf_annot_color(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
  459. /*
  460. Retrieve the annotation interior color.
  461. n components, each between 0 and 1.
  462. n = 1 (grey), 3 (rgb) or 4 (cmyk).
  463. */
  464. void pdf_annot_interior_color(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
  465. /*
  466. Retrieve the annotation quadding (justification) to use.
  467. 0 = Left-justified
  468. 1 = Centered
  469. 2 = Right-justified
  470. */
  471. int pdf_annot_quadding(fz_context *ctx, pdf_annot *annot);
  472. /*
  473. Retrieve the annotations text language (either from the
  474. annotation, or from the document).
  475. */
  476. fz_text_language pdf_annot_language(fz_context *ctx, pdf_annot *annot);
  477. /*
  478. How many quad points does an annotation have?
  479. */
  480. int pdf_annot_quad_point_count(fz_context *ctx, pdf_annot *annot);
  481. /*
  482. Get quadpoint i for an annotation.
  483. */
  484. fz_quad pdf_annot_quad_point(fz_context *ctx, pdf_annot *annot, int i);
  485. /*
  486. How many strokes in the ink list for an annotation?
  487. */
  488. int pdf_annot_ink_list_count(fz_context *ctx, pdf_annot *annot);
  489. /*
  490. How many vertices in stroke i of the ink list for an annotation?
  491. */
  492. int pdf_annot_ink_list_stroke_count(fz_context *ctx, pdf_annot *annot, int i);
  493. /*
  494. Get vertex k from stroke i of the ink list for an annotation, in
  495. doc space.
  496. */
  497. fz_point pdf_annot_ink_list_stroke_vertex(fz_context *ctx, pdf_annot *annot, int i, int k);
  498. /*
  499. Set the flags for an annotation.
  500. */
  501. void pdf_set_annot_flags(fz_context *ctx, pdf_annot *annot, int flags);
  502. /*
  503. Set the stamp appearance to a custom image.
  504. */
  505. pdf_obj *pdf_annot_stamp_image_obj(fz_context *ctx, pdf_annot *annot);
  506. void pdf_set_annot_stamp_image_obj(fz_context *ctx, pdf_annot *annot, pdf_obj *ref);
  507. void pdf_set_annot_stamp_image(fz_context *ctx, pdf_annot *annot, fz_image *image);
  508. /*
  509. Set the design rectangle for an annotation, in doc space.
  510. */
  511. void pdf_set_annot_rect(fz_context *ctx, pdf_annot *annot, fz_rect rect);
  512. /*
  513. Set the border width for an annotation, in points.
  514. DEPRECATED: Use pdf_set_annot_border_width instead.
  515. */
  516. void pdf_set_annot_border(fz_context *ctx, pdf_annot *annot, float width);
  517. /*
  518. Set the border style for an annotation.
  519. */
  520. void pdf_set_annot_border_style(fz_context *ctx, pdf_annot *annot, enum pdf_border_style style);
  521. /*
  522. Set the border width for an annotation in points;
  523. */
  524. void pdf_set_annot_border_width(fz_context *ctx, pdf_annot *annot, float width);
  525. /*
  526. Clear the entire border dash pattern for an annotation.
  527. */
  528. void pdf_clear_annot_border_dash(fz_context *ctx, pdf_annot *annot);
  529. /*
  530. Add an item to the end of the border dash pattern for an annotation.
  531. */
  532. void pdf_add_annot_border_dash_item(fz_context *ctx, pdf_annot *annot, float length);
  533. /*
  534. Set the border effect for an annotation.
  535. */
  536. void pdf_set_annot_border_effect(fz_context *ctx, pdf_annot *annot, enum pdf_border_effect effect);
  537. /*
  538. Set the border effect intensity for an annotation.
  539. */
  540. void pdf_set_annot_border_effect_intensity(fz_context *ctx, pdf_annot *annot, float intensity);
  541. /*
  542. Set the opacity for an annotation, between 0 (transparent) and 1
  543. (solid).
  544. */
  545. void pdf_set_annot_opacity(fz_context *ctx, pdf_annot *annot, float opacity);
  546. /*
  547. Set the annotation color.
  548. n components, each between 0 and 1.
  549. n = 1 (grey), 3 (rgb) or 4 (cmyk).
  550. */
  551. void pdf_set_annot_color(fz_context *ctx, pdf_annot *annot, int n, const float *color);
  552. /*
  553. Set the annotation interior color.
  554. n components, each between 0 and 1.
  555. n = 1 (grey), 3 (rgb) or 4 (cmyk).
  556. */
  557. void pdf_set_annot_interior_color(fz_context *ctx, pdf_annot *annot, int n, const float *color);
  558. /*
  559. Set the quadding (justification) to use for the annotation.
  560. 0 = Left-justified
  561. 1 = Centered
  562. 2 = Right-justified
  563. */
  564. void pdf_set_annot_quadding(fz_context *ctx, pdf_annot *annot, int q);
  565. /*
  566. Set the language for the annotation.
  567. */
  568. void pdf_set_annot_language(fz_context *ctx, pdf_annot *annot, fz_text_language lang);
  569. /*
  570. Set the quad points for an annotation to those in the qv array
  571. of length n.
  572. */
  573. void pdf_set_annot_quad_points(fz_context *ctx, pdf_annot *annot, int n, const fz_quad *qv);
  574. /*
  575. Clear the quadpoint data for an annotation.
  576. */
  577. void pdf_clear_annot_quad_points(fz_context *ctx, pdf_annot *annot);
  578. /*
  579. Append a new quad point to the quad point data in an annotation.
  580. */
  581. void pdf_add_annot_quad_point(fz_context *ctx, pdf_annot *annot, fz_quad quad);
  582. /*
  583. Set the ink list for an annotation.
  584. n strokes. For 0 <= i < n, stroke i has count[i] points,
  585. The vertices for all the strokes are packed into a single
  586. array, pointed to by v.
  587. */
  588. void pdf_set_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, const int *count, const fz_point *v);
  589. /*
  590. Clear the ink list for an annotation.
  591. */
  592. void pdf_clear_annot_ink_list(fz_context *ctx, pdf_annot *annot);
  593. /*
  594. Add a new stroke (initially empty) to the ink list for an
  595. annotation.
  596. */
  597. void pdf_add_annot_ink_list_stroke(fz_context *ctx, pdf_annot *annot);
  598. /*
  599. Add a new vertex to the last stroke in the ink list for an
  600. annotation.
  601. */
  602. void pdf_add_annot_ink_list_stroke_vertex(fz_context *ctx, pdf_annot *annot, fz_point p);
  603. /*
  604. Add a new stroke to the ink list for an annotation, and
  605. populate it with the n points from stroke[].
  606. */
  607. void pdf_add_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, fz_point stroke[]);
  608. /*
  609. */
  610. void pdf_set_annot_icon_name(fz_context *ctx, pdf_annot *annot, const char *name);
  611. void pdf_set_annot_is_open(fz_context *ctx, pdf_annot *annot, int is_open);
  612. enum pdf_line_ending pdf_annot_line_start_style(fz_context *ctx, pdf_annot *annot);
  613. enum pdf_line_ending pdf_annot_line_end_style(fz_context *ctx, pdf_annot *annot);
  614. void pdf_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, enum pdf_line_ending *start_style, enum pdf_line_ending *end_style);
  615. void pdf_set_annot_line_start_style(fz_context *ctx, pdf_annot *annot, enum pdf_line_ending s);
  616. void pdf_set_annot_line_end_style(fz_context *ctx, pdf_annot *annot, enum pdf_line_ending e);
  617. void pdf_set_annot_line_ending_styles(fz_context *ctx, pdf_annot *annot, enum pdf_line_ending start_style, enum pdf_line_ending end_style);
  618. const char *pdf_annot_icon_name(fz_context *ctx, pdf_annot *annot);
  619. int pdf_annot_is_open(fz_context *ctx, pdf_annot *annot);
  620. int pdf_annot_is_standard_stamp(fz_context *ctx, pdf_annot *annot);
  621. void pdf_annot_line(fz_context *ctx, pdf_annot *annot, fz_point *a, fz_point *b);
  622. void pdf_set_annot_line(fz_context *ctx, pdf_annot *annot, fz_point a, fz_point b);
  623. float pdf_annot_line_leader(fz_context *ctx, pdf_annot *annot);
  624. float pdf_annot_line_leader_extension(fz_context *ctx, pdf_annot *annot);
  625. float pdf_annot_line_leader_offset(fz_context *ctx, pdf_annot *annot);
  626. void pdf_set_annot_line_leader(fz_context *ctx, pdf_annot *annot, float ll);
  627. void pdf_set_annot_line_leader_extension(fz_context *ctx, pdf_annot *annot, float lle);
  628. void pdf_set_annot_line_leader_offset(fz_context *ctx, pdf_annot *annot, float llo);
  629. int pdf_annot_line_caption(fz_context *ctx, pdf_annot *annot);
  630. void pdf_set_annot_line_caption(fz_context *ctx, pdf_annot *annot, int cap);
  631. fz_point pdf_annot_line_caption_offset(fz_context *ctx, pdf_annot *annot);
  632. void pdf_set_annot_line_caption_offset(fz_context *ctx, pdf_annot *annot, fz_point offset);
  633. int pdf_annot_vertex_count(fz_context *ctx, pdf_annot *annot);
  634. fz_point pdf_annot_vertex(fz_context *ctx, pdf_annot *annot, int i);
  635. void pdf_set_annot_vertices(fz_context *ctx, pdf_annot *annot, int n, const fz_point *v);
  636. void pdf_clear_annot_vertices(fz_context *ctx, pdf_annot *annot);
  637. void pdf_add_annot_vertex(fz_context *ctx, pdf_annot *annot, fz_point p);
  638. void pdf_set_annot_vertex(fz_context *ctx, pdf_annot *annot, int i, fz_point p);
  639. const char *pdf_annot_contents(fz_context *ctx, pdf_annot *annot);
  640. void pdf_set_annot_contents(fz_context *ctx, pdf_annot *annot, const char *text);
  641. const char *pdf_annot_author(fz_context *ctx, pdf_annot *annot);
  642. void pdf_set_annot_author(fz_context *ctx, pdf_annot *annot, const char *author);
  643. int64_t pdf_annot_modification_date(fz_context *ctx, pdf_annot *annot);
  644. void pdf_set_annot_modification_date(fz_context *ctx, pdf_annot *annot, int64_t time);
  645. int64_t pdf_annot_creation_date(fz_context *ctx, pdf_annot *annot);
  646. void pdf_set_annot_creation_date(fz_context *ctx, pdf_annot *annot, int64_t time);
  647. int pdf_annot_has_intent(fz_context *ctx, pdf_annot *annot);
  648. enum pdf_intent pdf_annot_intent(fz_context *ctx, pdf_annot *annot);
  649. void pdf_set_annot_intent(fz_context *ctx, pdf_annot *annot, enum pdf_intent it);
  650. int pdf_annot_has_callout(fz_context *ctx, pdf_annot *annot);
  651. enum pdf_line_ending pdf_annot_callout_style(fz_context *ctx, pdf_annot *annot);
  652. void pdf_set_annot_callout_style(fz_context *ctx, pdf_annot *annot, enum pdf_line_ending style);
  653. void pdf_annot_callout_line(fz_context *ctx, pdf_annot *annot, fz_point callout[3], int *n);
  654. void pdf_set_annot_callout_line(fz_context *ctx, pdf_annot *annot, fz_point callout[3], int n);
  655. fz_point pdf_annot_callout_point(fz_context *ctx, pdf_annot *annot);
  656. void pdf_set_annot_callout_point(fz_context *ctx, pdf_annot *annot, fz_point p);
  657. int pdf_annot_has_default_appearance(fz_context *ctx, pdf_annot *annot);
  658. void pdf_parse_default_appearance_unmapped(fz_context *ctx, const char *da, char *font_name, int font_name_len, float *size, int *n, float color[4]);
  659. void pdf_parse_default_appearance(fz_context *ctx, const char *da, const char **font, float *size, int *n, float color[4]);
  660. void pdf_print_default_appearance(fz_context *ctx, char *buf, int nbuf, const char *font, float size, int n, const float *color);
  661. void pdf_annot_default_appearance_unmapped(fz_context *ctx, pdf_annot *annot, char *font_name, int font_name_len, float *size, int *n, float color[4]);
  662. void pdf_annot_default_appearance(fz_context *ctx, pdf_annot *annot, const char **font, float *size, int *n, float color[4]);
  663. void pdf_set_annot_default_appearance(fz_context *ctx, pdf_annot *annot, const char *font, float size, int n, const float *color);
  664. const char *pdf_annot_rich_contents(fz_context *ctx, pdf_annot *annot);
  665. void pdf_set_annot_rich_contents(fz_context *ctx, pdf_annot *annot, const char *plain, const char *rich);
  666. const char *pdf_annot_rich_defaults(fz_context *ctx, pdf_annot *annot);
  667. void pdf_set_annot_rich_defaults(fz_context *ctx, pdf_annot *annot, const char *style);
  668. /*
  669. * Request that an appearance stream should be generated for an annotation if none is present.
  670. * It will be created in future calls to pdf_update_annot or pdf_update_page.
  671. */
  672. void pdf_annot_request_synthesis(fz_context *ctx, pdf_annot *annot);
  673. /*
  674. * Request that an appearance stream should be re-generated for an annotation
  675. * the next time pdf_annot_update or pdf_page_update is called.
  676. * You usually won't need to call this, because changing any annotation attributes
  677. * via the pdf_annot functions will do so automatically.
  678. * It will be created in future calls to pdf_update_annot or pdf_update_page.
  679. */
  680. void pdf_annot_request_resynthesis(fz_context *ctx, pdf_annot *annot);
  681. int pdf_annot_needs_resynthesis(fz_context *ctx, pdf_annot *annot);
  682. void pdf_set_annot_resynthesised(fz_context *ctx, pdf_annot *annot);
  683. void pdf_dirty_annot(fz_context *ctx, pdf_annot *annot);
  684. int pdf_annot_field_flags(fz_context *ctx, pdf_annot *annot);
  685. const char *pdf_annot_field_value(fz_context *ctx, pdf_annot *annot);
  686. const char *pdf_annot_field_label(fz_context *ctx, pdf_annot *widget);
  687. int pdf_set_annot_field_value(fz_context *ctx, pdf_document *doc, pdf_annot *widget, const char *text, int ignore_trigger_events);
  688. /*
  689. Recreate the appearance stream for an annotation, if necessary.
  690. */
  691. fz_text *pdf_layout_fit_text(fz_context *ctx, fz_font *font, fz_text_language lang, const char *str, fz_rect bounds);
  692. /*
  693. Start/Stop using the annotation-local xref. This allows us to
  694. generate appearance streams that don't actually hit the underlying
  695. document.
  696. */
  697. void pdf_annot_push_local_xref(fz_context *ctx, pdf_annot *annot);
  698. void pdf_annot_pop_local_xref(fz_context *ctx, pdf_annot *annot);
  699. void pdf_annot_ensure_local_xref(fz_context *ctx, pdf_annot *annot);
  700. void pdf_annot_pop_and_discard_local_xref(fz_context *ctx, pdf_annot *annot);
  701. /*
  702. Regenerate any appearance streams that are out of date and check for
  703. cases where a different appearance stream should be selected because of
  704. state changes.
  705. Note that a call to pdf_pass_event for one page may lead to changes on
  706. any other, so an app should call pdf_update_annot for every annotation
  707. it currently displays. Also it is important that the pdf_annot object
  708. is the one used to last render the annotation. If instead the app were
  709. to drop the page or annotations and reload them then a call to
  710. pdf_update_annot would not reliably be able to report all changed
  711. annotations.
  712. Returns true if the annotation appearance has changed since the last time
  713. pdf_update_annot was called or the annotation was first loaded.
  714. */
  715. int pdf_update_annot(fz_context *ctx, pdf_annot *annot);
  716. /*
  717. Recalculate form fields if necessary.
  718. Loop through all annotations on the page and update them. Return true
  719. if any of them were changed (by either event or javascript actions, or
  720. by annotation editing) and need re-rendering.
  721. If you need more granularity, loop through the annotations and call
  722. pdf_update_annot for each one to detect changes on a per-annotation
  723. basis.
  724. */
  725. int pdf_update_page(fz_context *ctx, pdf_page *page);
  726. /*
  727. Update internal state appropriate for editing this field. When editing
  728. is true, updating the text of the text widget will not have any
  729. side-effects such as changing other widgets or running javascript.
  730. This state is intended for the period when a text widget is having
  731. characters typed into it. The state should be reverted at the end of
  732. the edit sequence and the text newly updated.
  733. */
  734. void pdf_set_widget_editing_state(fz_context *ctx, pdf_annot *widget, int editing);
  735. int pdf_get_widget_editing_state(fz_context *ctx, pdf_annot *widget);
  736. /*
  737. Toggle the state of a specified annotation. Applies only to check-box
  738. and radio-button widgets.
  739. */
  740. int pdf_toggle_widget(fz_context *ctx, pdf_annot *widget);
  741. fz_display_list *pdf_new_display_list_from_annot(fz_context *ctx, pdf_annot *annot);
  742. /*
  743. Render an annotation suitable for blending on top of the opaque
  744. pixmap returned by fz_new_pixmap_from_page_contents.
  745. */
  746. fz_pixmap *pdf_new_pixmap_from_annot(fz_context *ctx, pdf_annot *annot, fz_matrix ctm, fz_colorspace *cs, fz_separations *seps, int alpha);
  747. fz_stext_page *pdf_new_stext_page_from_annot(fz_context *ctx, pdf_annot *annot, const fz_stext_options *options);
  748. fz_layout_block *pdf_layout_text_widget(fz_context *ctx, pdf_annot *annot);
  749. /*
  750. Parameters for and embedded file. Obtained through
  751. pdf_get_filespec_params(). The creation and
  752. modification date fields are < 0 if unknown.
  753. */
  754. typedef struct pdf_filespec_params {
  755. const char *filename;
  756. const char *mimetype;
  757. int size;
  758. int64_t created;
  759. int64_t modified;
  760. } pdf_filespec_params;
  761. /*
  762. Check if pdf object is a file specification.
  763. */
  764. int pdf_is_filespec(fz_context *ctx, pdf_obj *fs);
  765. /*
  766. Check if pdf object is a file specification where the data
  767. is embedded within the PDF file.
  768. */
  769. int pdf_is_embedded_file(fz_context *ctx, pdf_obj *fs);
  770. /*
  771. Add an embedded file to the document. This can later
  772. be passed e.g. to pdf_annot_set_filespec(). If unknown,
  773. supply NULL for MIME type and -1 for the date arguments.
  774. If a checksum is added it can later be verified by calling
  775. pdf_verify_embedded_file_checksum().
  776. */
  777. pdf_obj *pdf_add_embedded_file(fz_context *ctx, pdf_document *doc, const char *filename, const char *mimetype, fz_buffer *contents, int64_t created, int64_t modified, int add_checksum);
  778. /*
  779. Obtain parameters for a filespec: name, size,
  780. creation and modification dates and MIME type.
  781. */
  782. void pdf_get_filespec_params(fz_context *ctx, pdf_obj *fs, pdf_filespec_params *out);
  783. /*
  784. Load embedded file contents in a buffer which
  785. needs to be dropped by the called after use.
  786. */
  787. fz_buffer *pdf_load_embedded_file_contents(fz_context *ctx, pdf_obj *fs);
  788. /*
  789. Verifies the embedded file checksum. Returns 1
  790. if the verification is successful or there is no
  791. checksum to be verified, or 0 if verification fails.
  792. */
  793. int pdf_verify_embedded_file_checksum(fz_context *ctx, pdf_obj *fs);
  794. pdf_obj *pdf_lookup_dest(fz_context *ctx, pdf_document *doc, pdf_obj *needle);
  795. fz_link *pdf_load_link_annots(fz_context *ctx, pdf_document *, pdf_page *, pdf_obj *annots, int pagenum, fz_matrix page_ctm);
  796. void pdf_annot_MK_BG(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
  797. void pdf_annot_MK_BC(fz_context *ctx, pdf_annot *annot, int *n, float color[4]);
  798. int pdf_annot_MK_BG_rgb(fz_context *ctx, pdf_annot *annot, float rgb[3]);
  799. int pdf_annot_MK_BC_rgb(fz_context *ctx, pdf_annot *annot, float rgb[3]);
  800. pdf_obj *pdf_annot_ap(fz_context *ctx, pdf_annot *annot);
  801. int pdf_annot_active(fz_context *ctx, pdf_annot *annot);
  802. void pdf_set_annot_active(fz_context *ctx, pdf_annot *annot, int active);
  803. int pdf_annot_hot(fz_context *ctx, pdf_annot *annot);
  804. void pdf_set_annot_hot(fz_context *ctx, pdf_annot *annot, int hot);
  805. void pdf_set_annot_appearance(fz_context *ctx, pdf_annot *annot, const char *appearance, const char *state, fz_matrix ctm, fz_rect bbox, pdf_obj *res, fz_buffer *contents);
  806. void pdf_set_annot_appearance_from_display_list(fz_context *ctx, pdf_annot *annot, const char *appearance, const char *state, fz_matrix ctm, fz_display_list *list);
  807. /*
  808. Check to see if an annotation has a file specification.
  809. */
  810. int pdf_annot_has_filespec(fz_context *ctx, pdf_annot *annot);
  811. /*
  812. Retrieve the file specification for the given annotation.
  813. */
  814. pdf_obj *pdf_annot_filespec(fz_context *ctx, pdf_annot *annot);
  815. /*
  816. Set the annotation file specification.
  817. */
  818. void pdf_set_annot_filespec(fz_context *ctx, pdf_annot *annot, pdf_obj *obj);
  819. /*
  820. Get/set a hidden flag preventing the annotation from being
  821. rendered when it is being edited. This flag is independent
  822. of the hidden flag in the PDF annotation object described in the PDF specification.
  823. */
  824. int pdf_annot_hidden_for_editing(fz_context *ctx, pdf_annot *annot);
  825. void pdf_set_annot_hidden_for_editing(fz_context *ctx, pdf_annot *annot, int hidden);
  826. /*
  827. * Apply Redaction annotation by redacting page underneath and removing the annotation.
  828. */
  829. int pdf_apply_redaction(fz_context *ctx, pdf_annot *annot, pdf_redact_options *opts);
  830. #endif