Subversion Repositories Kolibri OS

Rev

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