Rev 6806 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6806 | Rev 7285 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | void PreparePage() |
- | |
2 | { |
1 | void ParseTxt() |
3 | list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, kfont.size.pt+2); |
- | |
4 | strcpy(#title, history.current()+strrchr(history.current(),'/')); |
- | |
5 | //get font chars width, need to increase performance |
- | |
6 | get_label_symbols_size(); |
- | |
7 | ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
- | |
8 | link.clear(); |
- | |
9 | if (strstri(io.buffer_data, " |
- | |
10 | debugln("no found"); |
- | |
11 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceTxt(false); //get page height to calculate buffer size |
- | |
12 | DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true); //draw text in buffer |
- | |
13 | } else { |
- | |
14 | debugln(" tag found"); |
- | |
15 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceHtml(false); //get page height to calculate buffer size |
- | |
16 | // debugln("DONE STEP 2"); |
- | |
17 | DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true); //draw text in buffer |
- | |
18 | // debugln("DONE STEP 3"); |
- | |
19 | } |
- | |
20 | strcat(#title, " - Aelia"); |
- | |
21 | DrawTitle(#title); |
- | |
22 | DrawProgress(STEP_4_SMOOTH_FONT); kfont.ApplySmooth(); |
- | |
23 | DrawProgress(STEP_5_STOP); DrawPage(); |
- | |
24 | } |
- | |
25 | - | ||
26 | void ParceTxt(byte draw) |
- | |
27 | { |
- | |
28 | byte ch, zeroch=0; |
2 | { |
- | 3 | _canvas canvas; |
|
29 | dword bufoff, buflen, line_start, srch_pos; |
4 | byte ch, zeroch=0; |
30 | int stroka_y=5, line_length=0; |
5 | dword bufoff, buflen, line_start, srch_pos; |
31 | 6 | int stroka_y=5, line_length=0; |
|
Line 32... | Line 7... | ||
32 | line_start=io.buffer_data; |
7 | |
Line 42... | Line 17... | ||
42 | if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break |
17 | { |
43 | if (srch_pos == line_start) break; //no white space found in whole line |
18 | if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break |
44 | srch_pos--; |
19 | if (srch_pos == line_start) break; //no white space found in whole line |
45 | } |
20 | srch_pos--; |
46 | if (draw==true) { |
21 | } |
47 | ESBYTE[bufoff] >< zeroch; //set line end |
22 | if (kfont.size.height) { |
48 | WriteTextIntoBuf(8, stroka_y, 0x000000, line_start); |
23 | ESBYTE[bufoff] >< zeroch; //set line end |
49 | ESBYTE[bufoff] >< zeroch; //restore line |
24 | canvas.write_text(8, stroka_y, 0x000000, line_start); |
50 | } |
25 | ESBYTE[bufoff] >< zeroch; //restore line |
51 | stroka_y += list.item_h; |
26 | } |
52 | line_start = bufoff; |
27 | stroka_y += list.item_h; |
53 | line_length = 0; |
28 | line_start = bufoff; |
54 | } |
29 | line_length = 0; |
55 | } |
30 | } |
56 | if (draw==false) { |
31 | } |
57 | list.count = stroka_y/list.item_h+3; |
32 | if (!kfont.size.height) { |
58 | if (list.count < list.visible) list.count = list.visible; |
33 | list.count = stroka_y/list.item_h+3; |
59 | kfont.size.height = list.count+5*list.item_h; |
34 | if (list.count < list.visible) list.count = list.visible; |
60 | kfont.raw_size = 0; |
35 | kfont.size.height = list.count+5*list.item_h; |
61 | } |
36 | kfont.raw_size = 0; |
- | 37 | ParseTxt(); |
|
62 | if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start); |
38 | } |
63 | } |
39 | else canvas.write_text(8, stroka_y, 0x000000, line_start); |
64 | 40 | } |
|
Line 65... | Line -... | ||
65 | - | ||
66 | /*======================================================== |
41 | |
67 | = = |
42 | /*======================================================== |
68 | = HTML = |
43 | = = |
69 | = = |
44 | = STYLE = |
70 | ========================================================*/ |
45 | = = |
71 | - | ||
72 | #define HTML_PADDING_X 8; |
46 | ========================================================*/ |
73 | #define HTML_PADDING_Y 5; |
47 | #define HTML_PADDING_X 8; |
Line -... | Line 48... | ||
- | 48 | #define HTML_PADDING_Y 5; |
|
- | 49 | ||
- | 50 | struct _style { |
|
- | 51 | bool b, u, i, s; |
|
- | 52 | bool h1, h2, h3, h4, h5, h6; |
|
- | 53 | bool a; |
|
- | 54 | bool pre; |
|
- | 55 | bool ignore; |
|
- | 56 | dword color; |
|
- | 57 | void clear(); |
|
- | 58 | }; |
|
- | 59 | ||
- | 60 | void _style::clear() |
|
- | 61 | { |
|
- | 62 | b=u=i=s=0; |
|
- | 63 | h1=h2=h3=h4=h5=h6=0; |
|
- | 64 | a=0; |
|
- | 65 | pre=0; |
|
- | 66 | ignore=0; |
|
- | 67 | color=0; |
|
- | 68 | } |
|
- | 69 | ||
- | 70 | /*======================================================== |
|
- | 71 | = = |
|
- | 72 | = TAG = |
|
- | 73 | = = |
|
- | 74 | ========================================================*/ |
|
- | 75 | struct _tag { |
|
- | 76 | dword start; |
|
- | 77 | dword end; |
|
- | 78 | dword name; |
|
- | 79 | dword param[10]; |
|
- | 80 | dword value[10]; |
|
- | 81 | void parse(); |
|
Line 74... | Line 82... | ||
74 | 82 | int nameis(); |
|
75 | 83 | }; |
|
- | 84 | ||
- | 85 | void _tag::parse() |
|
- | 86 | { |
|
- | 87 | strlwr(name); |
|
- | 88 | } |
|
76 | void ParceHtml(byte draw) |
89 | |
- | 90 | int _tag::nameis(dword _in_tag_name) |
|
- | 91 | { |
|
- | 92 | if (name) && (strcmp(_in_tag_name, start)==0) return true; |
|
- | 93 | return false; |
|
- | 94 | } |
|
- | 95 | ||
- | 96 | /*======================================================== |
|
- | 97 | = = |
|
- | 98 | = DRAW = |
|
- | 99 | = = |
|
- | 100 | ========================================================*/ |
|
- | 101 | struct _draw |
|
- | 102 | { |
|
- | 103 | dword x; |
|
- | 104 | dword y; |
|
- | 105 | void init(); |
|
- | 106 | void line_break(); |
|
- | 107 | }; |
|
77 | { |
108 | |
78 | dword DOM_start, DOM_end, DOM_len, DOM_pos, aux2; |
109 | void _draw::init() |
- | 110 | { |
|
- | 111 | x = HTML_PADDING_X; |
|
- | 112 | y = HTML_PADDING_Y; |
|
- | 113 | } |
|
- | 114 | void _draw::line_break() |
|
- | 115 | { |
|
- | 116 | y+= list.item_h; |
|
- | 117 | x = HTML_PADDING_X; |
|
- | 118 | } |
|
- | 119 | ||
- | 120 | /*======================================================== |
|
- | 121 | = = |
|
- | 122 | = BUF = |
|
- | 123 | = = |
|
- | 124 | ========================================================*/ |
|
- | 125 | struct _buf |
|
- | 126 | { |
|
- | 127 | dword pointer; |
|
- | 128 | dword len; |
|
- | 129 | dword start; |
|
- | 130 | dword end; |
|
- | 131 | void init(); |
|
- | 132 | }; |
|
- | 133 | ||
- | 134 | void _buf::init(dword _buf_pointer, _buf_len) |
|
- | 135 | { |
|
- | 136 | pointer = _buf_pointer; |
|
- | 137 | len = _buf_len; |
|
- | 138 | start = malloc(len); |
|
- | 139 | end = start + len; |
|
- | 140 | strlcpy(start, pointer, len); |
|
- | 141 | } |
|
- | 142 | ||
- | 143 | /*======================================================== |
|
- | 144 | = = |
|
- | 145 | = TEXT = |
|
79 | int stroka_x = HTML_PADDING_X; |
146 | = = |
- | 147 | ========================================================*/ |
|
- | 148 | struct _text { |
|
- | 149 | int size_pt_change; |
|
- | 150 | dword start; |
|
- | 151 | dword end; |
|
80 | int stroka_y = HTML_PADDING_Y; |
152 | }; |
81 | int size_pt_change = 0; |
153 | |
82 | dword line_break; |
- | |
83 | byte ch, zeroch; |
- | |
84 | _text text; |
- | |
85 | _tag tag; |
- | |
86 | tag.clear(); |
- | |
87 | style.clear(); |
- | |
88 | /* Create DOM */ |
- | |
89 | debugln("creating DOM"); |
- | |
90 | DOM_len = strlen(io.buffer_data); |
- | |
91 | DOM_start = malloc(DOM_len); |
- | |
92 | DOM_end = DOM_start + DOM_len; |
154 | /* |
93 | strlcpy(DOM_start, io.buffer_data, DOM_len); |
- | |
94 | - | ||
95 | /* Parce DOM */ |
- | |
96 | debugln("starting DOM parce..."); |
- | |
97 | text.start = DOM_start; |
- | |
98 | for (DOM_pos=DOM_start; DOM_pos |
- | |
99 | { |
- | |
100 | if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' '; |
- | |
101 | ch = ESBYTE[DOM_pos]; |
155 | dword line_break; |
102 | if (ch=='<') { |
- | |
103 | ESBYTE[DOM_pos] = '\0'; |
156 | byte char_holder; |
104 | tag.start = DOM_pos + 1; |
- | |
105 | if (style.ignore) continue; |
157 | |
106 | if (tag.nameis("title")) { |
158 | if (ESBYTE[buf.pos]==0x0A) { |
107 | strcpy(#title, text.start); |
159 | if (style.pre) { |
108 | continue; |
- | |
109 | } |
- | |
110 | strtrim(text.start); |
- | |
- | 160 | draw.line_break(); |
|
Line 111... | Line 161... | ||
111 | // try to change the special symbols that may appear |
161 | continue; |
112 | text.fixSpecial(text.start); |
162 | } |
113 | - | ||
114 | while (get_label_len(text.start) + stroka_x + 30 > list.w) |
163 | } |
115 | { |
164 | |
116 | zeroch = 0; |
165 | while (get_label_len(text.start) + draw.x + 30 > list.w) |
- | 166 | { |
|
117 | for (line_break=tag.start-1; line_break>text.start; line_break--;) |
167 | for (line_break=tag.start-1; line_break>text.start; line_break--;) |
118 | { |
168 | { |
119 | ESBYTE[line_break] >< zeroch; //set line end |
169 | char_holder = ESBYTE[line_break]; //set line end |
120 | if (get_label_len(text.start) + stroka_x + 30 <= list.w) break; |
170 | ESBYTE[line_break] = '\0'; |
121 | ESBYTE[line_break] >< zeroch; //restore line |
171 | if (get_label_len(text.start) + draw.x + 30 <= list.w) break; |
122 | } |
172 | ESBYTE[line_break] = char_holder; //restore line |
123 | if (draw==true) { |
173 | } |
124 | if (style.a) { |
174 | if (draw_on) { |
125 | link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," "); |
175 | if (style.a) { |
126 | label_draw_bar(stroka_x, stroka_y+kfont.size.pt+1, get_label_len(text.start), style.color); |
176 | link.add(draw.x,draw.y + size_pt_change,get_label_len(text.start),list.item_h,text.start," "); |
127 | } |
177 | label_draw_bar(draw.x, draw.y+kfont.size.pt+1, get_label_len(text.start), style.color); |
128 | WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start); |
178 | } |
129 | } |
179 | WriteTextIntoBuf(draw.x, draw.y, style.color, text.start); |
130 | stroka_x+=char_width[' ']; |
- | |
131 | ESBYTE[line_break] >< zeroch; //restore line |
180 | } |
132 | text.start = line_break; |
181 | draw.x+=char_width[' ']; |
133 | stroka_x = HTML_PADDING_X; |
182 | ESBYTE[line_break] = char_holder; //restore line |
134 | stroka_y += list.item_h; |
183 | text.start = line_break; |
135 | } |
184 | draw.line_break(); |
136 | if (draw==true) { |
185 | } |
137 | if (style.a) { |
186 | if (draw_on) { |
138 | link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," "); |
187 | if (style.a) { |
139 | label_draw_bar(stroka_x, stroka_y+kfont.size.pt+1, get_label_len(text.start), style.color); |
188 | link.add(draw.x,draw.y + size_pt_change,get_label_len(text.start),list.item_h,text.start," "); |
140 | } |
189 | label_draw_bar(draw.x, draw.y+kfont.size.pt+1, get_label_len(text.start), style.color); |
141 | WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start); |
190 | } |
- | 191 | WriteTextIntoBuf(draw.x, draw.y, style.color, text.start); |
|
- | 192 | } |
|
- | 193 | draw.x += char_width[' ']; |
|
- | 194 | draw.x += get_label_len(text.start); |
|
- | 195 | */ |
|
- | 196 | ||
- | 197 | ||
- | 198 | /*======================================================== |
|
- | 199 | = = |
|
- | 200 | = DOM = |
|
- | 201 | = = |
|
- | 202 | ========================================================*/ |
|
- | 203 | struct _dom |
|
- | 204 | { |
|
- | 205 | _tag tag; |
|
- | 206 | _style style; |
|
- | 207 | _draw draw; |
|
- | 208 | _buf buf; |
|
- | 209 | _text text; |
|
- | 210 | _canvas canvas; |
|
- | 211 | void init(); |
|
- | 212 | void set_style(); |
|
- | 213 | void parse(); |
|
- | 214 | void apply_text(); |
|
- | 215 | }; |
|
- | 216 | ||
- | 217 | void _dom::init() |
|
142 | } |
218 | { |
- | 219 | style.clear(); |
|
143 | stroka_x+=char_width[' ']; |
220 | draw.init(); |
- | 221 | buf.init(io.buffer_data, strlen(io.buffer_data)); |
|
- | 222 | } |
|
144 | stroka_x += get_label_len(text.start); |
223 | |
145 | } |
224 | void _dom::set_style() |
- | 225 | { |
|
- | 226 | /* |
|
- | 227 | if (tag.nameis("pre")) style.pre = true; |
|
146 | if (ch=='>') { |
228 | if (tag.nameis("/pre")) style.pre = false; |
- | 229 | if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true; |
|
147 | ESBYTE[DOM_pos] = '\0'; |
230 | if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false; |
148 | text.start = DOM_pos + 1; |
231 | if (tag.nameis("a")) { style.a = true; style.color=0x0000FF; } |
149 | tag.parce(); |
232 | if (tag.nameis("/a")) { style.a = false; style.color=0x000000; } |
150 | if (tag.nameis("br")) |
233 | |
151 | || (tag.nameis("p")) |
234 | if (tag.nameis("br")) |
152 | || (tag.nameis("div")) |
- | |
153 | || (tag.nameis("tr")) { |
235 | || (tag.nameis("p")) |
154 | stroka_y+= list.item_h; |
236 | || (tag.nameis("div")) |
- | 237 | || (tag.nameis("tr")) { |
|
- | 238 | draw.line_break(); |
|
- | 239 | return; |
|
- | 240 | } |
|
- | 241 | ||
- | 242 | if (dom.tag.nameis("title")) { |
|
- | 243 | strcpy(#title, text.start); |
|
155 | stroka_x = HTML_PADDING_X; |
244 | strcat(#title, " - Aelia"); |
156 | continue; |
245 | DrawTitle(#title); |
157 | } |
246 | } |
158 | if (tag.nameis("h1")) || (tag.nameis("/h1")) || |
247 | |
159 | (tag.nameis("h2")) || (tag.nameis("/h2")) || |
248 | if (tag.nameis("h1")) || (tag.nameis("/h1")) || |
160 | (tag.nameis("h3")) || (tag.nameis("/h3")) { |
249 | (tag.nameis("h2")) || (tag.nameis("/h2")) || |
161 | if (tag.nameis("h1")) { |
250 | (tag.nameis("h3")) || (tag.nameis("/h3")) { |
162 | size_pt_change = 8; |
251 | if (tag.nameis("h1")) { |
163 | } else if (tag.nameis("/h1")) { |
252 | text.size_pt_change = 8; |
164 | size_pt_change = -8; |
253 | } else if (tag.nameis("/h1")) { |
165 | } else if (tag.nameis("h2")) { |
254 | text.size_pt_change = -8; |
166 | size_pt_change = 6; |
255 | } else if (tag.nameis("h2")) { |
167 | } else if (tag.nameis("/h2")) { |
256 | text.size_pt_change = 6; |
168 | size_pt_change = -6; |
257 | } else if (tag.nameis("/h2")) { |
169 | } else if (tag.nameis("h3")) { |
258 | text.size_pt_change = -6; |
170 | size_pt_change = 4; |
259 | } else if (tag.nameis("h3")) { |
171 | } else if (tag.nameis("/h3")) { |
260 | text.size_pt_change = 4; |
172 | size_pt_change = -4; |
261 | } else if (tag.nameis("/h3")) { |
173 | } |
262 | text.size_pt_change = -4; |
174 | kfont.size.pt += size_pt_change; |
263 | } |
175 | get_label_symbols_size(); |
264 | kfont.size.pt += text.size_pt_change; |
176 | if (size_pt_change > 0) { |
265 | get_label_symbols_size(); |
177 | stroka_y+= list.item_h;//что если будет очень длинная строка в теге? |
266 | if (text.size_pt_change > 0) { |
178 | } else {//коммент выше и коммент ниже связаны |
267 | draw.y+= list.item_h;//что если будет очень длинная строка в теге? |
179 | stroka_y+= list.item_h - size_pt_change;//не очень понятна логика этого места |
268 | } else {//коммент выше и коммент ниже связаны |
180 | size_pt_change = 0; |
269 | draw.y+= list.item_h - text.size_pt_change;//не очень понятна логика этого места |
181 | } |
270 | text.size_pt_change = 0; |
182 | stroka_x = HTML_PADDING_X; |
- | |
183 | continue; |
- | |
184 | } |
- | |
185 | if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true; |
- | |
- | 271 | } |
|
186 | if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false; |
272 | draw.x = HTML_PADDING_X; |
- | 273 | return; |
|
- | 274 | } |
|
- | 275 | */ |
|
- | 276 | } |
|
- | 277 | ||
187 | if (tag.nameis("a")) { style.a = true; style.color=0x0000FF; } |
278 | void _dom::apply_text() |
- | 279 | { |
|
- | 280 | if (kfont.size.height) canvas.write_text(draw.x, draw.y, style.color, text.start); |
|
- | 281 | draw.line_break(); |
|
- | 282 | } |
|
- | 283 | ||
- | 284 | void _dom::parse() |
|
- | 285 | { |
|
- | 286 | dword i; |
|
- | 287 | init(); |
|
- | 288 | ||
188 | if (tag.nameis("/a")) { style.a = false; style.color=0x000000; } |
289 | text.start = buf.start; |
- | 290 | tag.start = buf.start; |
|
- | 291 | for ( i=buf.start; i |
|
- | 292 | { |
|
- | 293 | if (ESBYTE[i]=='<') { |
|
- | 294 | tag.start = i+1; |
|
- | 295 | text.end = i-1; |
|
- | 296 | ESBYTE[i] = '\0'; |
|
- | 297 | debug("TXT "); debugln(text.start); |
|
- | 298 | apply_text(); |
|
- | 299 | } |
|
- | 300 | if (ESBYTE[i]=='>') { |
|
- | 301 | tag.end = i-1; |
|
- | 302 | text.start = i+1; |
|
- | 303 | ESBYTE[i] = '\0'; |
|
- | 304 | debug("TAG "); debugln(tag.start); |
|
- | 305 | //tag.parse(); |
|
- | 306 | //set_style(); |
|
- | 307 | } |
|
189 | } |
308 | } |
190 | } |
309 | |
191 | if (draw==false) { |
310 | free(buf.start); |
192 | list.count = stroka_y/list.item_h+3; |
311 | if (!kfont.size.height) { |
- | 312 | list.count = draw.y/list.item_h+3; |
|
193 | if (list.count < list.visible) list.count = list.visible; |
313 | if (list.count < list.visible) list.count = list.visible; |
- | 314 | kfont.size.height = list.count+5*list.item_h; |
|
- | 315 | kfont.raw_size = 0; |
|
- | 316 | parse(); |
|
- | 317 | } |
|
- | 318 | } |
|
- | 319 | ||
- | 320 | ||
- | 321 | ||
- | 322 | /*======================================================== |
|
- | 323 | = = |
|
- | 324 | = PREPARE = |
|
- | 325 | = = |
|
- | 326 | ========================================================*/ |
|
- | 327 | void PreparePage() |
|
- | 328 | { |
|
- | 329 | _dom dom; |
|
194 | kfont.size.height = list.count+5*list.item_h; |
330 | list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, kfont.size.pt+4); |
- | 331 | strcpy(#title, history.current()+strrchr(history.current(),'/')); |
|
- | 332 | get_label_symbols_size(); //get font chars width, need to increase performance |
|
- | 333 | ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
|
- | 334 | link.clear(); |
|
- | 335 | ||
- | 336 | kfont.size.height = 0; |
|
- | 337 | ||
- | 338 | if ( strstri(io.buffer_data, " |
|
195 | kfont.raw_size = 0; |
339 | |
196 | } |
340 | kfont.ApplySmooth(); |