Subversion Repositories Kolibri OS

Rev

Rev 6378 | 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.ApplySmooth();
6803 leency 23
	DrawProgress(STEP_5_STOP);                  DrawPage();
6053 leency 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
	tag.clear();
6058 leency 87
	style.clear();
88
	/* Create DOM */
6043 leency 89
	debugln("creating DOM");
6053 leency 90
	DOM_len = strlen(io.buffer_data);
6216 leency 91
	DOM_start = malloc(DOM_len);
92
	DOM_end = DOM_start + DOM_len;
93
	strlcpy(DOM_start, io.buffer_data, DOM_len);
94
6043 leency 95
 
96
	debugln("starting DOM parce...");
6053 leency 97
	text.start = DOM_start;
6216 leency 98
	for (DOM_pos=DOM_start; DOM_pos
99
	{
6043 leency 100
		if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
6053 leency 101
		ch = ESBYTE[DOM_pos];
6043 leency 102
		if (ch=='<') {
103
			ESBYTE[DOM_pos] = '\0';
6053 leency 104
			tag.start = DOM_pos + 1;
6043 leency 105
			if (style.ignore) continue;
6053 leency 106
			if (tag.nameis("title")) {
107
				strcpy(#title, text.start);
108
				continue;
109
			}
110
			strtrim(text.start);
6059 leency 111
			// try to change the special symbols that may appear
6375 guillem 112
			text.fixSpecial(text.start);
6378 guillem 113
6375 guillem 114
 
6053 leency 115
			{
116
				zeroch = 0;
117
				for (line_break=tag.start-1; line_break>text.start; line_break--;)
118
				{
119
					ESBYTE[line_break] >< zeroch; //set line end
120
					if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
121
					ESBYTE[line_break] >< zeroch; //restore line
122
				}
123
				if (draw==true) {
124
					if (style.a) {
6058 leency 125
						link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
6372 cheptil 126
						label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
6058 leency 127
					}
128
					WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 129
				}
130
				stroka_x+=char_width[' '];
6152 leency 131
				ESBYTE[line_break] >< zeroch; //restore line
6053 leency 132
				text.start = line_break;
133
				stroka_x = HTML_PADDING_X;
134
				stroka_y += list.item_h;
135
			}
136
			if (draw==true) {
137
				if (style.a) {
6058 leency 138
					link.add(stroka_x,stroka_y + size_pt_change,get_label_len(text.start),list.item_h,text.start," ");
6372 cheptil 139
					label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
6058 leency 140
				}
141
				WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 142
			}
143
			stroka_x+=char_width[' '];
6152 leency 144
			stroka_x += get_label_len(text.start);
6053 leency 145
		}
6043 leency 146
		if (ch=='>') {
147
			ESBYTE[DOM_pos] = '\0';
6053 leency 148
			text.start = DOM_pos + 1;
6043 leency 149
			tag.parce();
150
			if (tag.nameis("br"))
6059 leency 151
				|| (tag.nameis("p"))
152
				|| (tag.nameis("div"))
153
				|| (tag.nameis("tr")) {
154
				stroka_y+= list.item_h;
6053 leency 155
				stroka_x = HTML_PADDING_X;
156
				continue;
157
			}
158
			if 	(tag.nameis("h1")) || (tag.nameis("/h1")) ||
6370 cheptil 159
				(tag.nameis("h2")) || (tag.nameis("/h2")) ||
160
				(tag.nameis("h3")) || (tag.nameis("/h3")) {
161
				if (tag.nameis("h1")) {
162
					size_pt_change = 8;
163
				} else if (tag.nameis("/h1")) {
164
					size_pt_change = -8;
165
				} else if (tag.nameis("h2")) {
166
					size_pt_change = 6;
167
				} else if (tag.nameis("/h2")) {
168
					size_pt_change = -6;
169
				} else if (tag.nameis("h3")) {
170
					size_pt_change = 4;
171
				} else if (tag.nameis("/h3")) {
172
					size_pt_change = -4;
173
				}
174
				label.size.pt += size_pt_change;
175
				get_label_symbols_size();
6372 cheptil 176
				if (size_pt_change > 0) {
6370 cheptil 177
					stroka_y+= list.item_h;//что если будет очень длинная строка в теге?
6372 cheptil 178
				} else {//коммент выше и коммент ниже связаны
179
					stroka_y+= list.item_h - size_pt_change;//не очень понятна логика этого места
180
					size_pt_change = 0;
181
				}
6059 leency 182
				stroka_x = HTML_PADDING_X;
6370 cheptil 183
				continue;
184
			}
185
			if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
6053 leency 186
			if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
187
			if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
188
			if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
189
		}
6043 leency 190
	}
191
	if (draw==false) {
6053 leency 192
		list.count = stroka_y/list.item_h+3;
6059 leency 193
		if (list.count < list.visible) list.count = list.visible;
6053 leency 194
		label.size.height = list.count+5*list.item_h;
6059 leency 195
		label.raw_size = 0;
6053 leency 196
	}
197
	free(DOM_start);
6216 leency 198
}
6043 leency 199