comparison mupdf-source/source/xps/xps-imp.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright (C) 2004-2024 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
23 #ifndef SOURCE_XPS_IMP_H
24 #define SOURCE_XPS_IMP_H
25
26 typedef struct xps_document_s xps_document;
27 typedef struct xps_page_s xps_page;
28
29 fz_document *xps_open_document(fz_context *ctx, const char *filename);
30 fz_document *xps_open_document_with_stream(fz_context *ctx, fz_stream *file);
31 fz_document *xps_open_document_with_directory(fz_context *ctx, fz_archive *dir);
32 int xps_count_pages(fz_context *ctx, fz_document *doc, int chapter);
33 fz_page *xps_load_page(fz_context *ctx, fz_document *doc, int chapter, int number);
34 fz_outline *xps_load_outline(fz_context *ctx, fz_document *doc);
35 void xps_run_page(fz_context *ctx, fz_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
36 fz_link *xps_load_links(fz_context *ctx, fz_page *page);
37 fz_link_dest xps_lookup_link_target(fz_context *ctx, fz_document *doc, const char *target_uri);
38
39 int xps_strcasecmp(char *a, char *b);
40 void xps_resolve_url(fz_context *ctx, xps_document *doc, char *output, char *base_uri, char *path, int output_size);
41 char *xps_parse_point(fz_context *ctx, xps_document *doc, char *s_in, float *x, float *y);
42
43 typedef struct xps_part_s xps_part;
44
45 struct xps_part_s
46 {
47 char *name;
48 fz_buffer *data;
49 };
50
51 int xps_has_part(fz_context *ctx, xps_document *doc, char *partname);
52
53 /*
54 Read and interleave split parts from a ZIP file.
55 */
56 xps_part *xps_read_part(fz_context *ctx, xps_document *doc, char *partname);
57 void xps_drop_part(fz_context *ctx, xps_document *doc, xps_part *part);
58
59 typedef struct xps_fixdoc_s xps_fixdoc;
60 typedef struct xps_fixpage_s xps_fixpage;
61 typedef struct xps_target_s xps_target;
62
63 struct xps_fixdoc_s
64 {
65 char *name;
66 char *outline;
67 xps_fixdoc *next;
68 };
69
70 struct xps_fixpage_s
71 {
72 char *name;
73 int number;
74 int width;
75 int height;
76 xps_fixpage *next;
77 };
78
79 struct xps_page_s
80 {
81 fz_page super;
82 xps_fixpage *fix;
83 fz_xml_doc *xml;
84 };
85
86 struct xps_target_s
87 {
88 char *name;
89 int page;
90 xps_target *next;
91 };
92
93 void xps_read_page_list(fz_context *ctx, xps_document *doc);
94 void xps_print_page_list(fz_context *ctx, xps_document *doc);
95 void xps_drop_page_list(fz_context *ctx, xps_document *doc);
96
97 typedef struct xps_font_cache_s xps_font_cache;
98
99 struct xps_font_cache_s
100 {
101 char *name;
102 fz_font *font;
103 xps_font_cache *next;
104 };
105
106 typedef struct xps_glyph_metrics_s xps_glyph_metrics;
107
108 struct xps_glyph_metrics_s
109 {
110 float hadv, vadv, vorg;
111 };
112
113 int xps_count_font_encodings(fz_context *ctx, fz_font *font);
114 void xps_identify_font_encoding(fz_context *ctx, fz_font *font, int idx, int *pid, int *eid);
115 void xps_select_font_encoding(fz_context *ctx, fz_font *font, int idx);
116 int xps_encode_font_char(fz_context *ctx, fz_font *font, int key);
117
118 void xps_measure_font_glyph(fz_context *ctx, xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx);
119
120 void xps_print_path(fz_context *ctx, xps_document *doc);
121
122 void xps_parse_color(fz_context *ctx, xps_document *doc, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples);
123 void xps_set_color(fz_context *ctx, xps_document *doc, fz_colorspace *colorspace, float *samples);
124
125 typedef struct xps_resource_s xps_resource;
126
127 struct xps_resource_s
128 {
129 char *name;
130 char *base_uri; /* only used in the head nodes */
131 fz_xml_doc *base_xml; /* only used in the head nodes, to free the xml document */
132 fz_xml *data;
133 xps_resource *next;
134 xps_resource *parent; /* up to the previous dict in the stack */
135 };
136
137 xps_resource * xps_parse_resource_dictionary(fz_context *ctx, xps_document *doc, char *base_uri, fz_xml *root);
138 void xps_drop_resource_dictionary(fz_context *ctx, xps_document *doc, xps_resource *dict);
139 void xps_resolve_resource_reference(fz_context *ctx, xps_document *doc, xps_resource *dict, char **attp, fz_xml **tagp, char **urip);
140
141 void xps_print_resource_dictionary(fz_context *ctx, xps_document *doc, xps_resource *dict);
142
143 void xps_parse_fixed_page(fz_context *ctx, xps_document *doc, fz_matrix ctm, xps_page *page);
144 void xps_parse_canvas(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
145
146 /*
147 Parse an XPS <Path> element, and call relevant
148 functions for drawing and/or clipping the child elements.
149 */
150 void xps_parse_path(fz_context *ctx, xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node);
151 void xps_parse_glyphs(fz_context *ctx, xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node);
152 void xps_parse_solid_color_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, fz_xml *node);
153 void xps_parse_image_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
154 void xps_parse_visual_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
155 void xps_parse_linear_gradient_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
156 void xps_parse_radial_gradient_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
157
158 void xps_parse_tiling_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *root, void(*func)(fz_context *ctx, xps_document*, fz_matrix, fz_rect, char*, xps_resource*, fz_xml*, void*), void *user);
159
160 fz_font *xps_lookup_font(fz_context *ctx, xps_document *doc, char *base_uri, char *font_uri, char *style_att);
161
162 /*
163 Parse an abbreviated geometry string, and call
164 moveto/lineto/curveto functions to build up a path.
165 */
166 fz_path *xps_parse_abbreviated_geometry(fz_context *ctx, xps_document *doc, char *geom, int *fill_rule);
167 fz_path *xps_parse_path_geometry(fz_context *ctx, xps_document *doc, xps_resource *dict, fz_xml *root, int stroking, int *fill_rule);
168 fz_matrix xps_parse_transform(fz_context *ctx, xps_document *doc, char *att, fz_xml *tag, fz_matrix ctm);
169 fz_rect xps_parse_rectangle(fz_context *ctx, xps_document *doc, char *text);
170
171 void xps_begin_opacity(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag);
172 void xps_end_opacity(fz_context *ctx, xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag);
173
174 void xps_parse_brush(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
175 void xps_parse_element(fz_context *ctx, xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, fz_xml *node);
176
177 void xps_clip(fz_context *ctx, xps_document *doc, fz_matrix ctm, xps_resource *dict, char *clip_att, fz_xml *clip_tag);
178
179 fz_xml *xps_lookup_alternate_content(fz_context *ctx, xps_document *doc, fz_xml *node);
180
181 typedef struct xps_entry_s xps_entry;
182
183 /* Implementation details: Subject to change. */
184
185 struct xps_entry_s
186 {
187 char *name;
188 int64_t offset;
189 int csize;
190 int usize;
191 };
192
193 struct xps_document_s
194 {
195 fz_document super;
196 fz_archive *zip;
197
198 char *start_part; /* fixed document sequence */
199 xps_fixdoc *first_fixdoc; /* first fixed document */
200 xps_fixdoc *last_fixdoc; /* last fixed document */
201 xps_fixpage *first_page; /* first page of document */
202 xps_fixpage *last_page; /* last page of document */
203 int page_count;
204
205 xps_target *target; /* link targets */
206
207 char *base_uri; /* base uri for parsing XML and resolving relative paths */
208 char *part_uri; /* part uri for parsing metadata relations */
209
210 /* We cache font resources */
211 xps_font_cache *font_table;
212
213 /* Opacity attribute stack */
214 float opacity[64];
215 int opacity_top;
216
217 /* Current color */
218 fz_colorspace *colorspace;
219 float color[8];
220 float alpha;
221
222 /* Current device */
223 fz_device *dev;
224 fz_cookie *cookie;
225 };
226
227 /*
228 Parse unicode and indices strings and encode glyphs.
229 Calculate metrics for positioning.
230 */
231 fz_text *xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, fz_matrix ctm,
232 fz_font *font, float size, float originx, float originy,
233 int is_sideways, int bidi_level,
234 char *indices, char *unicode);
235
236 #endif