Subversion Repositories Kolibri OS

Rev

Rev 7285 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7285 Rev 7286
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;
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;
55
	bool ignore;
14
	bool ignore;
-
 
15
	bool body;
56
	dword color;
16
	dword color;
57
	void clear();
17
	void clear();
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;
66
	ignore=0;
26
	ignore=0;
67
	color=0;
27
	color=0;
-
 
28
	body=0;
68
}
29
}
69
 
30
 
70
/*========================================================
31
/*========================================================
71
=                                                        =
32
=                                                        =
72
=                         TAG                            =
33
=                         TAG                            =
73
=                                                        =
34
=                                                        =
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
};
84
 
49
 
85
void _tag::parse()
50
void _tag::parse()
86
{
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++;
-
 
68
 
87
	strlwr(name);
69
	strlwr(name);
-
 
70
 
-
 
71
	start = START;
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;
93
	return false;
77
	return false;
94
}
78
}
95
 
79
 
96
/*========================================================
80
/*========================================================
97
=                                                        =
81
=                                                        =
98
=                         DRAW                           =
82
=                         DRAW                           =
99
=                                                        =
83
=                                                        =
100
========================================================*/
84
========================================================*/
101
struct _draw
85
struct _draw
102
{
86
{
103
	dword x;
87
	dword x;
104
	dword y;
88
	dword y;
105
	void init();
89
	void init();
106
	void line_break();
90
	void line_break();
107
};
91
};
108
 
92
 
109
void _draw::init()
93
void _draw::init()
110
{
94
{
111
	x = HTML_PADDING_X;
95
	x = HTML_PADDING_X;
112
	y = HTML_PADDING_Y;
96
	y = HTML_PADDING_Y;
113
}
97
}
114
void _draw::line_break()
98
void _draw::line_break()
115
{
99
{
116
	y+= list.item_h;
100
	y+= list.item_h;
117
	x = HTML_PADDING_X;	
101
	x = HTML_PADDING_X;	
118
}
102
}
119
 
103
 
120
/*========================================================
104
/*========================================================
121
=                                                        =
105
=                                                        =
122
=                         BUF                            =
106
=                         BUF                            =
123
=                                                        =
107
=                                                        =
124
========================================================*/
108
========================================================*/
125
struct _buf
109
struct _buf
126
{
110
{
127
	dword pointer;
111
	dword pointer;
128
	dword len;
112
	dword len;
129
	dword start;
113
	dword start;
130
	dword end;
114
	dword end;
131
	void init();
115
	void init();
132
};
116
};
133
 
117
 
134
void _buf::init(dword _buf_pointer, _buf_len)
118
void _buf::init(dword _buf_pointer, _buf_len)
135
{
119
{
136
	pointer = _buf_pointer;
120
	pointer = _buf_pointer;
137
	len = _buf_len;
121
	len = _buf_len;
138
	start = malloc(len);
122
	start = malloc(len);
139
	end = start + len;
123
	end = start + len;
140
	strlcpy(start, pointer, len);	
124
	strlcpy(start, pointer, len);	
141
}
125
}
142
 
126
 
143
/*========================================================
127
/*========================================================
144
=                                                        =
128
=                                                        =
145
=                         TEXT                           =
129
=                         TEXT                           =
146
=                                                        =
130
=                                                        =
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
};
153
 
139
 
154
/*
140
/*
155
dword line_break;
141
dword line_break;
156
byte char_holder;
142
byte char_holder;
157
 
143
 
158
if (ESBYTE[buf.pos]==0x0A) {
144
if (ESBYTE[buf.pos]==0x0A) {
159
	if (style.pre) {
145
	if (style.pre) {
160
		draw.line_break();
146
		draw.line_break();
161
		continue;
147
		continue;
162
	}
148
	}
163
}
149
}
164
 
150
 
165
while (get_label_len(text.start) + draw.x + 30 > list.w)
151
while (get_label_len(text.start) + draw.x + 30 > list.w)
166
{
152
{
167
	for (line_break=tag.start-1; line_break>text.start; line_break--;)
153
	for (line_break=tag.start-1; line_break>text.start; line_break--;)
168
	{
154
	{
169
		char_holder = ESBYTE[line_break]; //set line end
155
		char_holder = ESBYTE[line_break]; //set line end
170
		ESBYTE[line_break] = '\0';
156
		ESBYTE[line_break] = '\0';
171
		if (get_label_len(text.start) + draw.x + 30 <= list.w) break;
157
		if (get_label_len(text.start) + draw.x + 30 <= list.w) break;
172
		ESBYTE[line_break] = char_holder; //restore line
158
		ESBYTE[line_break] = char_holder; //restore line
173
	}
159
	}
174
	if (draw_on) {
160
	if (draw_on) {
175
		if (style.a) {
161
		if (style.a) {
176
			link.add(draw.x,draw.y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
162
			link.add(draw.x,draw.y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
177
			label_draw_bar(draw.x, draw.y+kfont.size.pt+1, get_label_len(text.start), style.color);
163
			label_draw_bar(draw.x, draw.y+kfont.size.pt+1, get_label_len(text.start), style.color);
178
		}
164
		}
179
		WriteTextIntoBuf(draw.x, draw.y, style.color, text.start);
165
		WriteTextIntoBuf(draw.x, draw.y, style.color, text.start);
180
	}
166
	}
181
	draw.x+=char_width[' '];
167
	draw.x+=char_width[' '];
182
	ESBYTE[line_break] = char_holder; //restore line
168
	ESBYTE[line_break] = char_holder; //restore line
183
	text.start = line_break;
169
	text.start = line_break;
184
	draw.line_break();
170
	draw.line_break();
185
}
171
}
186
if (draw_on) {
172
if (draw_on) {
187
	if (style.a) {
173
	if (style.a) {
188
		link.add(draw.x,draw.y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");	
174
		link.add(draw.x,draw.y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");	
189
		label_draw_bar(draw.x, draw.y+kfont.size.pt+1, get_label_len(text.start), style.color);
175
		label_draw_bar(draw.x, draw.y+kfont.size.pt+1, get_label_len(text.start), style.color);
190
	}
176
	}
191
	WriteTextIntoBuf(draw.x, draw.y, style.color, text.start);
177
	WriteTextIntoBuf(draw.x, draw.y, style.color, text.start);
192
}
178
}
193
draw.x += char_width[' '];
179
draw.x += char_width[' '];
194
draw.x += get_label_len(text.start);
180
draw.x += get_label_len(text.start);
195
*/
181
*/
196
 
182
 
197
 
183
 
198
/*========================================================
184
/*========================================================
199
=                                                        =
185
=                                                        =
200
=                         DOM                            =
186
=                         DOM                            =
201
=                                                        =
187
=                                                        =
202
========================================================*/
188
========================================================*/
203
struct _dom
189
struct _dom
204
{
190
{
205
	_tag tag;
191
	_tag tag;
206
	_style style;
192
	_style style;
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
};
216
 
202
 
217
void _dom::init()
203
void _dom::init()
218
{
204
{
219
	style.clear();
205
	style.clear();
220
	draw.init();
206
	draw.init();
221
	buf.init(io.buffer_data, strlen(io.buffer_data));
207
	buf.init(io.buffer_data, strlen(io.buffer_data));
222
}
208
}
223
 
209
 
224
void _dom::set_style()
210
void _dom::set_style()
225
{
211
{
226
	/*
-
 
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;
232
	if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
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;
-
 
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();
239
		return;
228
		return;
240
	}
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
	}
-
 
240
 
241
 
241
	/*
242
	if (dom.tag.nameis("title")) {
242
	if (tag.nameis("title")) {
243
		strcpy(#title, text.start);
243
		strcpy(#title, text.start);
244
		strcat(#title, " - Aelia");
244
		strcat(#title, " - Aelia");
245
		DrawTitle(#title);
245
		DrawTitle(#title);
246
	}
246
	}
-
 
247
 
-
 
248
 
247
 
249
 
248
	if 	(tag.nameis("h1")) || (tag.nameis("/h1")) ||
250
	if 	(tag.nameis("h1")) || (tag.nameis("/h1")) ||
249
		(tag.nameis("h2")) || (tag.nameis("/h2")) ||
251
		(tag.nameis("h2")) || (tag.nameis("/h2")) ||
250
		(tag.nameis("h3")) || (tag.nameis("/h3")) {
252
		(tag.nameis("h3")) || (tag.nameis("/h3")) {
251
		if (tag.nameis("h1")) {
253
		if (tag.nameis("h1")) {
252
			text.size_pt_change = 8;
254
			text.size_pt_change = 8;
253
		} else if (tag.nameis("/h1")) {
255
		} else if (tag.nameis("/h1")) {
254
			text.size_pt_change = -8;
256
			text.size_pt_change = -8;
255
		} else if (tag.nameis("h2")) {
257
		} else if (tag.nameis("h2")) {
256
			text.size_pt_change = 6;
258
			text.size_pt_change = 6;
257
		} else if (tag.nameis("/h2")) {
259
		} else if (tag.nameis("/h2")) {
258
			text.size_pt_change = -6;
260
			text.size_pt_change = -6;
259
		} else if (tag.nameis("h3")) {
261
		} else if (tag.nameis("h3")) {
260
			text.size_pt_change = 4;
262
			text.size_pt_change = 4;
261
		} else if (tag.nameis("/h3")) {
263
		} else if (tag.nameis("/h3")) {
262
			text.size_pt_change = -4;
264
			text.size_pt_change = -4;
263
		}
265
		}
264
		kfont.size.pt += text.size_pt_change;
266
		kfont.size.pt += text.size_pt_change;
265
		get_label_symbols_size();
267
		get_label_symbols_size();
266
		if (text.size_pt_change > 0) {
268
		if (text.size_pt_change > 0) {
267
			draw.y+= list.item_h;//что если будет очень длинная строка в теге?
269
			draw.y+= list.item_h;//что если будет очень длинная строка в теге?
268
		} else {//коммент выше и коммент ниже связаны
270
		} else {//коммент выше и коммент ниже связаны
269
			draw.y+= list.item_h - text.size_pt_change;//не очень понятна логика этого места
271
			draw.y+= list.item_h - text.size_pt_change;//не очень понятна логика этого места
270
			text.size_pt_change = 0;
272
			text.size_pt_change = 0;
271
		}
273
		}
272
		draw.x = HTML_PADDING_X;
274
		draw.x = HTML_PADDING_X;
273
		return;					
275
		return;					
274
	}
276
	}
275
	*/
277
	*/
276
}
278
}
277
 
279
 
278
void _dom::apply_text()
280
void _dom::apply_text()
279
{
281
{
-
 
282
	if (kfont.size.height) && (style.body) {
-
 
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);
281
	draw.line_break();
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
		}
-
 
288
	}
282
}
289
}
283
 
290
 
284
void _dom::parse()
291
void _dom::parse()
285
{
292
{
286
	dword i;
293
	dword i;
287
	init();
294
	init();
288
 
295
 
289
	text.start = buf.start;
296
	text.start = buf.start;
290
	tag.start = buf.start;
297
	tag.start = buf.start;
291
	for ( i=buf.start; i
298
	for ( i=buf.start; i
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
	}
309
 
314
 
310
	free(buf.start);
315
	free(buf.start);
311
	if (!kfont.size.height) {
316
	if (!kfont.size.height) {
312
		list.count = draw.y/list.item_h+3;
317
		list.count = draw.y/list.item_h+3;
313
		if (list.count < list.visible) list.count = list.visible;
318
		if (list.count < list.visible) list.count = list.visible;
314
		kfont.size.height = list.count+5*list.item_h;
319
		kfont.size.height = list.count+5*list.item_h;
315
		kfont.raw_size = 0;
320
		kfont.raw_size = 0;
316
		parse();
321
		parse();
317
	}
322
	}
318
}
323
}
319
 
324
 
320
 
325
 
321
 
326
 
322
/*========================================================
327
/*========================================================
323
=                                                        =
328
=                                                        =
324
=                       PREPARE                          =
329
=                       PREPARE                          =
325
=                                                        =
330
=                                                        =
326
========================================================*/
331
========================================================*/
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();
335
 
339
 
336
	kfont.size.height = 0;
340
	kfont.size.height = 0;
337
 
341
 
338
	if ( strstri(io.buffer_data, "
342
	if ( strstri(io.buffer_data, "
339
 
343
 
340
	kfont.ApplySmooth();
344
	kfont.ApplySmooth();
341
 
345
 
342
	DrawPage();
346
	DrawPage();
343
}
347
}
344
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);
-
 
388
}
-
 
389
345
390