Rev 8490 | Rev 8492 | 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(); |
107 | strcpy(#line, "IFRAME: "); |
||
8491 | leency | 108 | RenderTextbuf(); |
8439 | leency | 109 | link=true; |
110 | links.add_link(tag.value); |
||
8491 | leency | 111 | strncpy(#line, tag.value, sizeof(TWebBrowser.line)-1); |
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); |
||
140 | if (streqrp(EDX,"utf-8")) || (streqrp(EDX,"utf8")) ChangeEncoding(CH_UTF8); |
||
141 | else if (streqrp(EDX,"windows-1251")) || (streqrp(EDX,"windows1251")) ChangeEncoding(CH_CP1251); |
||
142 | else if (streqrp(EDX,"dos")) || (streqrp(EDX,"cp-866")) ChangeEncoding(CH_CP866); |
||
143 | else if (streqrp(EDX,"iso-8859-5")) || (streqrp(EDX,"iso8859-5")) ChangeEncoding(CH_ISO8859_5); |
||
144 | else if (streqrp(EDX,"koi8-r")) || (streqrp(EDX,"koi8-u")) ChangeEncoding(CH_KOI8); |
||
145 | } |
||
8444 | leency | 146 | if (streq(tag.get_value_of("http-equiv"), "refresh")) && (tag.get_value_of("content")) { |
147 | if (tag.value = strstri(tag.value, "url")) strcpy(#redirect, tag.value); |
||
8439 | leency | 148 | } |
149 | } |
||
150 | |||
151 | void TWebBrowser::tag_code() |
||
152 | { |
||
153 | if (style.pre = tag.opened) { |
||
8451 | leency | 154 | bg_colors.add(0xe4ffcb); |
8439 | leency | 155 | } else { |
8451 | leency | 156 | bg_colors.pop(); |
8439 | leency | 157 | } |
158 | } |
||
159 | |||
160 | void TWebBrowser::tag_ol_ul_dt() |
||
161 | { |
||
162 | char type = ESBYTE[#tag.name]; |
||
163 | style.tag_list.upd_level(tag.opened, type); |
||
164 | switch(type) |
||
165 | { |
||
166 | case 'd': |
||
167 | if (tag.opened) NewLine(); |
||
168 | break; |
||
169 | case 'u': |
||
170 | case 'o': |
||
171 | if (!tag.opened) && (!style.pre) NewLine(); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | void TWebBrowser::tag_li() |
||
176 | { |
||
177 | if (tag.opened) { |
||
178 | if (!style.tag_list.level) style.tag_list.upd_level(1, 'u'); |
||
179 | if (!style.pre) NewLine(); |
||
180 | if (style.tag_list.order_type() == 'u') { |
||
181 | strcpy(#line, "\31 "); |
||
8462 | leency | 182 | draw_x = style.tag_list.level * 5 - 2 * list.font_w + left_gap; |
8439 | leency | 183 | } |
184 | if (style.tag_list.order_type() == 'o') { |
||
185 | sprintf(#line, "%i. ", style.tag_list.inc_counter()); |
||
8462 | leency | 186 | draw_x = style.tag_list.level * 5 - 1 - strlen(#line) * list.font_w + left_gap; |
8439 | leency | 187 | } |
188 | } |
||
189 | } |
||
190 | |||
191 | void TWebBrowser::tag_hr() |
||
192 | { |
||
8491 | leency | 193 | dword hrcol = 0x777777; |
194 | if (tag.get_value_of("color")) hrcol = GetColor(tag.value); |
||
195 | if (draw_x != left_gap) NewLine(); |
||
196 | canvas.DrawBar(5, style.cur_line_h / 2 + draw_y - 1, draw_w-10, 1, hrcol); |
||
8439 | leency | 197 | NewLine(); |
198 | return; |
||
199 | } |
||
200 | |||
201 | void TWebBrowser::tag_body() |
||
202 | { |
||
203 | t_body = tag.opened; |
||
8444 | leency | 204 | if (tag.get_value_of("link")) link_color_default = GetColor(tag.value); |
205 | if (tag.get_value_of("alink")) link_color_active = GetColor(tag.value); |
||
206 | if (tag.get_value_of("text")) text_colors.set(0, GetColor(tag.value)); |
||
207 | if (tag.get_value_of("bgcolor")) { |
||
8451 | leency | 208 | bg_colors.set(0, GetColor(tag.value)); |
209 | canvas.Fill(0, bg_colors.get(0)); |
||
8439 | leency | 210 | } |
211 | // Autodetecting encoding if no encoding was set |
||
212 | if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) { |
||
213 | if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8); |
||
214 | else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | void TWebBrowser::tag_q() |
||
219 | { |
||
8491 | leency | 220 | chrncat(#line, '\"', sizeof(TWebBrowser.line)); |
8439 | leency | 221 | } |
222 | |||
223 | void TWebBrowser::tag_h1234_caption() |
||
224 | { |
||
225 | if (ESBYTE[#tag.name+1]=='4') { |
||
226 | NewLine(); |
||
227 | NewLine(); |
||
228 | style.h = tag.opened; |
||
229 | style.b = tag.opened; |
||
230 | } else { |
||
231 | style.h = tag.opened; |
||
232 | if (tag.opened) { |
||
233 | if (!style.pre) NewLine(); |
||
234 | draw_y += 10; |
||
8457 | leency | 235 | list.SetFont(BASIC_CHAR_W*2, 14*2, 10011001b); |
8439 | leency | 236 | list.item_h = BASIC_LINE_H * 2 - 2; |
237 | if (tag.is("h1")) style.b = true; |
||
238 | } else { |
||
239 | if (tag.is("h1")) style.b = false; |
||
240 | NewLine(); |
||
8457 | leency | 241 | list.SetFont(BASIC_CHAR_W, 14, 10011000b); |
8451 | leency | 242 | style.cur_line_h = list.item_h = BASIC_LINE_H; |
8439 | leency | 243 | } |
244 | } |
||
245 | } |
||
246 | |||
247 | |||
248 | void TWebBrowser::tag_img() |
||
249 | { |
||
250 | char img_path[4096]=0; |
||
8462 | leency | 251 | dword base64img; |
8439 | leency | 252 | |
8454 | leency | 253 | if (!tag.get_value_of("data-large-image")) |
254 | if (!tag.get_value_of("data-src")) |
||
255 | if (!tag.get_value_of("src")) return; |
||
8439 | leency | 256 | |
257 | if (streqrp(tag.value, "data:")) { |
||
258 | if (!strstr(tag.value, "base64,")) goto NOIMG; |
||
259 | EDX = EAX+7; |
||
260 | if (ESBYTE[EDX]==' ') EDX++; |
||
8462 | leency | 261 | base64img = malloc(strlen(EDX)); |
262 | base64_decode stdcall (EDX, base64img, strlen(EDX)); |
||
263 | img_decode stdcall (base64img, EAX, 0); |
||
8439 | leency | 264 | $push eax |
8462 | leency | 265 | free(base64img); |
8439 | leency | 266 | $pop eax |
267 | if (EAX) goto IMGOK; else goto NOIMG; |
||
268 | } |
||
269 | |||
270 | if (!strcmp(tag.value + strrchr(tag.value, '.'), "svg")) goto NOIMG; |
||
8454 | leency | 271 | if (!strcmp(tag.value + strrchr(tag.value, '.'), "webp")) goto NOIMG; |
272 | |||
8439 | leency | 273 | strlcpy(#img_path, tag.value, sizeof(img_path)-1); |
8490 | leency | 274 | replace_char(#img_path, ' ', '\0', sizeof(img_path)); |
8439 | leency | 275 | get_absolute_url(#img_path, history.current()); |
276 | |||
277 | if (check_is_the_adress_local(#img_path)) { |
||
278 | img_from_file stdcall(#img_path); |
||
279 | if (EAX) goto IMGOK; else goto NOIMG; |
||
280 | } |
||
281 | |||
282 | if (cache.has(#img_path)) { |
||
283 | img_decode stdcall (cache.current_buf, cache.current_size, 0); |
||
284 | if (EAX) goto IMGOK; else goto NOIMG; |
||
285 | } else { |
||
286 | img_url.add(#img_path); |
||
287 | goto NOIMG; |
||
288 | } |
||
289 | |||
290 | IMGOK: |
||
8462 | leency | 291 | if (RenderImage(EAX)) return; |
8439 | leency | 292 | |
293 | NOIMG: |
||
8444 | leency | 294 | if (tag.get_value_of("title")) || (tag.get_value_of("alt")) { |
8491 | leency | 295 | strncpy(#img_path, tag.value, sizeof(TWebBrowser.line)-3); |
8439 | leency | 296 | sprintf(#line, "[%s]", #img_path); |
297 | } else { |
||
298 | if (streqrp(#img_path, "data:")) img_path=0; |
||
299 | replace_char(#img_path, '?', NULL, strlen(#img_path)); |
||
8491 | leency | 300 | img_path[sizeof(TWebBrowser.line)-3] = '\0'; //prevent overflow in sprintf |
8439 | leency | 301 | sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/')); |
302 | line[50]= NULL; |
||
303 | } |
||
304 | text_colors.add(0x9A6F29); |
||
305 | style.image = true; |
||
8491 | leency | 306 | RenderTextbuf(); |
8439 | leency | 307 | style.image = false; |
308 | text_colors.pop(); |
||
8462 | leency | 309 | } |
310 | |||
311 | |||
312 | |||
313 | unsigned tr_y; |
||
314 | unsigned td_x, td_w; |
||
315 | unsigned highest_td; |
||
316 | int table_c=0; |
||
317 | |||
318 | void TWebBrowser::tag_table() |
||
319 | { |
||
320 | if (tag.opened) table_c++; else table_c--; |
||
8491 | leency | 321 | if (!tag.opened) NewLine(); |
8462 | leency | 322 | } |
323 | |||
324 | void TWebBrowser::tag_tr() |
||
325 | { |
||
326 | if (table_c>1) return; |
||
327 | //style.tr = tag.opened; |
||
328 | NewLine(); |
||
329 | draw_w = list.w - left_gap; |
||
330 | left_gap = BODY_MARGIN; |
||
331 | td_w = 0; |
||
332 | if (tag.opened) { |
||
333 | tr_y = draw_y; |
||
334 | } else { |
||
335 | //draw_y = highest_td; |
||
336 | } |
||
337 | } |
||
338 | |||
339 | void TWebBrowser::tag_td() |
||
340 | { |
||
341 | if (table_c>1) return; |
||
342 | if (tag.opened) { |
||
343 | NewLine(); |
||
344 | //highest_td = math.max(draw_y, tr_y); |
||
345 | if (tag.get_value_of("width")) td_w = atoi(tag.value); |
||
346 | draw_y = tr_y; |
||
347 | draw_x = left_gap; |
||
348 | debugval("td_w", td_w); |
||
349 | if (td_w > 20) draw_w = td_w; else draw_w = list.w - left_gap; |
||
350 | } else { |
||
351 | left_gap += td_w; |
||
352 | draw_w = list.w - left_gap; |
||
353 | /* |
||
354 | draw_w -= left_gap; |
||
355 | if (left_gap < 0) left_gap = BODY_MARGIN; |
||
356 | if (draw_w < 0) { |
||
357 | left_gap = BODY_MARGIN; |
||
358 | draw_w = list.w - left_gap; |
||
359 | } |
||
360 | debugval("left_gap", left_gap); |
||
361 | */ |
||
362 | } |
||
363 | debugval("td_w", td_w); |
||
364 | debugval("left_gap", left_gap); |
||
8439 | leency | 365 | }>> |