Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7643 views
1
#ifndef MUPDF_XPS_H
2
#define MUPDF_XPS_H
3
4
#include "mupdf/fitz.h"
5
6
typedef struct xps_document_s xps_document;
7
typedef struct xps_page_s xps_page;
8
9
/*
10
xps_open_document: Open a document.
11
12
Open a document for reading so the library is able to locate
13
objects and pages inside the file.
14
15
The returned xps_document should be used when calling most
16
other functions. Note that it wraps the context, so those
17
functions implicitly get access to the global state in
18
context.
19
20
filename: a path to a file as it would be given to open(2).
21
*/
22
xps_document *xps_open_document(fz_context *ctx, const char *filename);
23
24
/*
25
xps_open_document_with_stream: Opens a document.
26
27
Same as xps_open_document, but takes a stream instead of a
28
filename to locate the document to open. Increments the
29
reference count of the stream. See fz_open_file,
30
fz_open_file_w or fz_open_fd for opening a stream, and
31
fz_drop_stream for closing an open stream.
32
*/
33
xps_document *xps_open_document_with_stream(fz_context *ctx, fz_stream *file);
34
35
/*
36
xps_close_document: Closes and frees an opened document.
37
38
The resource store in the context associated with xps_document
39
is emptied.
40
41
Does not throw exceptions.
42
*/
43
void xps_close_document(fz_context *ctx, xps_document *doc);
44
45
int xps_count_pages(fz_context *ctx, xps_document *doc);
46
xps_page *xps_load_page(fz_context *ctx, xps_document *doc, int number);
47
fz_outline *xps_load_outline(fz_context *ctx, xps_document *doc);
48
void xps_run_page(fz_context *ctx, xps_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie);
49
50
/* xps-internal.h */
51
52
/*
53
* Memory, and string functions.
54
*/
55
56
int xps_strcasecmp(char *a, char *b);
57
void xps_resolve_url(fz_context *ctx, xps_document *doc, char *output, char *base_uri, char *path, int output_size);
58
int xps_url_is_remote(fz_context *ctx, xps_document *doc, char *path);
59
char *xps_parse_point(fz_context *ctx, xps_document *doc, char *s_in, float *x, float *y);
60
61
/*
62
* Container parts.
63
*/
64
65
typedef struct xps_part_s xps_part;
66
67
struct xps_part_s
68
{
69
char *name;
70
int size;
71
unsigned char *data;
72
};
73
74
int xps_has_part(fz_context *ctx, xps_document *doc, char *partname);
75
xps_part *xps_read_part(fz_context *ctx, xps_document *doc, char *partname);
76
void xps_drop_part(fz_context *ctx, xps_document *doc, xps_part *part);
77
78
/*
79
* Document structure.
80
*/
81
82
typedef struct xps_fixdoc_s xps_fixdoc;
83
typedef struct xps_fixpage_s xps_fixpage;
84
typedef struct xps_target_s xps_target;
85
86
struct xps_fixdoc_s
87
{
88
char *name;
89
char *outline;
90
xps_fixdoc *next;
91
};
92
93
struct xps_fixpage_s
94
{
95
char *name;
96
int number;
97
int width;
98
int height;
99
int links_resolved;
100
fz_link *links;
101
xps_fixpage *next;
102
};
103
104
struct xps_page_s
105
{
106
fz_page super;
107
xps_document *doc;
108
xps_fixpage *fix;
109
fz_xml *root;
110
};
111
112
struct xps_target_s
113
{
114
char *name;
115
int page;
116
xps_target *next;
117
};
118
119
void xps_read_page_list(fz_context *ctx, xps_document *doc);
120
void xps_print_page_list(fz_context *ctx, xps_document *doc);
121
void xps_drop_page_list(fz_context *ctx, xps_document *doc);
122
123
int xps_lookup_link_target(fz_context *ctx, xps_document *doc, char *target_uri);
124
void xps_add_link(fz_context *ctx, xps_document *doc, const fz_rect *area, char *base_uri, char *target_uri);
125
126
/*
127
* Images, fonts, and colorspaces.
128
*/
129
130
typedef struct xps_font_cache_s xps_font_cache;
131
132
struct xps_font_cache_s
133
{
134
char *name;
135
fz_font *font;
136
xps_font_cache *next;
137
};
138
139
typedef struct xps_glyph_metrics_s xps_glyph_metrics;
140
141
struct xps_glyph_metrics_s
142
{
143
float hadv, vadv, vorg;
144
};
145
146
int xps_count_font_encodings(fz_font *font);
147
void xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid);
148
void xps_select_font_encoding(fz_font *font, int idx);
149
int xps_encode_font_char(fz_font *font, int key);
150
151
void xps_measure_font_glyph(fz_context *ctx, xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx);
152
153
void xps_print_path(fz_context *ctx, xps_document *doc);
154
155
void xps_parse_color(fz_context *ctx, xps_document *doc, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples);
156
void xps_set_color(fz_context *ctx, xps_document *doc, fz_colorspace *colorspace, float *samples);
157
158
/*
159
* Resource dictionaries.
160
*/
161
162
typedef struct xps_resource_s xps_resource;
163
164
struct xps_resource_s
165
{
166
char *name;
167
char *base_uri; /* only used in the head nodes */
168
fz_xml *base_xml; /* only used in the head nodes, to free the xml document */
169
fz_xml *data;
170
xps_resource *next;
171
xps_resource *parent; /* up to the previous dict in the stack */
172
};
173
174
xps_resource * xps_parse_resource_dictionary(fz_context *ctx, xps_document *doc, char *base_uri, fz_xml *root);
175
void xps_drop_resource_dictionary(fz_context *ctx, xps_document *doc, xps_resource *dict);
176
void xps_resolve_resource_reference(fz_context *ctx, xps_document *doc, xps_resource *dict, char **attp, fz_xml **tagp, char **urip);
177
178
void xps_print_resource_dictionary(fz_context *ctx, xps_document *doc, xps_resource *dict);
179
180
/*
181
* Fixed page/graphics parsing.
182
*/
183
184
void xps_parse_fixed_page(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, xps_page *page);
185
void xps_parse_canvas(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
186
void xps_parse_path(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *node);
187
void xps_parse_glyphs(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *node);
188
void xps_parse_solid_color_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *node);
189
void xps_parse_image_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
190
void xps_parse_visual_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
191
void xps_parse_linear_gradient_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
192
void xps_parse_radial_gradient_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
193
194
void xps_parse_tiling_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *root, void(*func)(fz_context *ctx, xps_document*, const fz_matrix *, const fz_rect *, char*, xps_resource*, fz_xml*, void*), void *user);
195
196
void xps_parse_matrix_transform(fz_context *ctx, xps_document *doc, fz_xml *root, fz_matrix *matrix);
197
void xps_parse_render_transform(fz_context *ctx, xps_document *doc, char *text, fz_matrix *matrix);
198
void xps_parse_rectangle(fz_context *ctx, xps_document *doc, char *text, fz_rect *rect);
199
200
void xps_begin_opacity(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag);
201
void xps_end_opacity(fz_context *ctx, xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag);
202
203
void xps_parse_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
204
void xps_parse_element(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
205
206
void xps_clip(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, xps_resource *dict, char *clip_att, fz_xml *clip_tag);
207
208
fz_xml *xps_lookup_alternate_content(fz_context *ctx, xps_document *doc, fz_xml *node);
209
210
/*
211
* The interpreter context.
212
*/
213
214
typedef struct xps_entry_s xps_entry;
215
216
struct xps_entry_s
217
{
218
char *name;
219
int offset;
220
int csize;
221
int usize;
222
};
223
224
struct xps_document_s
225
{
226
fz_document super;
227
fz_archive *zip;
228
229
char *start_part; /* fixed document sequence */
230
xps_fixdoc *first_fixdoc; /* first fixed document */
231
xps_fixdoc *last_fixdoc; /* last fixed document */
232
xps_fixpage *first_page; /* first page of document */
233
xps_fixpage *last_page; /* last page of document */
234
int page_count;
235
236
xps_target *target; /* link targets */
237
238
char *base_uri; /* base uri for parsing XML and resolving relative paths */
239
char *part_uri; /* part uri for parsing metadata relations */
240
241
/* We cache font resources */
242
xps_font_cache *font_table;
243
244
/* Opacity attribute stack */
245
float opacity[64];
246
int opacity_top;
247
248
/* Current color */
249
fz_colorspace *colorspace;
250
float color[8];
251
float alpha;
252
253
/* Current device */
254
fz_device *dev;
255
fz_cookie *cookie;
256
257
/* Current page we are loading */
258
xps_fixpage *current_page;
259
};
260
261
#endif
262
263