Rev 6043 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6043 | Rev 6053 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | char char_width[255]; |
- | |
Line 2... | Line 1... | ||
2 | 1 | void PreparePage() |
|
3 | void PreparePage() |
2 | { |
4 | { |
- | |
5 | int i; |
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(),'/')); |
|
6 | list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, label.size.pt+1); |
5 | //get font chars width, need to increase performance |
7 | //get font chars width, need to increase performance |
- | |
8 | //if (strstri(io.buffer_data, "")==-1) { |
- | |
9 | debugln("no found"); |
6 | get_label_symbols_size(); |
10 | label.changeSIZE(); |
- | |
11 | for (i=0; i<256; i++) char_width[i] = label.symbol_size(i); |
7 | ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
- | 8 | if (strstri(io.buffer_data, " |
|
- | 9 | debugln("no found"); |
|
12 | ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
10 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceTxt(false); //get page height to calculate buffer size |
13 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceTxt(false); //get page height to calculate buffer size |
11 | DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true); //draw text in buffer |
14 | DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true); //draw text in buffer |
- | |
15 | DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth(); |
- | |
16 | DrawProgress(STEP_5_STOP); DrawPage(); |
- | |
17 | /*} |
12 | } else { |
18 | else { |
13 | debugln(" tag found"); |
19 | debugln(" tag found"); |
- | |
20 | label.changeSIZE(); |
- | |
21 | for (i=0; i<256; i++) char_width[i] = label.symbol_size(i); |
- | |
22 | ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
14 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceHtml(false); //get page height to calculate buffer size |
23 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceHtml(false); //get page height to calculate buffer size |
15 | DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true); //draw text in buffer |
- | 16 | } |
|
- | 17 | strcat(#title, " - Aelia"); |
|
- | 18 | DrawTitle(#title); |
|
24 | DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true); //draw text in buffer |
19 | DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth(); |
25 | DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth(); |
20 | DrawProgress(STEP_5_STOP); DrawPage(); |
26 | DrawProgress(STEP_5_STOP); DrawPage(); |
- | |
27 | }*/ |
21 | } |
Line 28... | Line 22... | ||
28 | } |
22 | |
29 | 23 | void ParceTxt(byte draw) |
|
30 | void ParceTxt(byte draw) |
24 | { |
Line 47... | Line 41... | ||
47 | if (srch_pos == line_start) break; //no white space found in whole line |
41 | srch_pos--; |
48 | srch_pos--; |
42 | } |
49 | } |
43 | if (draw==true) { |
50 | if (draw==true) { |
44 | ESBYTE[bufoff] >< zeroch; //set line end |
51 | ESBYTE[bufoff] >< zeroch; //set line end |
45 | WriteTextIntoBuf(8, stroka_y, 0x000000, line_start); |
52 | label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start); |
46 | ESBYTE[bufoff] >< zeroch; //restore line |
53 | ESBYTE[bufoff] >< zeroch; //restore line |
47 | } |
54 | DrawProgressWhileDrawing(bufoff, buflen); |
- | |
55 | if (stroka_y/list.item_h-list.first==list.visible) DrawPage(); |
- | |
56 | } |
48 | stroka_y += list.item_h; |
57 | stroka_y += list.item_h; |
49 | line_start = bufoff; |
58 | line_start = bufoff; |
50 | line_length = 0; |
59 | line_length = 0; |
51 | } |
60 | } |
52 | } |
Line 63... | Line 55... | ||
63 | list.count = stroka_y/list.item_h+2; |
55 | if (list.count < list.visible) list.count = list.visible; |
64 | if (list.count < list.visible) list.count = list.visible; |
56 | label.size.height = list.count+1*list.item_h; |
65 | label.size.height = list.count+1*list.item_h; |
57 | label.raw_size = 0; |
66 | label.raw_size = 0; |
58 | } |
67 | } |
59 | if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start); |
68 | if (draw==true) label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start); |
60 | } |
69 | } |
61 | |
Line 70... | Line 62... | ||
70 | 62 | ||
71 | 63 | /*======================================================== |
|
72 | /*======================================================== |
64 | = = |
73 | = = |
65 | = HTML = |
74 | = HTML = |
66 | = = |
Line 75... | Line -... | ||
75 | = = |
- | |
76 | ========================================================*/ |
- | |
77 | - | ||
78 | /* |
- | |
79 | HTML parcer tags: |
- | |
80 | 67 | ========================================================*/ |
|
81 | - | ||
82 | - | ||
83 | - | ||
84 |
|
- | |
85 | - | ||
86 | - | ||
Line 87... | Line 68... | ||
87 | 68 | ||
88 | 69 | /* |
|
89 | */ |
70 | |
90 | 71 | struct _DOM { |
|
Line 97... | Line 78... | ||
97 | struct _style { |
78 | bool b, u, i, s; |
98 | bool b, u, i, s; |
79 | bool h1, h2, h3, h4, h5, h6; |
99 | bool h1, h2, h3, h4, h5, h6; |
80 | bool a; |
100 | bool a; |
81 | bool pre; |
101 | bool pre; |
82 | bool ignore; |
102 | bool title; |
83 | dword color; |
103 | bool br; |
84 | } style; |
104 | } style; |
85 | |
Line -... | Line 86... | ||
- | 86 | struct _text { |
|
- | 87 | dword start; |
|
- | 88 | int x, y; |
|
- | 89 | }; |
|
- | 90 | ||
105 | 91 | struct _tag { |
|
106 | struct _tag { |
92 | dword start; |
107 | dword start; |
93 | dword name; |
108 | dword name; |
94 | dword param[10]; |
109 | dword param[10]; |
95 | dword value[10]; |
110 | dword value[10]; |
96 | void parce(); |
111 | void parce(); |
97 | int nameis(); |
112 | void get_param_value(); |
98 | }; |
Line 113... | Line 99... | ||
113 | }; |
99 | |
114 | 100 | void _tag::parce() |
|
115 | void _tag::parce() |
101 | { |
116 | { |
102 | dword o = name = start; |
117 | bool closed_status = false; |
- | |
118 | if (start) debugln(start); |
103 | while (ESBYTE[o]!=' ') && (ESBYTE[o]) o++; //searching for a space after tag name |
119 | /* |
104 | ESBYTE[o] = '\0'; |
120 | if (strncmp(start, "/", 1)==0) { |
- | |
121 | start++; |
- | |
122 | closed_status = true; |
- | |
123 | } |
- | |
124 | if (!strcmp(start, "title")) style.title = closed_status; |
- | |
125 | if (!strcmp(start, "br")) style.br = closed_status; |
105 | strlwr(name); |
Line 126... | Line -... | ||
126 | */ |
- | |
127 | } |
- | |
128 | - | ||
129 | struct _text { |
- | |
130 | dword start; |
- | |
131 | int x, y; |
- | |
132 | void draw(); |
106 | } |
133 | }; |
107 | |
134 | - | ||
135 | void _text::draw() |
- | |
136 | { |
- | |
137 | if (start) debugln(start); |
108 | int _tag::nameis(dword _in_tag_name) |
138 | /* |
- | |
139 | if (style.title) { |
- | |
140 | strlcpy(#title, start, sizeof(title)); |
- | |
141 | DrawTitle(#title); |
- | |
142 | return; |
- | |
143 | } |
109 | { |
144 | if (style.br) { |
- | |
145 | y += list.item_h; |
- | |
146 | style.br = false; |
110 | if (strcmp(_in_tag_name, name)==0) return true; |
Line -... | Line 111... | ||
- | 111 | return false; |
|
- | 112 | } |
|
- | 113 | ||
Line 147... | Line 114... | ||
147 | } |
114 | #define HTML_PADDING_X 8; |
148 | */ |
115 | #define HTML_PADDING_Y 5; |
- | 116 | ||
- | 117 | ||
- | 118 | void ParceHtml(byte draw) |
|
149 | } |
119 | { |
150 | 120 | int stroka_x = HTML_PADDING_X; |
|
151 | 121 | int stroka_y = HTML_PADDING_Y; |
|
152 | void ParceHtml(byte draw) |
122 | dword line_break; |
153 | { |
123 | byte ch, zeroch; |
Line 154... | Line 124... | ||
154 | byte ch; |
124 | _DOM DOM; |
155 | _DOM DOM; |
125 | _text text; |
156 | _text text; |
126 | _tag tag; |
157 | _tag tag; |
127 | dword DOM_pos; |
158 | dword DOM_pos; |
128 | |
159 | 129 | /* Create DOM */ |
|
Line 160... | Line 130... | ||
160 | /* Create DOM */ |
130 | debugln("creating DOM"); |
- | 131 | DOM.len = strlen(io.buffer_data); |
|
161 | debugln("starting DOM parce"); |
132 | DOM.start = malloc(DOM.len); |
162 | DOM.len = strlen(io.buffer_data); |
133 | DOM.end = DOM.start + DOM.len; |
163 | DOM.start = malloc(DOM.len); |
134 | strlcpy(DOM.start, io.buffer_data, DOM.len); |
- | 135 | ||
164 | DOM.end = DOM.start + DOM.len; |
136 | /* Parce DOM */ |
- | 137 | debugln("starting DOM parce..."); |
|
165 | strlcpy(DOM.start, io.buffer_data, DOM.len); |
138 | text.start = DOM_pos; |
166 | 139 | for (DOM_pos=DOM.start; DOM_pos |
|
167 | /* Parce DOM */ |
140 | { |
- | 141 | if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' '; |
|
- | 142 | ch = ESBYTE[DOM_pos]; |
|
- | 143 | //debugch(ch); |
|
- | 144 | if (ch=='<') { |
|
- | 145 | ESBYTE[DOM_pos] = '\0'; |
|
- | 146 | tag.start = DOM_pos + 1; |
|
- | 147 | if (style.ignore) continue; |
|
- | 148 | if (tag.nameis("title")) { |
|
168 | text.start = DOM_pos; |
149 | strcpy(#title, text.start); |
- | 150 | continue; |
|
- | 151 | } |
|
- | 152 | while (get_label_len(text.start) + stroka_x + 30 > list.w) |
|
- | 153 | { |
|
- | 154 | //debugln("long line cut"); |
|
- | 155 | zeroch = 0; |
|
- | 156 | for (line_break=tag.start-1; line_break>text.start; line_break--;) |
|
- | 157 | { |
|
- | 158 | ESBYTE[line_break] >< zeroch; //set line end |
|
- | 159 | if (get_label_len(text.start) + stroka_x + 30 <= list.w) break; |
|
- | 160 | ESBYTE[line_break] >< zeroch; //restore line |
|
- | 161 | } |
|
- | 162 | if (draw==true) { |
|
- | 163 | if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color); |
|
- | 164 | WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start); |
|
- | 165 | } |
|
- | 166 | ESBYTE[line_break] >< zeroch; //restore line |
|
- | 167 | text.start = line_break; |
|
- | 168 | stroka_x = HTML_PADDING_X; |
|
- | 169 | stroka_y += list.item_h; |
|
169 | for (DOM_pos=DOM.start; DOM_pos |
170 | } |
170 | { |
171 | if (draw==true) { |
171 | ch = ESBYTE[DOM_pos]; |
172 | if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color); |
172 | if (ch=='<') { |
173 | WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start); |
173 | ESBYTE[DOM_pos] = NULL; |
174 | } |
- | 175 | stroka_x += get_label_len(text.start); |
|
- | 176 | } |
|
- | 177 | if (ch=='>') { |
|
- | 178 | ESBYTE[DOM_pos] = '\0'; |
|
- | 179 | text.start = DOM_pos + 1; |
|
- | 180 | tag.parce(); |
|
- | 181 | if (tag.nameis("br")) || (tag.nameis("p")) || (tag.nameis("div")) || (tag.nameis("h1")) || (tag.nameis("h2")) { |
|
- | 182 | stroka_y+= list.item_h; |
|
- | 183 | stroka_x = HTML_PADDING_X; |
|
174 | tag.start = DOM_pos + 1; |
184 | continue; |
175 | text.draw(); |
185 | } |
- | 186 | if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true; |
|
- | 187 | if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false; |
|
- | 188 | if (tag.nameis("a")) { style.a = true; style.color=0x0000FF; } |
|
- | 189 | if (tag.nameis("/a")) { style.a = false; style.color=0x000000; } |
|
- | 190 | } |
|
- | 191 | } |
|
176 | } |
192 | if (draw==false) { |
177 | if (ch=='>') { |
- | |
178 | ESBYTE[DOM_pos] = NULL; |
193 | list.count = stroka_y/list.item_h+2; |
179 | text.start = DOM_pos + 1; |
194 | if (list.count < list.visible) list.count = list.visible; |