kfont: remove italic style, some code cleanup in browser and lib/font.h

git-svn-id: svn://kolibrios.org@6803 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-12-21 10:56:06 +00:00
parent 4ded9c23de
commit 3c1b36e8f4
12 changed files with 145 additions and 192 deletions

View File

@ -17,6 +17,7 @@ struct TWebBrowser {
llist list; llist list;
_style style; _style style;
DrawBufer DrawBuf; DrawBufer DrawBuf;
int zoom;
void Prepare(); void Prepare();
void SetStyle(); void SetStyle();
void DrawStyle(); void DrawStyle();
@ -62,7 +63,6 @@ char tag[100];
char oldtag[100]; char oldtag[100];
char attr[1200]; char attr[1200];
char val[4096]; char val[4096];
char anchor[256]=0;
#include "..\TWB\absolute_url.h" #include "..\TWB\absolute_url.h"
#include "..\TWB\links.h" #include "..\TWB\links.h"
@ -75,7 +75,7 @@ char anchor[256]=0;
//============================================================================================ //============================================================================================
void TWebBrowser::DrawStyle() void TWebBrowser::DrawStyle()
{ {
int start_x, line_length, stolbec_len; dword start_x, line_length, stolbec_len;
if (!header) if (!header)
{ {
@ -86,19 +86,19 @@ void TWebBrowser::DrawStyle()
} }
if (t_html) && (!t_body) return; if (t_html) && (!t_body) return;
if (line) && (!anchor) if (line)
{ {
start_x = stolbec * list.font_w + body_magrin + list.x; start_x = stolbec * list.font_w + body_magrin + list.x;
stolbec_len = strlen(#line) * DrawBuf.zoom; stolbec_len = strlen(#line) * zoom;
line_length = stolbec_len * list.font_w; line_length = stolbec_len * list.font_w;
WriteBufText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line, buf_data); WriteBufText(start_x, draw_y, list.font_type, text_colors[text_color_index], #line, buf_data);
if (style.b) WriteBufText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line, buf_data); if (style.b) WriteBufText(start_x+1, draw_y, list.font_type, text_colors[text_color_index], #line, buf_data);
if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - DrawBuf.zoom + draw_y, line_length, DrawBuf.zoom, text_colors[text_color_index]); if (style.s) DrawBuf.DrawBar(start_x, list.item_h / 2 - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
if (style.u) DrawBuf.DrawBar(start_x, list.item_h - DrawBuf.zoom - DrawBuf.zoom + draw_y, line_length, DrawBuf.zoom, text_colors[text_color_index]); if (style.u) DrawBuf.DrawBar(start_x, list.item_h - zoom - zoom + draw_y, line_length, zoom, text_colors[text_color_index]);
if (link) { if (link) {
DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(DrawBuf.zoom*2), line_length, DrawBuf.zoom, text_colors[text_color_index]); DrawBuf.DrawBar(start_x, draw_y + list.item_h - calc(zoom*2), line_length, zoom, text_colors[text_color_index]);
PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(DrawBuf.zoom*2), UNDERLINE, DrawBuf.zoom); //TODO: set bigger underline_h for style.h PageLinks.AddText(start_x, draw_y + list.y, line_length, list.item_h - calc(zoom*2), UNDERLINE, zoom); //TODO: set bigger underline_h for style.h
} }
stolbec += stolbec_len; stolbec += stolbec_len;
} }
@ -112,10 +112,10 @@ void TWebBrowser::LoadInternalPage(dword bufpos, in_filesize){
//============================================================================================ //============================================================================================
void TWebBrowser::Prepare(){ void TWebBrowser::Prepare(){
word bukva[2]; word bukva[2];
int j; dword j;
byte ignor_param; byte ignor_param;
dword bufpos; dword bufpos;
int line_len; dword line_len;
style.b = style.u = style.s = style.h = style.blq = t_html = t_body = style.b = style.u = style.s = style.h = style.blq = t_html = t_body =
style.li = link = ignor_text = text_color_index = text_colors[0] = style.li_tab = 0; style.li = link = ignor_text = text_color_index = text_colors[0] = style.li_tab = 0;
style.align = ALIGN_LEFT; style.align = ALIGN_LEFT;
@ -128,6 +128,7 @@ void TWebBrowser::Prepare(){
draw_y = body_magrin; draw_y = body_magrin;
stolbec = 0; stolbec = 0;
line = 0; line = 0;
zoom = 1;
//for plaint text use CP866 for other UTF //for plaint text use CP866 for other UTF
if (strstri(bufpointer, "html")!=-1) if (strstri(bufpointer, "html")!=-1)
{ {
@ -226,21 +227,15 @@ void TWebBrowser::Prepare(){
NewLine(); NewLine();
if (list.first == 0) list.count = draw_y; if (list.first == 0) list.count = draw_y;
DrawPage(); DrawPage();
if (anchor)
{
anchor=NULL;
list.first = anchor_y;
Prepare();
}
} }
//============================================================================================ //============================================================================================
void TWebBrowser::Perenos() void TWebBrowser::Perenos()
{ {
int perenos_num; int perenos_num;
char new_line_text[4096]; char new_line_text[4096];
if (strlen(#line)*DrawBuf.zoom + stolbec < list.column_max) return; if (strlen(#line)*zoom + stolbec < list.column_max) return;
perenos_num = strrchr(#line, ' '); perenos_num = strrchr(#line, ' ');
if (!perenos_num) && (strlen(#line)*DrawBuf.zoom>list.column_max) perenos_num=list.column_max/DrawBuf.zoom; if (!perenos_num) && (strlen(#line)*zoom>list.column_max) perenos_num=list.column_max/zoom;
strcpy(#new_line_text, #line + perenos_num); strcpy(#new_line_text, #line + perenos_num);
line[perenos_num] = 0x00; line[perenos_num] = 0x00;
DrawStyle(); DrawStyle();
@ -277,9 +272,9 @@ void TWebBrowser::SetStyle() {
if (!opened) strcat(#line, "\" "); if (!opened) strcat(#line, "\" ");
return; return;
} }
if (anchor) if (isattr("id=")) || (isattr("name=")) { //very bad: if the tag is not the last it wound work //if (isattr("id=")) || (isattr("name=")) { //very bad: if the tag is not the last it wound work
if (!strcmp(#anchor, #val)) anchor_y=draw_y; //add anchor
} //}
if (istag("body")) { if (istag("body")) {
t_body = opened; t_body = opened;
do{ do{
@ -353,7 +348,7 @@ void TWebBrowser::SetStyle() {
{ {
NewLine(); NewLine();
draw_y += 10; draw_y += 10;
WB1.DrawBuf.zoom=2; WB1.zoom=2;
WB1.list.font_type |= 10011001b; WB1.list.font_type |= 10011001b;
if (isattr("align=")) && (isval("center")) style.align = ALIGN_CENTER; if (isattr("align=")) && (isval("center")) style.align = ALIGN_CENTER;
if (isattr("align=")) && (isval("right")) style.align = ALIGN_RIGHT; if (isattr("align=")) && (isval("right")) style.align = ALIGN_RIGHT;
@ -362,7 +357,7 @@ void TWebBrowser::SetStyle() {
else else
{ {
NewLine(); NewLine();
WB1.DrawBuf.zoom=1; WB1.zoom=1;
WB1.list.font_type = 10011000b; WB1.list.font_type = 10011000b;
style.align = ALIGN_LEFT; style.align = ALIGN_LEFT;
list.item_h = basic_line_h; list.item_h = basic_line_h;
@ -380,8 +375,7 @@ void TWebBrowser::SetStyle() {
if (opened) if (opened)
{ {
NewLine(); NewLine();
DrawBuf.DrawBar(style.li_tab * 5 * list.font_w * DrawBuf.zoom + list.x, strcpy(#line, "\31 \0");
list.item_h - calc(DrawBuf.zoom*2) /2 + draw_y, DrawBuf.zoom*2, DrawBuf.zoom*2, 0x454545);
} }
return; return;
} }
@ -422,9 +416,8 @@ void TWebBrowser::SetStyle() {
} }
} }
void TWebBrowser::BufEncode(int set_new_encoding) void TWebBrowser::BufEncode(dword set_new_encoding)
{ {
int bufpointer_realsize;
if (o_bufpointer==0) if (o_bufpointer==0)
{ {
o_bufpointer = malloc(bufsize); o_bufpointer = malloc(bufsize);
@ -456,7 +449,7 @@ void TWebBrowser::DrawScroller()
//============================================================================================ //============================================================================================
void TWebBrowser::NewLine() void TWebBrowser::NewLine()
{ {
int onleft, ontop; dword onleft, ontop;
if (!stolbec) && (draw_y==body_magrin) return; if (!stolbec) && (draw_y==body_magrin) return;
@ -468,9 +461,9 @@ void TWebBrowser::NewLine()
if (style.li) stolbec = style.li_tab * 5; if (style.li) stolbec = style.li_tab * 5;
} }
//============================================================================================ //============================================================================================
int istag(dword text) { if (!strcmp(#tag,text)) return true; else return false; } bool istag(dword text) { if (!strcmp(#tag,text)) return true; else return false; }
int isattr(dword text) { if (!strcmp(#attr,text)) return true; else return false; } bool isattr(dword text) { if (!strcmp(#attr,text)) return true; else return false; }
int isval(dword text) { if (!strcmp(#val,text)) return true; else return false; } bool isval(dword text) { if (!strcmp(#val,text)) return true; else return false; }
//============================================================================================ //============================================================================================
void TWebBrowser::DrawPage() void TWebBrowser::DrawPage()
{ {

View File

@ -34,11 +34,11 @@ int ImageCache::GetImage(dword i_path)
} }
void ImageCache::Images(int left1, top1, width1) void ImageCache::Images(dword left1, top1, width1)
{ {
dword image; dword image;
char img_path[4096], alt[4096]=0; char img_path[4096], alt[4096]=0;
int imgw=0, imgh=0, img_lines_first=0, cur_pic=0; dword imgw=0, imgh=0, img_lines_first=0, cur_pic=0;
do{ do{
if (isattr("src=")) if (isattr("src="))

View File

@ -31,7 +31,7 @@ void WriteTextIntoBuf(int _x, _y; dword _text_col, _text_off)
notify(#error_message); notify(#error_message);
return; return;
} }
label.write_buf(_x, _y, list.w, label.size.height, 0xFFFFFF, _text_col, label.size.pt, _text_off); label.WriteIntoBuffer(_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(); if (_y/list.item_h-list.first==list.visible) DrawPage();
} }

View File

@ -20,7 +20,7 @@ void PreparePage()
} }
strcat(#title, " - Aelia"); strcat(#title, " - Aelia");
DrawTitle(#title); DrawTitle(#title);
DrawProgress(STEP_4_SMOOTH_FONT); label.apply_smooth(); DrawProgress(STEP_4_SMOOTH_FONT); label.ApplySmooth();
DrawProgress(STEP_5_STOP); DrawPage(); DrawProgress(STEP_5_STOP); DrawPage();
} }

View File

@ -124,7 +124,6 @@ void main()
SetSkinColors(); SetSkinColors();
CreateDir("/tmp0/1/downloads"); CreateDir("/tmp0/1/downloads");
if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME); if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME);
WB1.DrawBuf.zoom = 1;
WB1.list.SetFont(8, 14, 10011000b); WB1.list.SetFont(8, 14, 10011000b);
WB1.list.no_selection = true; WB1.list.no_selection = true;
SetEventMask(0xa7); SetEventMask(0xa7);
@ -268,13 +267,13 @@ void SetElementSizes()
address_box.top = TOOLBAR_H/2-10; address_box.top = TOOLBAR_H/2-10;
basic_line_h = calc(WB1.list.font_h * 130) / 100; basic_line_h = calc(WB1.list.font_h * 130) / 100;
address_box.width = Form.cwidth - address_box.left - 50; address_box.width = Form.cwidth - address_box.left - 50;
WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x / WB1.DrawBuf.zoom, WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x,
Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h); Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h);
WB1.list.wheel_size = 7 * basic_line_h; WB1.list.wheel_size = 7 * basic_line_h;
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
WB1.list.visible = WB1.list.h; WB1.list.visible = WB1.list.h;
if (WB1.list.w!=WB1.DrawBuf.bufw) { if (WB1.list.w!=WB1.DrawBuf.bufw) {
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 2048 * WB1.list.item_h); WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700);
ProcessEvent(REFRESH_BUTTON); ProcessEvent(REFRESH_BUTTON);
} }
} }
@ -405,9 +404,6 @@ void SetPageDefaults()
WB1.list.count = WB1.list.first = 0; WB1.list.count = WB1.list.first = 0;
cur_encoding = CH_NULL; cur_encoding = CH_NULL;
if (o_bufpointer) o_bufpointer = free(o_bufpointer); if (o_bufpointer) o_bufpointer = free(o_bufpointer);
anchor_y = WB1.list.first;
//anchor[0]='|';
anchor=NULL;
} }
void OpenPage() void OpenPage()
@ -508,6 +504,7 @@ void DrawProgress()
DrawBar(address_box.left-2, address_box.top+20, btn, 2, wv_progress_bar.progress_color); DrawBar(address_box.left-2, address_box.top+20, btn, 2, wv_progress_bar.progress_color);
} }
char anchor[256];
void ClickLink() void ClickLink()
{ {
if (http_transfer > 0) if (http_transfer > 0)
@ -534,7 +531,7 @@ void ClickLink()
//liner.ru#1 //liner.ru#1
if (strrchr(#URL, '#')!=0) if (strrchr(#URL, '#')!=0)
{ {
strcpy(#anchor, #URL+strrchr(#URL, '#')); strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor));
URL[strrchr(#URL, '#')-1] = 0x00; URL[strrchr(#URL, '#')-1] = 0x00;
} }

View File

@ -731,7 +731,7 @@ void Line_ReDraw(dword bgcol, filenum){
} }
strcpy(#label_file_name+strlen(#label_file_name)-2, "..."); strcpy(#label_file_name+strlen(#label_file_name)-2, "...");
} }
label.write(files.x + 23, files.item_h - label.height / 2 + y, bgcol, text_col, label.size.pt, #label_file_name); label.WriteIntoWindow(files.x + 23, files.item_h - label.height / 2 + y, bgcol, text_col, label.size.pt, #label_file_name);
} }
DrawBar(files.x+files.w-141,y,1,files.item_h,system.color.work); //gray line 1 DrawBar(files.x+files.w-141,y,1,files.item_h,system.color.work); //gray line 1
DrawBar(files.x+files.w-68,y,1,files.item_h,system.color.work); //gray line 2 DrawBar(files.x+files.w-68,y,1,files.item_h,system.color.work); //gray line 2

View File

@ -7,7 +7,7 @@
proc_info Form; proc_info Form;
enum { enum {
STRONG_BTN=10, ITALIC_BTN, SMOOTH_BTN, STRONG_BTN=10, SMOOTH_BTN,
PHRASE_TAB=20, CHARS_TAB PHRASE_TAB=20, CHARS_TAB
}; };
@ -27,7 +27,6 @@ void main()
btn = GetButtonID(); btn = GetButtonID();
if (btn==1) ExitProcess(); if (btn==1) ExitProcess();
if (btn==STRONG_BTN) label.bold ^=1; if (btn==STRONG_BTN) label.bold ^=1;
if (btn==ITALIC_BTN) label.italic ^=1;
if (btn==SMOOTH_BTN) label.smooth ^=1; if (btn==SMOOTH_BTN) label.smooth ^=1;
if (btn==PHRASE_TAB) || (btn==CHARS_TAB) tabs.click(btn); if (btn==PHRASE_TAB) || (btn==CHARS_TAB) tabs.click(btn);
goto _DRAW_WINDOW_CONTENT; goto _DRAW_WINDOW_CONTENT;
@ -39,8 +38,7 @@ void main()
_DRAW_WINDOW_CONTENT: _DRAW_WINDOW_CONTENT:
DrawBar(0, 0, Form.cwidth, PANELH-1, system.color.work); DrawBar(0, 0, Form.cwidth, PANELH-1, system.color.work);
CheckBox(10, 8, STRONG_BTN, "Bold", label.bold); CheckBox(10, 8, STRONG_BTN, "Bold", label.bold);
CheckBox(83, 8, ITALIC_BTN, "Italic", label.italic); CheckBox(83,8, SMOOTH_BTN, "Smooth", label.smooth);
CheckBox(170,8, SMOOTH_BTN, "Smooth", label.smooth);
tabs.draw(Form.cwidth-150, PANELH, PHRASE_TAB, "Phrase"); tabs.draw(Form.cwidth-150, PANELH, PHRASE_TAB, "Phrase");
tabs.draw(Form.cwidth-70, PANELH, CHARS_TAB, "Chars"); tabs.draw(Form.cwidth-70, PANELH, CHARS_TAB, "Chars");
DrawBar(0, PANELH-1,Form.cwidth,1,system.color.work_graph); DrawBar(0, PANELH-1,Form.cwidth,1,system.color.work_graph);
@ -63,9 +61,9 @@ void DrawPreviewPhrase()
for (i=10, y=5; i<22; i++, y+=label.height;) //not flexible, need to calculate font count and max line length for (i=10, y=5; i<22; i++, y+=label.height;) //not flexible, need to calculate font count and max line length
{ {
sprintf(#line,"<EFBFBD> §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i); sprintf(#line,"<EFBFBD> §¬¥à èà¨äâ /size font %d ¯¨ªá¥«¥©.",i);
label.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, i, #line); label.WriteIntoBuffer(10,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, i, #line);
} }
if (label.smooth) label.apply_smooth(); if (label.smooth) label.ApplySmooth();
label.show_buf(0, PANELH); label.show_buf(0, PANELH);
} }
@ -78,13 +76,13 @@ void DrawPreviewChars()
for (i=0; i<255; i++) //not flexible, need to calculate font count and max line length for (i=0; i<255; i++) //not flexible, need to calculate font count and max line length
{ {
line[0]=i; line[0]=i;
label.write_buf(x,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, 16, #line); label.WriteIntoBuffer(x,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, 16, #line);
x+= label.height+2; x+= label.height+2;
if (x>=Form.cwidth-30) { if (x>=Form.cwidth-30) {
x=20; x=20;
y+=label.height+2; y+=label.height+2;
} }
} }
if (label.smooth) label.apply_smooth(); if (label.smooth) label.ApplySmooth();
label.show_buf(0, PANELH); label.show_buf(0, PANELH);
} }

View File

@ -6,17 +6,15 @@
#include "../lib/kolibri.h" #include "../lib/kolibri.h"
#endif #endif
unsigned buf_data; dword buf_data;
struct DrawBufer { struct DrawBufer {
unsigned bufx, bufy, bufw, bufh; dword bufx, bufy, bufw, bufh;
byte zoom;
bool Init(); bool Init();
void Show(); void Show();
void Fill(); void Fill();
void Skew();
void DrawBar(); void DrawBar();
void PutPixel(); void PutPixel();
void AlignCenter(); void AlignCenter();
@ -27,23 +25,22 @@ char draw_buf_not_enaught_ram[] =
"'DrawBufer needs more memory than currenly available. "'DrawBufer needs more memory than currenly available.
Application could be unstable. Application could be unstable.
Requested size: %i Kb Requested size: %i Mb
Free RAM: %i Kb' -E"; Free RAM: %i Mb' -E";
bool DrawBufer::Init(int i_bufx, i_bufy, i_bufw, i_bufh) bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
{ {
dword alloc_size, free_ram_size; dword alloc_size, free_ram_size;
char error_str[256]; char error_str[256];
if (!zoom) zoom = 1;
bufx = i_bufx; bufx = i_bufx;
bufy = i_bufy; bufy = i_bufy;
bufw = i_bufw * zoom; bufw = i_bufw;
bufh = i_bufh * zoom; bufh = i_bufh;
free(buf_data); free(buf_data);
free_ram_size = GetFreeRAM() * 1024; free_ram_size = GetFreeRAM() * 1024;
alloc_size = bufw * bufh * 4 + 8; alloc_size = bufw * bufh * 4 + 8;
if (alloc_size >= free_ram_size) { if (alloc_size >= free_ram_size) {
sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1024, free_ram_size/1024); sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size/1048576, free_ram_size/1048576);
notify(#error_str); notify(#error_str);
} }
buf_data = malloc(alloc_size); buf_data = malloc(alloc_size);
@ -54,43 +51,34 @@ bool DrawBufer::Init(int i_bufx, i_bufy, i_bufw, i_bufh)
return true; return true;
} }
void DrawBufer::Fill(unsigned fill_color) void DrawBufer::Fill(dword fill_color)
{ {
unsigned i; dword i;
unsigned max_i = bufw * bufh * 4 + buf_data + 8; dword max_i = bufw * bufh * 4 + buf_data + 8;
for (i=buf_data+8; i<max_i; i+=4) ESDWORD[i] = fill_color; for (i=buf_data+8; i<max_i; i+=4) ESDWORD[i] = fill_color;
} }
void DrawBufer::DrawBar(unsigned x, y, w, h, color) void DrawBufer::DrawBar(dword x, y, w, h, color)
{ {
int i, j; dword i, j;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
for (i = y+j*bufw+x<<2+8+buf_data; i<y+j*bufw+x+w<<2+8+buf_data; i+=4) ESDWORD[i] = color; for (i = y+j*bufw+x<<2+8+buf_data; i<y+j*bufw+x+w<<2+8+buf_data; i+=4) {
ESDWORD[i] = color;
}
} }
} }
void DrawBufer::PutPixel(unsigned x, y, color) void DrawBufer::PutPixel(dword x, y, color)
{ {
int pos = y*bufw+x*4+8+buf_data; dword pos = y*bufw+x*4+8+buf_data;
ESDWORD[pos] = color; ESDWORD[pos] = color;
} }
char shift[]={8,8,4,4}; void DrawBufer::AlignRight(dword x,y,w,h, content_width)
void DrawBufer::Skew(unsigned x, y, w, h)
{ {
int i, j; dword i, j, l;
for (j=0; j<=3; j++) dword content_left = w - content_width / 2;
{
for (i = y+j*bufw+x+w+h*4; i>y+j*bufw+x+h-12*4 ; i-=4)
ESDWORD[buf_data+i+8] = ESDWORD[-shift[j]+buf_data+i+8];
}
}
void DrawBufer::AlignRight(unsigned x,y,w,h, content_width)
{
int i, j, l;
int content_left = w - content_width / 2;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4) for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
@ -100,10 +88,10 @@ void DrawBufer::AlignRight(unsigned x,y,w,h, content_width)
} }
} }
void DrawBufer::AlignCenter(unsigned x,y,w,h, content_width) void DrawBufer::AlignCenter(dword x,y,w,h, content_width)
{ {
int i, j, l; dword i, j, l;
int content_left = w - content_width / 2; dword content_left = w - content_width / 2;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4) for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
@ -114,10 +102,10 @@ void DrawBufer::AlignCenter(unsigned x,y,w,h, content_width)
} }
/* /*
void DrawBufer::Zoom2x() void DrawBufer::Zoom2x(int zoom)
{ {
int i, s; int i, s;
unsigned point_x, max_i, zline_w, s_inc; dword point_x, max_i, zline_w, s_inc;
point_x = 0; point_x = 0;
max_i = bufw * bufh * 4 + buf_data+8; max_i = bufw * bufh * 4 + buf_data+8;

View File

@ -18,49 +18,44 @@
{ {
dword width,height; dword width,height;
signed offset_x, offset_y; signed offset_x, offset_y;
float offset_i,w_italic;
byte pt; byte pt;
byte TMP_WEIGHT;
}; };
:struct LABEL :struct LABEL
{ {
__SIZE size; __SIZE size;
int width,height; int width,height;
byte bold,italic,smooth; byte bold,smooth;
dword color, background; dword color, background;
dword font,font_begin; dword font,font_begin;
word block; word block;
dword raw;
dword raw_size;
byte init(); byte init();
byte changeSIZE(); bool changeSIZE();
byte symbol(); byte symbol();
byte symbol_size(); byte symbol_size();
dword getsize(); dword getsize();
dword raw; void ApplySmooth();
dword raw_size; int WriteIntoWindow();
void apply_smooth(); int WriteIntoWindowCenter();
int write_center(); void WriteIntoBuffer();
int write();
void write_buf();
void show_buf(); void show_buf();
} label; } label;
:byte LABEL::changeSIZE() :bool LABEL::changeSIZE()
{ {
dword file_size; dword file_size;
dword TMP_DATA;
dword ofs; dword ofs;
IF(size.pt<9) size.pt = 8; if(size.pt<9) size.pt = 8;
TMP_DATA = font = font_begin; font = font_begin;
TMP_DATA +=size.pt-8*4; ofs = DSDWORD[calc(size.pt-8<<2+font_begin)];
ofs = DSDWORD[TMP_DATA]; if(ofs==-1)return false;
IF(ofs==-1)return false;
font += ofs + 156; font += ofs + 156;
TMP_DATA = font; file_size = DSDWORD[calc(font)];
file_size = DSDWORD[TMP_DATA]; height = DSBYTE[calc(font+file_size) - 1];
TMP_DATA = font + file_size; width = DSBYTE[calc(font+file_size) - 2];
height = DSBYTE[TMP_DATA - 1];
width = DSBYTE[TMP_DATA - 2];
block = math.ceil(height*width/32); block = math.ceil(height*width/32);
return true; return true;
} }
@ -68,7 +63,7 @@
{ {
size.height = size.width = 0; size.height = size.width = 0;
size.offset_x = size.offset_y = -1; size.offset_x = size.offset_y = -1;
IF(size.pt)IF(!changeSIZE())return 0; if(size.pt)if(!changeSIZE())return 0;
WHILE(DSBYTE[text1]) WHILE(DSBYTE[text1])
{ {
symbol_size(DSBYTE[text1]); symbol_size(DSBYTE[text1]);
@ -78,13 +73,6 @@
$neg size.offset_x $neg size.offset_x
size.height += size.offset_y+1; size.height += size.offset_y+1;
size.width += size.offset_x+1; size.width += size.offset_x+1;
IF(italic)
{
size.w_italic = size.height/3;
size.offset_i = size.w_italic/size.height;
size.width += size.w_italic;
size.w_italic = -size.w_italic;
}
return size.width; return size.width;
} }
:byte LABEL::symbol_size(byte s) :byte LABEL::symbol_size(byte s)
@ -94,58 +82,52 @@
dword iii = 0; dword iii = 0;
byte rw=0; byte rw=0;
byte X; byte X;
size.TMP_WEIGHT = math.ceil(size.pt/17); if(bold) size.width+=math.ceil(size.pt/17);
IF(s==32) if(s==32)
{ {
size.width += width/4; size.width += width/4;
IF(bold) size.width+=size.TMP_WEIGHT;
return; return;
} }
IF(s==9) if(s==9)
{ {
size.width += width; size.width += width;
IF(bold) size.width+=size.TMP_WEIGHT;
return; return;
} }
s = Cp866ToAnsi(s); s = Cp866ToAnsi(s);
tmp = 4*block*s + font; tmp = block*s << 2 + font;
for(yi=0; yi<height; yi++) for(yi=0; yi<height; yi++)
{ {
for(xi=0; xi<width; xi++) for(xi=0; xi<width; xi++)
{ {
IF(iii%32) _ >>= 1; if(iii%32) _ >>= 1;
ELSE else
{ {
tmp += 4; tmp += 4;
_ = DSDWORD[tmp]; _ = DSDWORD[tmp];
} }
IF(_&1) if(_&1)
{ {
IF(xi>rw)rw=xi; if(xi>rw)rw=xi;
IF(size.height<yi)size.height = yi; if(size.height<yi)size.height = yi;
IF(size.offset_y<0)size.offset_y = yi; if(size.offset_y<0)size.offset_y = yi;
ELSE IF(yi<size.offset_y)size.offset_y = yi; else if(yi<size.offset_y)size.offset_y = yi;
IF(!X) X = xi; if(!X) X = xi;
ELSE IF(X>xi)X = xi; else if(X>xi)X = xi;
} }
iii++; iii++;
} }
} }
size.width += rw; size.width += rw;
IF(bold) size.width+=size.TMP_WEIGHT; if(size.offset_x<0)size.offset_x = X;
//IF(s=='_') size.width--; //http://board.kolibrios.org/viewtopic.php?f=44&t=973&start=645
IF(size.offset_x<0)size.offset_x = X;
} }
:byte LABEL::symbol(signed x,y; byte s; dword image_raw) :byte LABEL::symbol(signed x,y; byte s; dword image_raw)
{ {
dword xi,yi; dword xi,yi;
dword iii = 0; dword iii = 0;
dword offs; dword offs;
float ital = -size.w_italic;
dword ___x;
byte rw=0; byte rw=0;
IF(s==32)return width/4; if(s==32)return width/4;
IF(s==9)return width; if(s==9)return width;
s = Cp866ToAnsi(s); s = Cp866ToAnsi(s);
EBX = block*s << 2 + font; EBX = block*s << 2 + font;
for(yi=0; yi<height; yi++) for(yi=0; yi<height; yi++)
@ -153,54 +135,50 @@
EDI = size.offset_y + yi + y * size.width * 3 + image_raw; EDI = size.offset_y + yi + y * size.width * 3 + image_raw;
for(xi=0; xi<width; xi++) for(xi=0; xi<width; xi++)
{ {
IF(iii%32) $shr ecx,1 if(iii%32) $shr ecx,1
ELSE else
{ {
EBX += 4; EBX += 4;
ECX = DSDWORD[EBX]; ECX = DSDWORD[EBX];
} }
IF(ECX&true) if(ECX&true)
{ {
IF(xi>rw)rw=xi; if(xi>rw)rw=xi;
___x = x+xi; offs = x + xi *3 + EDI;
IF(italic)___x+=math.ceil(ital);
offs = ___x*3 + EDI;
DSDWORD[offs] = DSDWORD[offs] & 0xFF000000 | color; DSDWORD[offs] = DSDWORD[offs] & 0xFF000000 | color;
IF(bold) DSDWORD[offs+3] = DSDWORD[offs+3] & 0xFF000000 | color; if(bold) DSDWORD[offs+3] = DSDWORD[offs+3] & 0xFF000000 | color;
} }
iii++; iii++;
} }
if (italic) ital-=size.offset_i;
} }
return rw; return rw;
} }
byte Cp866ToAnsi(byte s) { inline fastcall Cp866ToAnsi(AL) {
IF(s>=128)&&(s<=175)s+=64; if (AL>=128)&&(AL<=175) return AL+64;
ELSE IF(s>=224)&&(s<=239)s+=16; if (AL>=224)&&(AL<=239) return AL+16;
ELSE IF(s==241)s=184; //e rus with dots (yo) if (AL==241) return 184; //e ruAL with dotAL (yo)
ELSE IF(s==240)s=168; //E rus with dots (yo) if (AL==240) return 168; //E ruAL with dotAL (yo)
ELSE IF(s==242)s='E'; //E ukr (ye) if (AL==242) return 'E'; //E ukr (ye)
ELSE IF(s==243)s=186; //e ukr (ye) if (AL==243) return 186; //e ukr (ye)
ELSE IF(s==244)s='I'; //I ukr (yi) if (AL==244) return 'I'; //I ukr (yi)
ELSE IF(s==245)s=191; //i ukr (yi) if (AL==245) return 191; //i ukr (yi)
return s; return AL;
} }
:byte LABEL::init(dword font_path) :byte LABEL::init(dword font_path)
{ {
IO label_io; IO label_io;
IF(font)free(font); if(font)free(font);
label_io.read(font_path); label_io.read(font_path);
IF(!EAX) { if(!EAX) {
debugln(font_path); debugln(font_path);
label_io.run("/sys/@notify", "'Error: KFONT is not loaded.' -E"); label_io.run("/sys/@notify", "'Error: KFONT is not loaded.' -E");
return false; return false;
} }
font_begin = font = label_io.buffer_data; font_begin = label_io.buffer_data;
height = DSBYTE[calc(font_begin+label_io.FILES_SIZE)-1]; size.pt = 9;
width = DSBYTE[calc(font_begin+label_io.FILES_SIZE)-2]; changeSIZE();
block = math.ceil(height*width/32);
smooth = true; smooth = true;
return true; return true;
} }
@ -214,7 +192,7 @@ byte Cp866ToAnsi(byte s) {
inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; } inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
:void LABEL::apply_smooth() :void LABEL::ApplySmooth()
{ {
dword i,line_w,to,dark_background; dword i,line_w,to,dark_background;
line_w = size.width * 3; line_w = size.width * 3;
@ -242,30 +220,30 @@ inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
} }
} }
:int LABEL::write_center(dword x,y,w,h; dword _background, _color; byte fontSizePoints; dword txt) :int LABEL::WriteIntoWindowCenter(dword x,y,w,h; dword _background, _color; byte fontSizePoints; dword txt)
{ {
size.pt = fontSizePoints; size.pt = fontSizePoints;
getsize(txt); getsize(txt);
return write(w-size.width/2+x,y, _background, _color, fontSizePoints, txt); return WriteIntoWindow(w-size.width/2+x,y, _background, _color, fontSizePoints, txt);
} }
:int LABEL::write(int x,y; dword _background, _color; byte fontSizePoints; dword text1) :int LABEL::WriteIntoWindow(int x,y; dword _background, _color; byte fontSizePoints; dword text1)
{ {
signed len=0; signed len=0;
IF(!text1)return false; if(!text1)return false;
IF(size.pt)IF(!changeSIZE())return false; if(size.pt)if(!changeSIZE())return false;
size.pt = fontSizePoints; size.pt = fontSizePoints;
getsize(text1); getsize(text1);
color = _color; color = _color;
background = _background; background = _background;
y -= size.offset_y; y -= size.offset_y;
EDX = size.width*size.height*3; EDX = size.width*size.height*3;
IF(!raw_size) if(!raw_size)
{ {
raw_size = EDX; raw_size = EDX;
raw = malloc(raw_size); raw = malloc(raw_size);
} }
ELSE IF(raw_size<EDX) else if(raw_size<EDX)
{ {
raw_size = EDX; raw_size = EDX;
raw = realloc(raw,raw_size); raw = realloc(raw,raw_size);
@ -278,21 +256,20 @@ inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
len = size.offset_x; len = size.offset_x;
WHILE(DSBYTE[text1]) WHILE(DSBYTE[text1])
{ {
//IF(DSBYTE[text1]=='_') len--; //http://board.kolibrios.org/viewtopic.php?f=44&t=973&start=645
len+=symbol(len,0,DSBYTE[text1], raw); len+=symbol(len,0,DSBYTE[text1], raw);
IF(bold)len+=math.ceil(size.pt/17); if(bold)len+=math.ceil(size.pt/17);
text1++; text1++;
} }
IF (smooth) apply_smooth(); IF (smooth) ApplySmooth();
show_buf(x,y); show_buf(x,y);
return len; return len;
} }
:void LABEL::write_buf(int x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1) :void LABEL::WriteIntoBuffer(int x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1)
{ {
dword new_raw_size; dword new_raw_size;
IF(!text1)return; if(!text1)return;
IF(size.pt)IF(!changeSIZE())return; if(size.pt)if(!changeSIZE())return;
if (size.pt != fontSizePoints) { if (size.pt != fontSizePoints) {
size.pt = fontSizePoints; size.pt = fontSizePoints;
@ -306,7 +283,7 @@ inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
size.height = h; size.height = h;
new_raw_size = w*h*3; new_raw_size = w*h*3;
IF(raw_size != new_raw_size) if(raw_size != new_raw_size)
{ {
raw_size = new_raw_size; raw_size = new_raw_size;
free(raw); free(raw);
@ -319,7 +296,7 @@ inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; }
WHILE(DSBYTE[text1]) WHILE(DSBYTE[text1])
{ {
x+=symbol(x,y,DSBYTE[text1], raw); x+=symbol(x,y,DSBYTE[text1], raw);
IF(bold)x+=math.ceil(size.pt/17); if(bold)x+=math.ceil(size.pt/17);
text1++; text1++;
} }
return; return;

View File

@ -135,8 +135,8 @@ byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32); img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
app_path_collection.add(key_value); app_path_collection.add(key_value);
//label.write_center(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name); //label.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name);
label.write_center(col*list.item_w+6,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name); label.WriteIntoWindowCenter(col*list.item_w+6,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name);
if (list.cur_y == list.count) DrawWideRectangle(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5, 2, 0x0080FF); if (list.cur_y == list.count) DrawWideRectangle(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5, 2, 0x0080FF);
list.count++; list.count++;
col++; col++;
@ -161,7 +161,7 @@ byte process_sections(dword sec_name, f_name)
col = 0; col = 0;
old_row = row; old_row = row;
DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR); DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
text_len = label.write(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name); text_len = label.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name);
DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC); DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC); DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
list_pos += 29; list_pos += 29;
@ -174,7 +174,7 @@ void draw_top_bar()
DrawBar(0,0,Form.cwidth, list.y-2, system.color.work); DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180)); DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph); DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
label.write_center(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title); label.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
} }
void EventRunApp(dword appid) void EventRunApp(dword appid)

View File

@ -1,5 +1,5 @@
@C-- "textreader.c" @C-- "txtread.c"
@del "textreader" @del "txtread"
@rename "textreader.com" "textreader" @rename "txtread.com" "txtread"
@del warning.txt @del warning.txt
@pause @pause

View File

@ -37,7 +37,7 @@ dword line_start=io.buffer_data;
if (mode==DRAW_BUF) { if (mode==DRAW_BUF) {
EBX = bufoff-line_start; EBX = bufoff-line_start;
strlcpy(#line, line_start, EBX); strlcpy(#line, line_start, EBX);
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, #line); label.WriteIntoBuffer(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, #line);
stroka_y += list.item_h; stroka_y += list.item_h;
line_start = bufoff; line_start = bufoff;
line_length = 30; line_length = 30;
@ -45,7 +45,7 @@ dword line_start=io.buffer_data;
} }
} }
if (mode==COUNT_BUF_HEIGHT) list.count+=2; if (mode==COUNT_BUF_HEIGHT) list.count+=2;
if (mode==DRAW_BUF) label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start); if (mode==DRAW_BUF) label.WriteIntoBuffer(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start);
} }
void PreparePage() void PreparePage()
@ -68,6 +68,6 @@ void PreparePage()
Parcer(DRAW_BUF); Parcer(DRAW_BUF);
//draw result //draw result
label.apply_smooth(); label.ApplySmooth();
DrawPage(); DrawPage();
} }