Rev 8499 | Rev 9103 | 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; } |
||
8500 | leency | 14 | if (tag.is("br")) { /*draw_x++;*/NewLine(); return; } |
8439 | leency | 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(); |
||
8499 | leency | 90 | if (bg_colors.count>1) bg_colors.pop(); //never pop the last color |
8451 | leency | 91 | } |
8439 | leency | 92 | } |
93 | |||
94 | void TWebBrowser::tag_div() |
||
95 | { |
||
8499 | leency | 96 | //if (streq(#tag.prior,"div")) && (tag.opened) return; |
8490 | leency | 97 | if (streq(#tag.prior,"td")) return; |
8499 | leency | 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 { |
8499 | leency | 164 | if (bg_colors.count>1) bg_colors.pop(); //never pop the last color |
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); |
||
8500 | leency | 205 | draw_x++; |
8439 | leency | 206 | NewLine(); |
207 | return; |
||
208 | } |
||
209 | |||
210 | void TWebBrowser::tag_body() |
||
211 | { |
||
212 | t_body = tag.opened; |
||
8444 | leency | 213 | if (tag.get_value_of("link")) link_color_default = GetColor(tag.value); |
214 | if (tag.get_value_of("alink")) link_color_active = GetColor(tag.value); |
||
215 | if (tag.get_value_of("text")) text_colors.set(0, GetColor(tag.value)); |
||
216 | if (tag.get_value_of("bgcolor")) { |
||
8451 | leency | 217 | bg_colors.set(0, GetColor(tag.value)); |
218 | canvas.Fill(0, bg_colors.get(0)); |
||
8439 | leency | 219 | } |
220 | // Autodetecting encoding if no encoding was set |
||
221 | if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) { |
||
222 | if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8); |
||
223 | else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251); |
||
224 | } |
||
225 | } |
||
226 | |||
227 | void TWebBrowser::tag_q() |
||
228 | { |
||
8492 | leency | 229 | chrncat(#linebuf, '\"', sizeof(TWebBrowser.linebuf)); |
8439 | leency | 230 | } |
231 | |||
232 | void TWebBrowser::tag_h1234_caption() |
||
233 | { |
||
234 | if (ESBYTE[#tag.name+1]=='4') { |
||
235 | NewLine(); |
||
236 | NewLine(); |
||
237 | style.h = tag.opened; |
||
238 | style.b = tag.opened; |
||
239 | } else { |
||
240 | style.h = tag.opened; |
||
241 | if (tag.opened) { |
||
242 | if (!style.pre) NewLine(); |
||
243 | draw_y += 10; |
||
8457 | leency | 244 | list.SetFont(BASIC_CHAR_W*2, 14*2, 10011001b); |
8439 | leency | 245 | list.item_h = BASIC_LINE_H * 2 - 2; |
246 | if (tag.is("h1")) style.b = true; |
||
247 | } else { |
||
248 | if (tag.is("h1")) style.b = false; |
||
249 | NewLine(); |
||
8457 | leency | 250 | list.SetFont(BASIC_CHAR_W, 14, 10011000b); |
8451 | leency | 251 | style.cur_line_h = list.item_h = BASIC_LINE_H; |
8439 | leency | 252 | } |
253 | } |
||
254 | } |
||
255 | |||
256 | |||
257 | void TWebBrowser::tag_img() |
||
258 | { |
||
259 | char img_path[4096]=0; |
||
8462 | leency | 260 | dword base64img; |
8439 | leency | 261 | |
8454 | leency | 262 | if (!tag.get_value_of("data-large-image")) |
263 | if (!tag.get_value_of("data-src")) |
||
264 | if (!tag.get_value_of("src")) return; |
||
8439 | leency | 265 | |
266 | if (streqrp(tag.value, "data:")) { |
||
267 | if (!strstr(tag.value, "base64,")) goto NOIMG; |
||
268 | EDX = EAX+7; |
||
269 | if (ESBYTE[EDX]==' ') EDX++; |
||
8462 | leency | 270 | base64img = malloc(strlen(EDX)); |
271 | base64_decode stdcall (EDX, base64img, strlen(EDX)); |
||
272 | img_decode stdcall (base64img, EAX, 0); |
||
8439 | leency | 273 | $push eax |
8462 | leency | 274 | free(base64img); |
8439 | leency | 275 | $pop eax |
276 | if (EAX) goto IMGOK; else goto NOIMG; |
||
277 | } |
||
278 | |||
279 | if (!strcmp(tag.value + strrchr(tag.value, '.'), "svg")) goto NOIMG; |
||
8454 | leency | 280 | if (!strcmp(tag.value + strrchr(tag.value, '.'), "webp")) goto NOIMG; |
281 | |||
8439 | leency | 282 | strlcpy(#img_path, tag.value, sizeof(img_path)-1); |
8490 | leency | 283 | replace_char(#img_path, ' ', '\0', sizeof(img_path)); |
8439 | leency | 284 | get_absolute_url(#img_path, history.current()); |
285 | |||
286 | if (check_is_the_adress_local(#img_path)) { |
||
287 | img_from_file stdcall(#img_path); |
||
288 | if (EAX) goto IMGOK; else goto NOIMG; |
||
289 | } |
||
290 | |||
291 | if (cache.has(#img_path)) { |
||
292 | img_decode stdcall (cache.current_buf, cache.current_size, 0); |
||
293 | if (EAX) goto IMGOK; else goto NOIMG; |
||
294 | } else { |
||
295 | img_url.add(#img_path); |
||
296 | goto NOIMG; |
||
297 | } |
||
298 | |||
299 | IMGOK: |
||
8462 | leency | 300 | if (RenderImage(EAX)) return; |
8439 | leency | 301 | |
302 | NOIMG: |
||
8444 | leency | 303 | if (tag.get_value_of("title")) || (tag.get_value_of("alt")) { |
8492 | leency | 304 | strncpy(#img_path, tag.value, sizeof(TWebBrowser.linebuf)-3); |
305 | sprintf(#linebuf, "[%s]", #img_path); |
||
8439 | leency | 306 | } else { |
307 | if (streqrp(#img_path, "data:")) img_path=0; |
||
308 | replace_char(#img_path, '?', NULL, strlen(#img_path)); |
||
8492 | leency | 309 | img_path[sizeof(TWebBrowser.linebuf)-3] = '\0'; //prevent overflow in sprintf |
310 | sprintf(#linebuf, "[%s]", #img_path+strrchr(#img_path, '/')); |
||
311 | linebuf[50]= NULL; |
||
8439 | leency | 312 | } |
313 | text_colors.add(0x9A6F29); |
||
314 | style.image = true; |
||
8491 | leency | 315 | RenderTextbuf(); |
8439 | leency | 316 | style.image = false; |
317 | text_colors.pop(); |
||
8462 | leency | 318 | } |
319 | |||
320 | |||
321 | |||
322 | |||
8500 | leency | 323 | int tdepth; |
324 | int col_n; |
||
8492 | leency | 325 | |
326 | struct TABLE { |
||
8500 | leency | 327 | collection_int col_w; |
328 | collection_int col_span; |
||
329 | collection_int row_h; |
||
8492 | leency | 330 | int row_y, next_row_y; |
8500 | leency | 331 | int colcount; |
332 | } t[5]; |
||
8492 | leency | 333 | |
334 | void TWebBrowser::tag_table_reset() |
||
335 | { |
||
8500 | leency | 336 | int i; |
337 | tdepth = 0; |
||
338 | for (i=0; i<5; i++) { |
||
339 | t[i].col_w.drop(); |
||
340 | t[i].row_h.drop(); |
||
341 | t[i].col_span.drop(); |
||
342 | t[i].row_y = 0; |
||
343 | t[i].next_row_y = 0; |
||
344 | } |
||
8492 | leency | 345 | } |
346 | |||
8462 | leency | 347 | void TWebBrowser::tag_table() |
348 | { |
||
8492 | leency | 349 | if (tag.opened) { |
8500 | leency | 350 | if (tdepth==0) { |
351 | t[0].next_row_y = t[0].row_y = draw_y; |
||
8492 | leency | 352 | } |
8500 | leency | 353 | tdepth++; |
8492 | leency | 354 | } else { |
8500 | leency | 355 | tdepth--; |
356 | if (tdepth==0) { |
||
357 | draw_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y); |
||
8492 | leency | 358 | left_gap = BODY_MARGIN; |
8500 | leency | 359 | draw_w = list.w - BODY_MARGIN; |
8492 | leency | 360 | } |
361 | } |
||
8462 | leency | 362 | } |
363 | |||
8500 | leency | 364 | :void TWebBrowser::tag_tr() |
8462 | leency | 365 | { |
366 | if (tag.opened) { |
||
8500 | leency | 367 | if (tdepth>1) { |
8492 | leency | 368 | NewLine(); |
369 | } else { |
||
8500 | leency | 370 | t[0].colcount = math.max(t[0].colcount, col_n); |
371 | col_n = 0; |
||
372 | t[0].row_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y); |
||
8492 | leency | 373 | left_gap = BODY_MARGIN; |
374 | NewLine(); |
||
375 | } |
||
8462 | leency | 376 | } |
377 | } |
||
378 | |||
8500 | leency | 379 | :void TWebBrowser::tag_td() |
8462 | leency | 380 | { |
8500 | leency | 381 | if (tdepth>1) return; |
8462 | leency | 382 | if (tag.opened) { |
8500 | leency | 383 | |
384 | t[0].next_row_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y); |
||
385 | style.cur_line_h = list.item_h; |
||
386 | t[0].col_w.set(col_n, math.max(draw_x,t[0].col_w.get(col_n)) ); |
||
387 | draw_x = left_gap = t[0].col_w.get(col_n); |
||
388 | draw_w = list.w - left_gap; |
||
389 | draw_y = t[0].row_y; |
||
390 | if (tag.get_number_of("width")) { |
||
391 | if (!strchr(tag.value, '%')) { |
||
392 | draw_w = tag.number; |
||
393 | } else { |
||
394 | if (tag.number < 100) { |
||
395 | draw_w = draw_w - left_gap * tag.number / 100; |
||
396 | if (draw_w > list.w - left_gap) draw_w = list.w - left_gap; |
||
397 | } |
||
398 | } |
||
8492 | leency | 399 | } |
8500 | leency | 400 | col_n++; |
401 | t[0].col_w.set(col_n, draw_x + draw_w); |
||
402 | |||
403 | if (left_gap >= list.w - list.font_w - 10) { |
||
404 | debugln("left_gap overflow"); |
||
405 | draw_x = left_gap = BODY_MARGIN; |
||
406 | t[0].col_w.drop(); |
||
407 | NewLine(); |
||
408 | canvas.WriteText(draw_x, draw_y, 10011001b, 0xFE0000, "lgo", NULL); |
||
409 | } |
||
410 | |||
411 | if (draw_w < 0) || (draw_w >= list.w) { |
||
412 | debugln("draw_w overflow"); |
||
413 | draw_x = left_gap = BODY_MARGIN; |
||
414 | draw_w = list.w - left_gap; |
||
415 | NewLine(); |
||
416 | canvas.WriteText(draw_x, draw_y, 10011001b, 0x0000FE, "drwo", NULL); |
||
417 | } |
||
8492 | leency | 418 | } |
419 | |||
420 | }>>5;> |