WebView 3.28: fixes in tags q, hr; refactoring

git-svn-id: svn://kolibrios.org@8491 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-12-28 21:43:46 +00:00
parent 0aaee5cee7
commit 7913a353d7
5 changed files with 92 additions and 105 deletions

View File

@ -12,8 +12,6 @@ dword link_color_active;
#define BASIC_CHAR_W 8 #define BASIC_CHAR_W 8
#define BASIC_LINE_H 18 #define BASIC_LINE_H 18
char line[500];
struct STYLE { struct STYLE {
bool bool
b, u, s, h, b, u, s, h,
@ -48,18 +46,19 @@ struct TWebBrowser {
dword is_html; dword is_html;
collection img_url; collection img_url;
char header[150]; char header[150];
char line[500];
char redirect[URL_SIZE]; char redirect[URL_SIZE];
void SetStyle(); void SetStyle();
void Render(); void RenderTextbuf();
void RenderLine();
bool RenderImage(); bool RenderImage();
void SetPageDefaults(); void SetPageDefaults();
void AddCharToTheLine();
void ParseHtml(); void ParseHtml();
bool CheckForLineBreak();
void NewLine(); void NewLine();
void ChangeEncoding(); void ChangeEncoding();
void AddCharToTheLine();
void DrawPage(); void DrawPage();
void tag_a(); void tag_a();
@ -119,8 +118,6 @@ void TWebBrowser::SetPageDefaults()
} }
//============================================================================================ //============================================================================================
void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
char unicode_symbol[10];
dword j;
int tab_len; int tab_len;
dword bufpos; dword bufpos;
bufsize = _bufsize; bufsize = _bufsize;
@ -148,40 +145,30 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
{ {
case 0x0a: case 0x0a:
if (style.pre) { if (style.pre) {
Render(); RenderTextbuf();
NewLine(); NewLine();
} else { } else {
AddCharToTheLine(' '); goto _DEFAULT;
} }
break; break;
case 0x09: case 0x09:
if (style.pre) { if (style.pre) {
tab_len = draw_x - left_gap / list.font_w + strlen(#line) % 4; tab_len = draw_x - left_gap / list.font_w + strlen(#line) % 4;
if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len; if (!tab_len) tab_len = 4; else tab_len = 4 - tab_len;
for (j=0; j<tab_len; j++;) chrcat(#line,' '); while (tab_len) {chrcat(#line,' '); tab_len--;}
} else { } else {
AddCharToTheLine(' '); goto _DEFAULT;
} }
break; break;
case '&': //&nbsp; and so on case '&': //&nbsp; and so on
for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (!__isWhite(ESBYTE[bufpos+j])) && (j<8); j++) bufpos = GetUnicodeSymbol(#line, sizeof(TWebBrowser.line), bufpos+1, bufpointer+bufsize);
{
chrcat(#unicode_symbol, ESBYTE[bufpos+j]);
}
if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
bufpos += j;
CheckForLineBreak();
} else {
AddCharToTheLine('&');
}
break; break;
case '<': case '<':
if (!is_html) goto _DEFAULT; if (!is_html) goto _DEFAULT;
if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT; if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT;
bufpos++; bufpos++;
if (tag.parse(#bufpos, bufpointer + bufsize)) { if (tag.parse(#bufpos, bufpointer + bufsize)) {
CheckForLineBreak(); RenderTextbuf();
Render();
$push cur_encoding $push cur_encoding
SetStyle(); SetStyle();
$pop eax $pop eax
@ -199,11 +186,10 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
AddCharToTheLine(ESBYTE[bufpos]); AddCharToTheLine(ESBYTE[bufpos]);
} }
} }
Render(); RenderTextbuf();
NewLine(); list.count = draw_y + style.cur_line_h;
list.count = draw_y;
canvas.bufh = math.max(list.visible, draw_y); canvas.bufh = math.max(list.visible, list.count);
buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8); buf_data = realloc(buf_data, canvas.bufh * canvas.bufw * 4 + 8);
list.CheckDoesValuesOkey(); list.CheckDoesValuesOkey();
@ -217,47 +203,16 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
//============================================================================================ //============================================================================================
void TWebBrowser::AddCharToTheLine(unsigned char _char) void TWebBrowser::AddCharToTheLine(unsigned char _char)
{ {
dword line_len; dword line_len = strlen(#line);
if (_char<=15) _char=' '; if (_char<=15) _char=' ';
line_len = strlen(#line);
if (!style.pre) && (_char == ' ') if (!style.pre) && (_char == ' ')
{ {
if (line[line_len-1]==' ') return; //no double spaces if (line[line_len-1]==' ') return; //no double spaces
if (draw_x==left_gap) && (!line) return; //no paces at the beginning of the line if (draw_x==left_gap) && (!line) return; //no paces at the beginning of the line
if (link) && (line_len==0) return; if (link) && (line_len==0) return;
} }
if (line_len < sizeof(line)) chrcat(#line, _char); if (line_len < sizeof(TWebBrowser.line)) chrcat(#line+line_len, _char);
CheckForLineBreak(); if (line_len+1 * list.font_w + draw_x >= draw_w) RenderTextbuf();
}
//============================================================================================
bool TWebBrowser::CheckForLineBreak()
{
int break_pos;
char next_line[4096];
int zoom = list.font_w / BASIC_CHAR_W;
//Do we need a line break?
if (strlen(#line) * list.font_w + draw_x < draw_w) return false;
//Yes, we do. Lets calculate where...
break_pos = strrchr(#line, ' ');
//Is a new line fits in the current line?
if (break_pos * list.font_w + draw_x > draw_w) {
break_pos = draw_w - draw_x /list.font_w;
while(break_pos) && (line[break_pos]!=' ') break_pos--;
}
//Maybe a new line is too big for the whole new line? Then we have to split it
if (!break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
break_pos = draw_w - draw_x / list.font_w;
}
strcpy(#next_line, #line + break_pos);
line[break_pos] = 0x00;
Render();
strcpy(#line, #next_line);
NewLine();
return true;
} }
//============================================================================================ //============================================================================================
void TWebBrowser::NewLine() void TWebBrowser::NewLine()
@ -290,9 +245,8 @@ void TWebBrowser::ChangeEncoding(int _new_encoding)
} }
} }
//============================================================================================ //============================================================================================
scroll_bar scroll_wv = scroll_bar scroll_wv = { 15,NULL,NULL,NULL,
{ 15,NULL,NULL,NULL,0,2,NULL, 0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
void TWebBrowser::DrawPage() void TWebBrowser::DrawPage()
{ {

View File

@ -1,6 +1,6 @@
CANVAS canvas; CANVAS canvas;
void TWebBrowser::Render() void TWebBrowser::RenderLine()
{ {
unsigned px; //paint x coordinate unsigned px; //paint x coordinate
unsigned pw; //paint y coordinate unsigned pw; //paint y coordinate
@ -58,6 +58,38 @@ void TWebBrowser::Render()
} }
} }
void TWebBrowser::RenderTextbuf()
{
int break_pos;
char next_line[4096];
int zoom = list.font_w / BASIC_CHAR_W;
//Do we need a line break?
while (strlen(#line) * list.font_w + draw_x >= draw_w) {
//Yes, we do. Lets calculate where...
break_pos = strrchr(#line, ' ');
//Is a new line fits in the current line?
if (break_pos * list.font_w + draw_x > draw_w) {
break_pos = draw_w - draw_x /list.font_w;
while(break_pos) && (line[break_pos]!=' ') break_pos--;
}
//Maybe a new line is too big for the whole new line? Then we have to split it
if (!break_pos) && (style.tag_list.level*5 + strlen(#line) * zoom >= list.column_max) {
break_pos = draw_w - draw_x / list.font_w;
}
strcpy(#next_line, #line + break_pos);
line[break_pos] = 0x00;
RenderLine();
strcpy(#line, #next_line);
NewLine();
}
RenderLine();
}
bool TWebBrowser::RenderImage(dword cur_img) bool TWebBrowser::RenderImage(dword cur_img)
{ {
int img_x, img_y, img_w, img_h; int img_x, img_y, img_w, img_h;

View File

@ -51,8 +51,8 @@ void TWebBrowser::SetStyle()
if (tag.is("body")) { tag_body(); return; } if (tag.is("body")) { tag_body(); return; }
if (tag.is("html")) { t_html = tag.opened; return; } if (tag.is("html")) { t_html = tag.opened; return; }
//TO BE REWORKED if (tag.is("table")) { tag_table(); 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("tr")) { tag_tr(); return; }
//if (tag.is("td")) { tag_td(); return; } //if (tag.is("td")) { tag_td(); return; }
} }
@ -105,12 +105,11 @@ void TWebBrowser::tag_iframe()
if (tag.get_value_of("src")) { if (tag.get_value_of("src")) {
NewLine(); NewLine();
strcpy(#line, "IFRAME: "); strcpy(#line, "IFRAME: ");
Render(); RenderTextbuf();
link=true; link=true;
links.add_link(tag.value); links.add_link(tag.value);
strncpy(#line, tag.value, sizeof(line)-1); strncpy(#line, tag.value, sizeof(TWebBrowser.line)-1);
while (CheckForLineBreak()) {}; RenderTextbuf();
Render();
link=false; link=false;
NewLine(); NewLine();
} }
@ -191,15 +190,11 @@ void TWebBrowser::tag_li()
void TWebBrowser::tag_hr() void TWebBrowser::tag_hr()
{ {
EAX = 0x999999; dword hrcol = 0x777777;
if (tag.get_value_of("color")) GetColor(tag.value); if (tag.get_value_of("color")) hrcol = GetColor(tag.value);
$push eax; if (draw_x != left_gap) NewLine();
canvas.DrawBar(5, style.cur_line_h / 2 + draw_y - 1, draw_w-10, 1, hrcol);
NewLine(); NewLine();
$pop edi;
draw_y += 10;
canvas.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
NewLine();
draw_y += 10;
return; return;
} }
@ -222,13 +217,7 @@ void TWebBrowser::tag_body()
void TWebBrowser::tag_q() void TWebBrowser::tag_q()
{ {
if (tag.opened) { chrncat(#line, '\"', sizeof(TWebBrowser.line));
AddCharToTheLine(' ');
AddCharToTheLine('\"');
} else {
AddCharToTheLine('\"');
AddCharToTheLine(' ');
}
} }
void TWebBrowser::tag_h1234_caption() void TWebBrowser::tag_h1234_caption()
@ -303,19 +292,18 @@ IMGOK:
NOIMG: NOIMG:
if (tag.get_value_of("title")) || (tag.get_value_of("alt")) { if (tag.get_value_of("title")) || (tag.get_value_of("alt")) {
strncpy(#img_path, tag.value, sizeof(line)-3); strncpy(#img_path, tag.value, sizeof(TWebBrowser.line)-3);
sprintf(#line, "[%s]", #img_path); sprintf(#line, "[%s]", #img_path);
} else { } else {
if (streqrp(#img_path, "data:")) img_path=0; if (streqrp(#img_path, "data:")) img_path=0;
replace_char(#img_path, '?', NULL, strlen(#img_path)); replace_char(#img_path, '?', NULL, strlen(#img_path));
img_path[sizeof(line)-3] = '\0'; //prevent overflow in sprintf img_path[sizeof(TWebBrowser.line)-3] = '\0'; //prevent overflow in sprintf
sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/')); sprintf(#line, "[%s]", #img_path+strrchr(#img_path, '/'));
line[50]= NULL; line[50]= NULL;
} }
while (CheckForLineBreak()) {};
text_colors.add(0x9A6F29); text_colors.add(0x9A6F29);
style.image = true; style.image = true;
Render(); RenderTextbuf();
style.image = false; style.image = false;
text_colors.pop(); text_colors.pop();
} }
@ -330,6 +318,7 @@ int table_c=0;
void TWebBrowser::tag_table() void TWebBrowser::tag_table()
{ {
if (tag.opened) table_c++; else table_c--; if (tag.opened) table_c++; else table_c--;
if (!tag.opened) NewLine();
} }
void TWebBrowser::tag_tr() void TWebBrowser::tag_tr()

View File

@ -68,32 +68,44 @@ char *unicode_symbols[]={
unsigned char unicode_chars[] = "<EFBFBD>ƒ„…†‡ˆ‰ŠŒ<EFBFBD>Ž<EFBFBD><EFBFBD>“”•˜™šœ<EFBFBD>žŸ ¡¢£¤¥¦§¨©ª«¬­®¯àáâãäåæçèéêëìíîïðñh£\243i\105\244\0"; unsigned char unicode_chars[] = "<EFBFBD>ƒ„…†‡ˆ‰ŠŒ<EFBFBD>Ž<EFBFBD><EFBFBD>“”•˜™šœ<EFBFBD>žŸ ¡¢£¤¥¦§¨©ª«¬­®¯àáâãäåæçèéêëìíîïðñh£\243i\105\244\0";
bool GetUnicodeSymbol(dword _line, in_tag, size) bool GetUnicodeSymbol(dword _line, line_size, bufpos, buf_end)
{ {
int j; int i;
int code; int code;
char special_code[10];
for (j=0; unicode_symbols[j]!=0; j+=2;) bool white_end = false;
dword bufstart = bufpos;
for (i=0; i<9; i++, bufpos++)
{ {
if (!strcmp(in_tag, unicode_symbols[j])) if (__isWhite(ESBYTE[bufpos])) {bufpos--; break;}
if (ESBYTE[bufpos] == ';') || (bufpos >= buf_end) break;
special_code[i] = ESBYTE[bufpos];
}
special_code[i] = '\0';
for (i=0; unicode_symbols[i]!=0; i+=2;)
{
if (!strcmp(#special_code, unicode_symbols[i]))
{ {
strncat(_line, unicode_symbols[j+1], size); strncat(_line, unicode_symbols[i+1], line_size);
return true; return bufpos;
} }
} }
if (ESBYTE[in_tag]=='#') if (special_code[0]=='#')
{ {
code = atoi(in_tag + 1); code = atoi(#special_code + 1);
if (code>=0) && (code<=255) { if (code>=0) && (code<=255) {
chrncat(_line, code, size); //NOT ALL ASCII CODES IN KOLIBRI ARE COMPATABLE WITH STANDARDS chrncat(_line, code, line_size); //NOT ALL ASCII CODES IN KOLIBRI ARE COMPATABLE WITH STANDARDS
return true; return bufpos;
} }
if (code>=1040) && (code<=1040+72) { if (code>=1040) && (code<=1040+72) {
chrncat(_line, unicode_chars[code-1040], size); chrncat(_line, unicode_chars[code-1040], line_size);
return true; return bufpos;
} }
} }
return false; chrncat(_line, '&', line_size);
return bufstart;
} }

View File

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