Aelia 0.2: improve label.smooth function (thanks e-andrew), a very basic html support implemented

git-svn-id: svn://kolibrios.org@6053 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-01-10 22:33:10 +00:00
parent de145064c8
commit e5231646b3
6 changed files with 149 additions and 115 deletions

View File

@ -59,6 +59,7 @@ edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#add
#include "ini.h" #include "ini.h"
#include "gui.h" #include "gui.h"
#include "label.h"
#include "prepare_page.h" #include "prepare_page.h"
void InitDlls() void InitDlls()
@ -96,12 +97,13 @@ void main()
HandleButtonEvent(); HandleButtonEvent();
break; break;
case evReDraw: case evReDraw:
draw_window();
if (menu.list.cur_y) { if (menu.list.cur_y) {
encoding = menu.list.cur_y - 10; encoding = menu.list.cur_y - 10;
debugln("evReDraw: charset changed"); debugln("evReDraw: charset changed");
EventOpenAddress(history.current()); EventOpenAddress(history.current());
menu.list.cur_y = 0;
} }
draw_window();
} }
} }
} }
@ -268,7 +270,7 @@ char temp[UML];
} }
if (!downloader.Start(#address)) { if (!downloader.Start(#address)) {
downloader.Stop(); downloader.Stop();
} else { } else {
while (downloader.state!=STATE_COMPLETED) while (downloader.state!=STATE_COMPLETED)
{ {
downloader.MonitorProgress(); downloader.MonitorProgress();

View File

@ -42,9 +42,9 @@ dword MakePageWithHistory()
enum { enum {
STEP_1_DOWNLOAD_PAGE = 0, STEP_1_DOWNLOAD_PAGE = 0,
STEP_2_COUNT_PAGE_HEIGHT = 30, STEP_2_COUNT_PAGE_HEIGHT = 35,
STEP_3_DRAW_PAGE_INTO_BUFFER = 60, STEP_3_DRAW_PAGE_INTO_BUFFER = 60,
STEP_4_SMOOTH_FONT = 94, STEP_4_SMOOTH_FONT = 88,
STEP_5_STOP = 100, STEP_5_STOP = 100,
}; };
@ -54,22 +54,9 @@ void DrawProgress(int percent)
if (percent<100) { if (percent<100) {
progress_width = address_box.width+5*percent/100; progress_width = address_box.width+5*percent/100;
DrawBar(address_box.left-3, address_box.top+16, progress_width, 2, 0x72B7EA); DrawBar(address_box.left-3, address_box.top+16, progress_width, 2, 0x72B7EA);
//debugi(percent);
} }
else { else {
progress_width = address_box.width+5; progress_width = address_box.width+5;
DrawBar(address_box.left-3, address_box.top+16, progress_width, 2, 0xFFFfff); DrawBar(address_box.left-3, address_box.top+16, progress_width, 2, 0xFFFfff);
} }
} }
int progress_percent;
void DrawProgressWhileDrawing(dword bufoff, buflen)
{
int progress_cur = bufoff - io.buffer_data;
int progress_max = buflen - io.buffer_data;
int new_progress_percent = STEP_4_SMOOTH_FONT-STEP_3_DRAW_PAGE_INTO_BUFFER*progress_cur/progress_max + STEP_3_DRAW_PAGE_INTO_BUFFER;
if (progress_percent != new_progress_percent) {
progress_percent = new_progress_percent;
DrawProgress(progress_percent);
}
}

View File

@ -0,0 +1,43 @@
char char_width[255];
void get_label_symbols_size()
{
int i;
label.changeSIZE();
for (i=0; i<256; i++) char_width[i] = label.symbol_size(i);
}
int get_label_len(dword _text)
{
int len=0;
byte ch;
loop () {
ch = ESBYTE[_text];
if (!ch) return len;
len += char_width[ch];
_text++;
}
}
void WriteTextIntoBuf(int _x, _y; dword _text_col, _text_off)
{
char error_message[128];
if (_x > list.w) {
sprintf(#error_message, "\nWriteTextIntoBuf _x overflow: H %d X %d \n", label.size.height, _x);
notify(#error_message);
}
if (_y+label.size.pt > label.size.height) {
sprintf(#error_message, "\nWriteTextIntoBuf _y overflow: H %d Y %d \n", label.size.height, _y);
notify(#error_message);
return;
}
label.write_buf(_x, _y, list.w, label.size.height, 0xFFFFFF, _text_col, label.size.pt, _text_off);
if (_y/list.item_h-list.first==list.visible) DrawPage();
}
void label_draw_bar(dword _x, _y, _w, _color)
{
int i;
for (i = _y*list.w+_x*3+label.raw ; i<_y*list.w+_x+_w*3+label.raw ; i+=3) ESDWORD[i] = _color;
}

View File

@ -1,30 +1,24 @@
char char_width[255];
void PreparePage() void PreparePage()
{ {
int i; list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, label.size.pt+2);
list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, Form.cheight-TOOLBAR_H, label.size.pt+1); strcpy(#title, history.current()+strrchr(history.current(),'/'));
//get font chars width, need to increase performance //get font chars width, need to increase performance
//if (strstri(io.buffer_data, "<html>")==-1) { get_label_symbols_size();
ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
if (strstri(io.buffer_data, "<html")==-1) {
debugln("no <html> found"); debugln("no <html> found");
label.changeSIZE(); DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceTxt(false); //get page height to calculate buffer size
for (i=0; i<256; i++) char_width[i] = label.symbol_size(i); DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true); //draw text in buffer
ChangeCharset(charsets[encoding], "CP866", io.buffer_data); } else {
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceTxt(false); //get page height to calculate buffer size
DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceTxt(true); //draw text in buffer
DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth();
DrawProgress(STEP_5_STOP); DrawPage();
/*}
else {
debugln("<html> tag found"); debugln("<html> tag found");
label.changeSIZE(); DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceHtml(false); //get page height to calculate buffer size
for (i=0; i<256; i++) char_width[i] = label.symbol_size(i); DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true); //draw text in buffer
ChangeCharset(charsets[encoding], "CP866", io.buffer_data); }
DrawProgress(STEP_2_COUNT_PAGE_HEIGHT); ParceHtml(false); //get page height to calculate buffer size strcat(#title, " - Aelia");
DrawProgress(STEP_3_DRAW_PAGE_INTO_BUFFER); ParceHtml(true); //draw text in buffer DrawTitle(#title);
DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth(); DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth();
DrawProgress(STEP_5_STOP); DrawPage(); DrawProgress(STEP_5_STOP); DrawPage();
}*/
} }
void ParceTxt(byte draw) void ParceTxt(byte draw)
@ -49,10 +43,8 @@ int stroka_y=5, line_length=0;
} }
if (draw==true) { if (draw==true) {
ESBYTE[bufoff] >< zeroch; //set line end ESBYTE[bufoff] >< zeroch; //set line end
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start); WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
ESBYTE[bufoff] >< zeroch; //restore line ESBYTE[bufoff] >< zeroch; //restore line
DrawProgressWhileDrawing(bufoff, buflen);
if (stroka_y/list.item_h-list.first==list.visible) DrawPage();
} }
stroka_y += list.item_h; stroka_y += list.item_h;
line_start = bufoff; line_start = bufoff;
@ -65,7 +57,7 @@ int stroka_y=5, line_length=0;
label.size.height = list.count+1*list.item_h; label.size.height = list.count+1*list.item_h;
label.raw_size = 0; label.raw_size = 0;
} }
if (draw==true) label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start); if (draw==true) WriteTextIntoBuf(8, stroka_y, 0x000000, line_start);
} }
@ -75,18 +67,7 @@ int stroka_y=5, line_length=0;
= = = =
========================================================*/ ========================================================*/
/* /* <title> <meta encoding> <a hrf=""> <img src="" alt=""> <h1>..<h6> <b> <u> <s> <pre> */
HTML parcer tags:
<title>
<meta encoding>
<a hrf="">
<img src="" alt="">
<h1> ... <h6>
<b>
<u>
<s>
<pre>
*/
struct _DOM { struct _DOM {
dword start; dword start;
@ -99,87 +80,121 @@ struct _style {
bool h1, h2, h3, h4, h5, h6; bool h1, h2, h3, h4, h5, h6;
bool a; bool a;
bool pre; bool pre;
bool title; bool ignore;
bool br; dword color;
} style; } style;
struct _text {
dword start;
int x, y;
};
struct _tag { struct _tag {
dword start; dword start;
dword name; dword name;
dword param[10]; dword param[10];
dword value[10]; dword value[10];
void parce(); void parce();
void get_param_value(); int nameis();
}; };
void _tag::parce() void _tag::parce()
{ {
bool closed_status = false; dword o = name = start;
if (start) debugln(start); while (ESBYTE[o]!=' ') && (ESBYTE[o]) o++; //searching for a space after tag name
/* ESBYTE[o] = '\0';
if (strncmp(start, "/", 1)==0) { strlwr(name);
start++;
closed_status = true;
}
if (!strcmp(start, "title")) style.title = closed_status;
if (!strcmp(start, "br")) style.br = closed_status;
*/
} }
struct _text { int _tag::nameis(dword _in_tag_name)
dword start;
int x, y;
void draw();
};
void _text::draw()
{ {
if (start) debugln(start); if (strcmp(_in_tag_name, name)==0) return true;
/* return false;
if (style.title) {
strlcpy(#title, start, sizeof(title));
DrawTitle(#title);
return;
}
if (style.br) {
y += list.item_h;
style.br = false;
}
*/
} }
#define HTML_PADDING_X 8;
#define HTML_PADDING_Y 5;
void ParceHtml(byte draw) void ParceHtml(byte draw)
{ {
byte ch; int stroka_x = HTML_PADDING_X;
int stroka_y = HTML_PADDING_Y;
dword line_break;
byte ch, zeroch;
_DOM DOM; _DOM DOM;
_text text; _text text;
_tag tag; _tag tag;
dword DOM_pos; dword DOM_pos;
/* Create DOM */ /* Create DOM */
debugln("starting DOM parce"); debugln("creating DOM");
DOM.len = strlen(io.buffer_data); DOM.len = strlen(io.buffer_data);
DOM.start = malloc(DOM.len); DOM.start = malloc(DOM.len);
DOM.end = DOM.start + DOM.len; DOM.end = DOM.start + DOM.len;
strlcpy(DOM.start, io.buffer_data, DOM.len); strlcpy(DOM.start, io.buffer_data, DOM.len);
/* Parce DOM */ /* Parce DOM */
debugln("starting DOM parce...");
text.start = DOM_pos; text.start = DOM_pos;
for (DOM_pos=DOM.start; DOM_pos<DOM.end; DOM_pos++) for (DOM_pos=DOM.start; DOM_pos<DOM.end; DOM_pos++)
{ {
if (ESBYTE[DOM_pos]==0x0D) || (ESBYTE[DOM_pos]==0x0A) ESBYTE[DOM_pos]=' ';
ch = ESBYTE[DOM_pos]; ch = ESBYTE[DOM_pos];
//debugch(ch);
if (ch=='<') { if (ch=='<') {
ESBYTE[DOM_pos] = NULL; ESBYTE[DOM_pos] = '\0';
tag.start = DOM_pos + 1; tag.start = DOM_pos + 1;
text.draw(); if (style.ignore) continue;
if (tag.nameis("title")) {
strcpy(#title, text.start);
continue;
}
while (get_label_len(text.start) + stroka_x + 30 > list.w)
{
//debugln("long line cut");
zeroch = 0;
for (line_break=tag.start-1; line_break>text.start; line_break--;)
{
ESBYTE[line_break] >< zeroch; //set line end
if (get_label_len(text.start) + stroka_x + 30 <= list.w) break;
ESBYTE[line_break] >< zeroch; //restore line
}
if (draw==true) {
if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
}
ESBYTE[line_break] >< zeroch; //restore line
text.start = line_break;
stroka_x = HTML_PADDING_X;
stroka_y += list.item_h;
}
if (draw==true) {
if (style.a) label_draw_bar(stroka_x, stroka_y+label.size.pt+1, get_label_len(text.start), style.color);
WriteTextIntoBuf(stroka_x, stroka_y, style.color, text.start);
}
stroka_x += get_label_len(text.start);
} }
if (ch=='>') { if (ch=='>') {
ESBYTE[DOM_pos] = NULL; ESBYTE[DOM_pos] = '\0';
text.start = DOM_pos + 1; text.start = DOM_pos + 1;
tag.parce(); tag.parce();
if (tag.nameis("br")) || (tag.nameis("p")) || (tag.nameis("div")) || (tag.nameis("h1")) || (tag.nameis("h2")) {
stroka_y+= list.item_h;
stroka_x = HTML_PADDING_X;
continue;
}
if (tag.nameis("script")) || (tag.nameis("style")) style.ignore = true;
if (tag.nameis("/script")) || (tag.nameis("/style")) style.ignore = false;
if (tag.nameis("a")) { style.a = true; style.color=0x0000FF; }
if (tag.nameis("/a")) { style.a = false; style.color=0x000000; }
} }
} }
if (draw==false) {
list.count = stroka_y/list.item_h+2;
if (list.count < list.visible) list.count = list.visible;
label.size.height = list.count+1*list.item_h;
label.raw_size = 0;
}
free(DOM.start); free(DOM.start);
ExitProcess();
} }

View File

@ -210,11 +210,10 @@ byte Cp866ToAnsi(byte s) {
=====================================================================================*/ =====================================================================================*/
inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
:void LABEL::apply_smooth() :void LABEL::apply_smooth()
{ {
dword i,line_w,to; dword i,line_w,to,dark_background;
rgb.DwordToRgb(ShadowPixel(background,2)); //get shadowed pixel
line_w = size.width * 3; line_w = size.width * 3;
to = size.height - 1 * line_w + raw - 3; to = size.height - 1 * line_w + raw - 3;
for(i=raw; i < to; i+=3) for(i=raw; i < to; i+=3)
@ -223,31 +222,19 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
// pixels position, where b - black, w - write // pixels position, where b - black, w - write
// bw // bw
// wb // wb
if(b24(i)==0x000000) && (b24(i+3)!=0x000000) && (b24(i+line_w)!=0x000000) && (b24(i+3+line_w)==0x000000) if(b24(i)!=background) && (b24(i+3)==background) && (b24(i+line_w)==background) && (b24(i+3+line_w)!=background)
{ {
ESBYTE[i+3] = rgb.b; dark_background = MixColors(background,b24(i),200);
ESBYTE[i+4] = rgb.g; DSDWORD[i+3] = DSDWORD[i+3] & 0xFF000000 | dark_background;
ESBYTE[i+5] = rgb.r; DSDWORD[i+line_w] = DSDWORD[i+line_w] & 0xFF000000 | dark_background;
ESBYTE[i+line_w ] = rgb.b;
ESBYTE[i+line_w+1] = rgb.g;
ESBYTE[i+line_w+2] = rgb.r;
// // I don't know why but underneath code works slower then beneath
// DSDWORD[i] = DSDWORD[i] & 0xFF000000 | dark_background;
// DSDWORD[i+line_w] = DSDWORD[i+3+line_w] & 0xFF000000 | dark_background;
} }
// wb // wb
// bw // bw
else if(b24(i)!=0x000000) && (b24(i+3)==0x000000) && (b24(i+line_w)==0x000000) && (b24(i+3+line_w)!=0x000000) else if(b24(i)==background) && (b24(i+3)!=background) && (b24(i+line_w)!=background) && (b24(i+3+line_w)==background)
{ {
ESBYTE[i ] = rgb.b; dark_background = MixColors(background,b24(i+3),200);
ESBYTE[i+1] = rgb.g; DSDWORD[i] = DSDWORD[i] & 0xFF000000 | dark_background;
ESBYTE[i+2] = rgb.r; DSDWORD[i+3+line_w] = DSDWORD[i+3+line_w] & 0xFF000000 | dark_background;
ESBYTE[i+line_w+3] = rgb.b;
ESBYTE[i+line_w+4] = rgb.g;
ESBYTE[i+line_w+5] = rgb.r;
// // I don't know why but underneath code works slower then beneath
// DSDWORD[i] = DSDWORD[i] & 0xFF000000 | dark_background;
// DSDWORD[i+3+line_w] = DSDWORD[i+3+line_w] & 0xFF000000 | dark_background;
} }
} }
} }