Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4680 right-hear 1
#ifndef _MUXPS_H_
2
#define _MUXPS_H_
3
 
4
#ifndef _FITZ_H_
5
#error "fitz.h must be included before muxps.h"
6
#endif
7
 
8
typedef unsigned char byte;
9
 
10
/*
11
 * XPS and ZIP constants.
12
 */
13
 
14
typedef struct xps_context_s xps_context;
15
 
16
#define REL_START_PART \
17
	"http://schemas.microsoft.com/xps/2005/06/fixedrepresentation"
18
#define REL_REQUIRED_RESOURCE \
19
	"http://schemas.microsoft.com/xps/2005/06/required-resource"
20
#define REL_REQUIRED_RESOURCE_RECURSIVE \
21
	"http://schemas.microsoft.com/xps/2005/06/required-resource#recursive"
22
 
23
#define ZIP_LOCAL_FILE_SIG 0x04034b50
24
#define ZIP_DATA_DESC_SIG 0x08074b50
25
#define ZIP_CENTRAL_DIRECTORY_SIG 0x02014b50
26
#define ZIP_END_OF_CENTRAL_DIRECTORY_SIG 0x06054b50
27
 
28
/*
29
 * Memory, and string functions.
30
 */
31
 
32
int xps_strcasecmp(char *a, char *b);
33
void xps_absolute_path(char *output, char *base_uri, char *path, int output_size);
34
 
35
/*
36
 * XML document model
37
 */
38
 
39
typedef struct element xml_element;
40
 
41
xml_element *xml_parse_document(byte *buf, int len);
42
xml_element *xml_next(xml_element *item);
43
xml_element *xml_down(xml_element *item);
44
char *xml_tag(xml_element *item);
45
char *xml_att(xml_element *item, const char *att);
46
void xml_free_element(xml_element *item);
47
void xml_print_element(xml_element *item, int level);
48
 
49
/*
50
 * Container parts.
51
 */
52
 
53
typedef struct xps_part_s xps_part;
54
 
55
struct xps_part_s
56
{
57
	char *name;
58
	int size;
59
	int cap;
60
	byte *data;
61
};
62
 
63
xps_part *xps_new_part(xps_context *ctx, char *name, int size);
64
xps_part *xps_read_part(xps_context *ctx, char *partname);
65
void xps_free_part(xps_context *ctx, xps_part *part);
66
 
67
/*
68
 * Document structure.
69
 */
70
 
71
typedef struct xps_document_s xps_document;
72
typedef struct xps_page_s xps_page;
73
 
74
struct xps_document_s
75
{
76
	char *name;
77
	xps_document *next;
78
};
79
 
80
struct xps_page_s
81
{
82
	char *name;
83
	int width;
84
	int height;
85
	xml_element *root;
86
	xps_page *next;
87
};
88
 
89
int xps_read_page_list(xps_context *ctx);
90
void xps_debug_page_list(xps_context *ctx);
91
void xps_free_page_list(xps_context *ctx);
92
 
93
int xps_count_pages(xps_context *ctx);
94
int xps_load_page(xps_page **page, xps_context *ctx, int number);
95
void xps_free_page(xps_context *ctx, xps_page *page);
96
 
97
/*
98
 * Images, fonts, and colorspaces.
99
 */
100
 
101
int xps_decode_jpeg(fz_pixmap **imagep, byte *rbuf, int rlen);
102
int xps_decode_png(fz_pixmap **imagep, byte *rbuf, int rlen);
103
int xps_decode_tiff(fz_pixmap **imagep, byte *rbuf, int rlen);
104
 
105
typedef struct xps_font_cache_s xps_font_cache;
106
 
107
struct xps_font_cache_s
108
{
109
	char *name;
110
	fz_font *font;
111
	xps_font_cache *next;
112
};
113
 
114
typedef struct xps_glyph_metrics_s xps_glyph_metrics;
115
 
116
struct xps_glyph_metrics_s
117
{
118
	float hadv, vadv, vorg;
119
};
120
 
121
int xps_count_font_encodings(fz_font *font);
122
void xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid);
123
void xps_select_font_encoding(fz_font *font, int idx);
124
int xps_encode_font_char(fz_font *font, int key);
125
 
126
void xps_measure_font_glyph(xps_context *ctx, fz_font *font, int gid, xps_glyph_metrics *mtx);
127
 
128
void xps_debug_path(xps_context *ctx);
129
 
130
void xps_parse_color(xps_context *ctx, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples);
131
void xps_set_color(xps_context *ctx, fz_colorspace *colorspace, float *samples);
132
 
133
/*
134
 * Resource dictionaries.
135
 */
136
 
137
typedef struct xps_resource_s xps_resource;
138
 
139
struct xps_resource_s
140
{
141
	char *name;
142
	char *base_uri; /* only used in the head nodes */
143
	xml_element *base_xml; /* only used in the head nodes, to free the xml document */
144
	xml_element *data;
145
	xps_resource *next;
146
	xps_resource *parent; /* up to the previous dict in the stack */
147
};
148
 
149
int xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base_uri, xml_element *root);
150
void xps_free_resource_dictionary(xps_context *ctx, xps_resource *dict);
151
void xps_resolve_resource_reference(xps_context *ctx, xps_resource *dict, char **attp, xml_element **tagp, char **urip);
152
 
153
void xps_debug_resource_dictionary(xps_resource *dict);
154
 
155
/*
156
 * Fixed page/graphics parsing.
157
 */
158
 
159
void xps_parse_fixed_page(xps_context *ctx, fz_matrix ctm, xps_page *page);
160
void xps_parse_canvas(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node);
161
void xps_parse_path(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node);
162
void xps_parse_glyphs(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node);
163
void xps_parse_solid_color_brush(xps_context *ctx, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node);
164
void xps_parse_image_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node);
165
void xps_parse_visual_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node);
166
void xps_parse_linear_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node);
167
void xps_parse_radial_gradient_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node);
168
 
169
void xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, void(*func)(xps_context*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user);
170
 
171
void xps_parse_matrix_transform(xps_context *ctx, xml_element *root, fz_matrix *matrix);
172
void xps_parse_render_transform(xps_context *ctx, char *text, fz_matrix *matrix);
173
void xps_parse_rectangle(xps_context *ctx, char *text, fz_rect *rect);
174
 
175
void xps_begin_opacity(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag);
176
void xps_end_opacity(xps_context *ctx, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag);
177
 
178
void xps_parse_brush(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node);
179
void xps_parse_element(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node);
180
 
181
void xps_clip(xps_context *ctx, fz_matrix ctm, xps_resource *dict, char *clip_att, xml_element *clip_tag);
182
 
183
/*
184
 * The interpreter context.
185
 */
186
 
187
typedef struct xps_entry_s xps_entry;
188
 
189
struct xps_entry_s
190
{
191
	char *name;
192
	int offset;
193
	int csize;
194
	int usize;
195
};
196
 
197
struct xps_context_s
198
{
199
	char *directory;
200
	fz_stream *file;
201
	int zip_count;
202
	xps_entry *zip_table;
203
 
204
	char *start_part; /* fixed document sequence */
205
	xps_document *first_fixdoc; /* first fixed document */
206
	xps_document *last_fixdoc; /* last fixed document */
207
	xps_page *first_page; /* first page of document */
208
	xps_page *last_page; /* last page of document */
209
 
210
	char *base_uri; /* base uri for parsing XML and resolving relative paths */
211
	char *part_uri; /* part uri for parsing metadata relations */
212
 
213
	/* We cache font resources */
214
	xps_font_cache *font_table;
215
 
216
	/* Opacity attribute stack */
217
	float opacity[64];
218
	int opacity_top;
219
 
220
	/* Current color */
221
	fz_colorspace *colorspace;
222
	float color[8];
223
	float alpha;
224
 
225
	/* Current device */
226
	fz_device *dev;
227
};
228
 
229
int xps_open_file(xps_context **ctxp, char *filename);
230
int xps_open_stream(xps_context **ctxp, fz_stream *file);
231
void xps_free_context(xps_context *ctx);
232
 
233
#endif