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