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_LINE_H 18
char line[500];
struct STYLE {
bool
b, u, s, h,
@ -48,18 +46,19 @@ struct TWebBrowser {
dword is_html;
collection img_url;
char header[150];
char line[500];
char redirect[URL_SIZE];
void SetStyle();
void Render();
void RenderTextbuf();
void RenderLine();
bool RenderImage();
void SetPageDefaults();
void AddCharToTheLine();
void ParseHtml();
bool CheckForLineBreak();
void NewLine();
void ChangeEncoding();
void AddCharToTheLine();
void DrawPage();
void tag_a();
@ -119,8 +118,6 @@ void TWebBrowser::SetPageDefaults()
}
//============================================================================================
void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
char unicode_symbol[10];
dword j;
int tab_len;
dword bufpos;
bufsize = _bufsize;
@ -148,40 +145,30 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
{
case 0x0a:
if (style.pre) {
Render();
RenderTextbuf();
NewLine();
} else {
AddCharToTheLine(' ');
goto _DEFAULT;
}
break;
case 0x09:
if (style.pre) {
tab_len = draw_x - left_gap / list.font_w + strlen(#line) % 4;
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 {
AddCharToTheLine(' ');
goto _DEFAULT;
}
break;
case '&': //&nbsp; and so on
for (j=1, unicode_symbol=0; (ESBYTE[bufpos+j]<>';') && (!__isWhite(ESBYTE[bufpos+j])) && (j<8); j++)
{
chrcat(#unicode_symbol, ESBYTE[bufpos+j]);
}
if (GetUnicodeSymbol(#line, #unicode_symbol, sizeof(line)-1)) {
bufpos += j;
CheckForLineBreak();
} else {
AddCharToTheLine('&');
}
bufpos = GetUnicodeSymbol(#line, sizeof(TWebBrowser.line), bufpos+1, bufpointer+bufsize);
break;
case '<':
if (!is_html) goto _DEFAULT;
if (!strchr("!/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", ESBYTE[bufpos+1])) goto _DEFAULT;
bufpos++;
if (tag.parse(#bufpos, bufpointer + bufsize)) {
CheckForLineBreak();
Render();
RenderTextbuf();
$push cur_encoding
SetStyle();
$pop eax
@ -199,11 +186,10 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
AddCharToTheLine(ESBYTE[bufpos]);
}
}
Render();
NewLine();
list.count = draw_y;
RenderTextbuf();
list.count = draw_y + style.cur_line_h;
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);
list.CheckDoesValuesOkey();
@ -217,47 +203,16 @@ void TWebBrowser::ParseHtml(dword _bufpointer, _bufsize){
//============================================================================================
void TWebBrowser::AddCharToTheLine(unsigned char _char)
{
dword line_len;
dword line_len = strlen(#line);
if (_char<=15) _char=' ';
line_len = strlen(#line);
if (!style.pre) && (_char == ' ')
{
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 (link) && (line_len==0) return;
}
if (line_len < sizeof(line)) chrcat(#line, _char);
CheckForLineBreak();
}
//============================================================================================
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;
if (line_len < sizeof(TWebBrowser.line)) chrcat(#line+line_len, _char);
if (line_len+1 * list.font_w + draw_x >= draw_w) RenderTextbuf();
}
//============================================================================================
void TWebBrowser::NewLine()
@ -290,9 +245,8 @@ void TWebBrowser::ChangeEncoding(int _new_encoding)
}
}
//============================================================================================
scroll_bar scroll_wv =
{ 15,NULL,NULL,NULL,0,2,NULL,
0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
scroll_bar scroll_wv = { 15,NULL,NULL,NULL,
0,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
void TWebBrowser::DrawPage()
{

View File

@ -1,6 +1,6 @@
CANVAS canvas;
void TWebBrowser::Render()
void TWebBrowser::RenderLine()
{
unsigned px; //paint x 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)
{
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("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("td")) { tag_td(); return; }
}
@ -105,12 +105,11 @@ void TWebBrowser::tag_iframe()
if (tag.get_value_of("src")) {
NewLine();
strcpy(#line, "IFRAME: ");
Render();
RenderTextbuf();
link=true;
links.add_link(tag.value);
strncpy(#line, tag.value, sizeof(line)-1);
while (CheckForLineBreak()) {};
Render();
strncpy(#line, tag.value, sizeof(TWebBrowser.line)-1);
RenderTextbuf();
link=false;
NewLine();
}
@ -191,15 +190,11 @@ void TWebBrowser::tag_li()
void TWebBrowser::tag_hr()
{
EAX = 0x999999;
if (tag.get_value_of("color")) GetColor(tag.value);
$push eax;
dword hrcol = 0x777777;
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);
NewLine();
$pop edi;
draw_y += 10;
canvas.DrawBar(5, draw_y - 1, list.w-10, 1, EDI);
NewLine();
draw_y += 10;
return;
}
@ -222,13 +217,7 @@ void TWebBrowser::tag_body()
void TWebBrowser::tag_q()
{
if (tag.opened) {
AddCharToTheLine(' ');
AddCharToTheLine('\"');
} else {
AddCharToTheLine('\"');
AddCharToTheLine(' ');
}
chrncat(#line, '\"', sizeof(TWebBrowser.line));
}
void TWebBrowser::tag_h1234_caption()
@ -303,19 +292,18 @@ IMGOK:
NOIMG:
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);
} else {
if (streqrp(#img_path, "data:")) img_path=0;
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, '/'));
line[50]= NULL;
}
while (CheckForLineBreak()) {};
text_colors.add(0x9A6F29);
style.image = true;
Render();
RenderTextbuf();
style.image = false;
text_colors.pop();
}
@ -330,6 +318,7 @@ int table_c=0;
void TWebBrowser::tag_table()
{
if (tag.opened) table_c++; else table_c--;
if (!tag.opened) NewLine();
}
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";
bool GetUnicodeSymbol(dword _line, in_tag, size)
bool GetUnicodeSymbol(dword _line, line_size, bufpos, buf_end)
{
int j;
int i;
int code;
char special_code[10];
bool white_end = false;
dword bufstart = bufpos;
for (j=0; unicode_symbols[j]!=0; j+=2;)
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);
return true;
strncat(_line, unicode_symbols[i+1], line_size);
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) {
chrncat(_line, code, size); //NOT ALL ASCII CODES IN KOLIBRI ARE COMPATABLE WITH STANDARDS
return true;
chrncat(_line, code, line_size); //NOT ALL ASCII CODES IN KOLIBRI ARE COMPATABLE WITH STANDARDS
return bufpos;
}
if (code>=1040) && (code<=1040+72) {
chrncat(_line, unicode_chars[code-1040], size);
return true;
chrncat(_line, unicode_chars[code-1040], line_size);
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
char version[]="WebView 3.27";
char version[]="WebView 3.28";