Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7638 views
1
#ifndef PDF_INTERPRET_H
2
#define PDF_INTERPRET_H
3
4
typedef struct pdf_csi_s pdf_csi;
5
typedef struct pdf_gstate_s pdf_gstate;
6
typedef struct pdf_processor_s pdf_processor;
7
8
void *pdf_new_processor(fz_context *ctx, int size);
9
void pdf_drop_processor(fz_context *ctx, pdf_processor *proc);
10
11
struct pdf_processor_s
12
{
13
void (*drop_imp)(fz_context *ctx, pdf_processor *proc);
14
15
/* general graphics state */
16
void (*op_w)(fz_context *ctx, pdf_processor *proc, float linewidth);
17
void (*op_j)(fz_context *ctx, pdf_processor *proc, int linejoin);
18
void (*op_J)(fz_context *ctx, pdf_processor *proc, int linecap);
19
void (*op_M)(fz_context *ctx, pdf_processor *proc, float miterlimit);
20
void (*op_d)(fz_context *ctx, pdf_processor *proc, pdf_obj *array, float phase);
21
void (*op_ri)(fz_context *ctx, pdf_processor *proc, const char *intent);
22
void (*op_i)(fz_context *ctx, pdf_processor *proc, float flatness);
23
24
void (*op_gs_begin)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_obj *extgstate);
25
void (*op_gs_BM)(fz_context *ctx, pdf_processor *proc, const char *blendmode);
26
void (*op_gs_ca)(fz_context *ctx, pdf_processor *proc, float alpha);
27
void (*op_gs_CA)(fz_context *ctx, pdf_processor *proc, float alpha);
28
void (*op_gs_SMask)(fz_context *ctx, pdf_processor *proc, pdf_xobject *smask, pdf_obj *page_resources, float *bc, int luminosity);
29
void (*op_gs_end)(fz_context *ctx, pdf_processor *proc);
30
31
/* special graphics state */
32
void (*op_q)(fz_context *ctx, pdf_processor *proc);
33
void (*op_Q)(fz_context *ctx, pdf_processor *proc);
34
void (*op_cm)(fz_context *ctx, pdf_processor *proc, float a, float b, float c, float d, float e, float f);
35
36
/* path construction */
37
void (*op_m)(fz_context *ctx, pdf_processor *proc, float x, float y);
38
void (*op_l)(fz_context *ctx, pdf_processor *proc, float x, float y);
39
void (*op_c)(fz_context *ctx, pdf_processor *proc, float x1, float y1, float x2, float y2, float x3, float y3);
40
void (*op_v)(fz_context *ctx, pdf_processor *proc, float x2, float y2, float x3, float y3);
41
void (*op_y)(fz_context *ctx, pdf_processor *proc, float x1, float y1, float x3, float y3);
42
void (*op_h)(fz_context *ctx, pdf_processor *proc);
43
void (*op_re)(fz_context *ctx, pdf_processor *proc, float x, float y, float w, float h);
44
45
/* path painting */
46
void (*op_S)(fz_context *ctx, pdf_processor *proc);
47
void (*op_s)(fz_context *ctx, pdf_processor *proc);
48
void (*op_F)(fz_context *ctx, pdf_processor *proc);
49
void (*op_f)(fz_context *ctx, pdf_processor *proc);
50
void (*op_fstar)(fz_context *ctx, pdf_processor *proc);
51
void (*op_B)(fz_context *ctx, pdf_processor *proc);
52
void (*op_Bstar)(fz_context *ctx, pdf_processor *proc);
53
void (*op_b)(fz_context *ctx, pdf_processor *proc);
54
void (*op_bstar)(fz_context *ctx, pdf_processor *proc);
55
void (*op_n)(fz_context *ctx, pdf_processor *proc);
56
57
/* clipping paths */
58
void (*op_W)(fz_context *ctx, pdf_processor *proc);
59
void (*op_Wstar)(fz_context *ctx, pdf_processor *proc);
60
61
/* text objects */
62
void (*op_BT)(fz_context *ctx, pdf_processor *proc);
63
void (*op_ET)(fz_context *ctx, pdf_processor *proc);
64
65
/* text state */
66
void (*op_Tc)(fz_context *ctx, pdf_processor *proc, float charspace);
67
void (*op_Tw)(fz_context *ctx, pdf_processor *proc, float wordspace);
68
void (*op_Tz)(fz_context *ctx, pdf_processor *proc, float scale);
69
void (*op_TL)(fz_context *ctx, pdf_processor *proc, float leading);
70
void (*op_Tf)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_font_desc *font, float size);
71
void (*op_Tr)(fz_context *ctx, pdf_processor *proc, int render);
72
void (*op_Ts)(fz_context *ctx, pdf_processor *proc, float rise);
73
74
/* text positioning */
75
void (*op_Td)(fz_context *ctx, pdf_processor *proc, float tx, float ty);
76
void (*op_TD)(fz_context *ctx, pdf_processor *proc, float tx, float ty);
77
void (*op_Tm)(fz_context *ctx, pdf_processor *proc, float a, float b, float c, float d, float e, float f);
78
void (*op_Tstar)(fz_context *ctx, pdf_processor *proc);
79
80
/* text showing */
81
void (*op_TJ)(fz_context *ctx, pdf_processor *proc, pdf_obj *array);
82
void (*op_Tj)(fz_context *ctx, pdf_processor *proc, char *str, int len);
83
void (*op_squote)(fz_context *ctx, pdf_processor *proc, char *str, int len);
84
void (*op_dquote)(fz_context *ctx, pdf_processor *proc, float aw, float ac, char *str, int len);
85
86
/* type 3 fonts */
87
void (*op_d0)(fz_context *ctx, pdf_processor *proc, float wx, float wy);
88
void (*op_d1)(fz_context *ctx, pdf_processor *proc, float wx, float wy, float llx, float lly, float urx, float ury);
89
90
/* color */
91
void (*op_CS)(fz_context *ctx, pdf_processor *proc, const char *name, fz_colorspace *cs);
92
void (*op_cs)(fz_context *ctx, pdf_processor *proc, const char *name, fz_colorspace *cs);
93
void (*op_SC_pattern)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_pattern *pat, int n, float *color);
94
void (*op_sc_pattern)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_pattern *pat, int n, float *color);
95
void (*op_SC_shade)(fz_context *ctx, pdf_processor *proc, const char *name, fz_shade *shade);
96
void (*op_sc_shade)(fz_context *ctx, pdf_processor *proc, const char *name, fz_shade *shade);
97
void (*op_SC_color)(fz_context *ctx, pdf_processor *proc, int n, float *color);
98
void (*op_sc_color)(fz_context *ctx, pdf_processor *proc, int n, float *color);
99
100
void (*op_G)(fz_context *ctx, pdf_processor *proc, float g);
101
void (*op_g)(fz_context *ctx, pdf_processor *proc, float g);
102
void (*op_RG)(fz_context *ctx, pdf_processor *proc, float r, float g, float b);
103
void (*op_rg)(fz_context *ctx, pdf_processor *proc, float r, float g, float b);
104
void (*op_K)(fz_context *ctx, pdf_processor *proc, float c, float m, float y, float k);
105
void (*op_k)(fz_context *ctx, pdf_processor *proc, float c, float m, float y, float k);
106
107
/* shadings, images, xobjects */
108
void (*op_BI)(fz_context *ctx, pdf_processor *proc, fz_image *image);
109
void (*op_sh)(fz_context *ctx, pdf_processor *proc, const char *name, fz_shade *shade);
110
void (*op_Do_image)(fz_context *ctx, pdf_processor *proc, const char *name, fz_image *image);
111
void (*op_Do_form)(fz_context *ctx, pdf_processor *proc, const char *name, pdf_xobject *form, pdf_obj *page_resources);
112
113
/* marked content */
114
void (*op_MP)(fz_context *ctx, pdf_processor *proc, const char *tag);
115
void (*op_DP)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties);
116
void (*op_BMC)(fz_context *ctx, pdf_processor *proc, const char *tag);
117
void (*op_BDC)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties);
118
void (*op_EMC)(fz_context *ctx, pdf_processor *proc);
119
120
/* compatibility */
121
void (*op_BX)(fz_context *ctx, pdf_processor *proc);
122
void (*op_EX)(fz_context *ctx, pdf_processor *proc);
123
124
/* END is used to signify end of stream (finalise and close down) */
125
void (*op_END)(fz_context *ctx, pdf_processor *proc);
126
127
/* interpreter state that persists across content streams */
128
const char *event;
129
int hidden;
130
};
131
132
struct pdf_csi_s
133
{
134
/* input */
135
pdf_document *doc;
136
pdf_obj *rdb;
137
pdf_lexbuf *buf;
138
fz_cookie *cookie;
139
140
/* state */
141
int gstate;
142
int xbalance;
143
int in_text;
144
fz_rect d1_rect;
145
146
/* stack */
147
pdf_obj *obj;
148
char name[256];
149
char string[256];
150
int string_len;
151
int top;
152
float stack[32];
153
};
154
155
/* Functions to set up pdf_process structures */
156
pdf_processor *pdf_new_run_processor(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, const char *event, pdf_gstate *gstate, int nested);
157
pdf_processor *pdf_new_buffer_processor(fz_context *ctx, fz_buffer *buffer);
158
pdf_processor *pdf_new_filter_processor(fz_context *ctx, pdf_processor *chain, pdf_document *doc, pdf_obj *old_res, pdf_obj *new_res);
159
160
/* Functions to actually process annotations, glyphs and general stream objects */
161
void pdf_process_contents(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_obj *obj, pdf_obj *res, fz_cookie *cookie);
162
void pdf_process_annot(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_page *page, pdf_annot *annot, fz_cookie *cookie);
163
void pdf_process_glyph(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_obj *resources, fz_buffer *contents);
164
165
#endif
166
167