Rev 8491 | Rev 8499 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8439 | leency | 1 | void TWebBrowser::SetStyle() |
2 | { |
||
8444 | leency | 3 | if (tag.get_value_of("name")) || (tag.get_value_of("id")) { |
8439 | leency | 4 | anchors.add(tag.value, draw_y); |
5 | if (anchors.current) && (streq(tag.value, #anchors.current+1)) { |
||
6 | list.first = draw_y; |
||
7 | anchors.current = NULL; |
||
8 | } |
||
9 | } |
||
10 | if (tag.is("a")) { tag_a(); return; } |
||
11 | if (tag.is("p")) { tag_p(); return; } |
||
12 | if (tag.is("img")) { tag_img(); return; } |
||
13 | if (tag.is("div")) { tag_div(); return; } |
||
14 | if (tag.is("br")) { NewLine(); return; } |
||
15 | if (tag.is("header")) { NewLine(); return; } |
||
16 | if (tag.is("article")) { NewLine(); return; } |
||
17 | if (tag.is("footer")) { NewLine(); return; } |
||
18 | if (tag.is("figure")) { NewLine(); return; } |
||
19 | if (tag.is("w:p")) { NewLine(); return; } |
||
8462 | leency | 20 | if (tag.is("b")) { style.b = tag.opened; return; } |
21 | if (tag.is("strong")) { style.b = tag.opened; return; } |
||
22 | if (tag.is("big")) { style.b = tag.opened; return; } |
||
23 | if (tag.is("w:b")) { style.b = tag.opened; return; } |
||
24 | if (tag.is("u")) { style.u = tag.opened; return; } |
||
25 | if (tag.is("ins")) { style.u = tag.opened; return; } |
||
26 | if (tag.is("s")) { style.s = tag.opened; return; } |
||
27 | if (tag.is("strike")) { style.s = tag.opened; return; } |
||
28 | if (tag.is("del")) { style.s = tag.opened; return; } |
||
29 | if (tag.is("pre")) { style.pre = tag.opened; return; } |
||
30 | if (tag.is("blockquote")) { style.blq = tag.opened; return; } |
||
31 | if (tag.is("button")) { style.button = tag.opened; return; } |
||
8439 | leency | 32 | if (tag.is("dl")) { if (tag.opened) NewLine(); return; } |
33 | if (tag.is("w:r")) { if (!tag.opened) style.b = false; return; } |
||
34 | if (tag.is("h1")) { tag_h1234_caption(); return; } |
||
35 | if (tag.is("h2")) { tag_h1234_caption(); return; } |
||
36 | if (tag.is("h3")) { tag_h1234_caption(); return; } |
||
37 | if (tag.is("h4")) { tag_h1234_caption(); return; } |
||
38 | if (tag.is("font")) { tag_font(); return; } |
||
39 | if (tag.is("dt")) { tag_ol_ul_dt(); return; } |
||
40 | if (tag.is("ul")) { tag_ol_ul_dt(); return; } |
||
41 | if (tag.is("ol")) { tag_ol_ul_dt(); return; } |
||
42 | if (tag.is("li")) { tag_li(); return; } |
||
43 | if (tag.is("q")) { tag_q(); return; } |
||
44 | if (tag.is("hr")) { tag_hr(); return; } |
||
45 | if (tag.is("meta")) { tag_meta_xml(); return; } |
||
46 | if (tag.is("?xml")) { tag_meta_xml(); return; } |
||
47 | if (tag.is("code")) { tag_code(); return; } |
||
48 | if (tag.is("iframe")) { tag_iframe(); return; } |
||
49 | if (tag.is("caption")) { tag_h1234_caption(); return; } |
||
50 | if (tag.is("title")) { tag_title(); return; } |
||
51 | if (tag.is("body")) { tag_body(); return; } |
||
52 | if (tag.is("html")) { t_html = tag.opened; return; } |
||
8462 | leency | 53 | |
8491 | leency | 54 | if (tag.is("table")) { tag_table(); return; } |
55 | if (tag.is("tr")) { if (tag.opened) NewLine(); return; } //temp |
||
8490 | leency | 56 | //if (tag.is("tr")) { tag_tr(); return; } |
8462 | leency | 57 | //if (tag.is("td")) { tag_td(); return; } |
8439 | leency | 58 | } |
59 | |||
60 | void TWebBrowser::tag_p() |
||
61 | { |
||
62 | IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return; |
||
63 | NewLine(); |
||
64 | } |
||
65 | |||
66 | void TWebBrowser::tag_title() |
||
67 | { |
||
68 | style.title = tag.opened; |
||
69 | if (!tag.opened) DrawTitle(#header); |
||
70 | } |
||
71 | |||
72 | void TWebBrowser::tag_font() |
||
73 | { |
||
74 | style.font = tag.opened; |
||
75 | if (tag.opened) |
||
76 | { |
||
8451 | leency | 77 | if (tag.get_value_of("bg")) { |
78 | bg_colors.add(GetColor(tag.value)); |
||
79 | } else { |
||
80 | bg_colors.add(bg_colors.get_last()); |
||
81 | } |
||
8444 | leency | 82 | if (tag.get_value_of("color")) { |
8439 | leency | 83 | text_colors.add(GetColor(tag.value)); |
84 | } else { |
||
85 | text_colors.add(text_colors.get_last()); |
||
86 | } |
||
87 | } |
||
8451 | leency | 88 | else { |
89 | text_colors.pop(); |
||
90 | bg_colors.pop(); |
||
91 | } |
||
8439 | leency | 92 | } |
93 | |||
94 | void TWebBrowser::tag_div() |
||
95 | { |
||
96 | if (streq(#tag.prior,"div")) && (tag.opened) return; |
||
8490 | leency | 97 | if (streq(#tag.prior,"td")) return; |
98 | //if (streq(#tag.prior,"div")) return; |
||
8439 | leency | 99 | if (!tag.opened) && (style.font) text_colors.pop(); |
100 | NewLine(); |
||
101 | } |
||
102 | |||
103 | void TWebBrowser::tag_iframe() |
||
104 | { |
||
8444 | leency | 105 | if (tag.get_value_of("src")) { |
8439 | leency | 106 | NewLine(); |
8492 | leency | 107 | strcpy(#linebuf, "IFRAME: "); |
8491 | leency | 108 | RenderTextbuf(); |
8439 | leency | 109 | link=true; |
110 | links.add_link(tag.value); |
||
8492 | leency | 111 | strncpy(#linebuf, tag.value, sizeof(TWebBrowser.linebuf)-1); |
8491 | leency | 112 | RenderTextbuf(); |
8439 | leency | 113 | link=false; |
114 | NewLine(); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | void TWebBrowser::tag_a() |
||
119 | { |
||
120 | if (tag.opened) |
||
121 | { |
||
8444 | leency | 122 | if (tag.get_value_of("href")) && (!strstr(tag.value,"javascript:")) |
8439 | leency | 123 | { |
124 | link = true; |
||
125 | links.add_link(tag.value); |
||
126 | } |
||
127 | } else { |
||
128 | link = false; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | void TWebBrowser::tag_meta_xml() |
||
133 | { |
||
8444 | leency | 134 | if (custom_encoding == -1) if (tag.get_value_of("charset")) |
135 | || (tag.get_value_of("content")) || (tag.get_value_of("encoding")) |
||
8439 | leency | 136 | { |
137 | EDX = strrchr(tag.value, '=') + tag.value; //search in content= |
||
138 | if (ESBYTE[EDX] == '"') EDX++; |
||
139 | strlwr(EDX); |
||
8492 | leency | 140 | EAX = get_encoding_type_by_name(EDX); |
141 | if (EAX!=-1) ChangeEncoding(EAX); |
||
8439 | leency | 142 | } |
8444 | leency | 143 | if (streq(tag.get_value_of("http-equiv"), "refresh")) && (tag.get_value_of("content")) { |
144 | if (tag.value = strstri(tag.value, "url")) strcpy(#redirect, tag.value); |
||
8439 | leency | 145 | } |
146 | } |
||
147 | |||
8492 | leency | 148 | signed int get_encoding_type_by_name(dword name) |
149 | { |
||
150 | EDX = name; |
||
151 | if (streqrp(EDX,"utf-8")) || (streqrp(EDX,"utf8")) return CH_UTF8; |
||
152 | else if (streqrp(EDX,"windows-1251")) || (streqrp(EDX,"windows1251")) return CH_CP1251; |
||
153 | else if (streqrp(EDX,"dos")) || (streqrp(EDX,"cp-866")) return CH_CP866; |
||
154 | else if (streqrp(EDX,"iso-8859-5")) || (streqrp(EDX,"iso8859-5")) return CH_ISO8859_5; |
||
155 | else if (streqrp(EDX,"koi8-r")) || (streqrp(EDX,"koi8-u")) return CH_KOI8; |
||
156 | return -1; |
||
157 | } |
||
158 | |||
8439 | leency | 159 | void TWebBrowser::tag_code() |
160 | { |
||
161 | if (style.pre = tag.opened) { |
||
8451 | leency | 162 | bg_colors.add(0xe4ffcb); |
8439 | leency | 163 | } else { |
8451 | leency | 164 | bg_colors.pop(); |
8439 | leency | 165 | } |
166 | } |
||
167 | |||
168 | void TWebBrowser::tag_ol_ul_dt() |
||
169 | { |
||
170 | char type = ESBYTE[#tag.name]; |
||
171 | style.tag_list.upd_level(tag.opened, type); |
||
172 | switch(type) |
||
173 | { |
||
174 | case 'd': |
||
175 | if (tag.opened) NewLine(); |
||
176 | break; |
||
177 | case 'u': |
||
178 | case 'o': |
||
179 | if (!tag.opened) && (!style.pre) NewLine(); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | void TWebBrowser::tag_li() |
||
184 | { |
||
185 | if (tag.opened) { |
||
186 | if (!style.tag_list.level) style.tag_list.upd_level(1, 'u'); |
||
187 | if (!style.pre) NewLine(); |
||
188 | if (style.tag_list.order_type() == 'u') { |
||
8492 | leency | 189 | strcpy(#linebuf, "\31 "); |
8462 | leency | 190 | draw_x = style.tag_list.level * 5 - 2 * list.font_w + left_gap; |
8439 | leency | 191 | } |
192 | if (style.tag_list.order_type() == 'o') { |
||
8492 | leency | 193 | sprintf(#linebuf, "%i. ", style.tag_list.inc_counter()); |
194 | draw_x = style.tag_list.level * 5 - 1 - strlen(#linebuf) * list.font_w + left_gap; |
||
8439 | leency | 195 | } |
196 | } |
||
197 | } |
||
198 | |||
199 | void TWebBrowser::tag_hr() |
||
200 | { |
||
8491 | leency | 201 | dword hrcol = 0x777777; |
202 | if (tag.get_value_of("color")) hrcol = GetColor(tag.value); |
||
203 | if (draw_x != left_gap) NewLine(); |
||
204 | canvas.DrawBar(5, style.cur_line_h / 2 + draw_y - 1, draw_w-10, 1, hrcol); |
||
8439 | leency | 205 | NewLine(); |
206 | return; |
||
207 | } |
||
208 | |||
209 | void TWebBrowser::tag_body() |
||
210 | { |
||
211 | t_body = tag.opened; |
||
8444 | leency | 212 | if (tag.get_value_of("link")) link_color_default = GetColor(tag.value); |
213 | if (tag.get_value_of("alink")) link_color_active = GetColor(tag.value); |
||
214 | if (tag.get_value_of("text")) text_colors.set(0, GetColor(tag.value)); |
||
215 | if (tag.get_value_of("bgcolor")) { |
||
8451 | leency | 216 | bg_colors.set(0, GetColor(tag.value)); |
217 | canvas.Fill(0, bg_colors.get(0)); |
||
8439 | leency | 218 | } |
219 | // Autodetecting encoding if no encoding was set |
||
220 | if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) { |
||
221 | if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8); |
||
222 | else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251); |
||
223 | } |
||
224 | } |
||
225 | |||
226 | void TWebBrowser::tag_q() |
||
227 | { |
||
8492 | leency | 228 | chrncat(#linebuf, '\"', sizeof(TWebBrowser.linebuf)); |
8439 | leency | 229 | } |
230 | |||
231 | void TWebBrowser::tag_h1234_caption() |
||
232 | { |
||
233 | if (ESBYTE[#tag.name+1]=='4') { |
||
234 | NewLine(); |
||
235 | NewLine(); |
||
236 | style.h = tag.opened; |
||
237 | style.b = tag.opened; |
||
238 | } else { |
||
239 | style.h = tag.opened; |
||
240 | if (tag.opened) { |
||
241 | if (!style.pre) NewLine(); |
||
242 | draw_y += 10; |
||
8457 | leency | 243 | list.SetFont(BASIC_CHAR_W*2, 14*2, 10011001b); |
8439 | leency | 244 | list.item_h = BASIC_LINE_H * 2 - 2; |
245 | if (tag.is("h1")) style.b = true; |
||
246 | } else { |
||
247 | if (tag.is("h1")) style.b = false; |
||
248 | NewLine(); |
||
8457 | leency | 249 | list.SetFont(BASIC_CHAR_W, 14, 10011000b); |
8451 | leency | 250 | style.cur_line_h = list.item_h = BASIC_LINE_H; |
8439 | leency | 251 | } |
252 | } |
||
253 | } |
||
254 | |||
255 | |||
256 | void TWebBrowser::tag_img() |
||
257 | { |
||
258 | char img_path[4096]=0; |
||
8462 | leency | 259 | dword base64img; |
8439 | leency | 260 | |
8454 | leency | 261 | if (!tag.get_value_of("data-large-image")) |
262 | if (!tag.get_value_of("data-src")) |
||
263 | if (!tag.get_value_of("src")) return; |
||
8439 | leency | 264 | |
265 | if (streqrp(tag.value, "data:")) { |
||
266 | if (!strstr(tag.value, "base64,")) goto NOIMG; |
||
267 | EDX = EAX+7; |
||
268 | if (ESBYTE[EDX]==' ') EDX++; |
||
8462 | leency | 269 | base64img = malloc(strlen(EDX)); |
270 | base64_decode stdcall (EDX, base64img, strlen(EDX)); |
||
271 | img_decode stdcall (base64img, EAX, 0); |
||
8439 | leency | 272 | $push eax |
8462 | leency | 273 | free(base64img); |
8439 | leency | 274 | $pop eax |
275 | if (EAX) goto IMGOK; else goto NOIMG; |
||
276 | } |
||
277 | |||
278 | if (!strcmp(tag.value + strrchr(tag.value, '.'), "svg")) goto NOIMG; |
||
8454 | leency | 279 | if (!strcmp(tag.value + strrchr(tag.value, '.'), "webp")) goto NOIMG; |
280 | |||
8439 | leency | 281 | strlcpy(#img_path, tag.value, sizeof(img_path)-1); |
8490 | leency | 282 | replace_char(#img_path, ' ', '\0', sizeof(img_path)); |
8439 | leency | 283 | get_absolute_url(#img_path, history.current()); |
284 | |||
285 | if (check_is_the_adress_local(#img_path)) { |
||
286 | img_from_file stdcall(#img_path); |
||
287 | if (EAX) goto IMGOK; else goto NOIMG; |
||
288 | } |
||
289 | |||
290 | if (cache.has(#img_path)) { |
||
291 | img_decode stdcall (cache.current_buf, cache.current_size, 0); |
||
292 | if (EAX) goto IMGOK; else goto NOIMG; |
||
293 | } else { |
||
294 | img_url.add(#img_path); |
||
295 | goto NOIMG; |
||
296 | } |
||
297 | |||
298 | IMGOK: |
||
8462 | leency | 299 | if (RenderImage(EAX)) return; |
8439 | leency | 300 | |
301 | NOIMG: |
||
8444 | leency | 302 | if (tag.get_value_of("title")) || (tag.get_value_of("alt")) { |
8492 | leency | 303 | strncpy(#img_path, tag.value, sizeof(TWebBrowser.linebuf)-3); |
304 | sprintf(#linebuf, "[%s]", #img_path); |
||
8439 | leency | 305 | } else { |
306 | if (streqrp(#img_path, "data:")) img_path=0; |
||
307 | replace_char(#img_path, '?', NULL, strlen(#img_path)); |
||
8492 | leency | 308 | img_path[sizeof(TWebBrowser.linebuf)-3] = '\0'; //prevent overflow in sprintf |
309 | sprintf(#linebuf, "[%s]", #img_path+strrchr(#img_path, '/')); |
||
310 | linebuf[50]= NULL; |
||
8439 | leency | 311 | } |
312 | text_colors.add(0x9A6F29); |
||
313 | style.image = true; |
||
8491 | leency | 314 | RenderTextbuf(); |
8439 | leency | 315 | style.image = false; |
316 | text_colors.pop(); |
||
8462 | leency | 317 | } |
318 | |||
319 | |||
320 | |||
321 | |||
8492 | leency | 322 | |
323 | |||
324 | struct TABLE { |
||
325 | int count; |
||
326 | int col; |
||
327 | collection_int cx; |
||
328 | int row_y, next_row_y; |
||
329 | } table; |
||
330 | |||
331 | void TWebBrowser::tag_table_reset() |
||
332 | { |
||
333 | table.count = 0; |
||
334 | table.cx.drop(); |
||
335 | table.row_y = 0; |
||
336 | table.next_row_y = 0; |
||
337 | } |
||
338 | |||
8462 | leency | 339 | void TWebBrowser::tag_table() |
340 | { |
||
8492 | leency | 341 | if (tag.opened) { |
342 | if (!table.count) { |
||
343 | table.next_row_y = table.row_y = draw_y; |
||
344 | } |
||
345 | table.count++; |
||
346 | } else { |
||
347 | table.count--; |
||
348 | if (!table.count) { |
||
349 | draw_y = math.max(draw_y + style.cur_line_h, table.next_row_y); |
||
350 | left_gap = BODY_MARGIN; |
||
351 | } |
||
352 | } |
||
8462 | leency | 353 | } |
354 | |||
355 | void TWebBrowser::tag_tr() |
||
356 | { |
||
357 | if (tag.opened) { |
||
8492 | leency | 358 | if (table.count>1) { |
359 | NewLine(); |
||
360 | } else { |
||
361 | table.col = 0; |
||
362 | table.row_y = math.max(draw_y + style.cur_line_h, table.next_row_y); |
||
363 | left_gap = BODY_MARGIN; |
||
364 | NewLine(); |
||
365 | } |
||
8462 | leency | 366 | } |
367 | } |
||
368 | |||
369 | void TWebBrowser::tag_td() |
||
370 | { |
||
8492 | leency | 371 | if (table.count>1) return; |
8462 | leency | 372 | if (tag.opened) { |
8492 | leency | 373 | table.next_row_y = math.max(draw_y + style.cur_line_h, table.next_row_y); |
374 | draw_y = table.row_y; |
||
375 | table.cx.set(table.col, math.max(draw_x,table.cx.get(table.col)) ); |
||
376 | draw_x = left_gap = table.cx.get(table.col); |
||
377 | table.col++; |
||
378 | if (tag.get_value_of("width")) { |
||
379 | draw_w = EAX; |
||
380 | //debugval("draw_w", atoi(tag.value)); |
||
381 | table.cx.set(table.col, draw_x + atoi(tag.value)); |
||
382 | } |
||
383 | //if (tag.get_value_of("height")) table.next_row_y = draw_y + atoi(tag.value); |
||
384 | } |
||
385 | |||
386 | if (left_gap >= list.w - list.font_w - 10) { |
||
387 | notify("left_gap overflow"); |
||
388 | draw_x = left_gap = BODY_MARGIN; |
||
389 | table.cx.drop(); |
||
390 | table.count = 999; |
||
8462 | leency | 391 | NewLine(); |
8492 | leency | 392 | } |
393 | |||
394 | if (draw_w < 0) || (draw_w >= list.w) { |
||
395 | notify("draw_w overflow"); |
||
396 | draw_x = left_gap = BODY_MARGIN; |
||
8462 | leency | 397 | draw_w = list.w - left_gap; |
8492 | leency | 398 | NewLine(); |
8462 | leency | 399 | } |
8492 | leency | 400 | }> |