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
This commit is contained in:
Kirill Lipatov (Leency) 2021-08-02 14:08:12 +00:00
parent 1a99d1d6bb
commit 778de94be4
7 changed files with 186 additions and 160 deletions

View File

@ -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, "<body")) {
t_body = true;
if (!strstri(bufpointer, "<html")) && (!strstri(bufpointer, "<head"))
&& (!strstr(bufpointer, "<?xml")) && (!strstr(bufpointer, "<xml")) {
style.pre = true; //show linebreaks for a plaint text
is_html = false;
}
}
}
//============================================================================================
void TWebBrowser::Reparse()
@ -142,45 +153,50 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
}
tr_col_count.drop();
secondrun = false;
_PARSE_START_:
SetPageDefaults();
is_html = true;
if (!strstri(bufpointer, "<body")) {
t_body = true;
if (!strstri(bufpointer, "<html")) && (!strstri(bufpointer, "<head"))
&& (!strstr(bufpointer, "<?xml")) && (!strstr(bufpointer, "<xml")) {
style.pre = true; //show linebreaks for a plaint text
is_html = false;
}
}
for (bufpos=bufpointer ; (bufpos < bufpointer+bufsize) && (ESBYTE[bufpos]!=0) ; bufpos++;)
for (bufpos=bufpointer; bufpos < bufpointer+bufsize; bufpos++;)
{
switch (ESBYTE[bufpos])
{
case 0x0a:
if (style.pre) {
if (ESBYTE[bufpos] == 0x0a) {
RenderTextbuf();
NewLine();
} else {
goto _DEFAULT;
continue;
}
break;
case 0x09:
if (style.pre) {
if (ESBYTE[bufpos] == 0x09) {
tab_len = draw_x - left_gap / list.font_w + strlen(#linebuf) % 4;
if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
while (tab_len) {chrcat(#linebuf,' '); tab_len--;}
} else {
goto _DEFAULT;
continue;
}
break;
case '&': //&nbsp; and so on
}
if (ESBYTE[bufpos] == '&') {
bufpos = GetUnicodeSymbol(#linebuf, sizeof(TWebBrowser.linebuf), bufpos+1, bufpointer+bufsize);
break;
case '<':
if (!is_html) goto _DEFAULT;
if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT;
continue;
}
if (ESBYTE[bufpos] == '<') && (is_html) {
if (strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) {
bufpos++;
if (tag.parse(#bufpos, bufpointer + bufsize)) {
/*
if (secondrun)
{
if (streq(#tag.name, "tr")) debugln(" ");
if (!tag.opened) {
debugch('/');
} else {
debugch(' ');
}
debugln(sprintf(#param, "%s x%i y%i %s",
#tag.name, draw_x, draw_y, #linebuf));
}
//*/
RenderTextbuf();
$push cur_encoding
SetStyle();
@ -193,12 +209,17 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
return;
}
}
break;
default:
_DEFAULT:
continue;
}
}
AddCharToTheLine(ESBYTE[bufpos]);
}
if (!secondrun) {
secondrun = true;
goto _PARSE_START_;
}
RenderTextbuf();
list.count = draw_y + style.cur_line_h;

View File

@ -1,3 +1,11 @@
/*
struct _DOM {
collection tag;
collection tagparam;
collection_int parent;
} dom;
*/
struct _tag
{
char name[32];
@ -121,7 +129,7 @@ dword _tag::get_next_param(dword ps, pe)
//find VAL start and copy
pe = strrchr(ps, q) + ps;
val = pe;
pe--;
if (pe>ps) pe--;
ESBYTE[pe] = '\0';
//find ATTR end

View File

@ -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,6 +152,8 @@ bool TWebBrowser::RenderImage(dword cur_img)
if (img_y + img_h >= canvas.bufh) canvas.IncreaseBufSize();
if (secondrun)
{
if (ESDWORD[cur_img+20] != IMAGE_BPP32) {
img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0);
$push eax
@ -160,8 +168,9 @@ bool TWebBrowser::RenderImage(dword cur_img)
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;
}

View File

@ -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;
}
if (tag.is("table")) {
if(tag.opened) {
tdepth++;
} else {
tdepth--;
if (tdepth>0) 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;
}
}
}
draw_x = left_gap = style.tag_list.level * 5 * list.font_w + BODY_MARGIN;
draw_w = list.w;
:void TWebBrowser::tag_tr()
{
if (tag.opened) {
if (tdepth>1) {
NewLine();
} 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();
}
}
}
: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);
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;
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;
}
}
}
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.number < 100) {
draw_w = draw_w - left_gap * tag.number / 100;
if (draw_w > list.w - left_gap) draw_w = list.w - left_gap;
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++;
}
}
}
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);
}
}
}

View File

@ -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';

View File

@ -107,4 +107,4 @@ char editbox_icons[] = FROM "res/editbox_icons.raw";
#define DEFAULT_URL URL_SERVICE_HOMEPAGE
char version[]="WebView 3.32";
char version[]="WebView 3.5";

View File

@ -20,14 +20,18 @@ Simple:
<a href=//mestack.narod.ru/index.html>mestack.narod.ru</a>
<a href=//coolthemes.narod.ru/indexold.html>coolthemes.narod.ru</a>
<a href=//vetusware.com>vetusware.com</a>
<a href=//th99.infania.net>Total Hardware 1999</a>
<a href=//toastytech.com/guis/index.html>GUI Gallery</a>
<a href=//menuetos.net>menuetos.net</a>
Moderate:
<a href=//fdd5-25.pdp-11.ru>fdd5-25</a>
<a href=//acmp.ru/index.asp?main=tasks>acmp.ru</a>
<a href=//old-dos.ru>old-dos.ru</a>
<a href=//www.weitek.com/textual/support/driver.html>weitek</a>
Complex:
<a href=//artcon.ru>artcon.ru</a>
<a href=//edition.cnn.com/EVENTS/1996/year.in.review>cnn 1996</a>
<a href=//nubo.ru>nubo.ru</a>
<a href=//salinc.ru>salinc.ru</a>
<a href=//electromyne.de>electromyne.de</a>