/src/mupdf/source/html/html-imp.h
Line | Count | Source |
1 | | // Copyright (C) 2004-2025 Artifex Software, Inc. |
2 | | // |
3 | | // This file is part of MuPDF. |
4 | | // |
5 | | // MuPDF is free software: you can redistribute it and/or modify it under the |
6 | | // terms of the GNU Affero General Public License as published by the Free |
7 | | // Software Foundation, either version 3 of the License, or (at your option) |
8 | | // any later version. |
9 | | // |
10 | | // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY |
11 | | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
12 | | // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
13 | | // details. |
14 | | // |
15 | | // You should have received a copy of the GNU Affero General Public License |
16 | | // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html> |
17 | | // |
18 | | // Alternative licensing terms are available from the licensor. |
19 | | // For commercial licensing, see <https://www.artifex.com/> or contact |
20 | | // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
21 | | // CA 94129, USA, for further information. |
22 | | |
23 | | #ifndef SOURCE_HTML_IMP_H |
24 | | #define SOURCE_HTML_IMP_H |
25 | | |
26 | | #include "mupdf/fitz.h" |
27 | | #include "mupdf/html.h" |
28 | | |
29 | | #include "../fitz/xml-imp.h" |
30 | | |
31 | | typedef struct fz_html_font_face_s fz_html_font_face; |
32 | | typedef struct fz_html_box_s fz_html_box; |
33 | | typedef struct fz_html_flow_s fz_html_flow; |
34 | | typedef struct fz_css_style_splay_s fz_css_style_splay; |
35 | | |
36 | | typedef struct fz_css_s fz_css; |
37 | | typedef struct fz_css_rule_s fz_css_rule; |
38 | | typedef struct fz_css_match_s fz_css_match; |
39 | | typedef struct fz_css_style_s fz_css_style; |
40 | | |
41 | | typedef struct fz_css_selector_s fz_css_selector; |
42 | | typedef struct fz_css_condition_s fz_css_condition; |
43 | | typedef struct fz_css_property_s fz_css_property; |
44 | | typedef struct fz_css_value_s fz_css_value; |
45 | | typedef struct fz_css_number_s fz_css_number; |
46 | | typedef struct fz_css_color_s fz_css_color; |
47 | | |
48 | | /* Enable the following to get sequence numbers in the html boxes to aid debugging. */ |
49 | | //#define DEBUG_HTML_SEQ |
50 | | |
51 | | struct fz_html_font_face_s |
52 | | { |
53 | | char *family; |
54 | | int is_bold; |
55 | | int is_italic; |
56 | | int is_small_caps; |
57 | | fz_font *font; |
58 | | char *src; |
59 | | fz_html_font_face *next; |
60 | | }; |
61 | | |
62 | | struct fz_html_font_set_s |
63 | | { |
64 | | fz_font *fonts[12]; /* Times, Helvetica, Courier in R,I,B,BI */ |
65 | | fz_html_font_face *custom; |
66 | | }; |
67 | | |
68 | 0 | #define UCS_MAX 0x10ffff |
69 | | |
70 | | enum |
71 | | { |
72 | | CSS_KEYWORD = UCS_MAX+1, |
73 | | CSS_HASH, |
74 | | CSS_STRING, |
75 | | CSS_NUMBER, |
76 | | CSS_LENGTH, |
77 | | CSS_PERCENT, |
78 | | CSS_URI, |
79 | | }; |
80 | | |
81 | | struct fz_css_s |
82 | | { |
83 | | fz_pool *pool; |
84 | | fz_css_rule *rule; |
85 | | }; |
86 | | |
87 | | struct fz_css_rule_s |
88 | | { |
89 | | fz_css_selector *selector; |
90 | | fz_css_property *declaration; |
91 | | fz_css_rule *next; |
92 | | int loaded; |
93 | | }; |
94 | | |
95 | | struct fz_css_selector_s |
96 | | { |
97 | | char *name; |
98 | | int combine; |
99 | | fz_css_condition *cond; |
100 | | fz_css_selector *left; |
101 | | fz_css_selector *right; |
102 | | fz_css_selector *next; |
103 | | }; |
104 | | |
105 | | struct fz_css_condition_s |
106 | | { |
107 | | int type; |
108 | | char *key; |
109 | | char *val; |
110 | | fz_css_condition *next; |
111 | | }; |
112 | | |
113 | | struct fz_css_property_s |
114 | | { |
115 | | int name; |
116 | | fz_css_value *value; |
117 | | short spec; |
118 | | short important; |
119 | | fz_css_property *next; |
120 | | }; |
121 | | |
122 | | struct fz_css_value_s |
123 | | { |
124 | | int type; |
125 | | char *data; |
126 | | fz_css_value *args; /* function arguments */ |
127 | | fz_css_value *next; |
128 | | }; |
129 | | |
130 | | enum |
131 | | { |
132 | | PRO_BACKGROUND_COLOR, |
133 | | PRO_BORDER_BOTTOM_COLOR, |
134 | | PRO_BORDER_BOTTOM_STYLE, |
135 | | PRO_BORDER_BOTTOM_WIDTH, |
136 | | PRO_BORDER_COLLAPSE, |
137 | | PRO_BORDER_LEFT_COLOR, |
138 | | PRO_BORDER_LEFT_STYLE, |
139 | | PRO_BORDER_LEFT_WIDTH, |
140 | | PRO_BORDER_RIGHT_COLOR, |
141 | | PRO_BORDER_RIGHT_STYLE, |
142 | | PRO_BORDER_RIGHT_WIDTH, |
143 | | PRO_BORDER_SPACING, |
144 | | PRO_BORDER_TOP_COLOR, |
145 | | PRO_BORDER_TOP_STYLE, |
146 | | PRO_BORDER_TOP_WIDTH, |
147 | | PRO_CLEAR, |
148 | | PRO_COLOR, |
149 | | PRO_COLUMNS, |
150 | | PRO_DIRECTION, |
151 | | PRO_DISPLAY, |
152 | | PRO_FLOAT, |
153 | | PRO_FONT, |
154 | | PRO_FONT_FAMILY, |
155 | | PRO_FONT_SIZE, |
156 | | PRO_FONT_STYLE, |
157 | | PRO_FONT_VARIANT, |
158 | | PRO_FONT_WEIGHT, |
159 | | PRO_HEIGHT, |
160 | | PRO_HYPHENS, |
161 | | PRO_INSET_BOTTOM, |
162 | | PRO_INSET_LEFT, |
163 | | PRO_INSET_RIGHT, |
164 | | PRO_INSET_TOP, |
165 | | PRO_LEADING, |
166 | | PRO_LETTER_SPACING, |
167 | | PRO_LINE_HEIGHT, |
168 | | PRO_LIST_STYLE_IMAGE, |
169 | | PRO_LIST_STYLE_POSITION, |
170 | | PRO_LIST_STYLE_TYPE, |
171 | | PRO_MARGIN_BOTTOM, |
172 | | PRO_MARGIN_LEFT, |
173 | | PRO_MARGIN_RIGHT, |
174 | | PRO_MARGIN_TOP, |
175 | | PRO_ORPHANS, |
176 | | PRO_OVERFLOW_WRAP, |
177 | | PRO_PADDING_BOTTOM, |
178 | | PRO_PADDING_LEFT, |
179 | | PRO_PADDING_RIGHT, |
180 | | PRO_PADDING_TOP, |
181 | | PRO_PAGE_BREAK_AFTER, |
182 | | PRO_PAGE_BREAK_BEFORE, |
183 | | PRO_POSITION, |
184 | | PRO_QUOTES, |
185 | | PRO_SRC, |
186 | | PRO_TEXT_ALIGN, |
187 | | PRO_TEXT_DECORATION, |
188 | | PRO_TEXT_FILL_COLOR, |
189 | | PRO_TEXT_INDENT, |
190 | | PRO_TEXT_STROKE_COLOR, |
191 | | PRO_TEXT_STROKE_WIDTH, |
192 | | PRO_TEXT_TRANSFORM, |
193 | | PRO_VERTICAL_ALIGN, |
194 | | PRO_VISIBILITY, |
195 | | PRO_WHITE_SPACE, |
196 | | PRO_WIDOWS, |
197 | | PRO_WIDTH, |
198 | | PRO_WORD_SPACING, |
199 | | |
200 | | /* Number of real properties. */ |
201 | | NUM_PROPERTIES, |
202 | | |
203 | | /* Short-hand properties (always expanded when applied, never used as is): */ |
204 | | PRO_BACKGROUND, |
205 | | PRO_BORDER, |
206 | | PRO_BORDER_BOTTOM, |
207 | | PRO_BORDER_COLOR, |
208 | | PRO_BORDER_LEFT, |
209 | | PRO_BORDER_RIGHT, |
210 | | PRO_BORDER_STYLE, |
211 | | PRO_BORDER_TOP, |
212 | | PRO_BORDER_WIDTH, |
213 | | PRO_INSET, |
214 | | PRO_LIST_STYLE, |
215 | | PRO_MARGIN, |
216 | | PRO_PADDING, |
217 | | }; |
218 | | |
219 | | struct fz_css_match_s |
220 | | { |
221 | | fz_css_match *up; |
222 | | short spec[NUM_PROPERTIES]; |
223 | | fz_css_value *value[NUM_PROPERTIES]; |
224 | | }; |
225 | | |
226 | | enum { DIS_NONE, DIS_BLOCK, DIS_INLINE, DIS_LIST_ITEM, DIS_INLINE_BLOCK, DIS_TABLE, DIS_TABLE_GROUP, DIS_TABLE_ROW, DIS_TABLE_CELL, DIS_TABLE_COLGROUP, DIS_TABLE_COL }; |
227 | | enum { POS_STATIC, POS_RELATIVE, POS_ABSOLUTE, POS_FIXED }; |
228 | | enum { TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY }; |
229 | | enum { VA_BASELINE, VA_SUB, VA_SUPER, VA_TOP, VA_BOTTOM, VA_TEXT_TOP, VA_TEXT_BOTTOM, VA_MIDDLE }; |
230 | | enum { BS_NONE, BS_SOLID, BS_DOTTED, BS_DASHED, BS_DOUBLE, BS_GROOVE, BS_RIDGE, BS_INSET, BS_OUTSET }; |
231 | | enum { V_VISIBLE, V_HIDDEN, V_COLLAPSE }; |
232 | | enum { PB_AUTO, PB_ALWAYS, PB_AVOID, PB_LEFT, PB_RIGHT }; |
233 | | enum { TD_NONE, TD_UNDERLINE, TD_LINE_THROUGH }; |
234 | | enum { HYP_NONE, HYP_MANUAL, HYP_AUTO }; |
235 | | |
236 | | enum { |
237 | | WS_COLLAPSE = 1, |
238 | | WS_ALLOW_BREAK_SPACE = 2, |
239 | | WS_FORCE_BREAK_NEWLINE = 4, |
240 | | WS_NORMAL = WS_COLLAPSE | WS_ALLOW_BREAK_SPACE, |
241 | | WS_PRE = WS_FORCE_BREAK_NEWLINE, |
242 | | WS_NOWRAP = WS_COLLAPSE, |
243 | | WS_PRE_WRAP = WS_ALLOW_BREAK_SPACE | WS_FORCE_BREAK_NEWLINE, |
244 | | WS_PRE_LINE = WS_COLLAPSE | WS_ALLOW_BREAK_SPACE | WS_FORCE_BREAK_NEWLINE |
245 | | }; |
246 | | |
247 | | enum { |
248 | | LST_NONE, |
249 | | LST_DISC, LST_CIRCLE, LST_SQUARE, |
250 | | LST_DECIMAL, LST_DECIMAL_ZERO, |
251 | | LST_LC_ROMAN, LST_UC_ROMAN, |
252 | | LST_LC_GREEK, LST_UC_GREEK, |
253 | | LST_LC_LATIN, LST_UC_LATIN, |
254 | | LST_LC_ALPHA, LST_UC_ALPHA, |
255 | | LST_ARMENIAN, LST_GEORGIAN, |
256 | | }; |
257 | | |
258 | | enum { |
259 | | OVERFLOW_WRAP_NORMAL = 0, |
260 | | OVERFLOW_WRAP_BREAK_WORD = 1 |
261 | | /* We do not support 'anywhere'. */ |
262 | | }; |
263 | | |
264 | | enum { N_NUMBER='u', N_LENGTH='p', N_SCALE='m', N_PERCENT='%', N_AUTO='a', N_UNDEFINED='x' }; |
265 | | |
266 | | struct fz_css_number_s |
267 | | { |
268 | | float value; |
269 | | int unit; |
270 | | }; |
271 | | |
272 | | struct fz_css_color_s |
273 | | { |
274 | | unsigned char r, g, b, a; |
275 | | }; |
276 | | |
277 | | struct fz_css_style_s |
278 | | { |
279 | | fz_font *font; |
280 | | fz_css_number font_size; |
281 | | fz_css_number width, height; |
282 | | fz_css_number margin[4]; |
283 | | fz_css_number padding[4]; |
284 | | fz_css_number border_width[4]; |
285 | | fz_css_number inset[4]; |
286 | | fz_css_number border_spacing; |
287 | | fz_css_number text_indent; |
288 | | fz_css_number text_stroke_width; |
289 | | fz_css_number line_height; |
290 | | fz_css_number leading; |
291 | | fz_css_color background_color; |
292 | | fz_css_color border_color[4]; |
293 | | fz_css_color color; |
294 | | fz_css_color text_fill_color; |
295 | | fz_css_color text_stroke_color; |
296 | | |
297 | | /* First group of 32 */ |
298 | | unsigned int rowspan : 10; /* Needs to be able to represent 1-1000 */ |
299 | | unsigned int colspan : 10; /* Needs to be able to represent 1-1000 */ |
300 | | unsigned int white_space : 3; |
301 | | unsigned int vertical_align : 3; |
302 | | unsigned int page_break_before : 3; |
303 | | unsigned int page_break_after : 3; |
304 | | |
305 | | /* Second group of 32 */ |
306 | | unsigned int visibility : 2; |
307 | | unsigned int text_align : 2; |
308 | | unsigned int direction : 1; |
309 | | unsigned int list_style_type : 4; |
310 | | unsigned int border_style_0 : 4; |
311 | | unsigned int border_style_1 : 4; |
312 | | unsigned int border_style_2 : 4; |
313 | | unsigned int border_style_3 : 4; |
314 | | unsigned int small_caps : 1; |
315 | | unsigned int text_decoration: 2; |
316 | | unsigned int overflow_wrap : 1; |
317 | | unsigned int position : 2; |
318 | | unsigned int border_collapse : 1; |
319 | | |
320 | | /* Third group of 32 */ |
321 | | unsigned int hyphens : 2; |
322 | | }; |
323 | | |
324 | | struct fz_css_style_splay_s { |
325 | | fz_css_style style; |
326 | | fz_css_style_splay *lt; |
327 | | fz_css_style_splay *gt; |
328 | | fz_css_style_splay *up; |
329 | | }; |
330 | | |
331 | | enum |
332 | | { |
333 | | BOX_BLOCK, /* block-level: contains block, break, flow, and table boxes */ |
334 | | BOX_FLOW, /* block-level: contains only inline boxes */ |
335 | | BOX_INLINE, /* inline-level: contains only inline boxes */ |
336 | | BOX_TABLE, /* table: contains table-row */ |
337 | | BOX_TABLE_ROW, /* table-row: contains table-cell */ |
338 | | BOX_TABLE_CELL, /* table-cell: contains block */ |
339 | | }; |
340 | | |
341 | | typedef struct |
342 | | { |
343 | | fz_storable storable; |
344 | | fz_pool *pool; /* pool allocator for this html tree */ |
345 | | fz_html_box *root; |
346 | | } fz_html_tree; |
347 | | |
348 | | struct fz_html_s |
349 | | { |
350 | | /* fz_html is derived from fz_html_tree, so must start with that. */ |
351 | | /* Arguably 'tree' should be called 'super'. */ |
352 | | fz_html_tree tree; |
353 | | |
354 | | float page_w, page_h; |
355 | | float layout_w, layout_h, layout_em; |
356 | | float page_margin[4]; |
357 | | char *title; |
358 | | }; |
359 | | |
360 | | typedef enum |
361 | | { |
362 | | FZ_HTML_RESTART_REASON_NONE = 0, |
363 | | FZ_HTML_RESTART_REASON_LINE_HEIGHT = 1, |
364 | | FZ_HTML_RESTART_REASON_LINE_WIDTH = 2 |
365 | | } fz_html_restart_reason; |
366 | | |
367 | | enum |
368 | | { |
369 | | FZ_HTML_RESTARTER_FLAGS_NO_OVERFLOW = 1 |
370 | | }; |
371 | | |
372 | | enum |
373 | | { |
374 | | FZ_HTML_RESTARTER_START_END_FLAGS_LEFT_SIDE = 1, |
375 | | FZ_HTML_RESTARTER_START_END_FLAGS_SPECIFIC_SIDE = 2 |
376 | | }; |
377 | | |
378 | | typedef struct { |
379 | | /* start will be filled in on entry with the first node to start |
380 | | * operation on. NULL means start 'immediately'. As we traverse |
381 | | * the tree, once we reach the node to start on, we set this to |
382 | | * NULL, hence if 'start != NULL' then we are still skipping to |
383 | | * find the starting node. */ |
384 | | fz_html_box *start; |
385 | | |
386 | | /* If start is a BOX_FLOW, then start_flow will be the flow entry |
387 | | * at which we should start. */ |
388 | | fz_html_flow *start_flow; |
389 | | |
390 | | /* If the SPECIFIC_SIDE bit is set, then we should only restart |
391 | | * layout if we are on appropriate side (as given by the LEFT_SIDE |
392 | | * bit). */ |
393 | | int start_flags; |
394 | | |
395 | | |
396 | | /* end should be NULL on entry. On exit, if it's NULL, then we |
397 | | * finished. Otherwise, this is where we should restart the |
398 | | * process the next time. */ |
399 | | fz_html_box *end; |
400 | | |
401 | | /* If end is a BOX_FLOW, then end_flow will be the flow entry at which |
402 | | * we should restart next time. */ |
403 | | fz_html_flow *end_flow; |
404 | | |
405 | | /* If the SPECIFIC_SIDE bit is set, then the next layout should only |
406 | | * restart if we are on appropriate side (as given by the LEFT_SIDE |
407 | | * bit). */ |
408 | | int end_flags; |
409 | | |
410 | | |
411 | | /* Workspace used on the traversal of the tree to store a good place |
412 | | * to restart. Typically this will be set to an enclosing box with |
413 | | * a border, so that if we then fail to put any content into the box |
414 | | * we'll elide the entire box/border, not output an empty one. */ |
415 | | fz_html_box *potential; |
416 | | |
417 | | fz_html_restart_reason reason; |
418 | | |
419 | | int flags; |
420 | | |
421 | | int left_page; |
422 | | } fz_html_restarter; |
423 | | |
424 | | struct fz_story |
425 | | { |
426 | | /* fz_story is derived from fz_html_tree, so must start with */ |
427 | | /* that. Arguably 'tree' should be called 'super'. */ |
428 | | fz_html_tree tree; |
429 | | |
430 | | /* The user_css (or NULL) */ |
431 | | char *user_css; |
432 | | |
433 | | /* The HTML story as XML nodes with a DOM */ |
434 | | fz_xml *dom; |
435 | | |
436 | | /* The fontset for the content. */ |
437 | | fz_html_font_set *font_set; |
438 | | |
439 | | /* restart_place holds the start position for the next place. |
440 | | * This is updated by draw. */ |
441 | | fz_html_restarter restart_place; |
442 | | |
443 | | /* restart_draw holds the start position for the next draw. |
444 | | * This is updated by place. */ |
445 | | fz_html_restarter restart_draw; |
446 | | |
447 | | /* complete is set true when all the story has been placed and |
448 | | * drawn. */ |
449 | | int complete; |
450 | | |
451 | | /* The last bbox we laid out for. Used for making a clipping |
452 | | * rectangle. */ |
453 | | fz_rect bbox; |
454 | | |
455 | | /* The default 'em' size. */ |
456 | | float em; |
457 | | |
458 | | /* Collected parsing warnings. */ |
459 | | fz_buffer *warnings; |
460 | | |
461 | | /* Rectangle layout count. */ |
462 | | int rect_count; |
463 | | |
464 | | /* Archive from which to load any resources. */ |
465 | | fz_archive *zip; |
466 | | }; |
467 | | |
468 | | struct fz_html_box_s |
469 | | { |
470 | | unsigned int type : 3; |
471 | | unsigned int is_first_flow : 1; /* for text-indent */ |
472 | | unsigned int markup_dir : 2; |
473 | | unsigned int heading : 3; |
474 | | unsigned int list_item : 16; |
475 | | unsigned int suppress_border: 4; |
476 | | unsigned int collapsed_cell : 1; |
477 | | |
478 | | fz_html_box *up, *down, *next; |
479 | | |
480 | | const char *tag, *id, *href; |
481 | | const fz_css_style *style; |
482 | | #ifdef DEBUG_HTML_SEQ |
483 | | int seq; |
484 | | #endif |
485 | | |
486 | | union { |
487 | | /* Only needed during build stage */ |
488 | | struct { |
489 | | fz_html_box *last_child; |
490 | | fz_html_flow **flow_tail; |
491 | | } build; |
492 | | |
493 | | /* Only needed during layout */ |
494 | | struct { |
495 | | float x, y, w, b; /* content */ |
496 | | float em, baseline; |
497 | | } layout; |
498 | | } s; |
499 | | |
500 | | union { |
501 | | /* Only BOX_FLOW use the following */ |
502 | | struct { |
503 | | fz_html_flow *head; |
504 | | } flow; |
505 | | |
506 | | /* Only BOX_{BLOCK,TABLE,TABLE_ROW,TABLE_CELL} use the following */ |
507 | | struct { |
508 | | float margin[4]; // TODO: is margin needed post layout? |
509 | | float border[4]; |
510 | | float padding[4]; |
511 | | } block; |
512 | | } u; |
513 | | }; |
514 | | |
515 | | static inline int |
516 | | fz_html_box_has_boxes(fz_html_box *box) |
517 | 0 | { |
518 | 0 | return (box->type == BOX_BLOCK || box->type == BOX_TABLE || box->type == BOX_TABLE_ROW || box->type == BOX_TABLE_CELL); |
519 | 0 | } Unexecuted instantiation: epub-doc.c:fz_html_box_has_boxes Unexecuted instantiation: html-doc.c:fz_html_box_has_boxes Unexecuted instantiation: html-font.c:fz_html_box_has_boxes Unexecuted instantiation: html-layout.c:fz_html_box_has_boxes Unexecuted instantiation: html-outline.c:fz_html_box_has_boxes Unexecuted instantiation: html-parse.c:fz_html_box_has_boxes Unexecuted instantiation: mobi.c:fz_html_box_has_boxes Unexecuted instantiation: office.c:fz_html_box_has_boxes Unexecuted instantiation: css-apply.c:fz_html_box_has_boxes Unexecuted instantiation: css-parse.c:fz_html_box_has_boxes |
520 | | |
521 | | enum |
522 | | { |
523 | | FLOW_WORD = 0, |
524 | | FLOW_SPACE = 1, |
525 | | FLOW_BREAK = 2, |
526 | | FLOW_IMAGE = 3, |
527 | | FLOW_SBREAK = 4, |
528 | | FLOW_SHYPHEN = 5, |
529 | | FLOW_ANCHOR = 6 |
530 | | }; |
531 | | |
532 | | struct fz_html_flow_s |
533 | | { |
534 | | /* What type of node */ |
535 | | unsigned int type : 3; |
536 | | |
537 | | /* Whether this should expand during justification */ |
538 | | unsigned int expand : 1; |
539 | | |
540 | | /* Whether this node is currently taken as a line break */ |
541 | | unsigned int breaks_line : 1; |
542 | | |
543 | | /* Whether this word node can be split or consists of a single glyph cluster */ |
544 | | unsigned int atomic : 1; |
545 | | |
546 | | /* Whether lines may be broken before this word for overflow-wrap: word-break */ |
547 | | unsigned int overflow_wrap : 1; |
548 | | |
549 | | /* Direction setting for text - UAX#9 says 125 is the max */ |
550 | | unsigned int bidi_level : 7; |
551 | | |
552 | | /* The script detected by the bidi code. */ |
553 | | unsigned int script : 8; |
554 | | |
555 | | /* Whether the markup specifies a given language. */ |
556 | | unsigned short markup_lang; |
557 | | |
558 | | float x, y, w, h; |
559 | | fz_html_box *box; /* for style and em */ |
560 | | fz_html_flow *next; |
561 | | union { |
562 | | char text[1]; |
563 | | fz_image *image; |
564 | | } content; |
565 | | }; |
566 | | |
567 | | |
568 | | fz_css *fz_new_css(fz_context *ctx); |
569 | | void fz_parse_css(fz_context *ctx, fz_css *css, const char *source, const char *file); |
570 | | fz_css_property *fz_parse_css_properties(fz_context *ctx, fz_pool *pool, const char *source); |
571 | | void fz_drop_css(fz_context *ctx, fz_css *css); |
572 | | void fz_debug_css(fz_context *ctx, fz_css *css); |
573 | | const char *fz_css_property_name(int name); |
574 | | |
575 | | void fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_match *up, fz_css *css, fz_xml *node); |
576 | | void fz_match_css_at_page(fz_context *ctx, fz_css_match *match, fz_css *css); |
577 | | |
578 | | int fz_get_css_match_display(fz_css_match *node); |
579 | | void fz_default_css_style(fz_context *ctx, fz_css_style *style); |
580 | | void fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style, fz_css_match *match); |
581 | | fz_css_color fz_css_color_from_string(const char *str); |
582 | | |
583 | | /* |
584 | | Lookup style in the splay tree, returning a pointer |
585 | | to the found instance if there is one, creating and |
586 | | inserting (and moving to root) one if there is not. |
587 | | */ |
588 | | const fz_css_style *fz_css_enlist(fz_context *ctx, const fz_css_style *style, fz_css_style_splay **tree, fz_pool *pool); |
589 | | |
590 | | float fz_from_css_number(fz_css_number number, float em, float percent_value, float auto_value); |
591 | | float fz_from_css_number_scale(fz_css_number number, float scale); |
592 | | int fz_css_number_defined(fz_css_number number); |
593 | | int fz_css_number_defined_not_auto(fz_css_number number); |
594 | | |
595 | | fz_html_font_set *fz_new_html_font_set(fz_context *ctx); |
596 | | void fz_add_html_font_face(fz_context *ctx, fz_html_font_set *set, |
597 | | const char *family, int is_bold, int is_italic, int is_small_caps, const char *src, fz_font *font); |
598 | | 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); |
599 | | void fz_drop_html_font_set(fz_context *ctx, fz_html_font_set *htx); |
600 | | |
601 | | void fz_add_css_font_faces(fz_context *ctx, fz_html_font_set *set, fz_archive *dir, const char *base_uri, fz_css *css); |
602 | | |
603 | | void fz_layout_html(fz_context *ctx, fz_html *html, float w, float h, float em); |
604 | | void fz_draw_html(fz_context *ctx, fz_device *dev, fz_matrix ctm, fz_html *html, int page); |
605 | | fz_outline *fz_load_html_outline(fz_context *ctx, fz_html *node); |
606 | | |
607 | | float fz_find_html_target(fz_context *ctx, fz_html *html, const char *id); |
608 | | fz_link *fz_load_html_links(fz_context *ctx, fz_html *html, int page, const char *base_uri); |
609 | | fz_html *fz_keep_html(fz_context *ctx, fz_html *html); |
610 | | void fz_drop_html(fz_context *ctx, fz_html *html); |
611 | | fz_bookmark fz_make_html_bookmark(fz_context *ctx, fz_html *html, int page); |
612 | | int fz_lookup_html_bookmark(fz_context *ctx, fz_html *html, fz_bookmark mark); |
613 | | void fz_debug_html(fz_context *ctx, fz_html_box *box); |
614 | | |
615 | | fz_html *fz_store_html(fz_context *ctx, fz_html *html, void *doc, int chapter); |
616 | | fz_html *fz_find_html(fz_context *ctx, void *doc, int chapter); |
617 | | void fz_purge_stored_html(fz_context *ctx, void *doc); |
618 | | |
619 | | void fz_restartable_layout_html(fz_context *ctx, fz_html_tree *tree, float start_x, float start_y, float page_w, float page_h, float em, fz_html_restarter *restart); |
620 | | |
621 | | fz_html_flow *fz_html_split_flow(fz_context *ctx, fz_pool *pool, fz_html_flow *flow, size_t offset); |
622 | | |
623 | | fz_archive *fz_extract_html_from_mobi(fz_context *ctx, fz_buffer *mobi); |
624 | | |
625 | | fz_structure fz_html_tag_to_structure(const char *tag); |
626 | | |
627 | | fz_html *fz_parse_html(fz_context *ctx, |
628 | | fz_html_font_set *set, fz_archive *dir, const char *base_uri, fz_buffer *buf, const char *user_css, |
629 | | int try_xml, int try_html5, int patch_mobi); |
630 | | |
631 | | fz_buffer *fz_txt_buffer_to_html(fz_context *ctx, fz_buffer *in); |
632 | | |
633 | | /* The only styles valid on cols are: |
634 | | * |
635 | | * width |
636 | | * visibility |
637 | | * background |
638 | | * background-color |
639 | | * background-image UNSUPPORTED |
640 | | * background-position UNSUPPORTED |
641 | | * background-size UNSUPPORTED |
642 | | * background-repeat UNSUPPORTED |
643 | | * background-origin UNSUPPORTED |
644 | | * background-clip UNSUPPORTED |
645 | | * background-attachment UNSUPPORTED |
646 | | * border |
647 | | * border-width |
648 | | * border-style |
649 | | * border-color |
650 | | * |
651 | | * We want to record both what these values are, and whether the col |
652 | | * actually had them. |
653 | | **/ |
654 | | typedef struct |
655 | | { |
656 | | unsigned int has_bg_col : 1; |
657 | | unsigned int has_border_col : 4; |
658 | | unsigned int has_border_width : 4; |
659 | | unsigned int has_visibility : 1; |
660 | | unsigned int has_width : 1; |
661 | | fz_css_color background_color; |
662 | | fz_css_color border_color[4]; |
663 | | fz_css_number border_width[4]; |
664 | | unsigned int visibility; |
665 | | fz_css_number width; |
666 | | } col_style; |
667 | | |
668 | | /* Retrieve the col_style information. */ |
669 | | void |
670 | | fz_css_colstyle(col_style *cs, fz_css_match *match); |
671 | | |
672 | | #endif |