Subversion Repositories Kolibri OS

Rev

Rev 7285 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7285 Rev 7286
Line 1... Line -...
1
void ParseTxt()
-
 
2
{
-
 
3
_canvas canvas;
-
 
4
byte ch, zeroch=0;
-
 
5
dword bufoff, buflen, line_start, srch_pos;
-
 
6
int stroka_y=5, line_length=0;
-
 
7
 
-
 
8
	line_start=io.buffer_data;
-
 
9
	buflen = strlen(io.buffer_data) + io.buffer_data;
-
 
10
	for (bufoff=io.buffer_data; bufoff
-
 
11
	{
-
 
12
		ch = ESBYTE[bufoff];
-
 
13
		line_length += char_width[ch];
-
 
14
		if (line_length>=list.w-30) || (ch==10) {
-
 
15
			srch_pos = bufoff;
-
 
16
			loop()
-
 
17
			{
-
 
18
				if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
-
 
19
				if (srch_pos == line_start) break; //no white space found in whole line
-
 
20
				srch_pos--;
-
 
21
			}
-
 
22
			if (kfont.size.height) {
-
 
23
				ESBYTE[bufoff] >< zeroch; //set line end
-
 
24
				canvas.write_text(8, stroka_y, 0x000000, line_start);
-
 
25
				ESBYTE[bufoff] >< zeroch; //restore line
-
 
26
			}
-
 
27
			stroka_y += list.item_h;
-
 
28
			line_start = bufoff;
-
 
29
			line_length = 0;
-
 
30
		}
-
 
31
	}
-
 
32
	if (!kfont.size.height) {
-
 
33
		list.count = stroka_y/list.item_h+3;
-
 
34
		if (list.count < list.visible) list.count = list.visible;
-
 
35
		kfont.size.height = list.count+5*list.item_h;
-
 
36
		kfont.raw_size = 0;
-
 
37
		ParseTxt();
-
 
38
	} 
-
 
39
	else canvas.write_text(8, stroka_y, 0x000000, line_start);
-
 
40
}
-
 
41
 
-
 
42
/*========================================================
1
/*========================================================
43
=                                                        =
2
=                                                        =
44
=                        STYLE                           =
3
=                        STYLE                           =
45
=                                                        =
4
=                                                        =
46
========================================================*/
5
========================================================*/
47
#define HTML_PADDING_X 8;
6
#define HTML_PADDING_X 8;
48
#define HTML_PADDING_Y 5;
7
#define HTML_PADDING_Y 5;
Line 49... Line 8...
49
 
8
 
50
struct _style {
9
struct _style {
51
	bool b, u, i, s;
10
	bool bold, underlined, italic, strike;
52
	bool h1, h2, h3, h4, h5, h6;
11
	bool h1, h2, h3, h4, h5, h6;
53
	bool a;
12
	bool a;
54
	bool pre;
13
	bool pre;
-
 
14
	bool ignore;
55
	bool ignore;
15
	bool body;
56
	dword color;
16
	dword color;
57
	void clear();
17
	void clear();
Line 58... Line 18...
58
};
18
};
59
 
19
 
60
void _style::clear()
20
void _style::clear()
61
{
21
{
62
	b=u=i=s=0;
22
	bold=underlined=italic=strike=0;
63
	h1=h2=h3=h4=h5=h6=0;
23
	h1=h2=h3=h4=h5=h6=0;
64
	a=0;
24
	a=0;
65
	pre=0;
25
	pre=0;
-
 
26
	ignore=0;
66
	ignore=0;
27
	color=0;
Line 67... Line 28...
67
	color=0;
28
	body=0;
68
}
29
}
69
 
30
 
Line 74... Line 35...
74
========================================================*/
35
========================================================*/
75
struct _tag {
36
struct _tag {
76
	dword start;
37
	dword start;
77
	dword end;
38
	dword end;
78
	dword name;
39
	dword name;
-
 
40
 
-
 
41
	bool opens;
-
 
42
 
79
	dword param[10];
43
	dword param;
80
	dword value[10];
44
	dword value;
-
 
45
 
81
	void parse();
46
	void parse();
82
	int nameis();
47
	int nameis();
83
};
48
};
Line 84... Line 49...
84
 
49
 
85
void _tag::parse()
50
void _tag::parse()
-
 
51
{
-
 
52
	dword START = start;
-
 
53
 
-
 
54
	calc(1); //WTF
-
 
55
 
-
 
56
	if (ESBYTE[START]=='/') {
-
 
57
		START++;
-
 
58
		opens = false;
-
 
59
	} else opens = true;
-
 
60
 
-
 
61
	name = START;
-
 
62
	
-
 
63
	while ( (START < end) && (!__isWhite(ESBYTE[START])) ) {
-
 
64
		START++;
-
 
65
	}
-
 
66
	if (START!=end) ESBYTE[START] = '\0';
-
 
67
	START++;
86
{
68
 
-
 
69
	strlwr(name);
-
 
70
 
87
	strlwr(name);
71
	start = START;
Line 88... Line 72...
88
}
72
}
89
 
73
 
90
int _tag::nameis(dword _in_tag_name)
74
int _tag::nameis(dword _in_tag_name)
91
{
75
{
92
	if (name) && (strcmp(_in_tag_name, start)==0) return true;
76
	if (name) && (streq(_in_tag_name, name)) return true;
Line 93... Line 77...
93
	return false;
77
	return false;
94
}
78
}
Line 147... Line 131...
147
========================================================*/
131
========================================================*/
148
struct _text {
132
struct _text {
149
	int size_pt_change;
133
	int size_pt_change;
150
	dword start;
134
	dword start;
151
	dword end;
135
	dword end;
-
 
136
 
-
 
137
	dword width;
152
};
138
};
Line 153... Line 139...
153
 
139
 
154
/*
140
/*
155
dword line_break;
141
dword line_break;
Line 207... Line 193...
207
	_draw draw;
193
	_draw draw;
208
	_buf buf;
194
	_buf buf;
209
	_text text;
195
	_text text;
210
	_canvas canvas;
196
	_canvas canvas;
211
	void init();
197
	void init();
-
 
198
	void apply_text();
212
	void set_style();
199
	void set_style();
213
	void parse();
200
	void parse();
214
	void apply_text();
-
 
215
};
201
};
Line 216... Line 202...
216
 
202
 
217
void _dom::init()
203
void _dom::init()
218
{
204
{
Line 221... Line 207...
221
	buf.init(io.buffer_data, strlen(io.buffer_data));
207
	buf.init(io.buffer_data, strlen(io.buffer_data));
222
}
208
}
Line 223... Line 209...
223
 
209
 
224
void _dom::set_style()
210
void _dom::set_style()
225
{
-
 
226
	/*
211
{
227
	if (tag.nameis("pre")) style.pre = true;
212
	if (tag.nameis("body")) style.body = tag.opens;
228
	if (tag.nameis("/pre")) style.pre = false;
213
	if (tag.nameis("b")) style.bold = tag.opens;
229
	if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
214
	if (tag.nameis("i")) style.italic = tag.opens;
230
	if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
215
	if (tag.nameis("s")) style.strike = tag.opens;
231
	if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
216
	if (tag.nameis("pre")) style.pre = tag.opens;
-
 
217
	if (tag.nameis("style")) style.ignore = tag.opens;
-
 
218
	if (tag.nameis("a"))  { 
-
 
219
		style.a = tag.opens;
-
 
220
		if (tag.opens) style.color=0x0000FF; else style.color=0;
Line 232... Line 221...
232
	if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
221
	}
233
 
222
	
234
	if (tag.nameis("br")) 
223
	if (tag.nameis("br")) 
235
		|| (tag.nameis("p")) 
224
		|| (tag.nameis("p")) 
236
		|| (tag.nameis("div")) 
225
		|| (tag.nameis("div")) 
237
		|| (tag.nameis("tr")) {
226
		|| (tag.nameis("tr")) {
238
		draw.line_break();
227
		draw.line_break();
Line -... Line 228...
-
 
228
		return;
-
 
229
	}
-
 
230
 
-
 
231
	if (tag.nameis("li")) && (tag.opens) {
-
 
232
		draw.line_break();
-
 
233
		return;
-
 
234
	}
-
 
235
 
-
 
236
	if (tag.nameis("td")) && (tag.opens) {
-
 
237
		draw.line_break();
-
 
238
		return;
239
		return;
239
	}
240
	}
240
 
241
 
241
	/*
242
	if (dom.tag.nameis("title")) {
242
	if (tag.nameis("title")) {
243
		strcpy(#title, text.start);
243
		strcpy(#title, text.start);
Line -... Line 244...
-
 
244
		strcat(#title, " - Aelia");
-
 
245
		DrawTitle(#title);
244
		strcat(#title, " - Aelia");
246
	}
245
		DrawTitle(#title);
247
 
246
	}
248
 
247
 
249
 
248
	if 	(tag.nameis("h1")) || (tag.nameis("/h1")) ||
250
	if 	(tag.nameis("h1")) || (tag.nameis("/h1")) ||
Line 275... Line 277...
275
	*/
277
	*/
276
}
278
}
Line 277... Line 279...
277
 
279
 
278
void _dom::apply_text()
280
void _dom::apply_text()
-
 
281
{
-
 
282
	if (kfont.size.height) && (style.body) {
279
{
283
		kfont.bold = style.bold;
280
	if (kfont.size.height) canvas.write_text(draw.x, draw.y, style.color, text.start);
284
		canvas.write_text(draw.x, draw.y, style.color, text.start);
-
 
285
		if (style.a) {
-
 
286
			canvas.draw_hor_line(draw.x+1, draw.y + list.item_h-2, kfont.get_label_width(text.start), style.color);
-
 
287
		}
281
	draw.line_break();
288
	}
Line 282... Line 289...
282
}
289
}
283
 
290
 
284
void _dom::parse()
291
void _dom::parse()
Line 292... Line 299...
292
	{
299
	{
293
		if (ESBYTE[i]=='<') {
300
		if (ESBYTE[i]=='<') {
294
			tag.start = i+1;
301
			tag.start = i+1;
295
			text.end = i-1;
302
			text.end = i-1;
296
			ESBYTE[i] = '\0';
303
			ESBYTE[i] = '\0';
297
			debug("TXT "); debugln(text.start);
-
 
298
			apply_text();
304
			apply_text();
299
		}
305
		}
300
		if (ESBYTE[i]=='>') {
306
		if (ESBYTE[i]=='>') {
301
			tag.end = i-1;
307
			tag.end = i-1;
302
			text.start = i+1;
308
			text.start = i+1;
303
			ESBYTE[i] = '\0';
309
			ESBYTE[i] = '\0';
304
			debug("TAG "); debugln(tag.start);
-
 
305
			//tag.parse();
310
			tag.parse();
306
			//set_style();
311
			set_style();
307
		}
312
		}
308
	}
313
	}
Line 309... Line 314...
309
 
314
 
310
	free(buf.start);
315
	free(buf.start);
Line 327... Line 332...
327
void PreparePage() 
332
void PreparePage() 
328
{
333
{
329
	_dom dom;
334
	_dom dom;
330
	list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, kfont.size.pt+4);
335
	list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, kfont.size.pt+4);
331
	strcpy(#title, history.current()+strrchr(history.current(),'/'));
336
	strcpy(#title, history.current()+strrchr(history.current(),'/'));
332
	get_label_symbols_size(); //get font chars width, need to increase performance
-
 
333
	ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
337
	ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
334
	link.clear();
338
	link.clear();
Line 335... Line 339...
335
 
339
 
Line 339... Line 343...
339
 
343
 
Line 340... Line 344...
340
	kfont.ApplySmooth();
344
	kfont.ApplySmooth();
341
 
345
 
342
	DrawPage();
346
	DrawPage();
-
 
347
}
-
 
348
 
-
 
349
void ParseTxt()
-
 
350
{
-
 
351
_canvas canvas;
-
 
352
byte ch, zeroch=0;
-
 
353
dword bufoff, buflen, line_start, srch_pos;
-
 
354
int stroka_y=5, line_length=0;
-
 
355
 
-
 
356
	line_start=io.buffer_data;
-
 
357
	buflen = strlen(io.buffer_data) + io.buffer_data;
-
 
358
	for (bufoff=io.buffer_data; bufoff
-
 
359
	{
-
 
360
		ch = ESBYTE[bufoff];
-
 
361
		line_length += kfont_char_width[ch];
-
 
362
		if (line_length>=list.w-30) || (ch==10) {
-
 
363
			srch_pos = bufoff;
-
 
364
			loop()
-
 
365
			{
-
 
366
				if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
-
 
367
				if (srch_pos == line_start) break; //no white space found in whole line
-
 
368
				srch_pos--;
-
 
369
			}
-
 
370
			if (kfont.size.height) {
-
 
371
				ESBYTE[bufoff] >< zeroch; //set line end
-
 
372
				canvas.write_text(8, stroka_y, 0x000000, line_start);
-
 
373
				ESBYTE[bufoff] >< zeroch; //restore line
-
 
374
			}
-
 
375
			stroka_y += list.item_h;
-
 
376
			line_start = bufoff;
-
 
377
			line_length = 0;
-
 
378
		}
-
 
379
	}
-
 
380
	if (!kfont.size.height) {
-
 
381
		list.count = stroka_y/list.item_h+3;
-
 
382
		if (list.count < list.visible) list.count = list.visible;
-
 
383
		kfont.size.height = list.count+5*list.item_h;
-
 
384
		kfont.raw_size = 0;
-
 
385
		ParseTxt();
-
 
386
	} 
-
 
387
	else canvas.write_text(8, stroka_y, 0x000000, line_start);
343
}
388
}