font.h: optimization, refactoring

git-svn-id: svn://kolibrios.org@5985 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-12-18 15:21:19 +00:00
parent 93f98eb37e
commit 4dfaf192c9
9 changed files with 78 additions and 91 deletions

View File

@ -117,7 +117,6 @@ void main()
WB1.list.SetFont(8, 14, 10111000b);
WB1.list.no_selection = true;
//font init
font.no_bg_copy = true;
font.bg_color = 0xFFFFFF;
font.load(DEFAULT_FONT);
if (!font.data) {
@ -286,16 +285,16 @@ void Draw_Window()
list__w = 200;
font.buffer_size = 0;
font.size.height = 200;
font.color = 0;
font.color = 0x000000;
font.size.text = 11;
font.prepare_buf(10,10,list__w,font.size.height, "Hello World!");
font.write_buf(10,10,list__w,font.size.height, "Hello World!");
font.color = 0xFF00FF;
font.size.text = 12;
font.prepare_buf(10,23,list__w,font.size.height, "How are you?");
font.write_buf(10,23,list__w,font.size.height, "How are you?");
font.color = 0x2E74BB;
font.size.text = 15;
font.prepare_buf(11,40,list__w,font.size.height, "Fine");
SmoothFont(font.buffer, font.size.width, font.size.height);
font.write_buf(11,40,list__w,font.size.height, "Fine");
font.apply_smooth();
_PutImage(0,0,list__w,font.size.height,font.buffer);
*/
}

View File

@ -719,8 +719,7 @@ void Line_ReDraw(dword bgcol, filenum){
{
font.bg_color = bgcol;
font.smooth = smooth_font;
font.prepare(files.x + 23, files.item_h - font.height / 2 + y, file_name_off);
font.show();
font.write(files.x + 23, files.item_h - font.height / 2 + y, file_name_off);
}
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

View File

@ -118,7 +118,6 @@ void LoadIniSettings()
ini_get_int stdcall (eolite_ini_path, #config_section, "WinH", 500); WinH = EAX;
ini_get_str stdcall (eolite_ini_path, #config_section, "DefaultPath", #path,4096,"/rd/1/");
font.no_bg_copy = true;
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font file",#temp,4096,"/sys/FONTS/Tahoma.kf");
font.load(#temp);
ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font smoothing",#temp,4096,"on");

View File

@ -10,7 +10,6 @@ void main()
proc_info Form;
word i, y, btn;
char line[256], title[4196];
font.no_bg_copy = true;
font.color = 0;
font.bg_color = 0xFFFFFF;
if (!param) strcpy(#param, DEFAULT_FONT);
@ -46,12 +45,10 @@ void main()
{
font.size.text = i;
sprintf(#line,"<EFBFBD>妞丞 魰其<E9ADB0>/size font %d 祠花市巧.",i);
font.prepare_buf(10,y,Form.cwidth,Form.cheight-PANELH, #line);
font.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, #line);
}
if (font.smooth) SmoothFont(font.buffer, font.size.width, font.size.height);
font.left = 0;
font.top = PANELH;
font.show();
if (font.smooth) font.apply_smooth();
font.show_buf(0, PANELH);
}
}
}

View File

@ -28,7 +28,6 @@
__SIZE size;
int left,top,width,height;
byte bold,italic,smooth;
byte no_bg_copy;
dword bg_color;
dword color;
dword file_size;
@ -38,23 +37,18 @@
dword data;
dword begin;
byte load(...);
byte symbol(word x,y;byte s;dword c);
byte symbol_size(byte s);
dword prepare(word x,y;dword text1);
void prepare_buf(dword x,y,w,h, text1);
void show();
byte textcenter(word x,y,w,h;dword txt);
dword getsize(dword text1);
byte changeSIZE();
void PixelRGB(dword x,y);
byte symbol(signed x,y;byte s;dword c);
byte symbol_size(byte s);
dword getsize(dword text1);
void apply_smooth();
int write_center(dword x,y,w,h;dword txt);
int write(int x,y;dword text1);
void write_buf(int x,y,w,h, text1);
void show_buf();
};
FONT font = 0;
:void FONT::PixelRGB(dword x,y)
{
dword offs = y*size.width+x*3 + buffer;
DSDWORD[offs] = DSDWORD[offs] & 0xFF000000 | color;
}
:byte FONT::changeSIZE()
{
dword TMP_DATA;
@ -73,15 +67,6 @@ FONT font = 0;
block = math.ceil(height*width/32);
return true;
}
:byte FONT::textcenter(word x,y,w,h;dword txt)
{
getsize(txt);
EDX = w/2;
ECX = size.width/2;
EDX -= ECX;
x += EDX;
prepare(x,y,txt);
}
:dword FONT::getsize(dword text1)
{
size.height = size.width = 0;
@ -109,7 +94,7 @@ FONT font = 0;
{
dword xi,yi;
dword tmp,_;
dword iii;
dword iii = 0;
byte rw=0;
byte X;
size.TMP_WEIGHT = math.ceil(size.text/17);
@ -126,7 +111,6 @@ FONT font = 0;
return;
}
s = AnsiToCp866(s);
iii = 0;
tmp = 4*block*s + data;
for(yi=0; yi<height; yi++)
{
@ -158,18 +142,18 @@ FONT font = 0;
:byte FONT::symbol(signed x,y;byte s)
{
dword xi,yi;
dword iii;
dword iii = 0;
dword offs;
float ital = -size.w_italic;
dword ___x;
byte rw=0;
IF(s==32)return width/4;
IF(s==9)return width;
s = AnsiToCp866(s);
iii = 0;
EBX = block*s << 2 + data;
for(yi=0; yi<height; yi++)
{
EDI = size.offset.y + yi + y;
EDI = size.offset.y + yi + y * size.width * 3 + buffer;
for(xi=0; xi<width; xi++)
{
IF(iii%32) $shr ecx,1
@ -183,8 +167,9 @@ FONT font = 0;
IF(xi>rw)rw=xi;
___x = x+xi;
IF(italic)___x+=math.ceil(ital);
PixelRGB(___x,EDI);
IF(bold) PixelRGB(___x+1,EDI);
offs = ___x*3 + EDI;
DSDWORD[offs] = DSDWORD[offs] & 0xFF000000 | color;
IF(bold) DSDWORD[offs+3] = DSDWORD[offs+3] & 0xFF000000 | color;
}
iii++;
}
@ -193,10 +178,6 @@ FONT font = 0;
return rw;
}
:void FONT::show(){
_PutImage(left,top,size.width,size.height,buffer);
}
byte AnsiToCp866(byte s) {
IF(s>=128)&&(s<=175)s+=64;
ELSE IF(s>=224)&&(s<=239)s+=16;
@ -206,22 +187,23 @@ byte AnsiToCp866(byte s) {
}
inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
:void SmoothFont(dword image, w, h)
:void FONT::apply_smooth()
{
dword i,line_w,to;
line_w = w * 3;
to = w*h*3 + image - line_w - 3;
for(i = image; i < to; i+=3) {
IF(i-image%line_w +3 == line_w) continue;
line_w = font.size.width * 3;
to = font.size.height - 1 * line_w + font.buffer - 3;
for(i=font.buffer; i < to; i+=3)
{
IF(i-font.buffer%line_w +3 == line_w) continue;
IF(b24(i)==0x000000) && (b24(i+3)!=0x000000) && (b24(i+line_w)!=0x000000) && (b24(i+3+line_w)==0x000000)
{
ShadowImage(i+3, 1, 1, 2);
ShadowImage(i+line_w, 1, 1, 2);
ShadowPixel(i+3, 2);
ShadowPixel(i+line_w, 2);
}
ELSE IF(b24(i)!=0x000000) && (b24(i+3)==0x000000) && (b24(i+line_w)==0x000000) && (b24(i+3+line_w)!=0x000000)
{
ShadowImage(i, 1, 1, 2);
ShadowImage(i+3+line_w, 1, 1, 2);
ShadowPixel(i, 2);
ShadowPixel(i+3+line_w, 2);
}
}
}
@ -240,11 +222,15 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
return true;
}
:dword FONT::prepare(int x,y;dword text1)
:int FONT::write_center(dword x,y,w,h;dword txt)
{
getsize(txt);
return write(w-size.width/2+x,y,txt);
}
:int FONT::write(int x,y; dword text1)
{
signed len=0;
proc_info Form_SELF_FONTS;
dword c;
IF(!text1)return false;
IF(size.text)IF(!changeSIZE())return false;
left = x;
@ -262,17 +248,11 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
buffer_size = EDX;
buffer = realloc(buffer,buffer_size);
}
IF (no_bg_copy)
{
EBX = bg_color;
EAX = buffer_size+buffer;
for (EDI=buffer; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
}
ELSE
{
GetProcessInfo(#Form_SELF_FONTS, SelfInfo);
CopyScreen(buffer,x+Form_SELF_FONTS.left+5,y+Form_SELF_FONTS.top+GetSkinHeight(),size.width,size.height);
}
// Fill background color {
EBX = bg_color;
EAX = buffer_size+buffer;
for (EDI=buffer; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
// }
len = size.offset.x;
WHILE(DSBYTE[text1])
{
@ -281,13 +261,14 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
IF(bold)len+=math.ceil(size.text/17);
text1++;
}
IF (smooth) SmoothFont(buffer, size.width, size.height);
IF (smooth) apply_smooth();
show_buf(left,top);
return len;
}
:void FONT::prepare_buf(int x,y,w,h; dword text1)
:void FONT::write_buf(int x,y,w,h; dword text1)
{
dword c, new_buffer_size;
dword new_buffer_size;
IF(!text1)return;
IF(size.text)IF(!changeSIZE())return;
getsize(text1);
@ -302,6 +283,7 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
buffer_size = new_buffer_size;
free(buffer);
buffer = malloc(buffer_size);
// Fill background color
EBX = bg_color;
EAX = buffer_size+buffer;
for (EDI=buffer; EDI<EAX; EDI+=3) ESDWORD[EDI] = EBX;
@ -315,4 +297,11 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
return;
}
:void FONT::show_buf(dword left1, top1){
_PutImage(left1,top1,size.width,size.height,buffer);
}
#endif

View File

@ -177,6 +177,16 @@
}
}
:void ShadowPixel(dword color_image, strength)
{
dword to = color_image + 3;
strength = 10 - strength;
for ( ; color_image < to; color_image++)
{
ESI = strength * DSBYTE[color_image] / 10;
DSBYTE[color_image] = ESI;
}
}
:void ShadowImage(dword color_image, w, h, strength)
{
dword col, to;

View File

@ -59,7 +59,6 @@ void main()
{
dword id, key;
font.load("/sys/fonts/Tahoma.kf");
font.no_bg_copy = true;
font.smooth = true;
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
@ -153,11 +152,9 @@ byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
font.color = 0xDCDCDC;
font.bold = false;
font.bg_color = LIST_BACKGROUND_COLOR;
font.textcenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0,key_name);
font.show();
font.write_center(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0,key_name);
font.color = 0;
font.textcenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0,key_name);
font.show();
font.write_center(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0,key_name);
current_item_id++;
col++;
return true;
@ -187,11 +184,10 @@ byte process_sections(dword sec_name, f_name)
old_row = row;
DrawBar(0, row * cell_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
//WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
font.size=14;
font.bold=true;
font.size=15;
font.bold=false;
font.bg_color = LIST_BACKGROUND_COLOR;
text_len = font.prepare(10, row * cell_h + 10 + list_pos,sec_name);
font.show();
text_len = font.write(10, row * cell_h + 10 + list_pos,sec_name);
DrawBar(text_len+20, row * cell_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
DrawBar(text_len+20, row * cell_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
list_pos += 29;
@ -208,8 +204,7 @@ void draw_top_bar()
font.size = 17;
font.bold = false;
font.bg_color = system.color.work;
font.prepare(Form.cwidth-font.getsize(#window_title)/2,0,#window_title);
font.show();
font.write(Form.cwidth-font.getsize(#window_title)/2,0,#window_title);
list_top = top_position;
list_pos = list_top;
row = -1;

View File

@ -58,13 +58,13 @@ void PreparePage()
}
i = bufoff-line_start;
strlcpy(#line, line_start, i);
font.prepare_buf(8,stroka_y,list.w,font.size.height, #line);
font.write_buf(8,stroka_y,list.w,font.size.height, #line);
stroka_y += list.item_h;
line_start = bufoff;
line_length = 30;
}
}
font.prepare_buf(8,stroka_y,list.w,font.size.height, line_start);
SmoothFont(font.buffer, font.size.width, font.size.height);
font.write_buf(8,stroka_y,list.w,font.size.height, line_start);
font.apply_smooth();
DrawPage();
}

View File

@ -19,7 +19,7 @@
#define DEFAULT_EDITOR "/sys/tinypad"
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
#define VERSION "Text Reader v1.03"
#define VERSION "Text Reader v1.04"
#define ABOUT "Idea: Leency, punk_joker
Code: Leency, Veliant, KolibriOS Team
@ -75,7 +75,6 @@ void main()
OpenDialog_init stdcall (#o_dialog);
font.no_bg_copy = true;
font.color = 0;
font.bg_color = 0xFFFFFF;