Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8439 leency 1
void TWebBrowser::SetStyle()
2
{
8444 leency 3
	if (tag.get_value_of("name")) || (tag.get_value_of("id")) {
8439 leency 4
		anchors.add(tag.value, draw_y);
5
		if (anchors.current) && (streq(tag.value, #anchors.current+1)) {
6
			list.first = draw_y;
7
			anchors.current = NULL;
8
		}
9
	}
10
	if (tag.is("a"))          { tag_a();                   return; }
11
	if (tag.is("p"))          { tag_p();                   return; }
12
	if (tag.is("img"))        { tag_img();                 return; }
13
	if (tag.is("div"))        { tag_div();                 return; }
14
	if (tag.is("br"))         { NewLine();                 return; }
15
	if (tag.is("header"))     { NewLine();                 return; }
16
	if (tag.is("article"))    { NewLine();                 return; }
17
	if (tag.is("footer"))     { NewLine();                 return; }
18
	if (tag.is("figure"))     { NewLine();                 return; }
19
	if (tag.is("w:p"))        { NewLine();                 return; }
20
	if (tag.is("b"))          { style.b   = tag.opened;    return; }
21
	if (tag.is("strong"))     { style.b   = tag.opened;    return; }
22
	if (tag.is("big"))        { style.b   = tag.opened;    return; }
23
	if (tag.is("w:b"))        { style.b   = tag.opened;    return; }
24
	if (tag.is("u"))          { style.u   = tag.opened;    return; }
25
	if (tag.is("ins"))        { style.u   = tag.opened;    return; }
26
	if (tag.is("s"))          { style.s   = tag.opened;    return; }
27
	if (tag.is("strike"))     { style.s   = tag.opened;    return; }
28
	if (tag.is("del"))        { style.s   = tag.opened;    return; }
29
	if (tag.is("pre"))        { style.pre = tag.opened;    return; }
30
	if (tag.is("blockquote")) { style.blq = tag.opened;    return; }
31
	if (tag.is("dl"))         { if (tag.opened) NewLine(); return; }
32
	if (tag.is("tr"))         { if (tag.opened) NewLine(); return; }
8454 leency 33
	if (tag.is("td"))         { /*if (tag.opened) AddCharToTheLine(' ');*/ return; }
8457 leency 34
	if (tag.is("button"))     { style.button = tag.opened; draw_x+=10;  return; }
8439 leency 35
	if (tag.is("w:r"))        { if (!tag.opened) style.b = false;      return; }
36
	if (tag.is("h1"))         { tag_h1234_caption();  return; }
37
	if (tag.is("h2"))         { tag_h1234_caption();  return; }
38
	if (tag.is("h3"))         { tag_h1234_caption();  return; }
39
	if (tag.is("h4"))         { tag_h1234_caption();  return; }
40
	if (tag.is("font"))       { tag_font();           return; }
41
	if (tag.is("dt"))         { tag_ol_ul_dt();       return; }
42
	if (tag.is("ul"))         { tag_ol_ul_dt();       return; }
43
	if (tag.is("ol"))         { tag_ol_ul_dt();       return; }
44
	if (tag.is("li"))         { tag_li();             return; }
45
	if (tag.is("q"))          { tag_q();              return; }
46
	if (tag.is("hr"))         { tag_hr();             return; }
47
	if (tag.is("meta"))       { tag_meta_xml();       return; }
48
	if (tag.is("?xml"))       { tag_meta_xml();       return; }
49
	if (tag.is("code"))       { tag_code();           return; }
50
	if (tag.is("iframe"))     { tag_iframe();         return; }
51
	if (tag.is("caption"))    { tag_h1234_caption();  return; }
52
	if (tag.is("title"))      { tag_title();          return; }
53
	if (tag.is("body"))       { tag_body();           return; }
54
	if (tag.is("html"))       { t_html = tag.opened;  return; }
55
	if (tag.is("dd")) {
56
		//NewLine();
8454 leency 57
		//if (tag.opened) stolbec += 5; //may overflow!
8439 leency 58
		return;
59
	}
60
}
61
 
62
void TWebBrowser::tag_p()
63
{
64
	IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
65
	NewLine();
66
}
67
 
68
void TWebBrowser::tag_title()
69
{
70
	style.title = tag.opened;
71
	if (!tag.opened) DrawTitle(#header);
72
}
73
 
74
void TWebBrowser::tag_font()
75
{
76
	style.font = tag.opened;
77
	if (tag.opened)
78
	{
8451 leency 79
		if (tag.get_value_of("bg")) {
80
			bg_colors.add(GetColor(tag.value));
81
		} else {
82
			bg_colors.add(bg_colors.get_last());
83
		}
8444 leency 84
		if (tag.get_value_of("color")) {
8439 leency 85
			text_colors.add(GetColor(tag.value));
86
		} else {
87
			text_colors.add(text_colors.get_last());
88
		}
89
	}
8451 leency 90
	else {
91
		text_colors.pop();
92
		bg_colors.pop();
93
	}
8439 leency 94
}
95
 
96
void TWebBrowser::tag_div()
97
{
98
	if (streq(#tag.prior,"div")) && (tag.opened) return;
99
	if (!tag.opened) && (style.font) text_colors.pop();
100
	NewLine();
101
}
102
 
103
void TWebBrowser::tag_iframe()
104
{
8444 leency 105
	if (tag.get_value_of("src")) {
8439 leency 106
		NewLine();
107
		strcpy(#line, "IFRAME: ");
108
		Paint();
109
		link=true;
110
		links.add_link(tag.value);
111
		strncpy(#line, tag.value, sizeof(line)-1);
112
		while (CheckForLineBreak()) {};
113
		Paint();
114
		link=false;
115
		NewLine();
116
	}
117
}
118
 
119
void TWebBrowser::tag_a()
120
{
121
	if (tag.opened)
122
	{
8444 leency 123
		if (tag.get_value_of("href")) && (!strstr(tag.value,"javascript:"))
8439 leency 124
		{
125
			link = true;
126
			links.add_link(tag.value);
127
		}
128
	} else {
129
		link = false;
130
	}
131
}
132
 
133
void TWebBrowser::tag_meta_xml()
134
{
8444 leency 135
	if (custom_encoding == -1) if (tag.get_value_of("charset"))
136
	|| (tag.get_value_of("content")) || (tag.get_value_of("encoding"))
8439 leency 137
	{
138
		EDX = strrchr(tag.value, '=') + tag.value; //search in content=
139
		if (ESBYTE[EDX] == '"') EDX++;
140
		strlwr(EDX);
141
		if      (streqrp(EDX,"utf-8"))        || (streqrp(EDX,"utf8"))        ChangeEncoding(CH_UTF8);
142
		else if (streqrp(EDX,"windows-1251")) || (streqrp(EDX,"windows1251")) ChangeEncoding(CH_CP1251);
143
		else if (streqrp(EDX,"dos"))          || (streqrp(EDX,"cp-866"))      ChangeEncoding(CH_CP866);
144
		else if (streqrp(EDX,"iso-8859-5"))   || (streqrp(EDX,"iso8859-5"))   ChangeEncoding(CH_ISO8859_5);
145
		else if (streqrp(EDX,"koi8-r"))       || (streqrp(EDX,"koi8-u"))      ChangeEncoding(CH_KOI8);
146
	}
8444 leency 147
	if (streq(tag.get_value_of("http-equiv"), "refresh")) && (tag.get_value_of("content")) {
148
		if (tag.value = strstri(tag.value, "url")) strcpy(#redirect, tag.value);
8439 leency 149
	}
150
}
151
 
152
void TWebBrowser::tag_code()
153
{
154
	if (style.pre = tag.opened) {
8451 leency 155
		bg_colors.add(0xe4ffcb);
8439 leency 156
	} else {
8451 leency 157
		bg_colors.pop();
8439 leency 158
	}
159
}
160
 
161
void TWebBrowser::tag_ol_ul_dt()
162
{
163
	char type = ESBYTE[#tag.name];
164
	style.tag_list.upd_level(tag.opened, type);
165
	switch(type)
166
	{
167
		case 'd':
168
			if (tag.opened) NewLine();
169
			break;
170
		case 'u':
171
		case 'o':
172
			if (!tag.opened) && (!style.pre) NewLine();
173
	}
174
}
175
 
176
void TWebBrowser::tag_li()
177
{
178
	if (tag.opened) {
179
		if (!style.tag_list.level) style.tag_list.upd_level(1, 'u');
180
		if (!style.pre) NewLine();
181
		if (style.tag_list.order_type() == 'u') {
182
			strcpy(#line, "\31 ");
8457 leency 183
			draw_x = style.tag_list.level * 5 - 2 * list.font_w + BODY_MARGIN;
8439 leency 184
		}
185
		if (style.tag_list.order_type() == 'o') {
186
			sprintf(#line, "%i. ", style.tag_list.inc_counter());
8457 leency 187
			draw_x = style.tag_list.level * 5 - 1 - strlen(#line) * list.font_w + BODY_MARGIN;
8439 leency 188
		}
189
	}
190
}
191
 
192
void TWebBrowser::tag_hr()
193
{
194
	EAX = 0x999999;
8444 leency 195
	if (tag.get_value_of("color")) GetColor(tag.value);
8439 leency 196
	$push eax;
197
	NewLine();
198
	$pop edi;
199
	draw_y += 10;
200
	canvas.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
201
	NewLine();
202
	draw_y += 10;
203
	return;
204
}
205
 
206
void TWebBrowser::tag_body()
207
{
208
	t_body = tag.opened;
8444 leency 209
	if (tag.get_value_of("link"))   link_color_default = GetColor(tag.value);
210
	if (tag.get_value_of("alink"))  link_color_active = GetColor(tag.value);
211
	if (tag.get_value_of("text"))   text_colors.set(0, GetColor(tag.value));
212
	if (tag.get_value_of("bgcolor")) {
8451 leency 213
		bg_colors.set(0, GetColor(tag.value));
214
		canvas.Fill(0, bg_colors.get(0));
8439 leency 215
	}
216
	// Autodetecting encoding if no encoding was set
217
	if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) {
218
		if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8);
219
		else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251);
220
	}
221
}
222
 
223
void TWebBrowser::tag_q()
224
{
225
	if (tag.opened)	{
226
		AddCharToTheLine(' ');
227
		AddCharToTheLine('\"');
228
	} else {
229
		AddCharToTheLine('\"');
230
		AddCharToTheLine(' ');
231
	}
232
}
233
 
234
void TWebBrowser::tag_h1234_caption()
235
{
236
	if (ESBYTE[#tag.name+1]=='4') {
237
		NewLine();
238
		NewLine();
239
		style.h = tag.opened;
240
		style.b = tag.opened;
241
	} else {
242
		style.h = tag.opened;
243
		if (tag.opened) {
244
			if (!style.pre) NewLine();
245
			draw_y += 10;
8457 leency 246
			list.SetFont(BASIC_CHAR_W*2, 14*2, 10011001b);
8439 leency 247
			list.item_h = BASIC_LINE_H * 2 - 2;
248
			if (tag.is("h1")) style.b = true;
249
		} else {
250
			if (tag.is("h1")) style.b = false;
251
			NewLine();
8457 leency 252
			list.SetFont(BASIC_CHAR_W, 14, 10011000b);
8451 leency 253
			style.cur_line_h = list.item_h = BASIC_LINE_H;
8439 leency 254
		}
255
	}
256
}
257
 
258
 
259
void TWebBrowser::tag_img()
260
{
261
	char img_path[4096]=0;
262
	dword imgbuf[44];
263
	dword cur_img;
264
	int img_x, img_y, img_w, img_h;
265
 
8454 leency 266
	if (!tag.get_value_of("data-large-image"))
267
		if (!tag.get_value_of("data-src"))
268
			if (!tag.get_value_of("src")) return;
8439 leency 269
 
270
	if (streqrp(tag.value, "data:")) {
271
		if (!strstr(tag.value, "base64,")) goto NOIMG;
272
		EDX = EAX+7;
273
		if (ESBYTE[EDX]==' ') EDX++;
274
		cur_img = malloc(strlen(EDX));
275
		base64_decode stdcall (EDX, cur_img, strlen(EDX));
276
		img_decode stdcall (cur_img, EAX, 0);
277
		$push eax
278
		free(cur_img);
279
		$pop eax
280
		if (EAX) goto IMGOK; else goto NOIMG;
281
	}
282
 
283
	if (!strcmp(tag.value + strrchr(tag.value, '.'), "svg")) goto NOIMG;
8454 leency 284
	if (!strcmp(tag.value + strrchr(tag.value, '.'), "webp")) goto NOIMG;
285
 
8439 leency 286
	strlcpy(#img_path, tag.value, sizeof(img_path)-1);
287
	get_absolute_url(#img_path, history.current());
288
 
289
	if (check_is_the_adress_local(#img_path)) {
290
		img_from_file stdcall(#img_path);
291
		if (EAX) goto IMGOK; else goto NOIMG;
292
	}
293
 
294
	if (cache.has(#img_path)) {
295
		img_decode stdcall (cache.current_buf, cache.current_size, 0);
296
		if (EAX) goto IMGOK; else goto NOIMG;
297
	} else {
298
		img_url.add(#img_path);
299
		goto NOIMG;
300
	}
301
 
302
IMGOK:
303
	cur_img = EAX;
304
	img_h = ESDWORD[cur_img+8];
305
	img_w = ESDWORD[cur_img+4];
306
 
8457 leency 307
	if (img_w + draw_x >= list.w) NewLine();
8439 leency 308
	img_y = draw_y;
8454 leency 309
	if (img_h < list.item_h) img_y += list.item_h - img_h / 2 - 1; else img_y -= 2;
8457 leency 310
	style.cur_line_h = math.max(style.cur_line_h, img_h);
8454 leency 311
 
8457 leency 312
	img_w = math.min(img_w, canvas.bufw - draw_x);
8439 leency 313
 
8457 leency 314
	if (link) links.add_text(draw_x + list.x, img_y + list.y, img_w, img_h, 0);
8451 leency 315
 
8439 leency 316
	if (img_y + img_h >= canvas.bufh) canvas.IncreaseBufSize();
317
 
318
	if (ESDWORD[cur_img+20] != IMAGE_BPP32) {
319
		img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0);
320
		$push eax
321
		img_destroy stdcall(cur_img);
322
		$pop eax
323
		cur_img = EAX;
324
		if (!EAX) goto NOIMG;
325
	}
326
	imgbuf[04] = canvas.bufw;
327
	imgbuf[08] = canvas.bufh;
328
	imgbuf[20] = IMAGE_BPP32;
329
	imgbuf[24] = buf_data+8;
8457 leency 330
	img_blend stdcall(#imgbuf, cur_img, draw_x, img_y, 0, 0, img_w, img_h);
8439 leency 331
	img_destroy stdcall(cur_img);
8457 leency 332
 
333
	draw_x += img_w;
334
	if (draw_x >= list.w) NewLine();
8439 leency 335
	return;
336
 
337
NOIMG:
8444 leency 338
	if (tag.get_value_of("title")) || (tag.get_value_of("alt")) {
8439 leency 339
		strncpy(#img_path, tag.value, sizeof(line)-3);
340
		sprintf(#line, "[%s]", #img_path);
341
	} else {
342
		if (streqrp(#img_path, "data:")) img_path=0;
343
		replace_char(#img_path, '?', NULL, strlen(#img_path));
344
		img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf
345
		sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
346
		line[50]= NULL;
347
	}
348
	while (CheckForLineBreak()) {};
349
	text_colors.add(0x9A6F29);
350
	style.image = true;
351
	Paint();
352
	style.image = false;
353
	text_colors.pop();
354
}