Subversion Repositories Kolibri OS

Rev

Rev 6053 | 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
		DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true);   //draw text in buffer
17
	}
18
	strcat(#title, " - Aelia");
19
	DrawTitle(#title);
20
	DrawProgress(STEP_4_SMOOTH_FONT);           label.apply_smooth();
21
	DrawProgress(STEP_5_STOP);                  DrawPage();
22
}
6043 leency 23
24
 
25
{
26
byte ch, zeroch=0;
27
dword bufoff, buflen, line_start, srch_pos;
28
int stroka_y=5, line_length=0;
29
30
 
31
	buflen = strlen(io.buffer_data) + io.buffer_data;
32
	for (bufoff=io.buffer_data; bufoff
33
	{
34
		ch = ESBYTE[bufoff];
35
		line_length += char_width[ch];
36
		if (line_length>=list.w-30) || (ch==10) {
37
			srch_pos = bufoff;
38
			loop()
39
			{
40
				if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
41
				if (srch_pos == line_start) break; //no white space found in whole line
42
				srch_pos--;
43
			}
44
			if (draw==true) {
45
				ESBYTE[bufoff] >< zeroch; //set line end
46
				WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
6053 leency 47
				ESBYTE[bufoff] >< zeroch; //restore line
6043 leency 48
			}
49
			stroka_y += list.item_h;
50
			line_start = bufoff;
51
			line_length = 0;
52
		}
53
	}
54
	if (draw==false) {
55
		list.count = stroka_y/list.item_h+2;
56
		if (list.count < list.visible) list.count = list.visible;
57
		label.size.height = list.count+1*list.item_h;
58
		label.raw_size = 0;
59
	}
60
	if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
6053 leency 61
}
6043 leency 62
63
 
64
 
65
=                                                        =
66
=                        HTML                            =
67
=                                                        =
68
========================================================*/
69
70
 
6053 leency 71
6043 leency 72
 
73
	dword start;
74
	dword end;
75
	dword len;
76
};
77
78
 
79
	bool b, u, i, s;
80
	bool h1, h2, h3, h4, h5, h6;
81
	bool a;
82
	bool pre;
83
	bool ignore;
6053 leency 84
	dword color;
85
	void clear();
6058 leency 86
} style;
6043 leency 87
88
 
6058 leency 89
{
90
	b=u=i=s=0;
91
	h1=h2=h3=h4=h5=h6=0;
92
	a=0;
93
	pre=0;
94
	ignore=0;
95
	color=0;
96
}
97
98
 
6053 leency 99
	dword start;
100
	int x, y;
101
};
102
103
 
6043 leency 104
	dword start;
105
	dword name;
106
	dword param[10];
107
	dword value[10];
108
	void parce();
109
	int nameis();
6053 leency 110
	void clear();
6058 leency 111
};
6043 leency 112
113
 
114
{
115
	dword o = name = start;
6053 leency 116
	while (ESBYTE[o]!=' ') && (ESBYTE[o]) o++; //searching for a space after tag name
117
	ESBYTE[o] = '\0';
118
	strlwr(name);
119
}
6043 leency 120
121
 
6053 leency 122
{
6043 leency 123
	if (name) && (strcmp(_in_tag_name, name)==0) return true;
6058 leency 124
	return false;
6053 leency 125
}
6043 leency 126
127
 
6058 leency 128
{
129
	start=name=0;
130
}
131
132
 
6053 leency 133
#define HTML_PADDING_Y 5;
134
6043 leency 135
 
6053 leency 136
 
6043 leency 137
{
138
int stroka_x = HTML_PADDING_X;
6053 leency 139
int stroka_y = HTML_PADDING_Y;
140
dword line_break;
141
byte ch, zeroch;
142
_DOM DOM;
6043 leency 143
_text text;
144
_tag tag;
145
dword DOM_pos;
146
147
 
6058 leency 148
	style.clear();
149
	/* Create DOM */
6043 leency 150
	debugln("creating DOM");
6053 leency 151
	DOM.len = strlen(io.buffer_data);
6043 leency 152
	DOM.start = malloc(DOM.len);
153
	DOM.end = DOM.start + DOM.len;
154
	strlcpy(DOM.start, io.buffer_data, DOM.len);
155
	//RemoveSpecialSymbols(DOM.start, DOM.len);
6058 leency 156
	//DOM.len = strlen(DOM.start);
157
6043 leency 158
 
159
	debugln("starting DOM parce...");
6053 leency 160
	text.start = DOM.start;
6058 leency 161
	for (DOM_pos=DOM.start; DOM_pos
6043 leency 162
	{
163
		if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
6053 leency 164
		ch = ESBYTE[DOM_pos];
6043 leency 165
		if (ch=='<') {
166
			ESBYTE[DOM_pos] = '\0';
6053 leency 167
			tag.start = DOM_pos + 1;
6043 leency 168
			if (style.ignore) continue;
6053 leency 169
			if (tag.nameis("title")) {
170
				strcpy(#title, text.start);
171
				continue;
172
			}
173
			while (get_label_len(text.start) + stroka_x + 30 > list.w)
174
			{
175
				zeroch = 0;
176
				for (line_break=tag.start-1; line_break>text.start; line_break--;)
177
				{
178
					ESBYTE[line_break] >< zeroch; //set line end
179
					if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
180
					ESBYTE[line_break] >< zeroch; //restore line
181
				}
182
				if (draw==true) {
183
					if (style.a) {
6058 leency 184
						link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");
185
						label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
186
					}
187
					WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 188
				}
189
				ESBYTE[line_break] >< zeroch; //restore line
190
				text.start = line_break;
191
				stroka_x = HTML_PADDING_X;
192
				stroka_y += list.item_h;
193
			}
194
			if (draw==true) {
195
				if (style.a) {
6058 leency 196
					link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");
197
					label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
198
				}
199
				WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 200
			}
201
			stroka_x += get_label_len(text.start);
202
		}
6043 leency 203
		if (ch=='>') {
204
			ESBYTE[DOM_pos] = '\0';
6053 leency 205
			text.start = DOM_pos + 1;
6043 leency 206
			tag.parce();
207
			if (tag.nameis("br")) || (tag.nameis("p")) || (tag.nameis("div")) || (tag.nameis("h1")) || (tag.nameis("h2")) {
6053 leency 208
				stroka_y+= list.item_h;
209
				stroka_x = HTML_PADDING_X;
210
				continue;
211
			}
212
			if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
213
			if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
214
			if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
215
			if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
216
		}
6043 leency 217
	}
218
	if (draw==false) {
6053 leency 219
		list.count = stroka_y/list.item_h+2;
220
		if (list.count < list.visible) list.count = list.visible;
221
		label.size.height = list.count+1*list.item_h;
222
		label.raw_size = 0;
223
	}
224
	free(DOM.start);
6043 leency 225
}
226