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