From 0cfade2ec008741906edd0ee6e20fbcd15729f6c Mon Sep 17 00:00:00 2001 From: leency Date: Mon, 10 Mar 2025 12:55:21 +0200 Subject: [PATCH] WebView 3.82: fix text rendering, speedup --- programs/cmm/browser/TWB/TWB.c | 27 +++---- programs/cmm/browser/TWB/render.h | 29 +++++--- programs/cmm/browser/TWB/set_style.h | 92 ++++++++++-------------- programs/cmm/browser/WebView.c | 2 +- programs/cmm/browser/const.h | 2 +- programs/cmm/browser/res/homepage_en.htm | 6 +- programs/cmm/browser/res/homepage_ru.htm | 19 +++-- 7 files changed, 82 insertions(+), 95 deletions(-) diff --git a/programs/cmm/browser/TWB/TWB.c b/programs/cmm/browser/TWB/TWB.c index 5d1159c8d..49d610519 100644 --- a/programs/cmm/browser/TWB/TWB.c +++ b/programs/cmm/browser/TWB/TWB.c @@ -101,16 +101,16 @@ void TWebBrowser::SetPageDefaults() img_url.drop(); text_colors.drop(); text_colors.add(0); - if (!secondrun) { - bg_colors.drop(); - bg_colors.add(DEFAULT_BG_COL); - } else { + if (secondrun) { + canvas.Init(list.x, list.y, list.w, math.max(list.visible, list.count)); canvas.Fill(0, bg_colors.get(0)); } + bg_colors.drop(); + bg_colors.add(DEFAULT_BG_COL); header = NULL; draw_y = BODY_MARGIN; draw_x = left_gap = BODY_MARGIN; - draw_w = list.w - BODY_MARGIN; + draw_w = list.w - BODY_MARGIN - BODY_MARGIN; linebuf = 0; redirect = '\0'; list.SetFont(8, 14, 10011000b); @@ -136,8 +136,6 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ dword bufpos; bufsize = _bufsize; - if (list.w!=canvas.bufw) canvas.Init(list.x, list.y, list.w, 400*20); - if (bufpointer == _bufpointer) { custom_encoding = cur_encoding; } else { @@ -156,7 +154,6 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ } } - table.cols.drop(); secondrun = false; @@ -219,19 +216,15 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ AddCharToTheLine(ESBYTE[bufpos]); } + RenderTextbuf(); + list.count = draw_y + style.cur_line_h; + list.CheckDoesValuesOkey(); + anchors.current = NULL; + if (!secondrun) { secondrun = true; goto _PARSE_START_; } - - RenderTextbuf(); - list.count = draw_y + style.cur_line_h; - - canvas.bufh = math.max(list.visible, list.count); - buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8); - - list.CheckDoesValuesOkey(); - anchors.current = NULL; if (!header) { strncpy(#header, #version, sizeof(TWebBrowser.header)-1); DrawTitle(#header); diff --git a/programs/cmm/browser/TWB/render.h b/programs/cmm/browser/TWB/render.h index 80f3be413..f1968fb56 100644 --- a/programs/cmm/browser/TWB/render.h +++ b/programs/cmm/browser/TWB/render.h @@ -22,11 +22,10 @@ void TWebBrowser::RenderLine(dword _line) zoom = list.font_w / BASIC_CHAR_W; //there is some shit happens!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - if (pw > draw_w) { - //draw_w = pw; - NewLine(); + if (pw > draw_w + BODY_MARGIN) { + //debugln("shit"); } - + if (debug_mode) { canvas.DrawBar(draw_x, draw_y, pw, list.item_h, 0xCCCccc); debugln(_line); @@ -83,12 +82,13 @@ void TWebBrowser::RenderTextbuf() //debugln(" \\n"); - //Is a new line fits in the current line? + //Is a new line fits in the maximum line width? if (br * list.font_w + draw_x - left_gap >= draw_w) { br = draw_w - draw_x + left_gap /list.font_w; + if (br < 0) br = 0; while(br) { if (ESBYTE[lbp + br]==' ') { - br++; + if (br < len) br++; break; } br--; @@ -96,7 +96,16 @@ void TWebBrowser::RenderTextbuf() } //Maybe a new line is too big for the whole new line? Then we have to split it if (!br) && (len * list.font_w >= draw_w) { + //debugln("bigbr"); + //debugval("draw_x", draw_x); + //debugval("draw_w", draw_w); br = draw_w - draw_x / list.font_w; + //debugval("cut into 1", br * list.font_w); + if (br < 0) { + NewLine(); + br = draw_w - draw_x / list.font_w; + //debugval("cut into 2", br * list.font_w); + } } if (br) { @@ -120,9 +129,13 @@ void TWebBrowser::NewLine() if (draw_x==left_gap) && (draw_y==BODY_MARGIN) return; if (t_html) && (!t_body) return; - + if (draw_x == style.tag_list.level * 5 * list.font_w + left_gap) { - if (!empty_line) empty_line=true; else return; + if (!empty_line) { + empty_line=true; + } else { + return; + } } else { empty_line = false; } diff --git a/programs/cmm/browser/TWB/set_style.h b/programs/cmm/browser/TWB/set_style.h index 8d140fadd..1f0e0393d 100644 --- a/programs/cmm/browser/TWB/set_style.h +++ b/programs/cmm/browser/TWB/set_style.h @@ -61,7 +61,7 @@ void TWebBrowser::SetStyle() void TWebBrowser::tag_p() { IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) return; - if (!tag.opened) && (streq(#tag.prior,"p")) return; + IF (!tag.opened) && (streq(#tag.prior,"p")) return; NewLine(); } @@ -119,6 +119,7 @@ void TWebBrowser::tag_iframe() void TWebBrowser::tag_a() { + if (!secondrun) return; if (tag.opened) { if (tag.get_value_of("href")) && (!strstr(tag.value,"javascript:")) @@ -133,6 +134,7 @@ void TWebBrowser::tag_a() void TWebBrowser::tag_meta_xml() { + if (secondrun) return; if (custom_encoding == -1) if (tag.get_value_of("charset")) || (tag.get_value_of("content")) || (tag.get_value_of("encoding")) { @@ -187,7 +189,7 @@ void TWebBrowser::tag_ol_ul_dt() void TWebBrowser::tag_li() { - if (style.nav) return; + //if (style.nav) return; if (tag.opened) { if (!style.tag_list.level) style.tag_list.upd_level(1, 'u'); if (!style.pre) NewLine(); @@ -216,13 +218,10 @@ void TWebBrowser::tag_hr() void TWebBrowser::tag_body() { t_body = tag.opened; - if (tag.get_value_of("link")) link_color_default = GetColor(tag.value); - if (tag.get_value_of("alink")) link_color_active = GetColor(tag.value); - if (tag.get_value_of("text")) text_colors.set(0, GetColor(tag.value)); - if (tag.get_value_of("bgcolor")) { - bg_colors.set(0, GetColor(tag.value)); - canvas.Fill(0, bg_colors.get(0)); - } + if (tag.get_value_of("link")) link_color_default = GetColor(tag.value); + if (tag.get_value_of("alink")) link_color_active = GetColor(tag.value); + if (tag.get_value_of("text")) text_colors.set(0, GetColor(tag.value)); + if (tag.get_value_of("bgcolor")) bg_colors.set(0, GetColor(tag.value)); // Autodetecting encoding if no encoding was set if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) { if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8); @@ -250,10 +249,10 @@ void TWebBrowser::tag_h1234_caption() NewLine(); } if (tag.is("h1")) { - list.SetFont(BASIC_CHAR_W*2, 14+12, 10011001b); + list.SetFont(BASIC_CHAR_W*2, 14+14, 10011001b); style.b = true; } else if (tag.is("h2")) { - list.SetFont(BASIC_CHAR_W*2, 14+12, 10011001b); + list.SetFont(BASIC_CHAR_W*2, 14+14, 10011001b); } else { list.SetFont(6*2, 9+7, 10001001b); } @@ -294,7 +293,7 @@ void TWebBrowser::tag_img() if (!strcmp(tag.value + strrchr(tag.value, '.'), "webp")) goto NOIMG; strlcpy(#img_path, tag.value, sizeof(img_path)-1); - replace_char(#img_path, ' ', '\0', sizeof(img_path)); + replace_char(#img_path, ' ', '\0', sizeof(img_path)-1); get_absolute_url(#img_path, history.current()); if (check_is_the_adress_local(#img_path)) { @@ -331,31 +330,28 @@ NOIMG: text_colors.pop(); } - - - - struct TABLE { - int count; int depth; int margin; collection_int cols; - collection_int width; } table; - -int tr_pos, td_pos; -int row_start_y; -int colcount; -dword tallest_cell_in_row; +unsigned table_id; +unsigned colcount; +unsigned tr_pos; +unsigned td_pos; +unsigned row_start_y; +unsigned tallest_cell_in_row; +unsigned cur_cell_w; void TWebBrowser::tag_table_reset() { - table.depth = 0; - table.count = 0; + table_id = 0; colcount = 0; tr_pos = 0; td_pos = 0; + table.depth = 0; + cur_cell_w = 0; } void TWebBrowser::tag_table() @@ -369,15 +365,15 @@ void TWebBrowser::tag_table() if(tag.opened) { table.depth++; if (table.depth==1) { - table.count++; + table_id++; colcount = 0; td_pos = 0; row_start_y = draw_y; if (tag.get_number_of("width")) { if (strchr(tag.value, '%')) tag.number = list.w * tag.number / 100; - table.width.set(table.count, math.min(tag.number,list.w)); + cur_cell_w = math.min(tag.number,list.w); } else { - table.width.set(table.count, list.w); + cur_cell_w = list.w; } } } else { @@ -436,26 +432,17 @@ void TWebBrowser::tag_table() if (!tr_pos) goto _TR_FIX; - /* - if (tag.opened) { - if (tag.get_value_of("bgcolor")) { - bg_colors.add(GetColor(tag.value)); - } else { - bg_colors.add(bg_colors.get(0)); - } - } */ - tallest_cell_in_row = math.max(draw_y+style.cur_line_h-list.item_h+1, tallest_cell_in_row); style.cur_line_h = list.item_h; - if (tag.opened) { - + if (tag.opened) + { if (!td_pos) { - table.margin = list.w - table.width.get(table.count) / 2 + BODY_MARGIN; + table.margin = list.w - cur_cell_w / 2 + BODY_MARGIN; draw_x = left_gap = table.margin; - draw_w = table.width.get(table.count) - BODY_MARGIN; + draw_w = cur_cell_w - BODY_MARGIN; } else { draw_x = left_gap = left_gap + draw_w; - draw_w = table.width.get(table.count) - left_gap + table.margin - BODY_MARGIN; + draw_w = cur_cell_w - left_gap + table.margin - BODY_MARGIN; } if (EAX = table.cols.get(tr_pos-1)-td_pos) { @@ -466,20 +453,18 @@ void TWebBrowser::tag_table() } if (table.cols.get(tr_pos-1)-td_pos>1) && (tag.get_number_of("width")) { if (strchr(tag.value, '%')) { - tag.number = table.width.get(table.count) - table.margin - 23 - left_gap * tag.number / 100; + tag.number = cur_cell_w - table.margin - 23 - left_gap * tag.number / 100; } if (tag.number < draw_w) draw_w = tag.number; } draw_y = row_start_y; - //canvas.WriteText(draw_x, draw_y, 10001001b, 0x0000FE, itoa(draw_x), NULL); - //canvas.WriteText(draw_x, draw_y+20, 10001001b, 0xFF0000, itoa(draw_w), NULL); td_pos++; } } } - if (draw_x > table.width.get(table.count)) { + if (draw_x > cur_cell_w) { draw_x = left_gap = table.margin; - draw_w = table.width.get(table.count) - table.margin - 23 - left_gap; + draw_w = cur_cell_w - table.margin - 23 - left_gap; table.depth = 0; NewLine(); if (debug_mode) { @@ -487,11 +472,8 @@ void TWebBrowser::tag_table() canvas.DrawBar(0, draw_y, 20, 20, 0xFF0000); } } - /* - if (left_gap + draw_w > list.w) { - draw_w = list.w - left_gap; - if (debug_mode) debugln("anomaly draw_W"); - } - */ -} - + //if (left_gap + draw_w > list.w) { + // draw_w = list.w - left_gap; + // if (debug_mode) debugln("anomaly draw_W"); + //} +} \ No newline at end of file diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 6ecfb9986..2a43dc97d 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -1,4 +1,4 @@ -//Copyright 2007-2021 by Veliant & Leency +//Copyright 2007-2025 by Veliant & Leency //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... //BUGS diff --git a/programs/cmm/browser/const.h b/programs/cmm/browser/const.h index 7b5ce7496..f6b155a59 100644 --- a/programs/cmm/browser/const.h +++ b/programs/cmm/browser/const.h @@ -112,4 +112,4 @@ char editbox_icons[] = FROM "res/editbox_icons.raw"; #define DEFAULT_URL URL_SERVICE_HOMEPAGE -char version[]="WebView 3.8"; \ No newline at end of file +char version[]="WebView 3.82"; \ No newline at end of file diff --git a/programs/cmm/browser/res/homepage_en.htm b/programs/cmm/browser/res/homepage_en.htm index 77f5f175c..f5107e5bf 100644 --- a/programs/cmm/browser/res/homepage_en.htm +++ b/programs/cmm/browser/res/homepage_en.htm @@ -4,10 +4,10 @@
Welcome to WebView a Text-Based Browser. 
 
-Bookmarks:
-1. KolibriOS homepage
+KolibriOS Bookmarks:
+1. Homepage
 2. Night-builds
-3. KolibriOS FTP
+3. FTP Server
 
 By the way, 
 • You can check for browser updates from the main menu.
diff --git a/programs/cmm/browser/res/homepage_ru.htm b/programs/cmm/browser/res/homepage_ru.htm
index 6db213579..2639aa66f 100644
--- a/programs/cmm/browser/res/homepage_ru.htm
+++ b/programs/cmm/browser/res/homepage_ru.htm
@@ -1,16 +1,15 @@
-
-
-
-Домашняя страница
-
-
Закладки:
-1. Официальный сайт KolibriOS
-2. Ночные сборки
-3. KolibriOS FTP
+
+Домашняя страница
+
Добро пожаловать текстовый браузер WebView!
+
+Ресурсы KolibriOS:
    +
  1. Официальный сайт +
  2. Ночные сборки +
  3. FTP сервер
Кстати, • Из главного меню можно проверить наличие обновлений • Для поиска в Google наберите тест в адресной строке и нажмите Ctrl+Enter • Клавиша F6 перемещает текстовый курсор в омнибокс. • Можно изменить кодировку страницы, для этого нажмите на надпись в правом нижнем углу окна. - +