Skip to content

Commit 54dd8e6

Browse files
author
rtoslab
committed
add xps sources.
1 parent 0b0d900 commit 54dd8e6

14 files changed

+5081
-0
lines changed

SConscript

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cwd = GetCurrentDir()
77
src = Glob('cbz/*.c')
88
src = Glob('draw/*.c')
99
src = Glob('pdf/*.c')
10+
src = Glob('xps/*.c')
1011

1112
path = [cwd + '/']
1213
path += [cwd + '/fitz']

xps/muxps-internal.h

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#ifndef MUXPS_INTERNAL_H
2+
#define MUXPS_INTERNAL_H
3+
4+
#include "muxps.h"
5+
#include "fitz-internal.h"
6+
7+
typedef unsigned char byte;
8+
9+
/*
10+
* Memory, and string functions.
11+
*/
12+
13+
int xps_strcasecmp(char *a, char *b);
14+
void xps_resolve_url(char *output, char *base_uri, char *path, int output_size);
15+
int xps_url_is_remote(char *path);
16+
char *xps_parse_point(char *s_in, float *x, float *y);
17+
18+
/*
19+
* Container parts.
20+
*/
21+
22+
typedef struct xps_part_s xps_part;
23+
24+
struct xps_part_s
25+
{
26+
char *name;
27+
int size;
28+
int cap;
29+
byte *data;
30+
};
31+
32+
xps_part *xps_new_part(xps_document *doc, char *name, int size);
33+
int xps_has_part(xps_document *doc, char *partname);
34+
xps_part *xps_read_part(xps_document *doc, char *partname);
35+
void xps_free_part(xps_document *doc, xps_part *part);
36+
37+
/*
38+
* Document structure.
39+
*/
40+
41+
typedef struct xps_fixdoc_s xps_fixdoc;
42+
typedef struct xps_target_s xps_target;
43+
44+
struct xps_fixdoc_s
45+
{
46+
char *name;
47+
char *outline;
48+
xps_fixdoc *next;
49+
};
50+
51+
struct xps_page_s
52+
{
53+
char *name;
54+
int number;
55+
int width;
56+
int height;
57+
fz_xml *root;
58+
int links_resolved;
59+
fz_link *links;
60+
xps_page *next;
61+
};
62+
63+
struct xps_target_s
64+
{
65+
char *name;
66+
int page;
67+
xps_target *next;
68+
};
69+
70+
void xps_read_page_list(xps_document *doc);
71+
void xps_print_page_list(xps_document *doc);
72+
void xps_free_page_list(xps_document *doc);
73+
74+
int xps_count_pages(xps_document *doc);
75+
xps_page *xps_load_page(xps_document *doc, int number);
76+
fz_link *xps_load_links(xps_document *doc, xps_page *page);
77+
fz_rect *xps_bound_page(xps_document *doc, xps_page *page, fz_rect *rect);
78+
void xps_free_page(xps_document *doc, xps_page *page);
79+
80+
fz_outline *xps_load_outline(xps_document *doc);
81+
82+
int xps_lookup_link_target(xps_document *doc, char *target_uri);
83+
void xps_add_link(xps_document *doc, const fz_rect *area, char *base_uri, char *target_uri);
84+
/*
85+
* Images, fonts, and colorspaces.
86+
*/
87+
88+
typedef struct xps_font_cache_s xps_font_cache;
89+
90+
struct xps_font_cache_s
91+
{
92+
char *name;
93+
fz_font *font;
94+
xps_font_cache *next;
95+
};
96+
97+
typedef struct xps_glyph_metrics_s xps_glyph_metrics;
98+
99+
struct xps_glyph_metrics_s
100+
{
101+
float hadv, vadv, vorg;
102+
};
103+
104+
int xps_count_font_encodings(fz_font *font);
105+
void xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid);
106+
void xps_select_font_encoding(fz_font *font, int idx);
107+
int xps_encode_font_char(fz_font *font, int key);
108+
109+
void xps_measure_font_glyph(xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx);
110+
111+
void xps_print_path(xps_document *doc);
112+
113+
void xps_parse_color(xps_document *doc, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples);
114+
void xps_set_color(xps_document *doc, fz_colorspace *colorspace, float *samples);
115+
116+
/*
117+
* Resource dictionaries.
118+
*/
119+
120+
typedef struct xps_resource_s xps_resource;
121+
122+
struct xps_resource_s
123+
{
124+
char *name;
125+
char *base_uri; /* only used in the head nodes */
126+
fz_xml *base_xml; /* only used in the head nodes, to free the xml document */
127+
fz_xml *data;
128+
xps_resource *next;
129+
xps_resource *parent; /* up to the previous dict in the stack */
130+
};
131+
132+
xps_resource * xps_parse_resource_dictionary(xps_document *doc, char *base_uri, fz_xml *root);
133+
void xps_free_resource_dictionary(xps_document *doc, xps_resource *dict);
134+
void xps_resolve_resource_reference(xps_document *doc, xps_resource *dict, char **attp, fz_xml **tagp, char **urip);
135+
136+
void xps_print_resource_dictionary(xps_resource *dict);
137+
138+
/*
139+
* Fixed page/graphics parsing.
140+
*/
141+
142+
void xps_parse_fixed_page(xps_document *doc, const fz_matrix *ctm, xps_page *page);
143+
void xps_parse_canvas(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
144+
void xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *node);
145+
void xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *node);
146+
void xps_parse_solid_color_brush(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_resource *dict, fz_xml *node);
147+
void xps_parse_image_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
148+
void xps_parse_visual_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
149+
void xps_parse_linear_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
150+
void xps_parse_radial_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
151+
152+
void xps_parse_tiling_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *root, void(*func)(xps_document*, const fz_matrix *, const fz_rect *, char*, xps_resource*, fz_xml*, void*), void *user);
153+
154+
void xps_parse_matrix_transform(xps_document *doc, fz_xml *root, fz_matrix *matrix);
155+
void xps_parse_render_transform(xps_document *doc, char *text, fz_matrix *matrix);
156+
void xps_parse_rectangle(xps_document *doc, char *text, fz_rect *rect);
157+
158+
void xps_begin_opacity(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);
159+
void xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, fz_xml *opacity_mask_tag);
160+
161+
void xps_parse_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
162+
void xps_parse_element(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node);
163+
164+
void xps_clip(xps_document *doc, const fz_matrix *ctm, xps_resource *dict, char *clip_att, fz_xml *clip_tag);
165+
166+
fz_xml *xps_lookup_alternate_content(fz_xml *node);
167+
168+
/*
169+
* The interpreter context.
170+
*/
171+
172+
typedef struct xps_entry_s xps_entry;
173+
174+
struct xps_entry_s
175+
{
176+
char *name;
177+
int offset;
178+
int csize;
179+
int usize;
180+
};
181+
182+
struct xps_document_s
183+
{
184+
fz_document super;
185+
186+
fz_context *ctx;
187+
char *directory;
188+
fz_stream *file;
189+
int zip_count;
190+
xps_entry *zip_table;
191+
192+
char *start_part; /* fixed document sequence */
193+
xps_fixdoc *first_fixdoc; /* first fixed document */
194+
xps_fixdoc *last_fixdoc; /* last fixed document */
195+
xps_page *first_page; /* first page of document */
196+
xps_page *last_page; /* last page of document */
197+
int page_count;
198+
199+
xps_target *target; /* link targets */
200+
201+
char *base_uri; /* base uri for parsing XML and resolving relative paths */
202+
char *part_uri; /* part uri for parsing metadata relations */
203+
204+
/* We cache font resources */
205+
xps_font_cache *font_table;
206+
207+
/* Opacity attribute stack */
208+
float opacity[64];
209+
int opacity_top;
210+
211+
/* Current color */
212+
fz_colorspace *colorspace;
213+
float color[8];
214+
float alpha;
215+
216+
/* Current device */
217+
fz_cookie *cookie;
218+
fz_device *dev;
219+
220+
/* Current page we are loading */
221+
xps_page *current_page;
222+
};
223+
224+
#endif

xps/muxps.h

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef MUXPS_H
2+
#define MUXPS_H
3+
4+
#include "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_close 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(xps_document *doc);
44+
45+
int xps_count_pages(xps_document *doc);
46+
xps_page *xps_load_page(xps_document *doc, int number);
47+
fz_rect *xps_bound_page(xps_document *doc, xps_page *page, fz_rect *rect);
48+
void xps_run_page(xps_document *doc, xps_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie);
49+
fz_link *xps_load_links(xps_document *doc, xps_page *page);
50+
void xps_free_page(xps_document *doc, xps_page *page);
51+
52+
fz_outline *xps_load_outline(xps_document *doc);
53+
54+
#endif

0 commit comments

Comments
 (0)