Subversion Repositories Kolibri OS

Rev

Rev 6216 | 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+3;
6059 leency 56
		if (list.count < list.visible) list.count = list.visible;
6043 leency 57
		label.size.height = list.count+5*list.item_h;
6059 leency 58
		label.raw_size = 0;
6043 leency 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
#define HTML_PADDING_Y 5;
72
6043 leency 73
 
6053 leency 74
 
6043 leency 75
{
76
dword DOM_start, DOM_end, DOM_len, DOM_pos;
6216 leency 77
int stroka_x = HTML_PADDING_X;
6053 leency 78
int stroka_y = HTML_PADDING_Y;
79
int size_pt_change;
6370 cheptil 80
dword line_break;
6053 leency 81
byte ch, zeroch;
82
_text text;
6043 leency 83
_tag tag;
84
85
 
6058 leency 86
	style.clear();
87
	/* Create DOM */
6043 leency 88
	debugln("creating DOM");
6053 leency 89
	DOM_len = strlen(io.buffer_data);
6216 leency 90
	DOM_start = malloc(DOM_len);
91
	DOM_end = DOM_start + DOM_len;
92
	strlcpy(DOM_start, io.buffer_data, DOM_len);
93
6043 leency 94
 
95
	debugln("starting DOM parce...");
6053 leency 96
	text.start = DOM_start;
6216 leency 97
	for (DOM_pos=DOM_start; DOM_pos
98
	{
6043 leency 99
		if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
6053 leency 100
		ch = ESBYTE[DOM_pos];
6043 leency 101
		if (ch=='<') {
102
			ESBYTE[DOM_pos] = '\0';
6053 leency 103
			tag.start = DOM_pos + 1;
6043 leency 104
			if (style.ignore) continue;
6053 leency 105
			if (tag.nameis("title")) {
106
				strcpy(#title, text.start);
107
				continue;
108
			}
109
			strtrim(text.start);
6059 leency 110
			while (get_label_len(text.start) + stroka_x + 30 > list.w)
6053 leency 111
			{
112
				zeroch = 0;
113
				for (line_break=tag.start-1; line_break>text.start; line_break--;)
114
				{
115
					ESBYTE[line_break] >< zeroch; //set line end
116
					if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
117
					ESBYTE[line_break] >< zeroch; //restore line
118
				}
119
				if (draw==true) {
120
					if (style.a) {
6058 leency 121
						link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");
122
						label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
123
					}
124
					WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 125
				}
126
				stroka_x+=char_width[' '];
6152 leency 127
				ESBYTE[line_break] >< zeroch; //restore line
6053 leency 128
				text.start = line_break;
129
				stroka_x = HTML_PADDING_X;
130
				stroka_y += list.item_h;
131
			}
132
			if (draw==true) {
133
				if (style.a) {
6058 leency 134
					link.add(stroka_x,stroka_y,get_label_len(text.start),list.item_h,text.start," ");
135
					label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
136
				}
137
				WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
6053 leency 138
			}
139
			stroka_x+=char_width[' '];
6152 leency 140
			stroka_x += get_label_len(text.start);
6053 leency 141
		}
6043 leency 142
		if (ch=='>') {
143
			ESBYTE[DOM_pos] = '\0';
6053 leency 144
			text.start = DOM_pos + 1;
6043 leency 145
			tag.parce();
146
			if (tag.nameis("br"))
6059 leency 147
				|| (tag.nameis("p"))
148
				|| (tag.nameis("div"))
149
				|| (tag.nameis("tr")) {
150
				stroka_y+= list.item_h;
6053 leency 151
				stroka_x = HTML_PADDING_X;
152
				continue;
153
			}
154
			if 	(tag.nameis("h1")) || (tag.nameis("/h1")) ||
6370 cheptil 155
				(tag.nameis("h2")) || (tag.nameis("/h2")) ||
156
				(tag.nameis("h3")) || (tag.nameis("/h3")) {
157
				if (tag.nameis("h1")) {
158
					size_pt_change = 8;
159
				} else if (tag.nameis("/h1")) {
160
					size_pt_change = -8;
161
				} else if (tag.nameis("h2")) {
162
					size_pt_change = 6;
163
				} else if (tag.nameis("/h2")) {
164
					size_pt_change = -6;
165
				} else if (tag.nameis("h3")) {
166
					size_pt_change = 4;
167
				} else if (tag.nameis("/h3")) {
168
					size_pt_change = -4;
169
				}
170
				label.size.pt += size_pt_change;
171
				if (size_pt_change > 0) {
172
					stroka_y+= list.item_h;
6059 leency 173
				} else {
6370 cheptil 174
					stroka_y+= list.item_h - size_pt_change;
175
				}
6059 leency 176
				stroka_x = HTML_PADDING_X;
6370 cheptil 177
				continue;
178
			}
179
			if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
6053 leency 180
			if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
181
			if (tag.nameis("a"))  { style.a = true;  style.color=0x0000FF; }
182
			if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
183
		}
6043 leency 184
	}
185
	if (draw==false) {
6053 leency 186
		list.count = stroka_y/list.item_h+3;
6059 leency 187
		if (list.count < list.visible) list.count = list.visible;
6053 leency 188
		label.size.height = list.count+5*list.item_h;
6059 leency 189
		label.raw_size = 0;
6053 leency 190
	}
191
	free(DOM_start);
6216 leency 192
}
6043 leency 193