From 778de94be43af9ed6946d3c455b423a3e9d04780 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Mon, 2 Aug 2021 14:08:12 +0000 Subject: [PATCH] WebView 3.5: basic table support (all cols are same width, no colspan, no borders...) git-svn-id: svn://kolibrios.org@9103 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/browser/TWB/TWB.c | 113 ++++++++++-------- programs/cmm/browser/TWB/parse_tag.h | 10 +- programs/cmm/browser/TWB/render.h | 47 +++++--- programs/cmm/browser/TWB/set_style.h | 166 ++++++++++++--------------- programs/cmm/browser/TWB/special.h | 2 +- programs/cmm/browser/const.h | 2 +- programs/cmm/browser/res/test.htm | 6 +- 7 files changed, 186 insertions(+), 160 deletions(-) diff --git a/programs/cmm/browser/TWB/TWB.c b/programs/cmm/browser/TWB/TWB.c index 842fa3b897..80eb3cd971 100644 --- a/programs/cmm/browser/TWB/TWB.c +++ b/programs/cmm/browser/TWB/TWB.c @@ -49,6 +49,8 @@ struct TWebBrowser { char linebuf[500]; char redirect[URL_SIZE]; + bool secondrun; + void SetStyle(); void RenderTextbuf(); void RenderLine(); @@ -109,6 +111,15 @@ void TWebBrowser::SetPageDefaults() redirect = '\0'; list.SetFont(8, 14, 10011000b); tag_table_reset(); + is_html = true; + if (!strstri(bufpointer, "ps) pe--; ESBYTE[pe] = '\0'; //find ATTR end diff --git a/programs/cmm/browser/TWB/render.h b/programs/cmm/browser/TWB/render.h index c1bf268b51..67cfa05c46 100644 --- a/programs/cmm/browser/TWB/render.h +++ b/programs/cmm/browser/TWB/render.h @@ -21,8 +21,9 @@ void TWebBrowser::RenderLine(dword _line) pw = strlen(_line) * list.font_w; zoom = list.font_w / BASIC_CHAR_W; + //there is some shit happens!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (pw > draw_w) { - draw_w = pw; + //draw_w = pw; NewLine(); } @@ -33,6 +34,7 @@ void TWebBrowser::RenderLine(dword _line) style.cur_line_h = math.max(style.cur_line_h, list.item_h); + if (!secondrun) goto _SKIP_DRAW; if (bg_colors.get_last() - bg_colors.get(0)) { canvas.DrawBar(draw_x, draw_y, pw, list.item_h, bg_colors.get_last()); } @@ -58,6 +60,7 @@ void TWebBrowser::RenderLine(dword _line) links.add_text(draw_x, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom); } } + _SKIP_DRAW: draw_x += pw; } ESBYTE[_line] = NULL; @@ -71,13 +74,16 @@ void TWebBrowser::RenderTextbuf() int len; //Do we need a line break? - while (len = strlen(lbp)) && (len * list.font_w + draw_x >= draw_w) { + + while (len = strlen(lbp)) && (len * list.font_w + draw_x - left_gap >= draw_w) { //Yes, we do. Lets calculate where... - br = strrchr(lbp, ' '); + br = len; + + //debugln(" \\n"); //Is a new line fits in the current line? - if (br * list.font_w + draw_x >= draw_w) { - br = draw_w - draw_x /list.font_w; + if (br * list.font_w + draw_x - left_gap >= draw_w) { + br = draw_w - draw_x + left_gap /list.font_w; while(br) { if (ESBYTE[lbp + br]==' ') { br++; @@ -135,7 +141,7 @@ bool TWebBrowser::RenderImage(dword cur_img) img_h = ESDWORD[cur_img+8]; img_w = ESDWORD[cur_img+4]; - if (img_w + draw_x >= draw_w) NewLine(); + if (img_w + draw_x - left_gap >= draw_w) NewLine(); img_y = draw_y; if (img_h < list.item_h) img_y += list.item_h - img_h / 2 - 1; else img_y -= 2; style.cur_line_h = math.max(style.cur_line_h, img_h); @@ -146,22 +152,25 @@ bool TWebBrowser::RenderImage(dword cur_img) if (img_y + img_h >= canvas.bufh) canvas.IncreaseBufSize(); - if (ESDWORD[cur_img+20] != IMAGE_BPP32) { - img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0); - $push eax + if (secondrun) + { + if (ESDWORD[cur_img+20] != IMAGE_BPP32) { + img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0); + $push eax + img_destroy stdcall(cur_img); + $pop eax + cur_img = EAX; + if (!EAX) return false; + } + imgbuf[04] = canvas.bufw; + imgbuf[08] = canvas.bufh; + imgbuf[20] = IMAGE_BPP32; + imgbuf[24] = buf_data+8; + img_blend stdcall(#imgbuf, cur_img, draw_x, img_y, 0, 0, img_w, img_h); img_destroy stdcall(cur_img); - $pop eax - cur_img = EAX; - if (!EAX) return false; } - imgbuf[04] = canvas.bufw; - imgbuf[08] = canvas.bufh; - imgbuf[20] = IMAGE_BPP32; - imgbuf[24] = buf_data+8; - img_blend stdcall(#imgbuf, cur_img, draw_x, img_y, 0, 0, img_w, img_h); - img_destroy stdcall(cur_img); draw_x += img_w; - if (draw_x >= draw_w) NewLine(); + if (draw_x - left_gap >= draw_w) NewLine(); return true; } \ No newline at end of file diff --git a/programs/cmm/browser/TWB/set_style.h b/programs/cmm/browser/TWB/set_style.h index 0904c2a3f1..e85b06e820 100644 --- a/programs/cmm/browser/TWB/set_style.h +++ b/programs/cmm/browser/TWB/set_style.h @@ -50,11 +50,7 @@ void TWebBrowser::SetStyle() if (tag.is("title")) { tag_title(); return; } if (tag.is("body")) { tag_body(); return; } if (tag.is("html")) { t_html = tag.opened; return; } - - if (tag.is("table")) { tag_table(); return; } - if (tag.is("tr")) { if (tag.opened) NewLine(); return; } //temp - //if (tag.is("tr")) { tag_tr(); return; } - //if (tag.is("td")) { tag_td(); return; } + tag_table(); } void TWebBrowser::tag_p() @@ -198,10 +194,10 @@ void TWebBrowser::tag_li() void TWebBrowser::tag_hr() { - dword hrcol = 0x777777; + dword hrcol = 0x00777777; if (tag.get_value_of("color")) hrcol = GetColor(tag.value); if (draw_x != left_gap) NewLine(); - canvas.DrawBar(5, style.cur_line_h / 2 + draw_y - 1, draw_w-10, 1, hrcol); + if (secondrun) canvas.DrawBar(5, style.cur_line_h / 2 + draw_y - 1, draw_w-10, 1, hrcol); draw_x++; NewLine(); return; @@ -320,101 +316,89 @@ NOIMG: -int tdepth; -int col_n; -struct TABLE { - collection_int col_w; - collection_int col_span; - collection_int row_h; - int row_y, next_row_y; - int colcount; -} t[5]; + + + + +int tdepth; +collection_int tr_col_count; //drop on once! +int tr_pos, td_pos; +int row_start_y; +int colcount; +dword tallest_cell_in_row; void TWebBrowser::tag_table_reset() { - int i; tdepth = 0; - for (i=0; i<5; i++) { - t[i].col_w.drop(); - t[i].row_h.drop(); - t[i].col_span.drop(); - t[i].row_y = 0; - t[i].next_row_y = 0; - } + colcount = 0; + tr_pos = 0; + td_pos = 0; } void TWebBrowser::tag_table() { - if (tag.opened) { - if (tdepth==0) { - t[0].next_row_y = t[0].row_y = draw_y; - } - tdepth++; - } else { - tdepth--; - if (tdepth==0) { - draw_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y); - left_gap = BODY_MARGIN; - draw_w = list.w - BODY_MARGIN; - } - } -} - -:void TWebBrowser::tag_tr() -{ - if (tag.opened) { - if (tdepth>1) { - NewLine(); + if (tag.is("table")) { + if(tag.opened) { + tdepth++; } else { - t[0].colcount = math.max(t[0].colcount, col_n); - col_n = 0; - t[0].row_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y); - left_gap = BODY_MARGIN; - NewLine(); + if (tdepth>0) tdepth--; + if (tdepth==0) { + draw_x = left_gap = style.tag_list.level * 5 * list.font_w + BODY_MARGIN; + draw_w = list.w; + + draw_y = math.max(draw_y+style.cur_line_h, tallest_cell_in_row); + row_start_y = draw_y = tallest_cell_in_row = draw_y; + style.cur_line_h = list.item_h; + } + } + } + if (tdepth>1) { + if (tag.is("tr")) && (tag.opened) NewLine(); + return; + } + + if (!secondrun) { + if (tag.is("tr")) { + if (colcount) tr_col_count.set(tr_col_count.count-1, colcount); + colcount = 0; + if (tag.opened) { + tr_col_count.add(1); + } + } + if (tag.opened) && (tag.is("td")) || (tag.is("th")) { + colcount++; + //if (tag.get_number_of("colspan")) colcount += tag.number-1; } + } else { + if (tag.is("tr")) { + if (tag.opened) { + if (draw_x==left_gap) && (draw_y==BODY_MARGIN) { + row_start_y = tallest_cell_in_row = draw_y; + } else { + row_start_y = tallest_cell_in_row = draw_y = draw_y + style.cur_line_h; + } + style.cur_line_h = list.item_h; + tr_pos++; + td_pos = 0; + } else { + draw_x = left_gap = style.tag_list.level * 5 * list.font_w + BODY_MARGIN; + draw_w = list.w; + draw_y = tallest_cell_in_row; + } + } + if (tr_pos) && (tag.is("td")) || (tag.is("th")) { + tallest_cell_in_row = math.max(draw_y+style.cur_line_h-list.item_h, tallest_cell_in_row); + style.cur_line_h = list.item_h; + if (tag.opened) { + draw_w = list.w - BODY_MARGIN - BODY_MARGIN - 23 / tr_col_count.get(tr_pos-1); + draw_x = left_gap = draw_w * td_pos + BODY_MARGIN; + //debugval(itoa(draw_x), list.w); + draw_y = row_start_y; + //canvas.WriteText(draw_x, draw_y, 10001001b, 0x0000FE, itoa(draw_x), NULL); + td_pos++; + } + } } } -:void TWebBrowser::tag_td() -{ - if (tdepth>1) return; - if (tag.opened) { - - t[0].next_row_y = math.max(draw_y + style.cur_line_h, t[0].next_row_y); - style.cur_line_h = list.item_h; - t[0].col_w.set(col_n, math.max(draw_x,t[0].col_w.get(col_n)) ); - draw_x = left_gap = t[0].col_w.get(col_n); - draw_w = list.w - left_gap; - draw_y = t[0].row_y; - if (tag.get_number_of("width")) { - if (!strchr(tag.value, '%')) { - draw_w = tag.number; - } else { - if (tag.number < 100) { - draw_w = draw_w - left_gap * tag.number / 100; - if (draw_w > list.w - left_gap) draw_w = list.w - left_gap; - } - } - } - col_n++; - t[0].col_w.set(col_n, draw_x + draw_w); - - if (left_gap >= list.w - list.font_w - 10) { - debugln("left_gap overflow"); - draw_x = left_gap = BODY_MARGIN; - t[0].col_w.drop(); - NewLine(); - canvas.WriteText(draw_x, draw_y, 10011001b, 0xFE0000, "lgo", NULL); - } - - if (draw_w < 0) || (draw_w >= list.w) { - debugln("draw_w overflow"); - draw_x = left_gap = BODY_MARGIN; - draw_w = list.w - left_gap; - NewLine(); - canvas.WriteText(draw_x, draw_y, 10011001b, 0x0000FE, "drwo", NULL); - } - } - -} diff --git a/programs/cmm/browser/TWB/special.h b/programs/cmm/browser/TWB/special.h index f2a834c522..75b73f6543 100644 --- a/programs/cmm/browser/TWB/special.h +++ b/programs/cmm/browser/TWB/special.h @@ -81,7 +81,7 @@ bool GetUnicodeSymbol(dword _line, line_size, bufpos, buf_end) { if (__isWhite(ESBYTE[bufpos])) {bufpos--; break;} if (ESBYTE[bufpos] == ';') || (bufpos >= buf_end) break; - if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", ESBYTE[bufpos])) {bufpos--; break;} + if (!strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789#", ESBYTE[bufpos])) {bufpos--; break;} special_code[i] = ESBYTE[bufpos]; } special_code[i] = '\0'; diff --git a/programs/cmm/browser/const.h b/programs/cmm/browser/const.h index 27b2ba38b8..c7b3d4fdfc 100644 --- a/programs/cmm/browser/const.h +++ b/programs/cmm/browser/const.h @@ -107,4 +107,4 @@ char editbox_icons[] = FROM "res/editbox_icons.raw"; #define DEFAULT_URL URL_SERVICE_HOMEPAGE -char version[]="WebView 3.32"; \ No newline at end of file +char version[]="WebView 3.5"; \ No newline at end of file diff --git a/programs/cmm/browser/res/test.htm b/programs/cmm/browser/res/test.htm index b90960ce72..dd9f2df789 100644 --- a/programs/cmm/browser/res/test.htm +++ b/programs/cmm/browser/res/test.htm @@ -20,14 +20,18 @@ Simple: mestack.narod.ru coolthemes.narod.ru vetusware.com +Total Hardware 1999 +GUI Gallery +menuetos.net Moderate: fdd5-25 acmp.ru old-dos.ru +weitek Complex: artcon.ru -cnn 1996 nubo.ru +salinc.ru electromyne.de \ No newline at end of file