Subversion Repositories Kolibri OS

Rev

Rev 8365 | Rev 8407 | 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
		//bukva = ESBYTE[bufpos];
193
		switch (ESBYTE[bufpos])
4411 leency 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
8319 leency 213
			for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (!__isWhite(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 '<':
8330 leency 226
			if (!is_html) goto _DEFAULT;
5749 leency 227
			bufpos++;
8330 leency 228
			switch (ESBYTE[bufpos]) {
229
				case '!':
230
				case '/':
231
				case 'a'...'z':
232
				case 'A'...'Z':
233
					goto _TAG;
234
				default:
235
					goto _DEFAULT;
236
			}
237
			_TAG:
5768 leency 238
			if (!strncmp(bufpos,"!--",3))
4411 leency 239
			{
6986 leency 240
				bufpos+=3;
8330 leency 241
				//STRSTR
6986 leency 242
				while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufpointer + bufsize)
243
				{
244
					bufpos++;
245
				}
7746 leency 246
				bufpos+=2;
6986 leency 247
				break;
4411 leency 248
			}
7752 leency 249
			tag.reset();
250
			if (ESBYTE[bufpos] == '/') {
251
				tag.opened = false;
252
				bufpos++;
253
			}
254
 
255
			ignor_param=false;
6735 leency 256
			while (ESBYTE[bufpos] !='>') && (bufpos < bufpointer + bufsize) //ïîëó÷àåì òåã è åãî ïàðàìåòðû
8336 leency 257
			//&& (!chrnum(#tag.params,'\"') % 2) //
4411 leency 258
			{
4508 leency 259
				bukva = ESBYTE[bufpos];
8330 leency 260
				if (__isWhite(bukva)) bukva = ' ';
8336 leency 261
				if (!ignor_param) && (bukva!=' ') {
7752 leency 262
					if (strlen(#tag.name)+1
8330 leency 263
				} else {
4411 leency 264
					ignor_param = true;
7752 leency 265
					if (strlen(#tag.params)+1
7762 leency 266
					//chrncat(#tag.params, bukva, sizeof(tag.params)-1);
4411 leency 267
				}
4508 leency 268
				bufpos++;
4411 leency 269
			}
7752 leency 270
			strlwr(#tag.name);
4411 leency 271
 
7746 leency 272
			// ignore text inside the next tags
7752 leency 273
			if (tag.is("script")) || (tag.is("style")) || (tag.is("binary")) || (tag.is("select"))  {
274
				sprintf(#tag.params, "", #tag.name);
7945 leency 275
				if (j = strstri(bufpos, #tag.params)) bufpos = j-1;
7746 leency 276
				break;
277
			}
278
 
7752 leency 279
			if (tag.name[strlen(#tag.name)-1]=='/') tag.name[strlen(#tag.name)-1]=NULL; //for br/ !!!!!!!!
280
			if (tag.params) tag.parse_params();
7746 leency 281
 
7757 leency 282
			if (tag.name) {
7750 leency 283
				CheckForLineBreak();
7771 leency 284
				Paint();
7752 leency 285
				if (tag.name) SetStyle();
7746 leency 286
			}
4411 leency 287
			break;
288
		default:
8330 leency 289
			_DEFAULT:
7752 leency 290
			AddCharToTheLine(ESBYTE[bufpos]);
4411 leency 291
		}
292
	}
7771 leency 293
	Paint();
5766 leency 294
	NewLine();
7752 leency 295
	list.count = draw_y;
7755 leency 296
	list.CheckDoesValuesOkey();
297
	anchors.current = NULL;
7759 leency 298
	custom_encoding = -1;
7758 leency 299
	if (!header) {
7759 leency 300
		strncpy(#header, #version, sizeof(TWebBrowser.header)-1);
7758 leency 301
		DrawTitle(#header);
302
	}
4411 leency 303
}
5747 leency 304
//============================================================================================
7750 leency 305
bool TWebBrowser::CheckForLineBreak()
4718 leency 306
{
7750 leency 307
	int line_break_pos;
4718 leency 308
	char new_line_text[4096];
7758 leency 309
	//Do we need a line break?
7750 leency 310
	if (strlen(#line)*zoom + stolbec < list.column_max) return false;
7758 leency 311
	//Yes, we do. Lets calculate where...
7750 leency 312
	line_break_pos = strrchr(#line, ' ');
7758 leency 313
	//Is a new line fits in the current line?
7750 leency 314
	if (line_break_pos*zoom + stolbec > list.column_max) {
315
		line_break_pos = list.column_max/zoom - stolbec;
316
		while(line_break_pos) && (line[line_break_pos]!=' ') line_break_pos--;
317
	}
7758 leency 318
	//Maybe a new line is too big for the whole new line? Then we have to split it
7759 leency 319
	if (!line_break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
7758 leency 320
		line_break_pos = list.column_max/zoom - stolbec;
7742 leency 321
	}
7750 leency 322
	strcpy(#new_line_text, #line + line_break_pos);
7758 leency 323
	line[line_break_pos] = 0x00;
324
 
7771 leency 325
	Paint();
7758 leency 326
 
4718 leency 327
	strcpy(#line, #new_line_text);
328
	NewLine();
7762 leency 329
	//while (CheckForLineBreak()==true) {};
7750 leency 330
	return true;
4718 leency 331
}
5747 leency 332
//============================================================================================
5773 leency 333
void TWebBrowser::SetStyle() {
7749 leency 334
	char img_path[4096]=0;
8396 leency 335
	dword imgbuf[44];
336
	dword cur_img;
337
	int img_x, img_y, img_w, img_h;
7752 leency 338
 
339
	dword value;
340
 
7755 leency 341
	if (value = tag.get_value_of("name=")) || (value = tag.get_value_of("id=")) {
342
		anchors.add(value, draw_y);
343
		if (anchors.current) && (streq(value, #anchors.current+1)) {
344
			list.first = draw_y;
345
			anchors.current = NULL;
346
		}
7758 leency 347
	}
7752 leency 348
	if (tag.is("html")) {
349
		t_html = tag.opened;
4411 leency 350
		return;
351
	}
7758 leency 352
	if (tag.is("title")) {
7759 leency 353
		style.tag_title = tag.opened;
7758 leency 354
		if (!tag.opened) DrawTitle(#header);
355
		return;
356
	}
7752 leency 357
	if (tag.is("body")) {
358
		t_body = tag.opened;
7893 leency 359
		if (value = tag.get_value_of("link="))   link_color_default = GetColor(value);
360
		if (value = tag.get_value_of("alink="))  link_color_active = GetColor(value);
8016 leency 361
		if (value = tag.get_value_of("text="))   text_colors.set(0, GetColor(value));
7752 leency 362
		if (value = tag.get_value_of("bgcolor=")) {
7970 leency 363
			style.bg_color = page_bg = GetColor(value);
7752 leency 364
			DrawBuf.Fill(0, page_bg);
365
		}
7762 leency 366
		// Autodetecting encoding if no encoding was set
367
		if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) {
368
			if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8);
7799 leency 369
			else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251);
7762 leency 370
		}
4411 leency 371
		return;
372
	}
7762 leency 373
	if (tag.is("br")) { NewLine(); return; }
7797 leency 374
	if (tag.is("b")) || (tag.is("strong")) || (tag.is("big")) || (tag.is("w:b")) {
7780 leency 375
		style.b = tag.opened;
376
		return;
377
	}
7797 leency 378
	if (tag.is("w:r")) && (!tag.opened) { style.b = false; return; }
7752 leency 379
	if (tag.is("a")) {
380
		if (tag.opened)
4411 leency 381
		{
7752 leency 382
			if (value = tag.get_value_of("href=")) && (!strstr(value,"javascript:"))
383
			{
7762 leency 384
				link = true;
7970 leency 385
				links.add_link(value);
7752 leency 386
			}
387
		} else {
7762 leency 388
			link = false;
7893 leency 389
			style.bg_color = page_bg;
4411 leency 390
		}
391
		return;
392
	}
7762 leency 393
	if (tag.is("iframe")) && (value = tag.get_value_of("src=")) {
394
		NewLine();
395
		strcpy(#line, "IFRAME: ");
7771 leency 396
		Paint();
7762 leency 397
		link=true;
7970 leency 398
		links.add_link(value);
7771 leency 399
		strncpy(#line, value, sizeof(line)-1);
7762 leency 400
		while (CheckForLineBreak()) {};
7771 leency 401
		Paint();
7762 leency 402
		link=false;
403
		NewLine();
404
	}
7752 leency 405
	if (tag.is("font")) {
8016 leency 406
		style.font = tag.opened;
7743 leency 407
		style.bg_color = page_bg;
7752 leency 408
		if (tag.opened)
4411 leency 409
		{
7752 leency 410
			if (value = tag.get_value_of("bg=")) style.bg_color = GetColor(value);
8016 leency 411
			if (value = tag.get_value_of("color=")) {
412
				text_colors.add(GetColor(value));
413
			} else {
414
				text_colors.add(text_colors.get_last());
415
			}
4411 leency 416
		}
8016 leency 417
		else text_colors.pop();
4411 leency 418
		return;
419
	}
7752 leency 420
	if (tag.is("div")) {
7756 leency 421
		if (streq(#tag.prior,"div")) && (tag.opened) return;
8016 leency 422
		if (!tag.opened) && (style.font) text_colors.pop();
7746 leency 423
		NewLine();
4411 leency 424
		return;
425
	}
7752 leency 426
	if (tag.is("header")) || (tag.is("article")) || (tag.is("footer")) || (tag.is("figure")) {
7746 leency 427
		NewLine();
428
		return;
429
	}
7780 leency 430
	if (tag.is("p")) || (tag.is("w:p"))  {
7756 leency 431
		IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
4692 leency 432
		NewLine();
4411 leency 433
		return;
434
	}
7762 leency 435
	if (tag.is("pre")) { style.pre = tag.opened; return; }
7757 leency 436
	if (tag.is("td")) { if (tag.opened) AddCharToTheLine(' '); return; }
7752 leency 437
	if (tag.is("tr")) { if (tag.opened) NewLine(); return; }
438
	if (tag.is("button")) { style.button = tag.opened; stolbec++; return; }
439
	if (tag.is("u")) || (tag.is("ins")) { style.u=tag.opened; return;}
440
	if (tag.is("s")) || (tag.is("strike")) || (tag.is("del")) { style.s=tag.opened; return; }
7764 leency 441
	if (tag.is("dl")) {
442
		if (tag.opened) NewLine();
443
		return;
444
	}
445
	if (tag.is("dd")) {
446
		//NewLine();
447
		//if (tag.opened) stolbec += 5;  //stolbec overflow!
448
		return;
449
	}
7752 leency 450
	if (tag.is("blockquote")) { style.blq = tag.opened; return; }
7759 leency 451
	if (tag.is("code")) {
452
		if (tag.opened) style.bg_color = 0xe4ffcb; else style.bg_color = page_bg;
453
		style.pre = tag.opened; return;
454
	}
7752 leency 455
	if (tag.is("img")) {
8330 leency 456
		value = tag.get_value_of("src=");
8336 leency 457
		if (!value) goto NOIMG;
8330 leency 458
 
8365 leency 459
		if (!strcmp(value + strrchr(value, '.'), "svg")) goto NOIMG;
460
 
8396 leency 461
		if (streqrp(value, "data:")) {
462
			if (!strstr(value, "base64,")) goto NOIMG;
463
			value = EAX+7;
464
			if (ESBYTE[value]==' ') value++;
465
			cur_img = malloc(strlen(value));
466
			base64_decode stdcall (value, cur_img, strlen(value));
467
			img_decode stdcall (cur_img, EAX, 0);
468
			$push eax
469
			free(cur_img);
470
			$pop eax
471
			if (EAX) goto IMGOK; else goto NOIMG;
472
		}
473
 
8336 leency 474
		strlcpy(#img_path, value, sizeof(img_path)-1);
475
		get_absolute_url(#img_path, history.current());
476
 
8396 leency 477
		if (check_is_the_adress_local(#img_path)) {
478
			img_from_file stdcall(#img_path);
479
			if (EAX) goto IMGOK; else goto NOIMG;
480
		}
481
 
8363 leency 482
		if (cache.has(#img_path)) && (cache.current_size)
8336 leency 483
		{
484
			img_decode stdcall (cache.current_buf, cache.current_size, 0);
485
			if (!EAX) goto NOIMG;
8396 leency 486
			IMGOK:
8336 leency 487
 
8396 leency 488
			cur_img = EAX;
489
			img_h = ESDWORD[cur_img+8];
490
			img_w = ESDWORD[cur_img+4];
8336 leency 491
 
8396 leency 492
			if (img_w / 6 + stolbec > list.column_max) {
8336 leency 493
				NewLine();
494
			}
8396 leency 495
			img_x = stolbec*list.font_w+3;
496
			img_y = draw_y;
8336 leency 497
 
8396 leency 498
			img_w = math.min(img_w, DrawBuf.bufw - img_x);
499
 
500
			stolbec += img_w / 6;
8350 leency 501
			if (stolbec > list.column_max) NewLine();
8336 leency 502
 
8396 leency 503
			if (img_h > list.item_h + 5) {
504
				draw_y += img_h - list.item_h;
8336 leency 505
				NewLine();
506
			}
507
 
8396 leency 508
			if (link) links.add_text(img_x + list.x, img_y + list.y, img_w, img_h, 0);
8336 leency 509
 
8396 leency 510
			if (img_y + img_h >= DrawBuf.bufh) DrawBuf.IncreaseBufSize();
8336 leency 511
 
8396 leency 512
			if (ESDWORD[cur_img+20] != IMAGE_BPP32) {
513
				img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0);
514
				$push eax
515
				img_destroy stdcall(cur_img);
516
				$pop eax
517
				cur_img = EAX;
518
				if (!EAX) goto NOIMG;
519
			}
520
			imgbuf[04] = DrawBuf.bufw;
521
			imgbuf[08] = DrawBuf.bufh;
522
			imgbuf[20] = IMAGE_BPP32;
523
			imgbuf[24] = buf_data+8;
524
			img_blend stdcall(#imgbuf, cur_img, img_x, img_y, 0, 0, img_w, img_h);
525
			img_destroy stdcall(cur_img);
8336 leency 526
			return;
527
		} else {
8396 leency 528
			img_url.add(#img_path);
8336 leency 529
		}
530
		NOIMG:
531
 
7771 leency 532
		if (value = tag.get_value_of("title=")) && (strlen(value)
8330 leency 533
		if (value = tag.get_value_of("alt=")) && (strlen(value)
7742 leency 534
		if (!line) {
535
			if (!strncmp(#img_path, "data:", 5)) img_path=0;
7749 leency 536
			replace_char(#img_path, '?', NULL, strlen(#img_path));
8350 leency 537
			img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf
7742 leency 538
			sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
539
			line[50]= NULL;
540
		}
7750 leency 541
		while (CheckForLineBreak()) {};
8330 leency 542
 
543
		text_colors.add(0x9A6F29);
544
		style.image = true;
7771 leency 545
		Paint();
8330 leency 546
		style.image = false;
8016 leency 547
		text_colors.pop();
7742 leency 548
		return;
549
	}
7758 leency 550
	if (tag.is("h4")) {
551
		NewLine();
7759 leency 552
		NewLine();
7758 leency 553
		style.h = tag.opened;
554
		style.b = tag.opened;
555
	}
7752 leency 556
	if (tag.is("h1")) || (tag.is("h2")) || (tag.is("h3")) || (tag.is("caption")) {
557
		style.h = tag.opened;
7758 leency 558
		if (tag.opened) {
7759 leency 559
			if (!style.pre) NewLine();
6794 leency 560
			draw_y += 10;
7759 leency 561
			zoom=2;
562
			list.font_type |= 10011001b;
563
			list.item_h = BASIC_LINE_H * 2 - 2;
7752 leency 564
			if (tag.is("h1")) style.b = true;
7758 leency 565
		} else {
7752 leency 566
			if (tag.is("h1")) style.b = false;
6794 leency 567
			NewLine();
7759 leency 568
			zoom=1;
569
			list.font_type = 10011000b;
570
			list.item_h = BASIC_LINE_H;
4411 leency 571
		}
572
		return;
573
	}
7752 leency 574
	if (tag.is("dt")) {
7759 leency 575
		style.tag_list.upd_level(tag.opened, DT);
7752 leency 576
		if (tag.opened) NewLine();
4411 leency 577
		return;
578
	}
7759 leency 579
	if (tag.is("ul")) {
580
		style.tag_list.upd_level(tag.opened, UL);
581
		if (!tag.opened) && (!style.pre) NewLine();
582
		return;
583
	}
584
	if (tag.is("ol")) {
585
		style.tag_list.upd_level(tag.opened, OL);
586
		if (!tag.opened) && (!style.pre) NewLine();
587
		return;
588
	}
589
	if (tag.is("li")) && (tag.opened)
4411 leency 590
	{
7759 leency 591
		if (!style.tag_list.level) style.tag_list.upd_level(1, UL);
592
		if (!style.pre) NewLine();
593
		if (style.tag_list.get_order_type() == UL) {
7742 leency 594
			strcpy(#line, "\31 ");
7759 leency 595
			stolbec = style.tag_list.level * 5 - 2;
596
		}
597
		if (style.tag_list.get_order_type() == OL) {
598
			sprintf(#line, "%i. ", style.tag_list.inc_counter());
599
			stolbec = style.tag_list.level * 5 - strlen(#line);
4411 leency 600
		}
601
		return;
602
	}
7762 leency 603
	if (tag.is("q"))
604
	{
605
		if (tag.opened)	{
606
			EAX = strlen(#line);
607
			if (line[EAX-1] != ' ') chrcat(#line, ' ');
608
			chrcat(#line, '\"');
609
		}
610
		if (!tag.opened) strcat(#line, "\" ");
611
		return;
612
	}
7752 leency 613
	if (tag.is("hr")) {
614
		if (value = tag.get_value_of("color=")) EDI = GetColor(value); else EDI = 0x999999;
5773 leency 615
		$push edi;
4692 leency 616
		NewLine();
5773 leency 617
		$pop edi;
7746 leency 618
		draw_y += 10;
6794 leency 619
		DrawBuf.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
4692 leency 620
		NewLine();
7746 leency 621
		draw_y += 10;
5773 leency 622
		return;
4411 leency 623
	}
8302 leency 624
	if (tag.is("meta")) {
625
		if (streq(tag.get_value_of("http-equiv="), "refresh")) && (value = tag.get_value_of("content=")) {
626
			if (value = strstri(value, "url=")) strcpy(#redirect, value);
627
		}
628
	}
7759 leency 629
	if (custom_encoding == -1) && (tag.is("meta")) || (tag.is("?xml")) {
7752 leency 630
		if (value = tag.get_value_of("charset=")) || (value = tag.get_value_of("content=")) || (value = tag.get_value_of("encoding="))
631
		{
632
			value += strrchr(value, '='); //search in content=
8302 leency 633
			if (ESBYTE[value] == '"') value++;
7752 leency 634
			strlwr(value);
8336 leency 635
			if      (streqrp(value,"utf-8"))        || (streqrp(value,"utf8"))        ChangeEncoding(CH_UTF8);
8302 leency 636
			else if (streqrp(value,"windows-1251")) || (streqrp(value,"windows1251")) ChangeEncoding(CH_CP1251);
637
			else if (streqrp(value,"dos"))          || (streqrp(value,"cp-866"))      ChangeEncoding(CH_CP866);
638
			else if (streqrp(value,"iso-8859-5"))   || (streqrp(value,"iso8859-5"))   ChangeEncoding(CH_ISO8859_5);
639
			else if (streqrp(value,"koi8-r"))       || (streqrp(value,"koi8-u"))      ChangeEncoding(CH_KOI8);
7752 leency 640
		}
4411 leency 641
		return;
642
	}
643
}
7746 leency 644
//============================================================================================
4674 leency 645
void TWebBrowser::DrawScroller()
4411 leency 646
{
4416 leency 647
	scroll_wv.max_area = list.count;
648
	scroll_wv.cur_area = list.visible;
649
	scroll_wv.position = list.first;
5519 leency 650
	scroll_wv.all_redraw = 0;
4486 leency 651
	scroll_wv.start_x = list.x + list.w;
4508 leency 652
	scroll_wv.start_y = list.y;
5678 leency 653
	scroll_wv.size_y = list.h;
4416 leency 654
	scrollbar_v_draw(#scroll_wv);
4411 leency 655
}
5747 leency 656
//============================================================================================
7762 leency 657
void TWebBrowser::ChangeEncoding(int _new_encoding)
658
{
659
	if (cur_encoding == _new_encoding) return;
660
	cur_encoding = _new_encoding;
7781 leency 661
	bufpointer = ChangeCharset(cur_encoding, "CP866", bufpointer);
7762 leency 662
	if (header) {
7781 leency 663
		ChangeCharset(cur_encoding, "CP866", #header);
7762 leency 664
		DrawTitle(#header);
665
	}
666
}
667
//============================================================================================
4692 leency 668
void TWebBrowser::NewLine()
4475 leency 669
{
6803 leency 670
	dword onleft, ontop;
7742 leency 671
	static int empty_line=0;
4692 leency 672
 
7759 leency 673
	if (!stolbec) && (draw_y==BODY_MARGIN) return;
7742 leency 674
 
7759 leency 675
	if (style.tag_list.level) && (stolbec == style.tag_list.level * 5) {
7742 leency 676
		if (empty_line<1) empty_line++;
677
		else return;
7749 leency 678
	} else if (!stolbec) {
679
		if (empty_line<1) empty_line++;
680
		else return;
7742 leency 681
	} else {
682
		empty_line=0;
683
	}
6794 leency 684
 
7759 leency 685
	onleft = list.x + BODY_MARGIN;
6794 leency 686
	ontop = draw_y + list.y;
4637 leency 687
	if (t_html) && (!t_body) return;
6794 leency 688
	draw_y += list.item_h;
5746 leency 689
	if (style.blq) stolbec = 6; else stolbec = 0;
7759 leency 690
	stolbec += style.tag_list.level * 5;
7750 leency 691
	if (debug_mode) debugln(NULL);
4488 leency 692
}
5747 leency 693
//============================================================================================
5766 leency 694
void TWebBrowser::DrawPage()
695
{
8396 leency 696
	DrawBuf.Show(list.first, list.h);
5766 leency 697
	DrawScroller();
698
}