Rev 8410 | Rev 8439 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8330 | leency | 1 | #include "TWB\colors.h" |
2 | #include "TWB\anchors.h" |
||
3 | #include "TWB\parse_tag.h" |
||
4 | #include "TWB\special.h" |
||
5 | #include "TWB\tag_list.h" |
||
7757 | leency | 6 | dword page_bg; |
7759 | leency | 7 | dword link_color_default; |
7757 | leency | 8 | dword link_color_active; |
8330 | leency | 9 | #include "TWB\links.h" |
4411 | leency | 10 | |
7759 | leency | 11 | #define BODY_MARGIN 6 |
12 | #define BASIC_LINE_H 18 |
||
4416 | leency | 13 | |
7771 | leency | 14 | DrawBufer DrawBuf; |
15 | char line[500]; |
||
16 | |||
5746 | leency | 17 | struct _style { |
7752 | leency | 18 | bool |
6794 | leency | 19 | b, u, s, h, |
8016 | leency | 20 | font, |
5746 | leency | 21 | pre, |
22 | blq, |
||
7742 | leency | 23 | button, |
7759 | leency | 24 | image; |
7752 | leency | 25 | dword bg_color; |
7759 | leency | 26 | LIST tag_list; |
27 | dword tag_title; |
||
5746 | leency | 28 | }; |
29 | |||
4411 | leency | 30 | struct TWebBrowser { |
4540 | leency | 31 | llist list; |
5746 | leency | 32 | _style style; |
7752 | leency | 33 | dword draw_y, stolbec; |
6803 | leency | 34 | int zoom; |
7752 | leency | 35 | dword o_bufpointer; |
7759 | leency | 36 | int cur_encoding, custom_encoding; |
37 | bool link, t_html, t_body; |
||
38 | dword bufpointer; |
||
39 | dword bufsize; |
||
7945 | leency | 40 | dword is_html; |
8396 | leency | 41 | collection img_url; |
7759 | leency | 42 | |
7771 | leency | 43 | void Paint(); |
7746 | leency | 44 | void SetPageDefaults(); |
7752 | leency | 45 | void AddCharToTheLine(); |
46 | void ParseHtml(); |
||
5766 | leency | 47 | void SetStyle(); |
7762 | leency | 48 | bool CheckForLineBreak(); |
49 | void NewLine(); |
||
50 | void DrawScroller(); |
||
51 | void ChangeEncoding(); |
||
4411 | leency | 52 | void DrawPage(); |
7759 | leency | 53 | char header[150]; |
8302 | leency | 54 | char redirect[URL_SIZE]; |
7759 | leency | 55 | }; |
4486 | leency | 56 | |
7757 | leency | 57 | scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; |
4411 | leency | 58 | |
5747 | leency | 59 | //============================================================================================ |
7771 | leency | 60 | void TWebBrowser::Paint() |
4411 | leency | 61 | { |
6803 | leency | 62 | dword start_x, line_length, stolbec_len; |
7762 | leency | 63 | dword text_color__; |
4411 | leency | 64 | |
7759 | leency | 65 | if (style.tag_title) |
4411 | leency | 66 | { |
7759 | leency | 67 | strncpy(#header, #line, sizeof(TWebBrowser.header)-1); |
68 | strncat(#header, " - ", sizeof(TWebBrowser.header)-1); |
||
69 | strncat(#header, #version, sizeof(TWebBrowser.header)-1); |
||
4411 | leency | 70 | line = 0; |
71 | return; |
||
72 | } |
||
7758 | leency | 73 | if (t_html) && (!t_body) { |
74 | line = 0; |
||
75 | return; |
||
76 | } |
||
4411 | leency | 77 | |
6803 | leency | 78 | if (line) |
4411 | leency | 79 | { |
7759 | leency | 80 | start_x = stolbec * list.font_w + BODY_MARGIN + list.x; |
6803 | leency | 81 | stolbec_len = strlen(#line) * zoom; |
5768 | leency | 82 | line_length = stolbec_len * list.font_w; |
4411 | leency | 83 | |
7749 | leency | 84 | if (debug_mode) { |
7750 | leency | 85 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd); |
7749 | leency | 86 | } |
87 | |||
7743 | leency | 88 | if (style.bg_color!=page_bg) { |
7750 | leency | 89 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color); |
7743 | leency | 90 | } |
91 | |||
7742 | leency | 92 | if (style.image) { |
7743 | leency | 93 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB); |
7742 | leency | 94 | } |
95 | if (style.button) { |
||
96 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc); |
||
97 | DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999); |
||
98 | } |
||
99 | |||
8016 | leency | 100 | text_color__ = text_colors.get_last(); |
101 | if (link) && (text_color__ == text_colors.get(0)) text_color__ = link_color_default; |
||
7762 | leency | 102 | |
7889 | leency | 103 | DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL); |
104 | if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL); |
||
7762 | leency | 105 | if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__); |
106 | if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__); |
||
5519 | leency | 107 | if (link) { |
7747 | leency | 108 | if (line[0]==' ') && (line[1]==NULL) {} else { |
7759 | leency | 109 | DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default); |
7970 | leency | 110 | links.add_text(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, zoom); |
7746 | leency | 111 | } |
4411 | leency | 112 | } |
4718 | leency | 113 | stolbec += stolbec_len; |
7750 | leency | 114 | if (debug_mode) debug(#line); |
115 | line = NULL; |
||
4411 | leency | 116 | } |
117 | } |
||
5747 | leency | 118 | //============================================================================================ |
7746 | leency | 119 | void TWebBrowser::SetPageDefaults() |
120 | { |
||
121 | style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = |
||
8016 | leency | 122 | link = style.tag_title = style.font = false; |
7759 | leency | 123 | style.tag_list.reset(); |
124 | link_color_default = 0x0000FF; |
||
4491 | leency | 125 | link_color_active = 0xFF0000; |
8396 | leency | 126 | page_bg = 0xffEBE8E9; //E0E3E3 EBE8E9 |
7743 | leency | 127 | style.bg_color = page_bg; |
128 | DrawBuf.Fill(0, page_bg); |
||
7970 | leency | 129 | links.clear(); |
7752 | leency | 130 | anchors.clear(); |
8396 | leency | 131 | img_url.drop(); |
8016 | leency | 132 | text_colors.drop(); |
133 | text_colors.add(0); |
||
7758 | leency | 134 | header = NULL; |
7759 | leency | 135 | cur_encoding = CH_CP866; |
136 | draw_y = BODY_MARGIN; |
||
4411 | leency | 137 | stolbec = 0; |
138 | line = 0; |
||
7752 | leency | 139 | zoom = 1; |
8302 | leency | 140 | redirect = '\0'; |
7757 | leency | 141 | //hold original buffer |
142 | if (o_bufpointer) o_bufpointer=free(o_bufpointer); |
||
143 | o_bufpointer = malloc(bufsize); |
||
144 | memmov(o_bufpointer, bufpointer, bufsize); |
||
7759 | leency | 145 | if (custom_encoding != -1) { |
146 | cur_encoding = custom_encoding; |
||
7781 | leency | 147 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
7759 | leency | 148 | } |
7746 | leency | 149 | } |
150 | //============================================================================================ |
||
7752 | leency | 151 | void TWebBrowser::AddCharToTheLine(unsigned char _char) |
152 | { |
||
153 | dword line_len; |
||
154 | if (_char<=15) _char=' '; |
||
155 | line_len = strlen(#line); |
||
156 | if (!style.pre) && (_char == ' ') |
||
157 | { |
||
158 | if (line[line_len-1]==' ') return; //no double spaces |
||
159 | if (!stolbec) && (!line) return; //no paces at the beginning of the line |
||
8350 | leency | 160 | if (link) && (line_len==0) return; |
7752 | leency | 161 | } |
7771 | leency | 162 | if (line_len < sizeof(line)) chrcat(#line, _char); |
7752 | leency | 163 | CheckForLineBreak(); |
164 | } |
||
165 | //============================================================================================ |
||
7759 | leency | 166 | void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ |
7746 | leency | 167 | word bukva[2]; |
7752 | leency | 168 | char unicode_symbol[10]; |
169 | dword unicode_symbol_result; |
||
7746 | leency | 170 | dword j; |
7752 | leency | 171 | bool ignor_param=false; |
172 | int tab_len; |
||
7746 | leency | 173 | dword bufpos; |
7759 | leency | 174 | bufsize = _bufsize; |
7771 | leency | 175 | if (bufpointer != _bufpointer) { |
176 | bufpointer = malloc(bufsize); |
||
177 | memmov(bufpointer, _bufpointer, bufsize); |
||
178 | } else { |
||
179 | custom_encoding = CH_CP866; |
||
180 | } |
||
7746 | leency | 181 | SetPageDefaults(); |
7945 | leency | 182 | is_html = true; |
183 | if (!strstri(bufpointer, " |
||
7749 | leency | 184 | t_body = true; |
7991 | leency | 185 | if (!strstri(bufpointer, " |
7945 | leency | 186 | style.pre = true; //show linebreaks for a plaint text |
187 | is_html = false; |
||
188 | } |
||
7749 | leency | 189 | } |
5773 | leency | 190 | for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;) |
4411 | leency | 191 | { |
8330 | leency | 192 | switch (ESBYTE[bufpos]) |
4411 | leency | 193 | { |
194 | case 0x0a: |
||
7752 | leency | 195 | if (style.pre) { |
7771 | leency | 196 | Paint(); |
5781 | leency | 197 | NewLine(); |
7752 | leency | 198 | } else { |
199 | AddCharToTheLine(0x0a); |
||
4411 | leency | 200 | } |
7752 | leency | 201 | break; |
202 | case 0x09: |
||
203 | if (style.pre) { |
||
204 | tab_len = strlen(#line) + stolbec % 4; |
||
205 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
||
4411 | leency | 206 | for (j=0; j |
7752 | leency | 207 | } else { |
208 | AddCharToTheLine(0x09); |
||
4411 | leency | 209 | } |
7752 | leency | 210 | break; |
4411 | leency | 211 | case '&': // and so on |
8319 | leency | 212 | for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (!__isWhite(ESBYTE[bufpos+j])) && (j<8); j++) |
4411 | leency | 213 | { |
8410 | leency | 214 | chrcat(#unicode_symbol, ESBYTE[bufpos+j]); |
4411 | leency | 215 | } |
7771 | leency | 216 | if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) { |
7749 | leency | 217 | bufpos += j; |
7750 | leency | 218 | CheckForLineBreak(); |
7749 | leency | 219 | } else { |
7752 | leency | 220 | AddCharToTheLine('&'); |
7749 | leency | 221 | } |
4411 | leency | 222 | break; |
223 | case '<': |
||
8330 | leency | 224 | if (!is_html) goto _DEFAULT; |
5749 | leency | 225 | bufpos++; |
8330 | leency | 226 | switch (ESBYTE[bufpos]) { |
227 | case '!': |
||
228 | case '/': |
||
8410 | leency | 229 | case '?': |
8330 | leency | 230 | case 'a'...'z': |
231 | case 'A'...'Z': |
||
232 | goto _TAG; |
||
233 | default: |
||
234 | goto _DEFAULT; |
||
235 | } |
||
236 | _TAG: |
||
5768 | leency | 237 | if (!strncmp(bufpos,"!--",3)) |
4411 | leency | 238 | { |
6986 | leency | 239 | bufpos+=3; |
8330 | leency | 240 | //STRSTR |
6986 | leency | 241 | while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize) |
242 | { |
||
243 | bufpos++; |
||
244 | } |
||
7746 | leency | 245 | bufpos+=2; |
6986 | leency | 246 | break; |
4411 | leency | 247 | } |
7752 | leency | 248 | tag.reset(); |
249 | if (ESBYTE[bufpos] == '/') { |
||
250 | tag.opened = false; |
||
251 | bufpos++; |
||
252 | } |
||
253 | |||
254 | ignor_param=false; |
||
6735 | leency | 255 | while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷à åì òåã è åãî ïà ðà ìåòðû |
8336 | leency | 256 | //&& (!chrnum(#tag.params,'\"') % 2) // |
4411 | leency | 257 | { |
4508 | leency | 258 | bukva = ESBYTE[bufpos]; |
8330 | leency | 259 | if (__isWhite(bukva)) bukva = ' '; |
8336 | leency | 260 | if (!ignor_param) && (bukva!=' ') { |
7752 | leency | 261 | if (strlen(#tag.name)+1 |
8330 | leency | 262 | } else { |
4411 | leency | 263 | ignor_param = true; |
7752 | leency | 264 | if (strlen(#tag.params)+1 |
7762 | leency | 265 | //chrncat(#tag.params, bukva, sizeof(tag.params)-1); |
4411 | leency | 266 | } |
4508 | leency | 267 | bufpos++; |
4411 | leency | 268 | } |
7752 | leency | 269 | strlwr(#tag.name); |
4411 | leency | 270 | |
7746 | leency | 271 | // ignore text inside the next tags |
7752 | leency | 272 | if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select")) { |
273 | sprintf(#tag.params, "%s>", #tag.name); |
||
7945 | leency | 274 | if (j = strstri(bufpos, #tag.params)) bufpos = j-1; |
7746 | leency | 275 | break; |
276 | } |
||
277 | |||
7752 | leency | 278 | if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!! |
279 | if (tag.params) tag.parse_params(); |
||
7746 | leency | 280 | |
7757 | leency | 281 | if (tag.name) { |
7750 | leency | 282 | CheckForLineBreak(); |
7771 | leency | 283 | Paint(); |
8407 | leency | 284 | if (tag.name) { |
285 | EAX = cur_encoding; |
||
286 | $push eax |
||
287 | SetStyle(); |
||
288 | $pop eax |
||
289 | // The thing is that UTF if longer than other encodings. |
||
290 | // So if encoding was changed to UTF than $bufpos position is wrong now, |
||
291 | // and we have to start parse from the very beginning |
||
292 | if (EAX != cur_encoding) && (cur_encoding == CH_UTF8) { |
||
293 | ParseHtml(bufpointer, bufsize); |
||
294 | return; |
||
295 | } |
||
296 | } |
||
7746 | leency | 297 | } |
4411 | leency | 298 | break; |
299 | default: |
||
8330 | leency | 300 | _DEFAULT: |
7752 | leency | 301 | AddCharToTheLine(ESBYTE[bufpos]); |
4411 | leency | 302 | } |
303 | } |
||
7771 | leency | 304 | Paint(); |
5766 | leency | 305 | NewLine(); |
7752 | leency | 306 | list.count = draw_y; |
8425 | leency | 307 | |
308 | DrawBuf.bufh = math.max(list.visible, draw_y); |
||
309 | debugval("DrawBuf.bufh", DrawBuf.bufh); |
||
310 | buf_data = realloc(buf_data, DrawBuf.bufh * DrawBuf.bufw * 4 + 8); |
||
311 | |||
7755 | leency | 312 | list.CheckDoesValuesOkey(); |
313 | anchors.current = NULL; |
||
7759 | leency | 314 | custom_encoding = -1; |
7758 | leency | 315 | if (!header) { |
7759 | leency | 316 | strncpy(#header, #version, sizeof(TWebBrowser.header)-1); |
7758 | leency | 317 | DrawTitle(#header); |
318 | } |
||
4411 | leency | 319 | } |
5747 | leency | 320 | //============================================================================================ |
7750 | leency | 321 | bool TWebBrowser::CheckForLineBreak() |
4718 | leency | 322 | { |
7750 | leency | 323 | int line_break_pos; |
4718 | leency | 324 | char new_line_text[4096]; |
7758 | leency | 325 | //Do we need a line break? |
7750 | leency | 326 | if (strlen(#line)*zoom + stolbec < list.column_max) return false; |
7758 | leency | 327 | //Yes, we do. Lets calculate where... |
7750 | leency | 328 | line_break_pos = strrchr(#line, ' '); |
7758 | leency | 329 | //Is a new line fits in the current line? |
7750 | leency | 330 | if (line_break_pos*zoom + stolbec > list.column_max) { |
331 | line_break_pos = list.column_max/zoom - stolbec; |
||
332 | while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--; |
||
333 | } |
||
7758 | leency | 334 | //Maybe a new line is too big for the whole new line? Then we have to split it |
7759 | leency | 335 | if (!line_break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) { |
7758 | leency | 336 | line_break_pos = list.column_max/zoom - stolbec; |
7742 | leency | 337 | } |
7750 | leency | 338 | strcpy(#new_line_text, #line + line_break_pos); |
7758 | leency | 339 | line[line_break_pos] = 0x00; |
340 | |||
7771 | leency | 341 | Paint(); |
7758 | leency | 342 | |
4718 | leency | 343 | strcpy(#line, #new_line_text); |
344 | NewLine(); |
||
7762 | leency | 345 | //while (CheckForLineBreak()==true) {}; |
7750 | leency | 346 | return true; |
4718 | leency | 347 | } |
5747 | leency | 348 | //============================================================================================ |
5773 | leency | 349 | void TWebBrowser::SetStyle() { |
7749 | leency | 350 | char img_path[4096]=0; |
8396 | leency | 351 | dword imgbuf[44]; |
352 | dword cur_img; |
||
353 | int img_x, img_y, img_w, img_h; |
||
7752 | leency | 354 | |
355 | dword value; |
||
356 | |||
7755 | leency | 357 | if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) { |
358 | anchors.add(value, draw_y); |
||
359 | if (anchors.current) && (streq(value, #anchors.current+1)) { |
||
360 | list.first = draw_y; |
||
361 | anchors.current = NULL; |
||
362 | } |
||
7758 | leency | 363 | } |
7752 | leency | 364 | if (tag.is("html")) { |
365 | t_html = tag.opened; |
||
4411 | leency | 366 | return; |
367 | } |
||
7758 | leency | 368 | if (tag.is("title")) { |
7759 | leency | 369 | style.tag_title = tag.opened; |
7758 | leency | 370 | if (!tag.opened) DrawTitle(#header); |
371 | return; |
||
372 | } |
||
7752 | leency | 373 | if (tag.is("body")) { |
374 | t_body = tag.opened; |
||
7893 | leency | 375 | if (value = tag.get_value_of("link=")) link_color_default = GetColor(value); |
376 | if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value); |
||
8016 | leency | 377 | if (value = tag.get_value_of("text=")) text_colors.set(0, GetColor(value)); |
7752 | leency | 378 | if (value = tag.get_value_of("bgcolor=")) { |
7970 | leency | 379 | style.bg_color = page_bg = GetColor(value); |
7752 | leency | 380 | DrawBuf.Fill(0, page_bg); |
381 | } |
||
7762 | leency | 382 | // Autodetecting encoding if no encoding was set |
383 | if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) { |
||
384 | if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8); |
||
7799 | leency | 385 | else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251); |
7762 | leency | 386 | } |
4411 | leency | 387 | return; |
388 | } |
||
7762 | leency | 389 | if (tag.is("br")) { NewLine(); return; } |
7797 | leency | 390 | if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) || (tag.is("w:b")) { |
7780 | leency | 391 | style.b = tag.opened; |
392 | return; |
||
393 | } |
||
7797 | leency | 394 | if (tag.is("w:r")) && (!tag.opened) { style.b = false; return; } |
7752 | leency | 395 | if (tag.is("a")) { |
396 | if (tag.opened) |
||
4411 | leency | 397 | { |
7752 | leency | 398 | if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:")) |
399 | { |
||
7762 | leency | 400 | link = true; |
7970 | leency | 401 | links.add_link(value); |
7752 | leency | 402 | } |
403 | } else { |
||
7762 | leency | 404 | link = false; |
7893 | leency | 405 | style.bg_color = page_bg; |
4411 | leency | 406 | } |
407 | return; |
||
408 | } |
||
7762 | leency | 409 | if (tag.is("iframe")) && (value = tag.get_value_of("src=")) { |
410 | NewLine(); |
||
411 | strcpy(#line, "IFRAME: "); |
||
7771 | leency | 412 | Paint(); |
7762 | leency | 413 | link=true; |
7970 | leency | 414 | links.add_link(value); |
7771 | leency | 415 | strncpy(#line, value, sizeof(line)-1); |
7762 | leency | 416 | while (CheckForLineBreak()) {}; |
7771 | leency | 417 | Paint(); |
7762 | leency | 418 | link=false; |
419 | NewLine(); |
||
420 | } |
||
7752 | leency | 421 | if (tag.is("font")) { |
8016 | leency | 422 | style.font = tag.opened; |
7743 | leency | 423 | style.bg_color = page_bg; |
7752 | leency | 424 | if (tag.opened) |
4411 | leency | 425 | { |
7752 | leency | 426 | if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value); |
8016 | leency | 427 | if (value = tag.get_value_of("color=")) { |
428 | text_colors.add(GetColor(value)); |
||
429 | } else { |
||
430 | text_colors.add(text_colors.get_last()); |
||
431 | } |
||
4411 | leency | 432 | } |
8016 | leency | 433 | else text_colors.pop(); |
4411 | leency | 434 | return; |
435 | } |
||
7752 | leency | 436 | if (tag.is("div")) { |
7756 | leency | 437 | if (streq(#tag.prior,"div")) && (tag.opened) return; |
8016 | leency | 438 | if (!tag.opened) && (style.font) text_colors.pop(); |
7746 | leency | 439 | NewLine(); |
4411 | leency | 440 | return; |
441 | } |
||
7752 | leency | 442 | if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) { |
7746 | leency | 443 | NewLine(); |
444 | return; |
||
445 | } |
||
7780 | leency | 446 | if (tag.is("p")) || (tag.is("w:p")) { |
7756 | leency | 447 | IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return; |
4692 | leency | 448 | NewLine(); |
4411 | leency | 449 | return; |
450 | } |
||
7762 | leency | 451 | if (tag.is("pre")) { style.pre = tag.opened; return; } |
7757 | leency | 452 | if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; } |
7752 | leency | 453 | if (tag.is("tr")) { if (tag.opened) NewLine(); return; } |
454 | if (tag.is("button")) { style.button = tag.opened; stolbec++; return; } |
||
455 | if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;} |
||
456 | if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; } |
||
7764 | leency | 457 | if (tag.is("dl")) { |
458 | if (tag.opened) NewLine(); |
||
459 | return; |
||
460 | } |
||
461 | if (tag.is("dd")) { |
||
462 | //NewLine(); |
||
463 | //if (tag.opened) stolbec += 5; //stolbec overflow! |
||
464 | return; |
||
465 | } |
||
7752 | leency | 466 | if (tag.is("blockquote")) { style.blq = tag.opened; return; } |
7759 | leency | 467 | if (tag.is("code")) { |
468 | if (tag.opened) style.bg_color = 0xe4ffcb; else style.bg_color = page_bg; |
||
469 | style.pre = tag.opened; return; |
||
470 | } |
||
7752 | leency | 471 | if (tag.is("img")) { |
8330 | leency | 472 | value = tag.get_value_of("src="); |
8336 | leency | 473 | if (!value) goto NOIMG; |
8330 | leency | 474 | |
8365 | leency | 475 | if (!strcmp(value + strrchr(value, '.'), "svg")) goto NOIMG; |
476 | |||
8396 | leency | 477 | if (streqrp(value, "data:")) { |
478 | if (!strstr(value, "base64,")) goto NOIMG; |
||
479 | value = EAX+7; |
||
480 | if (ESBYTE[value]==' ') value++; |
||
481 | cur_img = malloc(strlen(value)); |
||
482 | base64_decode stdcall (value, cur_img, strlen(value)); |
||
483 | img_decode stdcall (cur_img, EAX, 0); |
||
484 | $push eax |
||
485 | free(cur_img); |
||
486 | $pop eax |
||
487 | if (EAX) goto IMGOK; else goto NOIMG; |
||
488 | } |
||
489 | |||
8336 | leency | 490 | strlcpy(#img_path, value, sizeof(img_path)-1); |
491 | get_absolute_url(#img_path, history.current()); |
||
492 | |||
8396 | leency | 493 | if (check_is_the_adress_local(#img_path)) { |
494 | img_from_file stdcall(#img_path); |
||
495 | if (EAX) goto IMGOK; else goto NOIMG; |
||
496 | } |
||
497 | |||
8363 | leency | 498 | if (cache.has(#img_path)) && (cache.current_size) |
8336 | leency | 499 | { |
500 | img_decode stdcall (cache.current_buf, cache.current_size, 0); |
||
501 | if (!EAX) goto NOIMG; |
||
8396 | leency | 502 | IMGOK: |
8336 | leency | 503 | |
8396 | leency | 504 | cur_img = EAX; |
505 | img_h = ESDWORD[cur_img+8]; |
||
506 | img_w = ESDWORD[cur_img+4]; |
||
8336 | leency | 507 | |
8396 | leency | 508 | if (img_w / 6 + stolbec > list.column_max) { |
8336 | leency | 509 | NewLine(); |
510 | } |
||
8396 | leency | 511 | img_x = stolbec*list.font_w+3; |
512 | img_y = draw_y; |
||
8336 | leency | 513 | |
8396 | leency | 514 | img_w = math.min(img_w, DrawBuf.bufw - img_x); |
515 | |||
516 | stolbec += img_w / 6; |
||
8350 | leency | 517 | if (stolbec > list.column_max) NewLine(); |
8336 | leency | 518 | |
8396 | leency | 519 | if (img_h > list.item_h + 5) { |
520 | draw_y += img_h - list.item_h; |
||
8336 | leency | 521 | NewLine(); |
522 | } |
||
523 | |||
8396 | leency | 524 | if (link) links.add_text(img_x + list.x, img_y + list.y, img_w, img_h, 0); |
8336 | leency | 525 | |
8396 | leency | 526 | if (img_y + img_h >= DrawBuf.bufh) DrawBuf.IncreaseBufSize(); |
8336 | leency | 527 | |
8396 | leency | 528 | if (ESDWORD[cur_img+20] != IMAGE_BPP32) { |
529 | img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0); |
||
530 | $push eax |
||
531 | img_destroy stdcall(cur_img); |
||
532 | $pop eax |
||
533 | cur_img = EAX; |
||
534 | if (!EAX) goto NOIMG; |
||
535 | } |
||
536 | imgbuf[04] = DrawBuf.bufw; |
||
537 | imgbuf[08] = DrawBuf.bufh; |
||
538 | imgbuf[20] = IMAGE_BPP32; |
||
539 | imgbuf[24] = buf_data+8; |
||
540 | img_blend stdcall(#imgbuf, cur_img, img_x, img_y, 0, 0, img_w, img_h); |
||
541 | img_destroy stdcall(cur_img); |
||
8336 | leency | 542 | return; |
543 | } else { |
||
8396 | leency | 544 | img_url.add(#img_path); |
8336 | leency | 545 | } |
546 | NOIMG: |
||
547 | |||
7771 | leency | 548 | if (value = tag.get_value_of("title=")) && (strlen(value) |
8330 | leency | 549 | if (value = tag.get_value_of("alt=")) && (strlen(value) |
7742 | leency | 550 | if (!line) { |
551 | if (!strncmp(#img_path, "data:", 5)) img_path=0; |
||
7749 | leency | 552 | replace_char(#img_path, '?', NULL, strlen(#img_path)); |
8350 | leency | 553 | img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf |
7742 | leency | 554 | sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/')); |
555 | line[50]= NULL; |
||
556 | } |
||
7750 | leency | 557 | while (CheckForLineBreak()) {}; |
8330 | leency | 558 | |
559 | text_colors.add(0x9A6F29); |
||
560 | style.image = true; |
||
7771 | leency | 561 | Paint(); |
8330 | leency | 562 | style.image = false; |
8016 | leency | 563 | text_colors.pop(); |
7742 | leency | 564 | return; |
565 | } |
||
7758 | leency | 566 | if (tag.is("h4")) { |
567 | NewLine(); |
||
7759 | leency | 568 | NewLine(); |
7758 | leency | 569 | style.h = tag.opened; |
570 | style.b = tag.opened; |
||
571 | } |
||
7752 | leency | 572 | if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) { |
573 | style.h = tag.opened; |
||
7758 | leency | 574 | if (tag.opened) { |
7759 | leency | 575 | if (!style.pre) NewLine(); |
6794 | leency | 576 | draw_y += 10; |
7759 | leency | 577 | zoom=2; |
578 | list.font_type |= 10011001b; |
||
579 | list.item_h = BASIC_LINE_H * 2 - 2; |
||
7752 | leency | 580 | if (tag.is("h1")) style.b = true; |
7758 | leency | 581 | } else { |
7752 | leency | 582 | if (tag.is("h1")) style.b = false; |
6794 | leency | 583 | NewLine(); |
7759 | leency | 584 | zoom=1; |
585 | list.font_type = 10011000b; |
||
586 | list.item_h = BASIC_LINE_H; |
||
4411 | leency | 587 | } |
588 | return; |
||
589 | } |
||
7752 | leency | 590 | if (tag.is("dt")) { |
7759 | leency | 591 | style.tag_list.upd_level(tag.opened, DT); |
7752 | leency | 592 | if (tag.opened) NewLine(); |
4411 | leency | 593 | return; |
594 | } |
||
7759 | leency | 595 | if (tag.is("ul")) { |
596 | style.tag_list.upd_level(tag.opened, UL); |
||
597 | if (!tag.opened) && (!style.pre) NewLine(); |
||
598 | return; |
||
599 | } |
||
600 | if (tag.is("ol")) { |
||
601 | style.tag_list.upd_level(tag.opened, OL); |
||
602 | if (!tag.opened) && (!style.pre) NewLine(); |
||
603 | return; |
||
604 | } |
||
605 | if (tag.is("li")) && (tag.opened) |
||
4411 | leency | 606 | { |
7759 | leency | 607 | if (!style.tag_list.level) style.tag_list.upd_level(1, UL); |
608 | if (!style.pre) NewLine(); |
||
609 | if (style.tag_list.get_order_type() == UL) { |
||
7742 | leency | 610 | strcpy(#line, "\31 "); |
7759 | leency | 611 | stolbec = style.tag_list.level * 5 - 2; |
612 | } |
||
613 | if (style.tag_list.get_order_type() == OL) { |
||
614 | sprintf(#line, "%i. ", style.tag_list.inc_counter()); |
||
615 | stolbec = style.tag_list.level * 5 - strlen(#line); |
||
4411 | leency | 616 | } |
617 | return; |
||
618 | } |
||
7762 | leency | 619 | if (tag.is("q")) |
620 | { |
||
621 | if (tag.opened) { |
||
622 | EAX = strlen(#line); |
||
623 | if (line[EAX-1] != ' ') chrcat(#line, ' '); |
||
624 | chrcat(#line, '\"'); |
||
625 | } |
||
626 | if (!tag.opened) strcat(#line, "\" "); |
||
627 | return; |
||
628 | } |
||
7752 | leency | 629 | if (tag.is("hr")) { |
630 | if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999; |
||
5773 | leency | 631 | $push edi; |
4692 | leency | 632 | NewLine(); |
5773 | leency | 633 | $pop edi; |
7746 | leency | 634 | draw_y += 10; |
6794 | leency | 635 | DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI); |
4692 | leency | 636 | NewLine(); |
7746 | leency | 637 | draw_y += 10; |
5773 | leency | 638 | return; |
4411 | leency | 639 | } |
8302 | leency | 640 | if (tag.is("meta")) { |
641 | if (streq(tag.get_value_of("http-equiv="), "refresh")) && (value = tag.get_value_of("content=")) { |
||
642 | if (value = strstri(value, "url=")) strcpy(#redirect, value); |
||
643 | } |
||
644 | } |
||
7759 | leency | 645 | if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) { |
7752 | leency | 646 | if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding=")) |
647 | { |
||
648 | value += strrchr(value, '='); //search in content= |
||
8302 | leency | 649 | if (ESBYTE[value] == '"') value++; |
7752 | leency | 650 | strlwr(value); |
8336 | leency | 651 | if (streqrp(value,"utf-8")) || (streqrp(value,"utf8")) ChangeEncoding(CH_UTF8); |
8302 | leency | 652 | else if (streqrp(value,"windows-1251")) || (streqrp(value,"windows1251")) ChangeEncoding(CH_CP1251); |
653 | else if (streqrp(value,"dos")) || (streqrp(value,"cp-866")) ChangeEncoding(CH_CP866); |
||
654 | else if (streqrp(value,"iso-8859-5")) || (streqrp(value,"iso8859-5")) ChangeEncoding(CH_ISO8859_5); |
||
655 | else if (streqrp(value,"koi8-r")) || (streqrp(value,"koi8-u")) ChangeEncoding(CH_KOI8); |
||
7752 | leency | 656 | } |
4411 | leency | 657 | return; |
658 | } |
||
659 | } |
||
7746 | leency | 660 | //============================================================================================ |
4674 | leency | 661 | void TWebBrowser::DrawScroller() |
4411 | leency | 662 | { |
4416 | leency | 663 | scroll_wv.max_area = list.count; |
664 | scroll_wv.cur_area = list.visible; |
||
665 | scroll_wv.position = list.first; |
||
5519 | leency | 666 | scroll_wv.all_redraw = 0; |
4486 | leency | 667 | scroll_wv.start_x = list.x + list.w; |
4508 | leency | 668 | scroll_wv.start_y = list.y; |
5678 | leency | 669 | scroll_wv.size_y = list.h; |
4416 | leency | 670 | scrollbar_v_draw(#scroll_wv); |
4411 | leency | 671 | } |
5747 | leency | 672 | //============================================================================================ |
7762 | leency | 673 | void TWebBrowser::ChangeEncoding(int _new_encoding) |
674 | { |
||
675 | if (cur_encoding == _new_encoding) return; |
||
676 | cur_encoding = _new_encoding; |
||
7781 | leency | 677 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
7762 | leency | 678 | if (header) { |
7781 | leency | 679 | ChangeCharset(cur_encoding, "CP866", #header); |
7762 | leency | 680 | DrawTitle(#header); |
681 | } |
||
682 | } |
||
683 | //============================================================================================ |
||
4692 | leency | 684 | void TWebBrowser::NewLine() |
4475 | leency | 685 | { |
6803 | leency | 686 | dword onleft, ontop; |
7742 | leency | 687 | static int empty_line=0; |
4692 | leency | 688 | |
7759 | leency | 689 | if (!stolbec) && (draw_y==BODY_MARGIN) return; |
7742 | leency | 690 | |
7759 | leency | 691 | if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) { |
7742 | leency | 692 | if (empty_line<1) empty_line++; |
693 | else return; |
||
7749 | leency | 694 | } else if (!stolbec) { |
695 | if (empty_line<1) empty_line++; |
||
696 | else return; |
||
7742 | leency | 697 | } else { |
698 | empty_line=0; |
||
699 | } |
||
6794 | leency | 700 | |
7759 | leency | 701 | onleft = list.x + BODY_MARGIN; |
6794 | leency | 702 | ontop = draw_y + list.y; |
4637 | leency | 703 | if (t_html) && (!t_body) return; |
6794 | leency | 704 | draw_y += list.item_h; |
5746 | leency | 705 | if (style.blq) stolbec = 6; else stolbec = 0; |
7759 | leency | 706 | stolbec += style.tag_list.level * 5; |
7750 | leency | 707 | if (debug_mode) debugln(NULL); |
4488 | leency | 708 | } |
5747 | leency | 709 | //============================================================================================ |
5766 | leency | 710 | void TWebBrowser::DrawPage() |
711 | { |
||
8396 | leency | 712 | DrawBuf.Show(list.first, list.h); |
5766 | leency | 713 | DrawScroller(); |
714 | }1)>1)>>>>': |