Subversion Repositories Kolibri OS

Rev

Rev 7742 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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