Rev 7750 | Rev 7755 | 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" |
||
3 | #include "..\TWB\parce_tag.h" |
||
4 | #include "..\TWB\absolute_url.h" |
||
5 | char line[500]; |
||
6 | #include "..\TWB\unicode_tags.h" |
||
4411 | leency | 7 | |
5746 | leency | 8 | enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT}; |
4416 | leency | 9 | |
5746 | leency | 10 | struct _style { |
7752 | leency | 11 | bool |
6794 | leency | 12 | b, u, s, h, |
5746 | leency | 13 | pre, |
14 | blq, |
||
15 | li, |
||
16 | li_tab, |
||
7742 | leency | 17 | button, |
18 | image, |
||
5746 | leency | 19 | align; |
7752 | leency | 20 | dword bg_color; |
5746 | leency | 21 | }; |
22 | |||
4411 | leency | 23 | struct TWebBrowser { |
4540 | leency | 24 | llist list; |
5746 | leency | 25 | _style style; |
4475 | leency | 26 | DrawBufer DrawBuf; |
7752 | leency | 27 | dword draw_y, stolbec; |
6803 | leency | 28 | int zoom; |
7752 | leency | 29 | dword o_bufpointer; |
7746 | leency | 30 | void SetPageDefaults(); |
7752 | leency | 31 | void AddCharToTheLine(); |
32 | void ParseHtml(); |
||
5766 | leency | 33 | void SetStyle(); |
34 | void DrawStyle(); |
||
4411 | leency | 35 | void DrawPage(); |
36 | void DrawScroller(); |
||
4650 | leency | 37 | void NewLine(); |
7750 | leency | 38 | bool CheckForLineBreak(); |
5749 | leency | 39 | void BufEncode(); |
4686 | leency | 40 | } WB1; |
4486 | leency | 41 | |
7752 | leency | 42 | dword link_color_inactive; |
43 | dword link_color_active; |
||
44 | dword page_bg; |
||
5746 | leency | 45 | |
7742 | leency | 46 | bool |
5746 | leency | 47 | link, |
48 | cur_encoding, |
||
49 | t_html, |
||
50 | t_body; |
||
51 | |||
7752 | leency | 52 | #include "..\TWB\img_cache.h" |
53 | #include "..\TWB\links.h" |
||
54 | |||
5781 | leency | 55 | dword bufpointer=0; |
56 | dword bufsize=0; |
||
4411 | leency | 57 | |
7752 | leency | 58 | int body_magrin=6; |
6794 | leency | 59 | int basic_line_h=22; |
60 | |||
7752 | leency | 61 | char header[150]; |
5768 | leency | 62 | char oldtag[100]; |
4411 | leency | 63 | |
7752 | leency | 64 | scroll_bar scroll_wv = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
4411 | leency | 65 | |
5747 | leency | 66 | //============================================================================================ |
5766 | leency | 67 | void TWebBrowser::DrawStyle() |
4411 | leency | 68 | { |
6803 | leency | 69 | dword start_x, line_length, stolbec_len; |
4411 | leency | 70 | |
71 | if (!header) |
||
72 | { |
||
7752 | leency | 73 | strncpy(#header, #line, sizeof(header)-1); |
4411 | leency | 74 | line = 0; |
75 | return; |
||
76 | } |
||
4637 | leency | 77 | if (t_html) && (!t_body) return; |
4411 | leency | 78 | |
6803 | leency | 79 | if (line) |
4411 | leency | 80 | { |
6794 | leency | 81 | start_x = stolbec * list.font_w + body_magrin + 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 | |||
7738 | leency | 101 | DrawBuf.WriteText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line); |
102 | if (style.b) DrawBuf.WriteText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line); |
||
6803 | leency | 103 | if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]); |
104 | if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]); |
||
5519 | leency | 105 | if (link) { |
7747 | leency | 106 | if (line[0]==' ') && (line[1]==NULL) {} else { |
7750 | leency | 107 | DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, link_color_inactive); |
7746 | leency | 108 | PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2), UNDERLINE, zoom); |
109 | } |
||
4411 | leency | 110 | } |
4718 | leency | 111 | stolbec += stolbec_len; |
7750 | leency | 112 | if (debug_mode) debug(#line); |
113 | line = NULL; |
||
4411 | leency | 114 | } |
115 | } |
||
5747 | leency | 116 | //============================================================================================ |
7746 | leency | 117 | void TWebBrowser::SetPageDefaults() |
118 | { |
||
119 | style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = |
||
120 | style.li = link = text_color_index = text_colors[0] = style.li_tab = false; |
||
5746 | leency | 121 | style.align = ALIGN_LEFT; |
4491 | leency | 122 | link_color_inactive = 0x0000FF; |
123 | link_color_active = 0xFF0000; |
||
7743 | leency | 124 | page_bg = 0xFFFFFF; |
125 | style.bg_color = page_bg; |
||
126 | DrawBuf.Fill(0, page_bg); |
||
4504 | leency | 127 | PageLinks.Clear(); |
7752 | leency | 128 | anchors.clear(); |
129 | strncpy(#header, #version, sizeof(header)-1); |
||
7746 | leency | 130 | cur_encoding = CH_NULL; |
6794 | leency | 131 | draw_y = body_magrin; |
4411 | leency | 132 | stolbec = 0; |
133 | line = 0; |
||
7752 | leency | 134 | zoom = 1; |
135 | if (o_bufpointer) free(o_bufpointer); |
||
136 | o_bufpointer = 0; |
||
7746 | leency | 137 | } |
138 | //============================================================================================ |
||
7752 | leency | 139 | void TWebBrowser::AddCharToTheLine(unsigned char _char) |
140 | { |
||
141 | dword line_len; |
||
142 | if (_char<=15) _char=' '; |
||
143 | line_len = strlen(#line); |
||
144 | if (!style.pre) && (_char == ' ') |
||
145 | { |
||
146 | if (line[line_len-1]==' ') return; //no double spaces |
||
147 | if (!stolbec) && (!line) return; //no paces at the beginning of the line |
||
148 | } |
||
149 | if (line_len < sizeof(line)) chrcat(#line, _char); |
||
150 | CheckForLineBreak(); |
||
151 | } |
||
152 | //============================================================================================ |
||
153 | void TWebBrowser::ParseHtml(){ |
||
7746 | leency | 154 | word bukva[2]; |
7752 | leency | 155 | char unicode_symbol[10]; |
156 | dword unicode_symbol_result; |
||
7746 | leency | 157 | dword j; |
7752 | leency | 158 | bool ignor_param=false; |
159 | int tab_len; |
||
7746 | leency | 160 | dword bufpos; |
161 | SetPageDefaults(); |
||
7749 | leency | 162 | if (strstri(bufpointer, " |
163 | t_body = true; |
||
164 | if (strstri(bufpointer, " |
||
165 | } |
||
5773 | leency | 166 | for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;) |
4411 | leency | 167 | { |
4508 | leency | 168 | bukva = ESBYTE[bufpos]; |
4411 | leency | 169 | switch (bukva) |
170 | { |
||
171 | case 0x0a: |
||
7752 | leency | 172 | if (style.pre) { |
5781 | leency | 173 | DrawStyle(); |
174 | NewLine(); |
||
7752 | leency | 175 | } else { |
176 | AddCharToTheLine(0x0a); |
||
4411 | leency | 177 | } |
7752 | leency | 178 | break; |
179 | case 0x09: |
||
180 | if (style.pre) { |
||
181 | tab_len = strlen(#line) + stolbec % 4; |
||
182 | if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; |
||
4411 | leency | 183 | for (j=0; j |
7752 | leency | 184 | } else { |
185 | AddCharToTheLine(0x09); |
||
4411 | leency | 186 | } |
7752 | leency | 187 | break; |
4411 | leency | 188 | case '&': // and so on |
7752 | leency | 189 | for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (j<8); j++) |
4411 | leency | 190 | { |
7749 | leency | 191 | bukva = ESBYTE[bufpos+j]; |
7752 | leency | 192 | chrcat(#unicode_symbol, bukva); |
4411 | leency | 193 | } |
7752 | leency | 194 | if (bukva = GetUnicodeSymbol(#unicode_symbol)) { |
7749 | leency | 195 | bufpos += j; |
7750 | leency | 196 | CheckForLineBreak(); |
7749 | leency | 197 | } else { |
7752 | leency | 198 | AddCharToTheLine('&'); |
7749 | leency | 199 | } |
4411 | leency | 200 | break; |
201 | case '<': |
||
5749 | leency | 202 | bufpos++; |
5768 | leency | 203 | if (!strncmp(bufpos,"!--",3)) |
4411 | leency | 204 | { |
6986 | leency | 205 | bufpos+=3; |
206 | while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize) |
||
207 | { |
||
208 | bufpos++; |
||
209 | } |
||
7746 | leency | 210 | bufpos+=2; |
6986 | leency | 211 | break; |
4411 | leency | 212 | } |
7752 | leency | 213 | tag.reset(); |
214 | if (ESBYTE[bufpos] == '/') { |
||
215 | tag.opened = false; |
||
216 | bufpos++; |
||
217 | } |
||
218 | |||
219 | ignor_param=false; |
||
6735 | leency | 220 | while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷à åì òåã è åãî ïà ðà ìåòðû |
4411 | leency | 221 | { |
4508 | leency | 222 | bukva = ESBYTE[bufpos]; |
4411 | leency | 223 | if (bukva == '\9') || (bukva == '\x0a') || (bukva == '\x0d') bukva = ' '; |
224 | if (!ignor_param) && (bukva <>' ') |
||
225 | { |
||
7752 | leency | 226 | if (strlen(#tag.name)+1 |
4411 | leency | 227 | } |
228 | else |
||
229 | { |
||
230 | ignor_param = true; |
||
7752 | leency | 231 | if (strlen(#tag.params)+1 |
232 | // chrncat(#tag.params, bukva, sizeof(tag.params)-1); |
||
4411 | leency | 233 | } |
4508 | leency | 234 | bufpos++; |
4411 | leency | 235 | } |
7752 | leency | 236 | strlwr(#tag.name); |
4411 | leency | 237 | |
7746 | leency | 238 | // ignore text inside the next tags |
7752 | leency | 239 | if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select")) { |
240 | sprintf(#tag.params, "%s>", #tag.name); |
||
241 | j = strstri(bufpos, #tag.params); |
||
242 | if (j!=-1) bufpos = j-1; |
||
7746 | leency | 243 | break; |
244 | } |
||
245 | |||
7752 | leency | 246 | if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!! |
247 | if (tag.params) tag.parse_params(); |
||
7746 | leency | 248 | |
7752 | leency | 249 | if (tag.name) && (!tag.is("i")) && (!tag.is("svg")) { |
7750 | leency | 250 | CheckForLineBreak(); |
7746 | leency | 251 | DrawStyle(); |
7752 | leency | 252 | if (tag.name) SetStyle(); |
7746 | leency | 253 | } |
7752 | leency | 254 | strncpy(#oldtag, #tag.name, sizeof(oldtag)-1); |
4411 | leency | 255 | break; |
256 | default: |
||
7752 | leency | 257 | AddCharToTheLine(ESBYTE[bufpos]); |
4411 | leency | 258 | } |
259 | } |
||
5766 | leency | 260 | DrawStyle(); |
261 | NewLine(); |
||
7752 | leency | 262 | list.count = draw_y; |
4692 | leency | 263 | DrawPage(); |
4411 | leency | 264 | } |
5747 | leency | 265 | //============================================================================================ |
7750 | leency | 266 | bool TWebBrowser::CheckForLineBreak() |
4718 | leency | 267 | { |
7750 | leency | 268 | int line_break_pos; |
4718 | leency | 269 | char new_line_text[4096]; |
7750 | leency | 270 | if (strlen(#line)*zoom + stolbec < list.column_max) return false; |
271 | line_break_pos = strrchr(#line, ' '); |
||
272 | if (line_break_pos*zoom + stolbec > list.column_max) { |
||
273 | line_break_pos = list.column_max/zoom - stolbec; |
||
274 | while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--; |
||
275 | } |
||
276 | if (!line_break_pos) && (strlen(#line)*zoom>list.column_max) { |
||
277 | line_break_pos=list.column_max/zoom; |
||
7742 | leency | 278 | if (!stolbec)&&(style.pre) draw_y-=list.item_h; //hack to fix https://prnt.sc/rk3kyt |
279 | } |
||
7750 | leency | 280 | strcpy(#new_line_text, #line + line_break_pos); |
281 | line[line_break_pos] = 0x00; |
||
5766 | leency | 282 | DrawStyle(); |
4718 | leency | 283 | strcpy(#line, #new_line_text); |
284 | NewLine(); |
||
7750 | leency | 285 | //if (strlen(#line)*zoom + stolbec > list.column_max)CheckForLineBreak(); |
286 | return true; |
||
4718 | leency | 287 | } |
5747 | leency | 288 | //============================================================================================ |
5773 | leency | 289 | void TWebBrowser::SetStyle() { |
7749 | leency | 290 | char img_path[4096]=0; |
7742 | leency | 291 | int meta_encoding; |
7752 | leency | 292 | |
293 | dword value; |
||
294 | |||
295 | if (tag.is("html")) { |
||
296 | t_html = tag.opened; |
||
4411 | leency | 297 | return; |
298 | } |
||
7752 | leency | 299 | if(tag.is("title")) { |
300 | if (tag.opened) header=NULL; |
||
4411 | leency | 301 | return; |
302 | } |
||
303 | |||
7752 | leency | 304 | IF(tag.is("q")) |
4491 | leency | 305 | { |
7752 | leency | 306 | if (tag.opened) { |
7750 | leency | 307 | meta_encoding = strlen(#line); |
308 | if (line[meta_encoding-1] != ' ') chrcat(#line, ' '); |
||
309 | chrcat(#line, '\"'); |
||
310 | } |
||
7752 | leency | 311 | if (!tag.opened) strcat(#line, "\" "); |
5749 | leency | 312 | return; |
4491 | leency | 313 | } |
7752 | leency | 314 | if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) { |
315 | anchors.add(value, draw_y); |
||
7738 | leency | 316 | } |
7752 | leency | 317 | if (tag.is("body")) { |
318 | t_body = tag.opened; |
||
319 | if (value = tag.get_value_of("link=")) link_color_inactive = GetColor(value); |
||
320 | if (value = tag.get_value_of("alink=")) link_color_active = GetColor(value); |
||
321 | if (value = tag.get_value_of("text=")) text_colors[0]=GetColor(value); |
||
322 | if (value = tag.get_value_of("bgcolor=")) { |
||
323 | style.bg_color = page_bg = GetColor(value); |
||
324 | DrawBuf.Fill(0, page_bg); |
||
325 | } |
||
326 | if (tag.opened) { |
||
327 | if (cur_encoding==CH_NULL) { |
||
328 | cur_encoding = CH_CP866; |
||
329 | //BufEncode(CH_UTF8); |
||
330 | debugln("Document has no information about encoding!"); |
||
4411 | leency | 331 | } |
7752 | leency | 332 | if (!streq(#header, #version)) { |
7056 | leency | 333 | ChangeCharset(charsets[cur_encoding], "CP866", #header); |
7752 | leency | 334 | strncat(#header, " - ", sizeof(header)-1); |
335 | strncat(#header, #version, sizeof(header)-1); |
||
7056 | leency | 336 | } |
7032 | leency | 337 | DrawTitle(#header); |
338 | } |
||
4411 | leency | 339 | return; |
340 | } |
||
7752 | leency | 341 | if (tag.is("a")) { |
342 | if (tag.opened) |
||
4411 | leency | 343 | { |
6735 | leency | 344 | if (link) IF(text_color_index > 0) text_color_index--; //åñëè ïðåäûäóùèé òåã à ÃÃ¥ áûë çà êðûò |
7752 | leency | 345 | if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:")) |
346 | { |
||
347 | text_color_index++; |
||
348 | text_colors[text_color_index] = text_colors[text_color_index-1]; |
||
349 | link = 1; |
||
350 | text_colors[text_color_index] = link_color_inactive; |
||
351 | PageLinks.AddLink(value); |
||
352 | } |
||
353 | } else { |
||
4411 | leency | 354 | link = 0; |
355 | IF(text_color_index > 0) text_color_index--; |
||
356 | } |
||
357 | return; |
||
358 | } |
||
7752 | leency | 359 | if (tag.is("font")) { |
7743 | leency | 360 | style.bg_color = page_bg; |
7752 | leency | 361 | if (tag.opened) |
4411 | leency | 362 | { |
363 | text_color_index++; |
||
364 | text_colors[text_color_index] = text_colors[text_color_index-1]; |
||
7752 | leency | 365 | if (value = tag.get_value_of("color=")) text_colors[text_color_index] = GetColor(value); |
366 | if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value); |
||
4411 | leency | 367 | } |
5749 | leency | 368 | else if (text_color_index > 0) text_color_index--; |
4411 | leency | 369 | return; |
370 | } |
||
7752 | leency | 371 | if (tag.is("div")) { |
372 | if (streq(#oldtag,"div")) && (tag.opened) return; |
||
7746 | leency | 373 | NewLine(); |
374 | //IF (oldtag[0] != 'h') |
||
4411 | leency | 375 | return; |
376 | } |
||
7752 | leency | 377 | if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) { |
7746 | leency | 378 | NewLine(); |
379 | return; |
||
380 | } |
||
7752 | leency | 381 | if (tag.is("p")) { |
7746 | leency | 382 | IF (oldtag[0] == 'h') || (streq(#oldtag,"td")) || (streq(#oldtag,"p")) return; |
4692 | leency | 383 | NewLine(); |
7752 | leency | 384 | //IF(tag.opened) NewLine(); |
4411 | leency | 385 | return; |
386 | } |
||
7752 | leency | 387 | if (tag.is("br")) { NewLine(); return; } |
388 | if (tag.is("tr")) { if (tag.opened) NewLine(); return; } |
||
389 | if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) { style.b = tag.opened; return; } |
||
390 | if (tag.is("button")) { style.button = tag.opened; stolbec++; return; } |
||
391 | if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;} |
||
392 | if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; } |
||
393 | if (tag.is("dd")) { stolbec += 5; return; } |
||
394 | if (tag.is("blockquote")) { style.blq = tag.opened; return; } |
||
395 | if (tag.is("pre")) || (tag.is("code")) { style.pre = tag.opened; return; } |
||
396 | if (tag.is("img")) { |
||
397 | if (value = tag.get_value_of("src=")) strlcpy(#img_path, value, sizeof(img_path)-1); |
||
398 | if (value = tag.get_value_of("title=")) && (strlen(value) |
||
399 | if (value = tag.get_value_of("alt=")) && (strlen(value) |
||
7750 | leency | 400 | if (!img_path) { line=0; return; } |
7742 | leency | 401 | style.image = true; |
402 | text_color_index++; |
||
403 | text_colors[text_color_index] = 0x9A6F29; |
||
404 | if (!line) { |
||
405 | if (!strncmp(#img_path, "data:", 5)) img_path=0; |
||
7749 | leency | 406 | replace_char(#img_path, '?', NULL, strlen(#img_path)); |
7742 | leency | 407 | sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/')); |
408 | line[50]= NULL; |
||
409 | } |
||
7750 | leency | 410 | while (CheckForLineBreak()) {}; |
7742 | leency | 411 | DrawStyle(); |
412 | text_color_index--; |
||
413 | style.image = false; |
||
7752 | leency | 414 | //ImgCache.Images( list.x, draw_y, WB1.list.w); |
7742 | leency | 415 | return; |
416 | } |
||
7752 | leency | 417 | if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) { |
418 | style.h = tag.opened; |
||
419 | if (tag.opened) |
||
4411 | leency | 420 | { |
6794 | leency | 421 | NewLine(); |
422 | draw_y += 10; |
||
6803 | leency | 423 | WB1.zoom=2; |
6045 | leency | 424 | WB1.list.font_type |= 10011001b; |
7752 | leency | 425 | if (value = tag.get_value_of("align=")) { |
426 | if (streq(value, "center")) style.align = ALIGN_CENTER; |
||
427 | if (streq(value, "right")) style.align = ALIGN_RIGHT; |
||
428 | } |
||
6794 | leency | 429 | list.item_h = basic_line_h * 2; |
7752 | leency | 430 | if (tag.is("h1")) style.b = true; |
4411 | leency | 431 | } |
5768 | leency | 432 | else |
4411 | leency | 433 | { |
7752 | leency | 434 | if (tag.is("h1")) style.b = false; |
6794 | leency | 435 | NewLine(); |
6803 | leency | 436 | WB1.zoom=1; |
6045 | leency | 437 | WB1.list.font_type = 10011000b; |
5746 | leency | 438 | style.align = ALIGN_LEFT; |
6794 | leency | 439 | list.item_h = basic_line_h; |
4411 | leency | 440 | } |
441 | return; |
||
442 | } |
||
7752 | leency | 443 | if (tag.is("dt")) { |
444 | style.li = tag.opened; |
||
445 | if (tag.opened) NewLine(); |
||
4411 | leency | 446 | return; |
447 | } |
||
7752 | leency | 448 | if (tag.is("li")) || (tag.is("dt")) |
4411 | leency | 449 | { |
7752 | leency | 450 | style.li = tag.opened; |
451 | if (tag.opened) |
||
4411 | leency | 452 | { |
4692 | leency | 453 | NewLine(); |
7743 | leency | 454 | stolbec = style.li_tab * 5 - 2; |
7742 | leency | 455 | strcpy(#line, "\31 "); |
7743 | leency | 456 | //stolbec-=2; |
4411 | leency | 457 | } |
458 | return; |
||
459 | } |
||
7752 | leency | 460 | if (tag.is("ul")) || (tag.is("ol")) { |
461 | if (!tag.opened) |
||
5749 | leency | 462 | { |
7752 | leency | 463 | style.li = tag.opened; |
5749 | leency | 464 | style.li_tab--; |
465 | NewLine(); |
||
466 | } |
||
467 | else style.li_tab++; |
||
468 | } |
||
7752 | leency | 469 | if (tag.is("hr")) { |
470 | if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999; |
||
5773 | leency | 471 | $push edi; |
4692 | leency | 472 | NewLine(); |
5773 | leency | 473 | $pop edi; |
7746 | leency | 474 | draw_y += 10; |
6794 | leency | 475 | DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI); |
4692 | leency | 476 | NewLine(); |
7746 | leency | 477 | draw_y += 10; |
5773 | leency | 478 | return; |
4411 | leency | 479 | } |
7752 | leency | 480 | if (tag.is("meta")) || (tag.is("?xml")) { |
6045 | leency | 481 | meta_encoding = CH_NULL; |
7752 | leency | 482 | if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding=")) |
483 | { |
||
484 | value += strrchr(value, '='); //search in content= |
||
485 | strlwr(value); |
||
486 | if (streq(value,"utf-8")) || (streq(value,"utf8")) meta_encoding = CH_UTF8; |
||
487 | else if (streq(value,"windows-1251")) || (streq(value,"windows1251")) meta_encoding = CH_CP1251; |
||
488 | else if (streq(value,"dos")) || (streq(value,"cp-866")) meta_encoding = CH_CP866; |
||
489 | else if (streq(value,"iso-8859-5")) || (streq(value,"iso8859-5")) meta_encoding = CH_ISO8859_5; |
||
490 | else if (streq(value,"koi8-r")) || (streq(value,"koi8-u")) meta_encoding = CH_KOI8; |
||
491 | } |
||
6045 | leency | 492 | if (meta_encoding!=CH_NULL) BufEncode(meta_encoding); |
4411 | leency | 493 | return; |
494 | } |
||
495 | } |
||
7746 | leency | 496 | //============================================================================================ |
6803 | leency | 497 | void TWebBrowser::BufEncode(dword set_new_encoding) |
5704 | leency | 498 | { |
7032 | leency | 499 | if (cur_encoding == set_new_encoding) return; |
7752 | leency | 500 | if (o_bufpointer==0) { |
5704 | leency | 501 | o_bufpointer = malloc(bufsize); |
502 | strcpy(o_bufpointer, bufpointer); |
||
7752 | leency | 503 | } else { |
5704 | leency | 504 | strcpy(bufpointer, o_bufpointer); |
505 | } |
||
7742 | leency | 506 | //debugval("cur_encoding ", cur_encoding); |
507 | //debugval("set_new_encoding", set_new_encoding); |
||
7032 | leency | 508 | cur_encoding = set_new_encoding; |
509 | bufpointer = ChangeCharset(charsets[cur_encoding], "CP866", bufpointer); |
||
5704 | leency | 510 | } |
5747 | leency | 511 | //============================================================================================ |
4674 | leency | 512 | void TWebBrowser::DrawScroller() |
4411 | leency | 513 | { |
4416 | leency | 514 | scroll_wv.max_area = list.count; |
515 | scroll_wv.cur_area = list.visible; |
||
516 | scroll_wv.position = list.first; |
||
5519 | leency | 517 | scroll_wv.all_redraw = 0; |
4486 | leency | 518 | scroll_wv.start_x = list.x + list.w; |
4508 | leency | 519 | scroll_wv.start_y = list.y; |
5678 | leency | 520 | scroll_wv.size_y = list.h; |
4416 | leency | 521 | scrollbar_v_draw(#scroll_wv); |
4411 | leency | 522 | } |
5747 | leency | 523 | //============================================================================================ |
4692 | leency | 524 | void TWebBrowser::NewLine() |
4475 | leency | 525 | { |
6803 | leency | 526 | dword onleft, ontop; |
7742 | leency | 527 | static int empty_line=0; |
4692 | leency | 528 | |
6794 | leency | 529 | if (!stolbec) && (draw_y==body_magrin) return; |
7742 | leency | 530 | |
7749 | leency | 531 | if (style.li) && (stolbec == style.li_tab * 5) { |
7742 | leency | 532 | if (empty_line<1) empty_line++; |
533 | else return; |
||
7749 | leency | 534 | } else if (!stolbec) { |
535 | if (empty_line<1) empty_line++; |
||
536 | else return; |
||
7742 | leency | 537 | } else { |
538 | empty_line=0; |
||
539 | } |
||
6794 | leency | 540 | |
541 | onleft = list.x + body_magrin; |
||
542 | ontop = draw_y + list.y; |
||
4637 | leency | 543 | if (t_html) && (!t_body) return; |
6794 | leency | 544 | draw_y += list.item_h; |
5746 | leency | 545 | if (style.blq) stolbec = 6; else stolbec = 0; |
546 | if (style.li) stolbec = style.li_tab * 5; |
||
7750 | leency | 547 | if (debug_mode) debugln(NULL); |
4488 | leency | 548 | } |
5747 | leency | 549 | //============================================================================================ |
5766 | leency | 550 | void TWebBrowser::DrawPage() |
551 | { |
||
6794 | leency | 552 | PutPaletteImage(list.first * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0); |
5766 | leency | 553 | DrawScroller(); |
554 | }1)>1)>>>>>': |