1 | #ifndef SOURCE_HTML_IMP_H |
2 | #define SOURCE_HTML_IMP_H |
3 | |
4 | typedef struct fz_html_font_face_s fz_html_font_face; |
5 | typedef struct fz_html_font_set_s fz_html_font_set; |
6 | typedef struct fz_html_s fz_html; |
7 | typedef struct fz_html_box_s fz_html_box; |
8 | typedef struct fz_html_flow_s fz_html_flow; |
9 | |
10 | typedef struct fz_css_s fz_css; |
11 | typedef struct fz_css_rule_s fz_css_rule; |
12 | typedef struct fz_css_match_prop_s fz_css_match_prop; |
13 | typedef struct fz_css_match_s fz_css_match; |
14 | typedef struct fz_css_style_s fz_css_style; |
15 | |
16 | typedef struct fz_css_selector_s fz_css_selector; |
17 | typedef struct fz_css_condition_s fz_css_condition; |
18 | typedef struct fz_css_property_s fz_css_property; |
19 | typedef struct fz_css_value_s fz_css_value; |
20 | typedef struct fz_css_number_s fz_css_number; |
21 | typedef struct fz_css_color_s fz_css_color; |
22 | |
23 | struct fz_html_font_face_s |
24 | { |
25 | char *family; |
26 | int is_bold; |
27 | int is_italic; |
28 | int is_small_caps; |
29 | fz_font *font; |
30 | char *src; |
31 | fz_html_font_face *next; |
32 | }; |
33 | |
34 | struct fz_html_font_set_s |
35 | { |
36 | fz_font *fonts[12]; /* Times, Helvetica, Courier in R,I,B,BI */ |
37 | fz_html_font_face *custom; |
38 | }; |
39 | |
40 | enum |
41 | { |
42 | CSS_KEYWORD = 256, |
43 | CSS_HASH, |
44 | CSS_STRING, |
45 | CSS_NUMBER, |
46 | CSS_LENGTH, |
47 | CSS_PERCENT, |
48 | CSS_URI, |
49 | }; |
50 | |
51 | struct fz_css_s |
52 | { |
53 | fz_pool *pool; |
54 | fz_css_rule *rule; |
55 | }; |
56 | |
57 | struct fz_css_rule_s |
58 | { |
59 | fz_css_selector *selector; |
60 | fz_css_property *declaration; |
61 | fz_css_rule *next; |
62 | }; |
63 | |
64 | struct fz_css_selector_s |
65 | { |
66 | char *name; |
67 | int combine; |
68 | fz_css_condition *cond; |
69 | fz_css_selector *left; |
70 | fz_css_selector *right; |
71 | fz_css_selector *next; |
72 | }; |
73 | |
74 | struct fz_css_condition_s |
75 | { |
76 | int type; |
77 | char *key; |
78 | char *val; |
79 | fz_css_condition *next; |
80 | }; |
81 | |
82 | struct fz_css_property_s |
83 | { |
84 | char *name; |
85 | fz_css_value *value; |
86 | short spec; |
87 | short important; |
88 | fz_css_property *next; |
89 | }; |
90 | |
91 | struct fz_css_value_s |
92 | { |
93 | int type; |
94 | char *data; |
95 | fz_css_value *args; /* function arguments */ |
96 | fz_css_value *next; |
97 | }; |
98 | |
99 | struct fz_css_match_prop_s |
100 | { |
101 | const char *name; /* not owned */ |
102 | fz_css_value *value; /* not owned */ |
103 | int spec; |
104 | }; |
105 | |
106 | struct fz_css_match_s |
107 | { |
108 | fz_css_match *up; |
109 | int count; |
110 | fz_css_match_prop prop[64]; |
111 | }; |
112 | |
113 | enum { DIS_NONE, DIS_BLOCK, DIS_INLINE, DIS_LIST_ITEM, DIS_INLINE_BLOCK, DIS_TABLE, DIS_TABLE_ROW, DIS_TABLE_CELL }; |
114 | enum { POS_STATIC, POS_RELATIVE, POS_ABSOLUTE, POS_FIXED }; |
115 | enum { TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY }; |
116 | enum { VA_BASELINE, VA_SUB, VA_SUPER, VA_TOP, VA_BOTTOM, VA_TEXT_TOP, VA_TEXT_BOTTOM }; |
117 | enum { BS_NONE, BS_SOLID }; |
118 | enum { V_VISIBLE, V_HIDDEN, V_COLLAPSE }; |
119 | enum { PB_AUTO, PB_ALWAYS, PB_AVOID, PB_LEFT, PB_RIGHT }; |
120 | |
121 | enum { |
122 | WS_COLLAPSE = 1, |
123 | WS_ALLOW_BREAK_SPACE = 2, |
124 | WS_FORCE_BREAK_NEWLINE = 4, |
125 | WS_NORMAL = WS_COLLAPSE | WS_ALLOW_BREAK_SPACE, |
126 | WS_PRE = WS_FORCE_BREAK_NEWLINE, |
127 | WS_NOWRAP = WS_COLLAPSE, |
128 | WS_PRE_WRAP = WS_ALLOW_BREAK_SPACE | WS_FORCE_BREAK_NEWLINE, |
129 | WS_PRE_LINE = WS_COLLAPSE | WS_ALLOW_BREAK_SPACE | WS_FORCE_BREAK_NEWLINE |
130 | }; |
131 | |
132 | enum { |
133 | LST_NONE, |
134 | LST_DISC, LST_CIRCLE, LST_SQUARE, |
135 | LST_DECIMAL, LST_DECIMAL_ZERO, |
136 | LST_LC_ROMAN, LST_UC_ROMAN, |
137 | LST_LC_GREEK, LST_UC_GREEK, |
138 | LST_LC_LATIN, LST_UC_LATIN, |
139 | LST_LC_ALPHA, LST_UC_ALPHA, |
140 | LST_ARMENIAN, LST_GEORGIAN, |
141 | }; |
142 | |
143 | enum { N_NUMBER='u', N_LENGTH='p', N_SCALE='m', N_PERCENT='%', N_AUTO='a' }; |
144 | |
145 | struct fz_css_number_s |
146 | { |
147 | float value; |
148 | int unit; |
149 | }; |
150 | |
151 | struct fz_css_color_s |
152 | { |
153 | unsigned char r, g, b, a; |
154 | }; |
155 | |
156 | struct fz_css_style_s |
157 | { |
158 | fz_css_number font_size; |
159 | fz_css_number width, height; |
160 | fz_css_number margin[4]; |
161 | fz_css_number padding[4]; |
162 | fz_css_number border_width[4]; |
163 | fz_css_number text_indent; |
164 | unsigned int visibility : 2; |
165 | unsigned int white_space : 3; |
166 | unsigned int text_align : 2; |
167 | unsigned int vertical_align : 3; |
168 | unsigned int list_style_type : 4; |
169 | unsigned int page_break_before : 3; |
170 | unsigned int page_break_after : 3; |
171 | unsigned int border_style_0 : 1; |
172 | unsigned int border_style_1 : 1; |
173 | unsigned int border_style_2 : 1; |
174 | unsigned int border_style_3 : 1; |
175 | unsigned int small_caps : 1; |
176 | fz_css_number line_height; |
177 | fz_css_color background_color; |
178 | fz_css_color border_color[4]; |
179 | fz_css_color color; |
180 | fz_font *font; |
181 | }; |
182 | |
183 | enum |
184 | { |
185 | BOX_BLOCK, /* block-level: contains block, break, flow, and table boxes */ |
186 | BOX_BREAK, /* block-level: empty <br> tag boxes */ |
187 | BOX_FLOW, /* block-level: contains only inline boxes */ |
188 | BOX_INLINE, /* inline-level: contains only inline boxes */ |
189 | BOX_TABLE, /* table: contains table-row */ |
190 | BOX_TABLE_ROW, /* table-row: contains table-cell */ |
191 | BOX_TABLE_CELL, /* table-cell: contains block */ |
192 | }; |
193 | |
194 | struct fz_html_s |
195 | { |
196 | fz_pool *pool; /* pool allocator for this html tree */ |
197 | float page_w, page_h; |
198 | float page_margin[4]; |
199 | fz_html_box *root; |
200 | char *title; |
201 | }; |
202 | |
203 | struct fz_html_box_s |
204 | { |
205 | unsigned int type : 3; |
206 | unsigned int is_first_flow : 1; /* for text-indent */ |
207 | unsigned int markup_dir : 2; |
208 | unsigned int heading : 3; /* h1..h6 */ |
209 | unsigned int list_item : 23; |
210 | float x, y, w, b; /* content */ |
211 | float padding[4]; |
212 | float margin[4]; |
213 | float border[4]; |
214 | float em; |
215 | fz_html_box *up, *down, *last, *next; |
216 | fz_html_flow *flow_head, **flow_tail; |
217 | char *id, *href; |
218 | fz_css_style style; |
219 | }; |
220 | |
221 | enum |
222 | { |
223 | FLOW_WORD = 0, |
224 | FLOW_SPACE = 1, |
225 | FLOW_BREAK = 2, |
226 | FLOW_IMAGE = 3, |
227 | FLOW_SBREAK = 4, |
228 | FLOW_SHYPHEN = 5, |
229 | FLOW_ANCHOR = 6 |
230 | }; |
231 | |
232 | struct fz_html_flow_s |
233 | { |
234 | /* What type of node */ |
235 | unsigned int type : 3; |
236 | |
237 | /* Whether this should expand during justification */ |
238 | unsigned int expand : 1; |
239 | |
240 | /* Whether this node is currently taken as a line break */ |
241 | unsigned int breaks_line : 1; |
242 | |
243 | /* Direction setting for text - UAX#9 says 125 is the max */ |
244 | unsigned int bidi_level : 7; |
245 | |
246 | /* The script detected by the bidi code. */ |
247 | unsigned int script : 8; |
248 | |
249 | /* Whether the markup specifies a given language. */ |
250 | unsigned int markup_lang : 15; |
251 | |
252 | float x, y, w, h; |
253 | fz_html_box *box; /* for style and em */ |
254 | union { |
255 | char *text; |
256 | fz_image *image; |
257 | } content; |
258 | fz_html_flow *next; |
259 | }; |
260 | |
261 | fz_css *fz_new_css(fz_context *ctx); |
262 | void fz_parse_css(fz_context *ctx, fz_css *css, const char *source, const char *file); |
263 | fz_css_property *fz_parse_css_properties(fz_context *ctx, fz_pool *pool, const char *source); |
264 | void fz_drop_css(fz_context *ctx, fz_css *css); |
265 | void fz_debug_css(fz_context *ctx, fz_css *css); |
266 | |
267 | void fz_match_css(fz_context *ctx, fz_css_match *match, fz_css *css, fz_xml *node); |
268 | void fz_match_css_at_page(fz_context *ctx, fz_css_match *match, fz_css *css); |
269 | |
270 | int fz_get_css_match_display(fz_css_match *node); |
271 | void fz_default_css_style(fz_context *ctx, fz_css_style *style); |
272 | void fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style, fz_css_match *match); |
273 | |
274 | float fz_from_css_number(fz_css_number number, float em, float percent_value, float auto_value); |
275 | float fz_from_css_number_scale(fz_css_number number, float scale); |
276 | |
277 | fz_html_font_set *fz_new_html_font_set(fz_context *ctx); |
278 | void fz_add_html_font_face(fz_context *ctx, fz_html_font_set *set, |
279 | const char *family, int is_bold, int is_italic, int is_small_caps, const char *src, fz_font *font); |
280 | fz_font *fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, int is_bold, int is_italic, int is_small_caps); |
281 | void fz_drop_html_font_set(fz_context *ctx, fz_html_font_set *htx); |
282 | |
283 | void fz_add_css_font_faces(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_css *css); |
284 | |
285 | 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); |
286 | void fz_layout_html(fz_context *ctx, fz_html *html, float w, float h, float em); |
287 | void fz_draw_html(fz_context *ctx, fz_device *dev, fz_matrix ctm, fz_html *html, int page); |
288 | fz_outline *fz_load_html_outline(fz_context *ctx, fz_html *node); |
289 | |
290 | float fz_find_html_target(fz_context *ctx, fz_html *html, const char *id); |
291 | fz_link *fz_load_html_links(fz_context *ctx, fz_html *html, int page, const char *base_uri, void *doc); |
292 | void fz_drop_html(fz_context *ctx, fz_html *html); |
293 | fz_bookmark fz_make_html_bookmark(fz_context *ctx, fz_html *html, int page); |
294 | int fz_lookup_html_bookmark(fz_context *ctx, fz_html *html, fz_bookmark mark); |
295 | void fz_debug_html(fz_context *ctx, fz_html_box *box); |
296 | |
297 | #endif |
298 | |