File: css.h

package info (click to toggle)
qemacs 0.3.1-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,040 kB
  • ctags: 3,226
  • sloc: ansic: 29,371; sh: 353; makefile: 338
file content (644 lines) | stat: -rw-r--r-- 20,691 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
#ifndef CSS_H
#define CSS_H

struct CSSBox;

typedef struct CSSBox CSSBox;

/* display property */
enum CSSDisplay {
    CSS_DISPLAY_INLINE,
    CSS_DISPLAY_BLOCK,
    CSS_DISPLAY_TABLE,
    CSS_DISPLAY_TABLE_ROW,
    CSS_DISPLAY_TABLE_ROW_GROUP,
    CSS_DISPLAY_TABLE_HEADER_GROUP,
    CSS_DISPLAY_TABLE_FOOTER_GROUP,
    CSS_DISPLAY_TABLE_COLUMN,
    CSS_DISPLAY_TABLE_COLUMN_GROUP,
    CSS_DISPLAY_TABLE_CELL,
    CSS_DISPLAY_TABLE_CAPTION,
    CSS_DISPLAY_LIST_ITEM,
    CSS_DISPLAY_MARKER,
    CSS_DISPLAY_INLINE_BLOCK, /* qemacs extension (CSS3 ?) */
    CSS_DISPLAY_INLINE_TABLE,
    CSS_DISPLAY_NONE,
};

enum CSSProperties {
    CSS_display,
    CSS_color,
    CSS_background_color,
    CSS_white_space,
#define CSS_WHITE_SPACE_NORMAL  0
#define CSS_WHITE_SPACE_PRE     1
#define CSS_WHITE_SPACE_NOWRAP  2
#define CSS_WHITE_SPACE_PREWRAP 3 /* qemacs extension for editing
                                     (XXX: use CSS3)*/
    CSS_direction,
#define CSS_DIRECTION_LTR       0
#define CSS_DIRECTION_RTL       1
    CSS_float,
#define CSS_FLOAT_NONE  0
#define CSS_FLOAT_LEFT  1
#define CSS_FLOAT_RIGHT 2
    CSS_font_family,
    CSS_font_style,
#define CSS_FONT_STYLE_NORMAL 0
#define CSS_FONT_STYLE_ITALIC 1
    CSS_font_weight,
#define CSS_FONT_WEIGHT_NORMAL  0
#define CSS_FONT_WEIGHT_BOLD    1
#define CSS_FONT_WEIGHT_BOLDER  2
#define CSS_FONT_WEIGHT_LIGHTER 3
    CSS_font_size,
    CSS_text_decoration,
#define CSS_TEXT_DECORATION_NONE         0
#define CSS_TEXT_DECORATION_UNDERLINE    1
#define CSS_TEXT_DECORATION_LINE_THROUGH 2
    CSS_text_align,
#define CSS_TEXT_ALIGN_LEFT    0
#define CSS_TEXT_ALIGN_RIGHT   1
#define CSS_TEXT_ALIGN_CENTER  2
    CSS_width,
    CSS_height,
    CSS_unicode_bidi,
#define CSS_UNICODE_BIDI_NORMAL   0
#define CSS_UNICODE_BIDI_EMBED    1
#define CSS_UNICODE_BIDI_OVERRIDE 2
    CSS_border_width,
    CSS_border_left_width,
    CSS_border_top_width,
    CSS_border_right_width,
    CSS_border_bottom_width,

    CSS_border_color,
    CSS_border_left_color,
    CSS_border_top_color,
    CSS_border_right_color,
    CSS_border_bottom_color,

    CSS_border_style,
    CSS_border_left_style,
    CSS_border_top_style,
    CSS_border_right_style,
    CSS_border_bottom_style,
#define CSS_BORDER_STYLE_NONE    0
#define CSS_BORDER_STYLE_HIDDEN  1
#define CSS_BORDER_STYLE_DOTTED  2
#define CSS_BORDER_STYLE_DASHED  3
#define CSS_BORDER_STYLE_SOLID   4
#define CSS_BORDER_STYLE_DOUBLE  5
#define CSS_BORDER_STYLE_GROOVE  6
#define CSS_BORDER_STYLE_RIDGE   7
#define CSS_BORDER_STYLE_INSET   8
#define CSS_BORDER_STYLE_OUTSET  9

    CSS_border,
    CSS_border_left,
    CSS_border_top,
    CSS_border_right,
    CSS_border_bottom,
    
    CSS_padding,
    CSS_padding_left,
    CSS_padding_top,
    CSS_padding_right,
    CSS_padding_bottom,

    CSS_margin,
    CSS_margin_left,
    CSS_margin_top,
    CSS_margin_right,
    CSS_margin_bottom,
    CSS_clear,
#define CSS_CLEAR_NONE  0
#define CSS_CLEAR_LEFT  1
#define CSS_CLEAR_RIGHT 2
#define CSS_CLEAR_BOTH  3
    CSS_overflow,
#define CSS_OVERFLOW_VISIBLE 0
#define CSS_OVERFLOW_HIDDEN  1
    CSS_visibility,
#define CSS_VISIBILITY_VISIBLE 0
#define CSS_VISIBILITY_HIDDEN  1
    CSS_table_layout,
#define CSS_TABLE_LAYOUT_AUTO  0
#define CSS_TABLE_LAYOUT_FIXED 1
    CSS_vertical_align,
#define CSS_VERTICAL_ALIGN_BASELINE     0
#define CSS_VERTICAL_ALIGN_SUB          1
#define CSS_VERTICAL_ALIGN_SUPER        2
#define CSS_VERTICAL_ALIGN_TOP          3
#define CSS_VERTICAL_ALIGN_TEXT_TOP     4
#define CSS_VERTICAL_ALIGN_MIDDLE       5
#define CSS_VERTICAL_ALIGN_BOTTOM       6
#define CSS_VERTICAL_ALIGN_TEXT_BOTTOM  7
    CSS_border_collapse,
#define CSS_BORDER_COLLAPSE_COLLAPSE    0
#define CSS_BORDER_COLLAPSE_SEPARATE    1
    CSS_border_spacing,
    CSS_border_spacing_horizontal,
    CSS_border_spacing_vertical,
    CSS_line_height,
    CSS_position,
#define CSS_POSITION_STATIC     0
#define CSS_POSITION_RELATIVE   1
#define CSS_POSITION_ABSOLUTE   2
#define CSS_POSITION_FIXED      3
    CSS_content,
    CSS_caption_side,
#define CSS_CAPTION_SIDE_TOP    0
#define CSS_CAPTION_SIDE_BOTTOM 1
#define CSS_CAPTION_SIDE_LEFT   2
#define CSS_CAPTION_SIDE_RIGHT  3
    CSS_marker_offset,
    CSS_list_style_type,
#define CSS_LIST_STYLE_TYPE_DISC        0
#define CSS_LIST_STYLE_TYPE_CIRCLE      1
#define CSS_LIST_STYLE_TYPE_SQUARE      2
#define CSS_LIST_STYLE_TYPE_DECIMAL     3
#define CSS_LIST_STYLE_TYPE_LOWER_ALPHA 4
#define CSS_LIST_STYLE_TYPE_UPPER_ALPHA 5
#define CSS_LIST_STYLE_TYPE_LOWER_ROMAN 6
#define CSS_LIST_STYLE_TYPE_UPPER_ROMAN 7
#define CSS_LIST_STYLE_TYPE_NONE        8
    CSS_column_span, /* qemacs extension */
    CSS_row_span,    /* qemacs extension */
    CSS_content_alt, /* qemacs extension */
    CSS_list_style_position,
#define CSS_LIST_STYLE_POSITION_OUTSIDE 0
#define CSS_LIST_STYLE_POSITION_INSIDE  1
    CSS_counter_reset,
    CSS_counter_increment,
    CSS_bidi_mode, /* qemacs extension */
#define CSS_BIDI_MODE_NORMAL            0
#define CSS_BIDI_MODE_TEST              1
    CSS_left,
    CSS_top,
    CSS_right,
    CSS_bottom,
    NB_PROPERTIES,
};

#define CSS_AUTO    0x80000000
#define CSS_INHERIT 0x80000001

typedef unsigned int CSSColor;

typedef struct CSSPropertyDef {
    const char *name;
    unsigned short struct_offset; /* in CSSState */
    unsigned char storage;
#define CSS_STORAGE_INT     0
#define CSS_STORAGE_PTR     1
    unsigned int type;
#define CSS_TYPE_AUTO          0x80000000
#define CSS_TYPE_NOINHERIT     0x40000000
/* the four next properties will be set according to the CSS rules for
   margin, borders and padding */
#define CSS_TYPE_FOUR          0x20000000
#define CSS_TYPE_TWO           0x10000000 /* the same with two args */
#define CSS_TYPE_SPECIAL       0x08000000 /* XXX: special storage needed */
#define CSS_TYPE_INHERITED     0x04000000 /* property is inherited */
#define CSS_TYPE_ARGS          0x02000000 /* no limit on number of args */
/* types can be ored */
#define CSS_TYPE_LENGTH        0x00000001
#define CSS_TYPE_COLOR         0x00000002
#define CSS_TYPE_ENUM          0x00000004
#define CSS_TYPE_BORDER_STYLE  0x00000008  
#define CSS_TYPE_FONT_FAMILY   0x00000010
#define CSS_TYPE_BORDER_ENUM   0x00000020
#define CSS_TYPE_STRING        0x00000040
#define CSS_TYPE_INTEGER       0x00000080
#define CSS_TYPE_ATTR          0x00000100 /* attr(x) */
#define CSS_TYPE_COUNTER       0x00000200 /* counter(x[,type]) */
#define CSS_TYPE_LIST_STYLE    0x00000400
#define CSS_TYPE_IDENT         0x00000800

} CSSPropertyDef;

extern const CSSPropertyDef css_properties[NB_PROPERTIES];

/* CSS parsing */

/* length are normalized to this value, except pixel units */
#define CSS_LENGTH_FRAC_BITS 8
#define CSS_LENGTH_FRAC_BASE (1 << CSS_LENGTH_FRAC_BITS)

/* number of pixels for one px */
#define CSS_SCREEN_PX_SIZE   1
/* resolution */
#define CSS_SCREEN_DPI       72

#define CSS_TTY_PX_SIZE      (1.0/8.0)
#define CSS_TTY_DPI          9

/* currently, we define ex as a scaling of the font size */
#define CSS_EX_SCALE         ((int)(0.8 * CSS_LENGTH_FRAC_BASE))

#define CSS_UNIT_NONE       0
#define CSS_UNIT_PIXEL      1
#define CSS_UNIT_PERCENT    2
#define CSS_UNIT_EX         3
#define CSS_UNIT_EM         4
#define CSS_UNIT_IN         6

/* the following units are never used except in parsing */
#define CSS_UNIT_MM         5
#define CSS_UNIT_CM         7
#define CSS_UNIT_PT         8
#define CSS_UNIT_PC         9

/* additionnal values */
#define CSS_VALUE_STRING     11
#define CSS_VALUE_COUNTER    12
#define CSS_VALUE_ATTR       13
#define CSS_VALUE_COLOR      14
#define CSS_VALUE_IDENT      15
#define CSS_VALUE_INTEGER    16

/* CSS identifier handling */
typedef enum CSSIdent {
    CSS_ID_NIL = 0,
    CSS_ID_ALL = 1,    /* '*' ident */
#define CSSID(id) CSS_ID_ ## id,
#define CSSIDSTR(id, str) CSS_ID_ ## id,
#include "cssid.h"
#undef CSSID
#undef CSSIDSTR
} CSSIdent;

typedef struct CSSIdentEntry {
    CSSIdent id;
    struct CSSIdentEntry *hash_next;
    char str[1];
} CSSIdentEntry;

const char *css_ident_str(CSSIdent id);
CSSIdent css_new_ident(const char *str);

static inline unsigned int css_hash_ident(CSSIdent id, unsigned int hash_size)
{
    return (unsigned int)id % hash_size;
}

/* property handlign */

typedef struct CSSPropertyValue {
    int type; /* see CSS_UNIT_xxx or CSS_VALUE_xxx */
    union {
        int val;
        char *str;
        CSSIdent attr_id;
        struct {
            CSSIdent counter_id;
            int type;
        } counter;
    } u;
} CSSPropertyValue;

typedef struct CSSProperty {
    unsigned short property;
    unsigned short nb_values;
    struct CSSProperty *next; /* may change: use array ? */
    CSSPropertyValue value;   /* in fact an array, but need 
                                 to change all the types */
} CSSProperty;

/* tag attribute handling */

typedef struct CSSAttribute {
    CSSIdent attr;
    struct CSSAttribute *next;
    char value[1];
} CSSAttribute;

/* css box definition (most important data structure) */

struct CSSBox {
    CSSIdent tag;          /* tag name of the box, may be CSS_ID_NIL
                              for anonymous box */
    CSSAttribute *attrs;   /* attributes (may be NULL) */
    CSSProperty *properties;  /* explicit properties */
    struct CSSState *props;          /* computed properties for this box */
    struct CSSBox *next; /* next box at same level */
    /* bounding box of the draw primitives of the box and all its
       childs */
    CSSRect bbox;
    /* layout info */
    int x, y; /* absolute content position. XXX: currently also
                 relative to parent in the layout */
    int width, height; /* content width & height */
    /* inline specific layout. Not useful in fact XXX: use an union,
       or merge with padding_xx */
    unsigned short padding_top;
    unsigned short padding_bottom;
    unsigned short ascent; /* cannot use font ascent in case of
    fallback XXX: find a way to suppress this field */
    unsigned char embedding_level; /* from layout: bidir embedding level */
    unsigned char content_type;
#define CSS_CONTENT_TYPE_CHILDS  0
#define CSS_CONTENT_TYPE_BUFFER  1
#define CSS_CONTENT_TYPE_STRING  2
#define CSS_CONTENT_TYPE_IMAGE   3
    /* true if the content ends with eol. (used in
       CSS_CONTENT_TYPE_BUFFER to display the cursor */
    unsigned char content_eol:1;
    unsigned char absolute_pos:1; /* true if absolute position (only
                                     meaningful during layout */
    unsigned char split:1;        /* true if this box is a splitted box
                                     (no need to free its content) */
    /* true if there was a space in the previous box (useful in inline
       formatting context) */
    unsigned char last_space;
    /* next inline box in an inline formatting context. Only used
       during bidi pass, so we could put this field in another field
       to save space */
    struct CSSBox *next_inline; 
    /* parent box */
    struct CSSBox *parent; 
    union {
        struct {
            struct CSSBox *last;  /* used only when building the tree */
            struct CSSBox *first; /* first box under this box, if any */
        } child;
        /* either pointers to memory or in a buffer */
        struct {
            unsigned long start;       /* start of text */
            unsigned long end;         /* end of text */
        } buffer;
        struct {
            char *content_alt;         /* alternate content */
        } image;
    } u;
};

/* horrible, but simple: we store EOL content (\A) as this value. Need
   to find a better unicode value and to store it in UTF8 */
#define CSS_CONTENT_EOL     0x01

typedef struct CSSState {
    int display;
    CSSColor color;
    CSSColor bgcolor;
    CSSColor border_colors[4];
    CSSRect padding;
    CSSRect border;
    CSSRect margin;
    int border_styles[4];
    int white_space;
    int direction;
    int block_float;
    int font_family;
    int font_style;
    int text_decoration;
    int font_weight;
    int font_size;
    int text_align;
    int width;
    int height;
    int unicode_bidi;
    int clear;
    int overflow;
    int visibility; /* XXX: initial value should be inherit */
    int table_layout;
    int vertical_align;
    int border_collapse;
    int border_spacing_horizontal;
    int border_spacing_vertical;
    int line_height;
    int position;
    int caption_side;
    int marker_offset;
    int list_style_type;
    int column_span;
    int row_span;
    int list_style_position;
    int bidi_mode;
    int left;
    int top;
    int right;
    int bottom;
    /* after hash_next, no hashing or bulk comparisons are done */
    struct CSSState *hash_next;
    /* set of complex properties which are handled once after the
       cascade is done */
    struct CSSProperty *content;
    struct CSSProperty *content_alt;
    struct CSSProperty *counter_reset;
    struct CSSProperty *counter_increment;
} CSSState;

/* style sheet handling */

typedef struct CSSStyleSheetAttributeEntry {
    struct CSSStyleSheetAttributeEntry *next;
    CSSIdent attr;        /* attribute */
    unsigned char op;
#define CSS_ATTR_OP_SET      0
#define CSS_ATTR_OP_EQUAL    1
#define CSS_ATTR_OP_IN_LIST  2
#define CSS_ATTR_OP_IN_HLIST 3
    char value[1];
} CSSStyleSheetAttributeEntry;

/* simple selector */
typedef struct CSSSimpleSelector {
    /* relation between next and current simple selector */
    unsigned char tree_op;
#define CSS_TREE_OP_NONE       0  /* no next simple selector */
#define CSS_TREE_OP_DESCENDANT 1
#define CSS_TREE_OP_CHILD      2
#define CSS_TREE_OP_PRECEEDED  3
    unsigned short pclasses; /* pseudo classes & elements */
#define CSS_PCLASS_FIRST_CHILD 0x0001
#define CSS_PCLASS_LINK        0x0002
#define CSS_PCLASS_VISITED     0x0004
#define CSS_PCLASS_ACTIVE      0x0008
#define CSS_PCLASS_HOVER       0x0010
#define CSS_PCLASS_FOCUS       0x0020
    /* pseudo elements */
#define CSS_PCLASS_FIRST_LINE   0x0040
#define CSS_PCLASS_FIRST_LETTER 0x0080
#define CSS_PCLASS_BEFORE       0x0100
#define CSS_PCLASS_AFTER        0x0200

    CSSIdent tag;      /* selection tag, CSS_ID_ALL means all */
    CSSIdent tag_id;   /* id */
    CSSStyleSheetAttributeEntry *attrs; /* attribute list */
    struct CSSSimpleSelector *next; /* next selector operation */
} CSSSimpleSelector;

typedef struct CSSStyleSheetEntry {
    CSSSimpleSelector sel; /* main selector */
    int media;         /* CSS2 media mask */
    CSSProperty *props; /* associated properties */
    struct CSSStyleSheetEntry *hash_next; /* hash table for next matching tag */
    struct CSSStyleSheetEntry *next; /* next entry in style sheet */
} CSSStyleSheetEntry;

#define CSS_TAG_HASH_SIZE 521

typedef struct CSSStyleSheet {
    CSSStyleSheetEntry *first_entry, **plast_entry;
    CSSStyleSheetEntry *tag_hash[CSS_TAG_HASH_SIZE];
} CSSStyleSheet;

typedef struct {
    const char *ptr;
    int line_num;
    const char *filename;
    int ignore_case; /* true if case must be ignored (convert to lower case) */
} CSSParseState;

CSSStyleSheet *css_new_style_sheet(void);
void css_parse_style_sheet_str(CSSStyleSheet *s, const char *buffer, int flags);
void css_parse_style_sheet(CSSStyleSheet *s, CSSParseState *b);
void css_free_style_sheet(CSSStyleSheet *s);
void css_dump_style_sheet(CSSStyleSheet *s);
void css_merge_style_sheet(CSSStyleSheet *s, CSSStyleSheet *a);

CSSProperty *css_parse_properties(CSSParseState *b, const char *props_str);
void css_add_prop_values(CSSProperty ***last_prop, 
                         int property_index, 
                         int nb_values, CSSPropertyValue *val_ptr);
void css_add_prop(CSSProperty ***last_prop, 
                  int property_index, CSSPropertyValue *val_ptr);
void css_add_prop_unit(CSSProperty ***last_prop, 
                       int property_index, int type, int val);
void css_add_prop_int(CSSProperty ***last_prop, 
                      int property_index, int val);
CSSStyleSheetEntry *add_style_entry(CSSStyleSheet *s,
                                    CSSSimpleSelector *ss,
                                    int media);
void add_attribute(CSSStyleSheetAttributeEntry ***last_attr,
                   CSSIdent attr, int op, const char *value);
int get_font_size(int i);

/* CSS creating, layout and display */

struct CSSContext;

#define PROPS_HASH_SIZE 521
#define PROPS_SIZE ((int)&((CSSState *)0)->hash_next)

typedef struct CSSCounterValue {
    CSSIdent counter_id;
    int value;
    struct CSSCounterValue *prev;
} CSSCounterValue;

typedef struct CSSContext {
    CSSStyleSheet *style_sheet;
    QEditScreen *screen;
    /* various default settings */
    /* XXX: use style sheet ? */
    int selection_bgcolor;
    int selection_fgcolor;
    int default_bgcolor;
    
    /* edit buffer */
    EditBuffer *b;
    /* selection handling */
    int selection_start, selection_end;
    /* private content */
    int media;     /* initialized when creating CSSContext */
    int px_size; /* px unit size, in displayed pixels (CSS_LENGTH_FRAC_BASE) */
    int dots_per_inch; /* convert from inch to displayed pixels */
    int bg_drawn; /* temporary for css_display */
    CSSRect bg_rect; /* temporary for css_display */
    CSSAbortFunc *abort_func;
    void *abort_opaque;
    int nb_props; /* statistics */

    /* only used during css_compute() */
    CSSCounterValue *counter_stack_ptr;
    CSSCounterValue *counter_stack_base;

    /* css attributes for the boxes are shared here */
    CSSState *hash_props[PROPS_HASH_SIZE]; 
} CSSContext;

/* document managing */

void css_init(void);

CSSContext *css_new_document(QEditScreen *screen,
                             EditBuffer *b);
void css_delete_document(CSSContext *s);

int css_compute(CSSContext *s, CSSBox *box);
int css_layout(CSSContext *s, CSSBox *box, int width,
               CSSAbortFunc *abort_func, void *abort_opaque);
void css_display(CSSContext *s, CSSBox *box, 
                 CSSRect *clip_box, int dx, int dy);

/* cursor/edition handling */
int box_get_text(CSSContext *s,
                 unsigned int *line_buf, int max_size, 
                 int *offsets, CSSBox *box);
int css_get_cursor_pos(CSSContext *s, CSSBox *box, 
                       CSSBox **box_ptr, int *x0_ptr, int *y0_ptr,
                       CSSRect *cursor_ptr, int *dir_ptr, 
                       int offset);
int css_get_offset_pos(CSSContext *s, CSSBox *box, int xc, int dir);

typedef int (*CSSIterateFunc)(void *opaque, CSSBox *box, int x0, int y0);
int css_box_iterate(CSSContext *s, CSSBox *box, void *opaque, 
                    CSSIterateFunc iterate_func);


/* box tree handling */
CSSBox *css_new_box(CSSIdent tag, CSSAttribute *attrs);
CSSBox *css_add_box(CSSBox *parent_box, CSSBox *box);
void css_delete_box(CSSBox *box);
void css_set_text_buffer(CSSBox *box,
                         int offset1, int offset2, int eol);
void css_set_text_string(CSSBox *box, const char *string);
void css_make_child_box(CSSBox *box);
void css_set_child_box(CSSBox *parent_box, CSSBox *box);

/* box tree display (debug) */
void css_dump_box(CSSBox *box, int level);
void css_dump(CSSBox *box);

/* XML parser */
struct XMLState;
typedef struct XMLState XMLState;

#define XML_HTML        0x0001 /* enable html tag interpretation which cannot
                                  be specified in a stylesheet */
#define XML_IGNORE_CASE 0x0002 /* ignore case for both xml/css tag parsing */
#define XML_DOCBOOK     0x0004 /* programlisting is handled as PRE */
#define XML_HTML_SYNTAX 0x0008 /* modify xml parser to accept HTML syntax */

XMLState *xml_begin(CSSStyleSheet *style_sheet, int flags,
                    CSSAbortFunc *abort_func, void *abort_opaque, 
                    const char *filename, QECharset *charset);
int xml_parse(XMLState *s, char *buf, int buf_len);
CSSBox *xml_end(XMLState *s);

CSSBox *xml_parse_buffer(EditBuffer *b, int offset_start, int offset_end, 
                         CSSStyleSheet *style_sheet, int flags,
                         CSSAbortFunc *abort_func, void *abort_opaque);
int find_entity(const char *str);
const char *find_entity_str(int code);
#endif

/* The following functions must be provided by the user */

/* error reporting during parsing */
void html_error(int line_num, const char *fmt, va_list ap);

void css_error(const char *filename, int line_num, const char *msg);

/* file handling (for external scripts/css) */
struct CSSFile;
typedef struct CSSFile CSSFile;

CSSFile *css_open(CSSContext *s, const char *filename);
int css_filesize(CSSFile *f);
int css_read(CSSFile *f, unsigned char *buf, int size);
void css_close(CSSFile *f);