Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7643 views
1
#ifndef MUPDF_HTML_H
2
#define MUPDF_HTML_H
3
4
#include "mupdf/fitz.h"
5
6
typedef struct fz_html_font_set_s fz_html_font_set;
7
typedef struct fz_html_s fz_html;
8
typedef struct fz_html_flow_s fz_html_flow;
9
10
typedef struct fz_css_rule_s fz_css_rule;
11
typedef struct fz_css_match_s fz_css_match;
12
typedef struct fz_css_style_s fz_css_style;
13
14
typedef struct fz_css_selector_s fz_css_selector;
15
typedef struct fz_css_condition_s fz_css_condition;
16
typedef struct fz_css_property_s fz_css_property;
17
typedef struct fz_css_value_s fz_css_value;
18
typedef struct fz_css_number_s fz_css_number;
19
typedef struct fz_css_color_s fz_css_color;
20
21
struct fz_html_font_set_s
22
{
23
fz_font *fonts[16];
24
};
25
26
enum
27
{
28
CSS_KEYWORD = 256,
29
CSS_STRING,
30
CSS_NUMBER,
31
CSS_LENGTH,
32
CSS_PERCENT,
33
CSS_COLOR,
34
CSS_URI,
35
};
36
37
struct fz_css_rule_s
38
{
39
fz_css_selector *selector;
40
fz_css_property *declaration;
41
fz_css_property *garbage; /* for freeing inline style attributes at the end */
42
fz_css_rule *next;
43
};
44
45
struct fz_css_selector_s
46
{
47
char *name;
48
int combine;
49
fz_css_condition *cond;
50
fz_css_selector *left;
51
fz_css_selector *right;
52
fz_css_selector *next;
53
};
54
55
struct fz_css_condition_s
56
{
57
int type;
58
char *key;
59
char *val;
60
fz_css_condition *next;
61
};
62
63
struct fz_css_property_s
64
{
65
char *name;
66
fz_css_value *value;
67
int spec;
68
fz_css_property *next;
69
};
70
71
struct fz_css_value_s
72
{
73
int type;
74
char *data;
75
fz_css_value *args; /* function arguments */
76
fz_css_value *next;
77
};
78
79
struct fz_css_match_s
80
{
81
fz_css_match *up;
82
int count;
83
struct {
84
const char *name; /* not owned */
85
fz_css_value *value; /* not owned */
86
int spec;
87
} prop[64];
88
};
89
90
enum { DIS_NONE, DIS_BLOCK, DIS_INLINE, DIS_LIST_ITEM };
91
enum { POS_STATIC, POS_RELATIVE, POS_ABSOLUTE, POS_FIXED };
92
enum { WS_NORMAL, WS_PRE, WS_NOWRAP, WS_PRE_WRAP, WS_PRE_LINE };
93
enum { TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY };
94
enum { VA_BASELINE, VA_SUB, VA_SUPER, VA_TOP, VA_BOTTOM };
95
enum { BS_NONE, BS_SOLID };
96
97
enum { N_NUMBER='p', N_SCALE='m', N_PERCENT='%' };
98
99
struct fz_css_number_s
100
{
101
float value;
102
int unit;
103
};
104
105
struct fz_css_color_s
106
{
107
unsigned char r, g, b, a;
108
};
109
110
struct fz_css_style_s
111
{
112
fz_css_number font_size;
113
fz_css_number margin[4];
114
fz_css_number padding[4];
115
fz_css_number border_width[4];
116
fz_css_number text_indent;
117
int white_space;
118
int text_align;
119
int vertical_align;
120
int border_style;
121
fz_css_number line_height;
122
fz_css_color background_color;
123
fz_css_color border_color;
124
fz_css_color color;
125
fz_font *font;
126
};
127
128
enum
129
{
130
BOX_BLOCK, /* block-level: contains block, break, and flow boxes */
131
BOX_BREAK, /* block-level: empty <br> tag boxes */
132
BOX_FLOW, /* block-level: contains only inline boxes */
133
BOX_INLINE, /* inline-level: contains only inline boxes */
134
};
135
136
struct fz_html_s
137
{
138
int type;
139
float x, y, w, h; /* content */
140
float padding[4];
141
float margin[4];
142
float border[4];
143
fz_html *up, *down, *last, *next;
144
fz_html_flow *flow_head, **flow_tail;
145
fz_css_style style;
146
int is_first_flow; /* for text-indent */
147
};
148
149
enum
150
{
151
FLOW_WORD,
152
FLOW_GLUE,
153
FLOW_IMAGE,
154
};
155
156
struct fz_html_flow_s
157
{
158
int type;
159
float x, y, w, h, em;
160
fz_css_style *style;
161
char *text, *broken_text;
162
fz_image *image;
163
fz_html_flow *next;
164
};
165
166
fz_css_rule *fz_parse_css(fz_context *ctx, fz_css_rule *chain, const char *source, const char *file);
167
fz_css_property *fz_parse_css_properties(fz_context *ctx, const char *source);
168
void fz_drop_css(fz_context *ctx, fz_css_rule *rule);
169
170
void fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *rule, fz_xml *node);
171
172
int fz_get_css_match_display(fz_css_match *node);
173
void fz_default_css_style(fz_context *ctx, fz_css_style *style);
174
void fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style, fz_css_match *match);
175
176
float fz_from_css_number(fz_css_number, float em, float width);
177
float fz_from_css_number_scale(fz_css_number number, float scale, float em, float width);
178
179
fz_html_font_set *fz_new_html_font_set(fz_context *ctx);
180
fz_font *fz_load_html_font(fz_context *ctx, fz_html_font_set *set,
181
const char *family, const char *variant, const char *style, const char *weight);
182
void fz_drop_html_font_set(fz_context *ctx, fz_html_font_set *htx);
183
184
fz_html *fz_parse_html(fz_context *ctx, fz_html_font_set *htx, fz_archive *zip, const char *base_uri, fz_buffer *buf, const char *user_css);
185
void fz_layout_html(fz_context *ctx, fz_html *box, float w, float h, float em);
186
void fz_draw_html(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm);
187
void fz_drop_html(fz_context *ctx, fz_html *box);
188
189
#endif
190
191