Trying backport
[AROS.git] / workbench / classes / datatypes / html / common.h
blobff579f74b641e24a900c2e9cb2df0534a74535a5
1 /*
2 Copyright © 2004, Martin Gierich. All rights reserved.
3 Licensed under the terms of the AROS Public License (APL)
4 $Id$
6 Desc: Structs for both HTML parser and layout engine
7 */
9 #ifndef TRUE
10 #define TRUE -1
11 #define FALSE 0
12 #endif
14 typedef char* string;
15 #define G(o) ((struct Gadget *)(o))
16 #ifdef __AROS__
17 #include <clib/alib_protos.h>
18 #include <proto/exec.h>
19 #define MALLOC(pool,size) AllocPooled((pool),(size))
20 #define MFREE(pool,ptr)
21 typedef unsigned char u_char;
22 typedef unsigned short u_short;
23 #undef DEBUG
24 #define DEBUG 1
25 #include <aros/debug.h>
26 #define printf bug
28 #else
30 #define MALLOC(pool,size) malloc(size)
31 #define MFREE(pool,ptr) free(ptr)
33 #endif
35 /*******************************************************************************************/
36 /* Prototypes */
38 /* Types */
39 typedef union _para_flags para_flags;
40 typedef union _style_flags style_flags;
41 typedef struct _image_struct image_struct;
42 typedef struct _seg_struct seg_struct;
43 typedef struct _page_struct page_struct;
44 typedef struct _parse_struct parse_struct;
45 typedef struct _layout_struct layout_struct;
47 /* General */
48 page_struct * parse_init( void *mempool );
49 int parse_do( page_struct *page, string inbuf, int inbufbytes );
50 int parse_end( page_struct *page );
51 void parse_free( page_struct *page );
52 int layout_init( page_struct *page );
53 int layout_do( page_struct *page, int winwidth, int *width, int *height );
54 void layout_free( page_struct *page );
56 /*******************************************************************************************/
57 /* Structures common to parse and layout */
59 struct _page_struct
61 string title;
62 void *mempool;
63 seg_struct *seglist;
64 parse_struct *pdata;
65 layout_struct *ldata;
68 struct p_flags
70 u_short align:2;
71 #define ALIGN_LEFT 0
72 #define ALIGN_RIGHT 1
73 #define ALIGN_CENTER 2
74 #define ALIGN_JUSTIFY 3
75 u_short nowordwrap:1;
76 } __attribute__((packed));
78 union _para_flags
80 u_short value;
81 struct p_flags fl;
82 } __attribute__((packed));
84 struct s_flags
86 u_short fontsize:4;
87 u_short bold:1;
88 u_short italics:1;
89 u_short underlined:1;
90 u_short fixedwidth:1;
91 } __attribute__((packed));
93 union _style_flags
95 u_short value;
96 struct s_flags fl;
97 } __attribute__((packed));
99 struct _image_struct
101 string src;
102 string alt;
103 int width;
104 int height;
107 /*******************************************************************************************/
108 /* Text Segments */
110 enum SegCmd
112 SEG_CMD_Next,
113 SEG_CMD_Sublist,
114 SEG_CMD_Blockstart,
115 SEG_CMD_Blockend,
116 SEG_CMD_Text,
117 SEG_CMD_Linebreak,
118 SEG_CMD_Image,
119 SEG_CMD_Ruler,
120 SEG_CMD_Parastyle,
121 SEG_CMD_Softstyle,
122 SEG_CMD_MAX
125 #define SEG_CMD_MASK 0x1f
126 #define SEG_CMD_LAST 0x80
128 struct _seg_struct
130 u_char cmd;
131 u_char pad;
132 union
134 u_short textlen;
135 u_short flags;
136 style_flags stylemask;
137 para_flags paramask;
139 union
141 string textseg;
142 seg_struct *next;
143 seg_struct *sublist;
144 image_struct *image;
145 style_flags styleflags;
146 para_flags paraflags;
148 } __attribute__((packed));
150 /*******************************************************************************************/
151 /* Layout Prototypes */
152 int text_len( layout_struct *ldata, string str, int strlen );
153 int text_height( layout_struct *ldata );
154 int text_fit( layout_struct *ldata, string str, int strlen, int *strsize, int maxwidth );
156 int linelist_init( layout_struct *ldata );
157 void * linelist_store( layout_struct *ldata, string textseg, u_short textlen,
158 u_short xpos, u_short ypos, u_short width, u_short height, style_flags style, int linebreak );
159 void * linelist_addlf( layout_struct *ldata, void * line );
160 void linelist_free( layout_struct *ldata );
162 /*******************************************************************************************/
163 /* Private Layout Data */
165 struct _layout_struct
167 void *userdata;
168 void *oldline;
169 int nowordwrap;
170 int xsize;
171 int xpos;
172 int fontheight;
173 int indent;
174 para_flags paraflags;
175 style_flags styleflags;