Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6043 leency 1
 
2
{
3
	list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, label.size.pt+2);
6053 leency 4
	strcpy(#title, history.current()+strrchr(history.current(),'/'));
5
	//get font chars width, need to increase performance
6043 leency 6
	get_label_symbols_size();
6053 leency 7
	ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
8
	link.clear();
6058 leency 9
	if (strstri(io.buffer_data, "
6053 leency 10
		debugln("no  found");
6043 leency 11
		DrawProgress(STEP_2_COUNT_PAGE_HEIGHT);     ParceTxt(false);   //get page height to calculate buffer size
6053 leency 12
		DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true);    //draw text in buffer
13
	} else {
14
		debugln(" tag found");
6043 leency 15
		DrawProgress(STEP_2_COUNT_PAGE_HEIGHT);     ParceHtml(false);  //get page height to calculate buffer size
6053 leency 16
		// debugln("DONE STEP 2");
6375 guillem 17
		DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true);   //draw text in buffer
6053 leency 18
		// debugln("DONE STEP 3");
6375 guillem 19
	}
6053 leency 20
	strcat(#title, " - Aelia");
21
	DrawTitle(#title);
22
	DrawProgress(STEP_4_SMOOTH_FONT);           label.apply_smooth();
23
	DrawProgress(STEP_5_STOP);                  DrawPage();
24
}
6043 leency 25
26
 
27
{
28
byte ch, zeroch=0;
29
dword bufoff, buflen, line_start, srch_pos;
30
int stroka_y=5, line_length=0;
31
32
 
33
	buflen = strlen(io.buffer_data) + io.buffer_data;
34
	for (bufoff=io.buffer_data; bufoff
35
	{
36
		ch = ESBYTE[bufoff];
37
		line_length += char_width[ch];
38
		if (line_length>=list.w-30) || (ch==10) {
39
			srch_pos = bufoff;
40
			loop()
41
			{
42
				if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
43
				if (srch_pos == line_start) break; //no white space found in whole line
44
				srch_pos--;
45
			}
46
			if (draw==true) {
47
				ESBYTE[bufoff] >< zeroch; //set line end
48
				WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
6053 leency 49
				ESBYTE[bufoff] >< zeroch; //restore line
6043 leency 50
			}
51
			stroka_y += list.item_h;
52
			line_start = bufoff;
53
			line_length = 0;
54
		}
55
	}
56
	if (draw==false) {
57
		list.count = stroka_y/list.item_h+3;
6059 leency 58
		if (list.count < list.visible) list.count = list.visible;
6043 leency 59
		label.size.height = list.count+5*list.item_h;
6059 leency 60
		label.raw_size = 0;
6043 leency 61
	}
62
	if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
6053 leency 63
}
6043 leency 64
65
 
66
 
67
=                                                        =
68
=                        HTML                            =
69
=                                                        =
70
========================================================*/
71
72
 
6053 leency 73
#define HTML_PADDING_Y 5;
74
6043 leency 75
 
6053 leency 76
 
6043 leency 77
{
6375 guillem 78
dword DOM_start, DOM_end, DOM_len, DOM_pos, aux2;
79
int stroka_x = HTML_PADDING_X;
6053 leency 80
int stroka_y = HTML_PADDING_Y;
81
int size_pt_change = 0;
6372 cheptil 82
dword line_break;
6053 leency 83
byte ch, zeroch;
84
_text text;
6043 leency 85
_tag tag;
86
	debugln("-------START PARCING-------");
6375 guillem 87
	tag.clear();
6058 leency 88
	style.clear();
89
	/* Create DOM */
6043 leency 90
	debugln("creating DOM");
6053 leency 91
	DOM_len = strlen(io.buffer_data);
6216 leency 92
	DOM_start = malloc(DOM_len);
93
	DOM_end = DOM_start + DOM_len;
94
	strlcpy(DOM_start, io.buffer_data, DOM_len);
95
6043 leency 96
 
97
	debugln("starting DOM parce...");
6053 leency 98
	text.start = DOM_start;
6216 leency 99
	for (DOM_pos=DOM_start; DOM_pos
100
	{
6043 leency 101
		if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
6053 leency 102
		ch = ESBYTE[DOM_pos];
6043 leency 103
		if (ch=='<') {
104
			ESBYTE[DOM_pos] = '\0';
6053 leency 105
			tag.start = DOM_pos + 1;
6043 leency 106
			if (style.ignore) continue;
6053 leency 107
			if (tag.nameis("title")) {
108
				strcpy(#title, text.start);
109
				continue;
110
			}
111
			strtrim(text.start);
6059 leency 112
			// try to change the special symbols that may appear
6375 guillem 113
			text.fixSpecial();
114
115
 
6053 leency 116
			{
117
				zeroch = 0;
118
				for (line_break=tag.start-1; line_break>text.start; line_break--;)
119
				{
120
					ESBYTE[line_break] >< zeroch; //set line end
121
					if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
122
					ESBYTE[line_break] >< zeroch; //restore line
123
				}
124
				if (draw==true) {
125
					if (style.a) {
6058 leency 126
						link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
6372 cheptil 127
						label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
6058 leency 128
					}
129
					WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 130
				}
131
				stroka_x+=char_width[' '];
6152 leency 132
				ESBYTE[line_break] >< zeroch; //restore line
6053 leency 133
				text.start = line_break;
134
				stroka_x = HTML_PADDING_X;
135
				stroka_y += list.item_h;
136
			}
137
			if (draw==true) {
138
				if (style.a) {
6058 leency 139
					link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
6372 cheptil 140
					label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
6058 leency 141
				}
142
				WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 143
			}
144
			stroka_x+=char_width[' '];
6152 leency 145
			stroka_x += get_label_len(text.start);
6053 leency 146
		}
6043 leency 147
		if (ch=='>') {
148
			ESBYTE[DOM_pos] = '\0';
6053 leency 149
			text.start = DOM_pos + 1;
6043 leency 150
			tag.parce();
151
			if (tag.nameis("br"))
6059 leency 152
				|| (tag.nameis("p"))
153
				|| (tag.nameis("div"))
154
				|| (tag.nameis("tr")) {
155
				stroka_y+= list.item_h;
6053 leency 156
				stroka_x = HTML_PADDING_X;
157
				continue;
158
			}
159
			if 	(tag.nameis("h1")) || (tag.nameis("/h1")) ||
6370 cheptil 160
				(tag.nameis("h2")) || (tag.nameis("/h2")) ||
161
				(tag.nameis("h3")) || (tag.nameis("/h3")) {
162
				if (tag.nameis("h1")) {
163
					size_pt_change = 8;
164
				} else if (tag.nameis("/h1")) {
165
					size_pt_change = -8;
166
				} else if (tag.nameis("h2")) {
167
					size_pt_change = 6;
168
				} else if (tag.nameis("/h2")) {
169
					size_pt_change = -6;
170
				} else if (tag.nameis("h3")) {
171
					size_pt_change = 4;
172
				} else if (tag.nameis("/h3")) {
173
					size_pt_change = -4;
174
				}
175
				label.size.pt += size_pt_change;
176
				get_label_symbols_size();
6372 cheptil 177
				if (size_pt_change > 0) {
6370 cheptil 178
					stroka_y+= list.item_h;//что если будет очень длинная строка в теге?
6372 cheptil 179
				} else {//коммент выше и коммент ниже связаны
180
					stroka_y+= list.item_h - size_pt_change;//не очень понятна логика этого места
181
					size_pt_change = 0;
182
				}
6059 leency 183
				stroka_x = HTML_PADDING_X;
6370 cheptil 184
				continue;
185
			}
186
			if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
6053 leency 187
			if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
188
			if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
189
			if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
190
		}
6043 leency 191
	}
192
	if (draw==false) {
6053 leency 193
		list.count = stroka_y/list.item_h+3;
6059 leency 194
		if (list.count < list.visible) list.count = list.visible;
6053 leency 195
		label.size.height = list.count+5*list.item_h;
6059 leency 196
		label.raw_size = 0;
6053 leency 197
	}
198
	free(DOM_start);
6216 leency 199
	debugln("-------STOP PARCING--------");
6375 guillem 200
}
6043 leency 201