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