Rev 8425 | Rev 8440 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8425 | Rev 8439 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | #include "TWB\links.h" |
9 | #include "TWB\links.h" |
Line 10... | Line 10... | ||
10 | 10 | ||
11 | #define BODY_MARGIN 6 |
11 | #define BODY_MARGIN 6 |
Line 12... | Line 12... | ||
12 | #define BASIC_LINE_H 18 |
12 | #define BASIC_LINE_H 18 |
13 | 13 | ||
Line 14... | Line 14... | ||
14 | DrawBufer DrawBuf; |
14 | CANVAS canvas; |
15 | char line[500]; |
15 | char line[500]; |
16 | 16 | ||
17 | struct _style { |
17 | struct STYLE { |
18 | bool |
18 | bool |
19 | b, u, s, h, |
19 | b, u, s, h, |
20 | font, |
20 | font, |
21 | pre, |
21 | pre, |
22 | blq, |
22 | blq, |
23 | button, |
23 | button, |
24 | image; |
24 | image; |
- | 25 | dword bg_color; |
|
25 | dword bg_color; |
26 | LIST tag_list; |
Line -... | Line 27... | ||
- | 27 | dword title; |
|
- | 28 | void reset(); |
|
- | 29 | }; |
|
- | 30 | ||
- | 31 | void STYLE::reset() |
|
- | 32 | { |
|
- | 33 | b = u = s = h = blq = pre = title = false; |
|
26 | LIST tag_list; |
34 | font = false; |
27 | dword tag_title; |
35 | tag_list.reset(); |
28 | }; |
36 | } |
29 | 37 | ||
30 | struct TWebBrowser { |
38 | struct TWebBrowser { |
31 | llist list; |
39 | llist list; |
32 | _style style; |
40 | STYLE style; |
33 | dword draw_y, stolbec; |
41 | dword draw_y, stolbec; |
34 | int zoom; |
42 | int zoom; |
35 | dword o_bufpointer; |
43 | dword o_bufpointer; |
36 | int cur_encoding, custom_encoding; |
44 | int cur_encoding, custom_encoding; |
37 | bool link, t_html, t_body; |
45 | bool link, t_html, t_body; |
- | 46 | dword bufpointer; |
|
- | 47 | dword bufsize; |
|
Line 38... | Line 48... | ||
38 | dword bufpointer; |
48 | dword is_html; |
39 | dword bufsize; |
49 | collection img_url; |
40 | dword is_html; |
50 | char header[150]; |
41 | collection img_url; |
51 | char redirect[URL_SIZE]; |
42 | 52 | ||
43 | void Paint(); |
53 | void Paint(); |
44 | void SetPageDefaults(); |
54 | void SetPageDefaults(); |
45 | void AddCharToTheLine(); |
- | |
46 | void ParseHtml(); |
55 | void AddCharToTheLine(); |
47 | void SetStyle(); |
56 | void ParseHtml(); |
- | 57 | void SetStyle(); |
|
- | 58 | bool CheckForLineBreak(); |
|
- | 59 | void NewLine(); |
|
- | 60 | void ChangeEncoding(); |
|
- | 61 | void DrawPage(); |
|
- | 62 | ||
- | 63 | void tag_a(); |
|
- | 64 | void tag_p(); |
|
- | 65 | void tag_img(); |
|
- | 66 | void tag_div(); |
|
48 | bool CheckForLineBreak(); |
67 | void tag_h1234_caption(); |
49 | void NewLine(); |
68 | void tag_ol_ul_dt(); |
- | 69 | void tag_li(); |
|
- | 70 | void tag_q(); |
|
- | 71 | void tag_hr(); |
|
- | 72 | void tag_code(); |
|
50 | void DrawScroller(); |
73 | void tag_meta_xml(); |
Line 51... | Line 74... | ||
51 | void ChangeEncoding(); |
74 | void tag_body(); |
Line 52... | Line 75... | ||
52 | void DrawPage(); |
75 | void tag_iframe(); |
53 | char header[150]; |
76 | void tag_title(); |
54 | char redirect[URL_SIZE]; |
77 | void tag_font(); |
55 | }; |
78 | }; |
56 | 79 | ||
Line 57... | Line 80... | ||
57 | scroll_bar scroll_wv = { 15,NULL,NULL,NULL,0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; |
80 | #include "TWB\set_style.h" |
58 | 81 | ||
59 | //============================================================================================ |
82 | //============================================================================================ |
60 | void TWebBrowser::Paint() |
83 | void TWebBrowser::Paint() |
61 | { |
84 | { |
62 | dword start_x, line_length, stolbec_len; |
85 | dword start_x, line_length, stolbec_len; |
Line 79... | Line 102... | ||
79 | { |
102 | { |
80 | start_x = stolbec * list.font_w + BODY_MARGIN + list.x; |
103 | start_x = stolbec * list.font_w + BODY_MARGIN + list.x; |
81 | stolbec_len = strlen(#line) * zoom; |
104 | stolbec_len = strlen(#line) * zoom; |
82 | line_length = stolbec_len * list.font_w; |
105 | line_length = stolbec_len * list.font_w; |
Line 83... | Line -... | ||
83 | - | ||
84 | if (debug_mode) { |
- | |
85 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, 0xDDDddd); |
- | |
86 | } |
- | |
87 | 106 | ||
88 | if (style.bg_color!=page_bg) { |
107 | if (style.bg_color!=page_bg) { |
89 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color); |
108 | canvas.DrawBar(start_x, draw_y, line_length, list.item_h, style.bg_color); |
Line 90... | Line 109... | ||
90 | } |
109 | } |
91 | 110 | ||
92 | if (style.image) { |
111 | if (style.image) { |
93 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB); |
112 | canvas.DrawBar(start_x, draw_y, line_length, list.item_h-1, 0xF9DBCB); |
94 | } |
113 | } |
95 | if (style.button) { |
114 | if (style.button) { |
96 | DrawBuf.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc); |
115 | canvas.DrawBar(start_x, draw_y, line_length, list.item_h - calc(zoom*2), 0xCCCccc); |
Line 97... | Line 116... | ||
97 | DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999); |
116 | canvas.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, 0x999999); |
98 | } |
117 | } |
Line 99... | Line 118... | ||
99 | 118 | ||
100 | text_color__ = text_colors.get_last(); |
119 | text_color__ = text_colors.get_last(); |
101 | if (link) && (text_color__ == text_colors.get(0)) text_color__ = link_color_default; |
120 | if (link) && (text_color__ == text_colors.get(0)) text_color__ = link_color_default; |
102 | 121 | ||
103 | DrawBuf.WriteText(start_x, draw_y, list.font_type, text_color__, #line, NULL); |
122 | canvas.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); |
123 | if (style.b) canvas.WriteText(start_x+1, draw_y, list.font_type, text_color__, #line, NULL); |
105 | if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_color__); |
124 | if (style.s) canvas.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__); |
125 | if (style.u) canvas.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_color__); |
107 | if (link) { |
126 | if (link) { |
108 | if (line[0]==' ') && (line[1]==NULL) {} else { |
127 | if (line[0]==' ') && (line[1]==NULL) {} else { |
109 | DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default); |
128 | canvas.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2)-1, line_length, zoom, link_color_default); |
110 | links.add_text(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, zoom); |
129 | links.add_text(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2)-1, zoom); |
111 | } |
130 | } |
112 | } |
131 | } |
113 | stolbec += stolbec_len; |
132 | stolbec += stolbec_len; |
114 | if (debug_mode) debug(#line); |
133 | if (debug_mode) debugln(#line); |
115 | line = NULL; |
134 | line = NULL; |
116 | } |
135 | } |
117 | } |
- | |
118 | //============================================================================================ |
136 | } |
119 | void TWebBrowser::SetPageDefaults() |
137 | //============================================================================================ |
120 | { |
138 | void TWebBrowser::SetPageDefaults() |
121 | style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.pre = |
139 | { |
122 | link = style.tag_title = style.font = false; |
140 | t_html = t_body = link = false; |
123 | style.tag_list.reset(); |
141 | style.reset(); |
124 | link_color_default = 0x0000FF; |
142 | link_color_default = 0x0000FF; |
125 | link_color_active = 0xFF0000; |
143 | link_color_active = 0xFF0000; |
126 | page_bg = 0xffEBE8E9; //E0E3E3 EBE8E9 |
144 | page_bg = 0xffEBE8E9; //E0E3E3 EBE8E9 |
127 | style.bg_color = page_bg; |
145 | style.bg_color = page_bg; |
128 | DrawBuf.Fill(0, page_bg); |
146 | canvas.Fill(0, page_bg); |
129 | links.clear(); |
147 | links.clear(); |
Line 162... | Line 180... | ||
162 | if (line_len < sizeof(line)) chrcat(#line, _char); |
180 | if (line_len < sizeof(line)) chrcat(#line, _char); |
163 | CheckForLineBreak(); |
181 | CheckForLineBreak(); |
164 | } |
182 | } |
165 | //============================================================================================ |
183 | //============================================================================================ |
166 | void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ |
184 | void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ |
167 | word bukva[2]; |
- | |
168 | char unicode_symbol[10]; |
185 | char unicode_symbol[10]; |
169 | dword unicode_symbol_result; |
- | |
170 | dword j; |
186 | dword j; |
171 | bool ignor_param=false; |
- | |
172 | int tab_len; |
187 | int tab_len; |
173 | dword bufpos; |
188 | dword bufpos; |
174 | bufsize = _bufsize; |
189 | bufsize = _bufsize; |
- | 190 | ||
175 | if (bufpointer != _bufpointer) { |
191 | if (bufpointer != _bufpointer) { |
176 | bufpointer = malloc(bufsize); |
192 | bufpointer = malloc(bufsize); |
177 | memmov(bufpointer, _bufpointer, bufsize); |
193 | memmov(bufpointer, _bufpointer, bufsize); |
178 | } else { |
194 | } else { |
179 | custom_encoding = CH_CP866; |
195 | custom_encoding = CH_CP866; |
Line 222... | Line 238... | ||
222 | break; |
238 | break; |
223 | case '<': |
239 | case '<': |
224 | if (!is_html) goto _DEFAULT; |
240 | if (!is_html) goto _DEFAULT; |
225 | bufpos++; |
241 | bufpos++; |
226 | switch (ESBYTE[bufpos]) { |
242 | switch (ESBYTE[bufpos]) { |
227 | case '!': |
- | |
228 | case '/': |
- | |
229 | case '?': |
- | |
230 | case 'a'...'z': |
243 | case '!': case '/': case '?': |
231 | case 'A'...'Z': |
244 | case 'a'...'z': case 'A'...'Z': |
232 | goto _TAG; |
245 | goto _TAG; |
233 | default: |
246 | default: |
234 | goto _DEFAULT; |
247 | goto _DEFAULT; |
235 | } |
248 | } |
236 | _TAG: |
249 | _TAG: |
237 | if (!strncmp(bufpos,"!--",3)) |
- | |
238 | { |
- | |
239 | bufpos+=3; |
- | |
240 | //STRSTR |
- | |
241 | while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize) |
250 | if (tag.parse_tag(#bufpos, bufpointer + bufsize)) { |
242 | { |
- | |
243 | bufpos++; |
- | |
244 | } |
- | |
245 | bufpos+=2; |
- | |
246 | break; |
- | |
247 | } |
- | |
248 | tag.reset(); |
- | |
249 | if (ESBYTE[bufpos] == '/') { |
- | |
250 | tag.opened = false; |
- | |
251 | bufpos++; |
- | |
252 | } |
- | |
253 | - | ||
254 | ignor_param=false; |
- | |
255 | while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû |
- | |
256 | //&& (!chrnum(#tag.params,'\"') % 2) // |
- | |
257 | { |
- | |
258 | bukva = ESBYTE[bufpos]; |
- | |
259 | if (__isWhite(bukva)) bukva = ' '; |
- | |
260 | if (!ignor_param) && (bukva!=' ') { |
- | |
261 | if (strlen(#tag.name)+1 |
- | |
262 | } else { |
- | |
263 | ignor_param = true; |
- | |
264 | if (strlen(#tag.params)+1 |
- | |
265 | //chrncat(#tag.params, bukva, sizeof(tag.params)-1); |
- | |
266 | } |
- | |
267 | bufpos++; |
- | |
268 | } |
- | |
269 | strlwr(#tag.name); |
- | |
270 | - | ||
271 | // ignore text inside the next tags |
- | |
272 | if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select")) { |
- | |
273 | sprintf(#tag.params, "%s>", #tag.name); |
- | |
274 | if (j = strstri(bufpos, #tag.params)) bufpos = j-1; |
- | |
275 | break; |
- | |
276 | } |
- | |
277 | - | ||
278 | if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!! |
- | |
279 | if (tag.params) tag.parse_params(); |
- | |
280 | - | ||
281 | if (tag.name) { |
- | |
282 | CheckForLineBreak(); |
251 | CheckForLineBreak(); |
283 | Paint(); |
252 | Paint(); |
284 | if (tag.name) { |
- | |
285 | EAX = cur_encoding; |
253 | $push cur_encoding |
286 | $push eax |
- | |
287 | SetStyle(); |
254 | SetStyle(); |
288 | $pop eax |
255 | $pop eax |
289 | // The thing is that UTF if longer than other encodings. |
256 | // The thing is that UTF if longer than other encodings. |
290 | // So if encoding was changed to UTF than $bufpos position is wrong now, |
257 | // So if encoding was changed from UTF to DOS than $bufpos position got wrong, |
291 | // and we have to start parse from the very beginning |
258 | // and we have to start parse from the very beginning |
292 | if (EAX != cur_encoding) && (cur_encoding == CH_UTF8) { |
259 | if (EAX != cur_encoding) && (cur_encoding == CH_UTF8) { |
293 | ParseHtml(bufpointer, bufsize); |
260 | ParseHtml(bufpointer, bufsize); |
294 | return; |
261 | return; |
295 | } |
262 | } |
296 | } |
263 | } |
297 | } |
- | |
298 | break; |
264 | break; |
299 | default: |
265 | default: |
300 | _DEFAULT: |
266 | _DEFAULT: |
301 | AddCharToTheLine(ESBYTE[bufpos]); |
267 | AddCharToTheLine(ESBYTE[bufpos]); |
302 | } |
268 | } |
303 | } |
269 | } |
304 | Paint(); |
270 | Paint(); |
305 | NewLine(); |
271 | NewLine(); |
306 | list.count = draw_y; |
272 | list.count = draw_y; |
Line 307... | Line 273... | ||
307 | 273 | ||
308 | DrawBuf.bufh = math.max(list.visible, draw_y); |
- | |
309 | debugval("DrawBuf.bufh", DrawBuf.bufh); |
274 | canvas.bufh = math.max(list.visible, draw_y); |
Line 310... | Line 275... | ||
310 | buf_data = realloc(buf_data, DrawBuf.bufh * DrawBuf.bufw * 4 + 8); |
275 | buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8); |
311 | 276 | ||
312 | list.CheckDoesValuesOkey(); |
277 | list.CheckDoesValuesOkey(); |
313 | anchors.current = NULL; |
278 | anchors.current = NULL; |
Line 344... | Line 309... | ||
344 | NewLine(); |
309 | NewLine(); |
345 | //while (CheckForLineBreak()==true) {}; |
310 | //while (CheckForLineBreak()==true) {}; |
346 | return true; |
311 | return true; |
347 | } |
312 | } |
348 | //============================================================================================ |
313 | //============================================================================================ |
349 | void TWebBrowser::SetStyle() { |
- | |
350 | char img_path[4096]=0; |
- | |
351 | dword imgbuf[44]; |
- | |
352 | dword cur_img; |
- | |
353 | int img_x, img_y, img_w, img_h; |
- | |
354 | - | ||
355 | dword value; |
- | |
356 | - | ||
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 | } |
- | |
363 | } |
- | |
364 | if (tag.is("html")) { |
- | |
365 | t_html = tag.opened; |
- | |
366 | return; |
- | |
367 | } |
- | |
368 | if (tag.is("title")) { |
- | |
369 | style.tag_title = tag.opened; |
- | |
370 | if (!tag.opened) DrawTitle(#header); |
- | |
371 | return; |
- | |
372 | } |
- | |
373 | if (tag.is("body")) { |
- | |
374 | t_body = tag.opened; |
- | |
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); |
- | |
377 | if (value = tag.get_value_of("text=")) text_colors.set(0, GetColor(value)); |
- | |
378 | if (value = tag.get_value_of("bgcolor=")) { |
- | |
379 | style.bg_color = page_bg = GetColor(value); |
- | |
380 | DrawBuf.Fill(0, page_bg); |
- | |
381 | } |
- | |
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); |
- | |
385 | else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251); |
- | |
386 | } |
- | |
387 | return; |
- | |
388 | } |
- | |
389 | if (tag.is("br")) { NewLine(); return; } |
- | |
390 | if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) || (tag.is("w:b")) { |
- | |
391 | style.b = tag.opened; |
- | |
392 | return; |
- | |
393 | } |
- | |
394 | if (tag.is("w:r")) && (!tag.opened) { style.b = false; return; } |
- | |
395 | if (tag.is("a")) { |
- | |
396 | if (tag.opened) |
- | |
397 | { |
- | |
398 | if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:")) |
- | |
399 | { |
- | |
400 | link = true; |
- | |
401 | links.add_link(value); |
- | |
402 | } |
- | |
403 | } else { |
- | |
404 | link = false; |
- | |
405 | style.bg_color = page_bg; |
- | |
406 | } |
- | |
407 | return; |
- | |
408 | } |
- | |
409 | if (tag.is("iframe")) && (value = tag.get_value_of("src=")) { |
- | |
410 | NewLine(); |
- | |
411 | strcpy(#line, "IFRAME: "); |
- | |
412 | Paint(); |
- | |
413 | link=true; |
- | |
414 | links.add_link(value); |
- | |
415 | strncpy(#line, value, sizeof(line)-1); |
- | |
416 | while (CheckForLineBreak()) {}; |
- | |
417 | Paint(); |
- | |
418 | link=false; |
- | |
419 | NewLine(); |
- | |
420 | } |
- | |
421 | if (tag.is("font")) { |
- | |
422 | style.font = tag.opened; |
- | |
423 | style.bg_color = page_bg; |
- | |
424 | if (tag.opened) |
- | |
425 | { |
- | |
426 | if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value); |
- | |
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 | } |
- | |
432 | } |
- | |
433 | else text_colors.pop(); |
- | |
434 | return; |
- | |
435 | } |
- | |
436 | if (tag.is("div")) { |
- | |
437 | if (streq(#tag.prior,"div")) && (tag.opened) return; |
- | |
438 | if (!tag.opened) && (style.font) text_colors.pop(); |
- | |
439 | NewLine(); |
- | |
440 | return; |
- | |
441 | } |
- | |
442 | if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) { |
- | |
443 | NewLine(); |
- | |
444 | return; |
- | |
445 | } |
- | |
446 | if (tag.is("p")) || (tag.is("w:p")) { |
- | |
447 | IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return; |
- | |
448 | NewLine(); |
- | |
449 | return; |
- | |
450 | } |
- | |
451 | if (tag.is("pre")) { style.pre = tag.opened; return; } |
- | |
452 | if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; } |
- | |
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; } |
- | |
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 | } |
- | |
466 | if (tag.is("blockquote")) { style.blq = tag.opened; return; } |
- | |
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 | } |
- | |
471 | if (tag.is("img")) { |
- | |
472 | value = tag.get_value_of("src="); |
- | |
473 | if (!value) goto NOIMG; |
- | |
474 | - | ||
475 | if (!strcmp(value + strrchr(value, '.'), "svg")) goto NOIMG; |
- | |
476 | - | ||
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 | - | ||
490 | strlcpy(#img_path, value, sizeof(img_path)-1); |
- | |
491 | get_absolute_url(#img_path, history.current()); |
- | |
492 | - | ||
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 | - | ||
498 | if (cache.has(#img_path)) && (cache.current_size) |
- | |
499 | { |
- | |
500 | img_decode stdcall (cache.current_buf, cache.current_size, 0); |
- | |
501 | if (!EAX) goto NOIMG; |
- | |
502 | IMGOK: |
- | |
503 | - | ||
504 | cur_img = EAX; |
- | |
505 | img_h = ESDWORD[cur_img+8]; |
- | |
506 | img_w = ESDWORD[cur_img+4]; |
- | |
507 | - | ||
508 | if (img_w / 6 + stolbec > list.column_max) { |
- | |
509 | NewLine(); |
- | |
510 | } |
- | |
511 | img_x = stolbec*list.font_w+3; |
- | |
512 | img_y = draw_y; |
- | |
513 | - | ||
514 | img_w = math.min(img_w, DrawBuf.bufw - img_x); |
- | |
515 | - | ||
516 | stolbec += img_w / 6; |
- | |
517 | if (stolbec > list.column_max) NewLine(); |
- | |
518 | - | ||
519 | if (img_h > list.item_h + 5) { |
- | |
520 | draw_y += img_h - list.item_h; |
- | |
521 | NewLine(); |
- | |
522 | } |
- | |
523 | - | ||
524 | if (link) links.add_text(img_x + list.x, img_y + list.y, img_w, img_h, 0); |
- | |
525 | - | ||
526 | if (img_y + img_h >= DrawBuf.bufh) DrawBuf.IncreaseBufSize(); |
- | |
527 | - | ||
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); |
- | |
542 | return; |
- | |
543 | } else { |
- | |
544 | img_url.add(#img_path); |
- | |
545 | } |
- | |
546 | NOIMG: |
- | |
547 | - | ||
548 | if (value = tag.get_value_of("title=")) && (strlen(value) |
- | |
549 | if (value = tag.get_value_of("alt=")) && (strlen(value) |
- | |
550 | if (!line) { |
- | |
551 | if (!strncmp(#img_path, "data:", 5)) img_path=0; |
- | |
552 | replace_char(#img_path, '?', NULL, strlen(#img_path)); |
- | |
553 | img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf |
- | |
554 | sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/')); |
- | |
555 | line[50]= NULL; |
- | |
556 | } |
- | |
557 | while (CheckForLineBreak()) {}; |
- | |
558 | - | ||
559 | text_colors.add(0x9A6F29); |
- | |
560 | style.image = true; |
- | |
561 | Paint(); |
- | |
562 | style.image = false; |
- | |
563 | text_colors.pop(); |
- | |
564 | return; |
- | |
565 | } |
- | |
566 | if (tag.is("h4")) { |
- | |
567 | NewLine(); |
- | |
568 | NewLine(); |
- | |
569 | style.h = tag.opened; |
- | |
570 | style.b = tag.opened; |
- | |
571 | } |
- | |
572 | if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) { |
- | |
573 | style.h = tag.opened; |
- | |
574 | if (tag.opened) { |
- | |
575 | if (!style.pre) NewLine(); |
- | |
576 | draw_y += 10; |
- | |
577 | zoom=2; |
- | |
578 | list.font_type |= 10011001b; |
- | |
579 | list.item_h = BASIC_LINE_H * 2 - 2; |
- | |
580 | if (tag.is("h1")) style.b = true; |
- | |
581 | } else { |
- | |
582 | if (tag.is("h1")) style.b = false; |
- | |
583 | NewLine(); |
- | |
584 | zoom=1; |
- | |
585 | list.font_type = 10011000b; |
- | |
586 | list.item_h = BASIC_LINE_H; |
- | |
587 | } |
- | |
588 | return; |
- | |
589 | } |
- | |
590 | if (tag.is("dt")) { |
- | |
591 | style.tag_list.upd_level(tag.opened, DT); |
- | |
592 | if (tag.opened) NewLine(); |
- | |
593 | return; |
- | |
594 | } |
- | |
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) |
- | |
606 | { |
- | |
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) { |
- | |
610 | strcpy(#line, "\31 "); |
- | |
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); |
- | |
616 | } |
- | |
617 | return; |
- | |
618 | } |
- | |
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 | } |
- | |
629 | if (tag.is("hr")) { |
- | |
630 | if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999; |
- | |
631 | $push edi; |
- | |
632 | NewLine(); |
- | |
633 | $pop edi; |
- | |
634 | draw_y += 10; |
- | |
635 | DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI); |
- | |
636 | NewLine(); |
- | |
637 | draw_y += 10; |
- | |
638 | return; |
- | |
639 | } |
- | |
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 | } |
- | |
645 | if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) { |
- | |
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= |
- | |
649 | if (ESBYTE[value] == '"') value++; |
- | |
650 | strlwr(value); |
- | |
651 | if (streqrp(value,"utf-8")) || (streqrp(value,"utf8")) ChangeEncoding(CH_UTF8); |
- | |
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); |
- | |
656 | } |
- | |
657 | return; |
- | |
658 | } |
- | |
659 | } |
- | |
660 | //============================================================================================ |
- | |
661 | void TWebBrowser::DrawScroller() |
- | |
662 | { |
- | |
663 | scroll_wv.max_area = list.count; |
- | |
664 | scroll_wv.cur_area = list.visible; |
- | |
665 | scroll_wv.position = list.first; |
- | |
666 | scroll_wv.all_redraw = 0; |
- | |
667 | scroll_wv.start_x = list.x + list.w; |
- | |
668 | scroll_wv.start_y = list.y; |
- | |
669 | scroll_wv.size_y = list.h; |
- | |
670 | scrollbar_v_draw(#scroll_wv); |
- | |
671 | } |
- | |
672 | //============================================================================================ |
- | |
673 | void TWebBrowser::ChangeEncoding(int _new_encoding) |
314 | void TWebBrowser::ChangeEncoding(int _new_encoding) |
674 | { |
315 | { |
675 | if (cur_encoding == _new_encoding) return; |
316 | if (cur_encoding == _new_encoding) return; |
676 | cur_encoding = _new_encoding; |
317 | cur_encoding = _new_encoding; |
677 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
318 | bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer); |
Line 681... | Line 322... | ||
681 | } |
322 | } |
682 | } |
323 | } |
683 | //============================================================================================ |
324 | //============================================================================================ |
684 | void TWebBrowser::NewLine() |
325 | void TWebBrowser::NewLine() |
685 | { |
326 | { |
686 | dword onleft, ontop; |
- | |
687 | static int empty_line=0; |
327 | static int empty_line=0; |
Line 688... | Line 328... | ||
688 | 328 | ||
Line 689... | Line 329... | ||
689 | if (!stolbec) && (draw_y==BODY_MARGIN) return; |
329 | if (!stolbec) && (draw_y==BODY_MARGIN) return; |
Line 696... | Line 336... | ||
696 | else return; |
336 | else return; |
697 | } else { |
337 | } else { |
698 | empty_line=0; |
338 | empty_line=0; |
699 | } |
339 | } |
Line 700... | Line -... | ||
700 | - | ||
701 | onleft = list.x + BODY_MARGIN; |
- | |
702 | ontop = draw_y + list.y; |
340 | |
703 | if (t_html) && (!t_body) return; |
341 | if (t_html) && (!t_body) return; |
704 | draw_y += list.item_h; |
342 | draw_y += list.item_h; |
705 | if (style.blq) stolbec = 6; else stolbec = 0; |
343 | if (style.blq) stolbec = 6; else stolbec = 0; |
706 | stolbec += style.tag_list.level * 5; |
- | |
707 | if (debug_mode) debugln(NULL); |
344 | stolbec += style.tag_list.level * 5; |
708 | } |
345 | } |
- | 346 | //============================================================================================ |
|
- | 347 | scroll_bar scroll_wv = |
|
- | 348 | { 15,NULL,NULL,NULL,0,2,NULL, |
|
- | 349 | 0,0,0xeeeeee,0xBBBbbb,0xeeeeee}; |
|
709 | //============================================================================================ |
350 | |
710 | void TWebBrowser::DrawPage() |
351 | void TWebBrowser::DrawPage() |
- | 352 | { |
|
- | 353 | scroll_wv.max_area = list.count; |
|
- | 354 | scroll_wv.cur_area = list.visible; |
|
- | 355 | scroll_wv.position = list.first; |
|
711 | { |
356 | scroll_wv.all_redraw = 0; |
- | 357 | scroll_wv.start_x = list.x + list.w; |
|
- | 358 | scroll_wv.start_y = list.y; |
|
712 | DrawBuf.Show(list.first, list.h); |
359 | scroll_wv.size_y = list.h; |
- | 360 | scrollbar_v_draw(#scroll_wv); |
|
- | 361 | ||
713 | DrawScroller(); |
362 | canvas.Show(list.first, list.h); |
714 | }1)>1)>>>>': |
363 | }1)>1)>>': |