1#ifndef MUPDF_PDF_XREF_H
2#define MUPDF_PDF_XREF_H
3
4int pdf_create_object(fz_context *ctx, pdf_document *doc);
5
6void pdf_delete_object(fz_context *ctx, pdf_document *doc, int num);
7
8void pdf_update_object(fz_context *ctx, pdf_document *doc, int num, pdf_obj *obj);
9
10void pdf_update_stream(fz_context *ctx, pdf_document *doc, pdf_obj *ref, fz_buffer *buf, int compressed);
11
12pdf_obj *pdf_add_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
13pdf_obj *pdf_add_object_drop(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
14pdf_obj *pdf_add_stream(fz_context *ctx, pdf_document *doc, fz_buffer *buf, pdf_obj *obj, int compressed);
15
16pdf_obj *pdf_add_new_dict(fz_context *ctx, pdf_document *doc, int initial);
17pdf_obj *pdf_add_new_array(fz_context *ctx, pdf_document *doc, int initial);
18
19typedef struct pdf_xref_entry_s pdf_xref_entry;
20
21struct pdf_xref_entry_s
22{
23 char type; /* 0=unset (f)ree i(n)use (o)bjstm */
24 unsigned char marked; /* marked to keep alive with pdf_mark_xref */
25 unsigned short gen; /* generation / objstm index */
26 int num; /* original object number (for decryption after renumbering) */
27 int64_t ofs; /* file offset / objstm object number */
28 int64_t stm_ofs; /* on-disk stream */
29 fz_buffer *stm_buf; /* in-memory stream (for updated objects) */
30 pdf_obj *obj; /* stored/cached object */
31};
32
33typedef struct pdf_xref_subsec_s pdf_xref_subsec;
34
35struct pdf_xref_subsec_s
36{
37 pdf_xref_subsec *next;
38 int len;
39 int start;
40 pdf_xref_entry *table;
41};
42
43struct pdf_xref_s
44{
45 int num_objects;
46 pdf_xref_subsec *subsec;
47 pdf_obj *trailer;
48 pdf_obj *pre_repair_trailer;
49 pdf_unsaved_sig *unsaved_sigs;
50 pdf_unsaved_sig **unsaved_sigs_end;
51 int64_t end_ofs; /* file offset to end of xref */
52};
53
54pdf_xref_entry *pdf_cache_object(fz_context *ctx, pdf_document *doc, int num);
55
56int pdf_count_objects(fz_context *ctx, pdf_document *doc);
57pdf_obj *pdf_resolve_indirect(fz_context *ctx, pdf_obj *ref);
58pdf_obj *pdf_resolve_indirect_chain(fz_context *ctx, pdf_obj *ref);
59pdf_obj *pdf_load_object(fz_context *ctx, pdf_document *doc, int num);
60pdf_obj *pdf_load_unencrypted_object(fz_context *ctx, pdf_document *doc, int num);
61
62fz_buffer *pdf_load_raw_stream_number(fz_context *ctx, pdf_document *doc, int num);
63fz_buffer *pdf_load_raw_stream(fz_context *ctx, pdf_obj *ref);
64fz_buffer *pdf_load_stream_number(fz_context *ctx, pdf_document *doc, int num);
65fz_buffer *pdf_load_stream(fz_context *ctx, pdf_obj *ref);
66fz_stream *pdf_open_raw_stream_number(fz_context *ctx, pdf_document *doc, int num);
67fz_stream *pdf_open_raw_stream(fz_context *ctx, pdf_obj *ref);
68fz_stream *pdf_open_stream_number(fz_context *ctx, pdf_document *doc, int num);
69fz_stream *pdf_open_stream(fz_context *ctx, pdf_obj *ref);
70
71fz_stream *pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, fz_compression_params *params);
72fz_compressed_buffer *pdf_load_compressed_stream(fz_context *ctx, pdf_document *doc, int num);
73void pdf_load_compressed_inline_image(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int length, fz_stream *cstm, int indexed, fz_compressed_image *image);
74fz_stream *pdf_open_stream_with_offset(fz_context *ctx, pdf_document *doc, int num, pdf_obj *dict, int64_t stm_ofs);
75fz_stream *pdf_open_compressed_stream(fz_context *ctx, fz_compressed_buffer *);
76fz_stream *pdf_open_contents_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
77
78pdf_obj *pdf_trailer(fz_context *ctx, pdf_document *doc);
79void pdf_set_populating_xref_trailer(fz_context *ctx, pdf_document *doc, pdf_obj *trailer);
80int pdf_xref_len(fz_context *ctx, pdf_document *doc);
81pdf_xref_entry *pdf_get_populating_xref_entry(fz_context *ctx, pdf_document *doc, int i);
82pdf_xref_entry *pdf_get_xref_entry(fz_context *ctx, pdf_document *doc, int i);
83void pdf_replace_xref(fz_context *ctx, pdf_document *doc, pdf_xref_entry *entries, int n);
84void pdf_forget_xref(fz_context *ctx, pdf_document *doc);
85void pdf_xref_ensure_incremental_object(fz_context *ctx, pdf_document *doc, int num);
86int pdf_xref_is_incremental(fz_context *ctx, pdf_document *doc, int num);
87void pdf_xref_store_unsaved_signature(fz_context *ctx, pdf_document *doc, pdf_obj *field, pdf_pkcs7_signer *signer);
88int pdf_xref_obj_is_unsaved_signature(pdf_document *doc, pdf_obj *obj);
89
90void pdf_repair_xref(fz_context *ctx, pdf_document *doc);
91void pdf_repair_obj_stms(fz_context *ctx, pdf_document *doc);
92void pdf_ensure_solid_xref(fz_context *ctx, pdf_document *doc, int num);
93void pdf_mark_xref(fz_context *ctx, pdf_document *doc);
94void pdf_clear_xref(fz_context *ctx, pdf_document *doc);
95void pdf_clear_xref_to_mark(fz_context *ctx, pdf_document *doc);
96
97int pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int64_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int64_t *tmpofs, pdf_obj **root);
98
99pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum);
100
101#endif
102