diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index ba2bf3b76..18a8d0177 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -116,14 +116,7 @@ void main() WB1.DrawBuf.zoom = 1; WB1.list.SetFont(8, 14, 10111000b); WB1.list.no_selection = true; - //font init - font.bg_color = 0xFFFFFF; - font.load(DEFAULT_FONT); - if (!font.data) { - notify("'Error: Font is not loaded.' -E"); - ExitProcess(); - } - // + label.init(DEFAULT_FONT); SetEventMask(0xa7); BEGIN_LOOP_APPLICATION: WaitEventTimeout(2); @@ -263,7 +256,7 @@ void SetElementSizes() void Draw_Window() { - int list__w; + int list__w, list__h; DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color); DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3); DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color); @@ -283,19 +276,13 @@ void Draw_Window() /* list__w = 200; - font.buffer_size = 0; - font.size.height = 200; - font.color = 0x000000; - font.size.text = 11; - font.write_buf(10,10,list__w,font.size.height, "Hello World!"); - font.color = 0xFF00FF; - font.size.text = 12; - font.write_buf(10,23,list__w,font.size.height, "How are you?"); - font.color = 0x2E74BB; - font.size.text = 15; - font.write_buf(11,40,list__w,font.size.height, "Fine"); - font.apply_smooth(); - _PutImage(0,0,list__w,font.size.height,font.buffer); + list__h = 200; + label.raw_size = 0; + label.write_buf(10,10, list__w, list__h, 0xFFFFFF, 0, 11, "Hello World!"); + label.write_buf(10,23, list__w, list__h, 0xFFFFFF, 0xFF00FF, 12, "How are you?"); + label.write_buf(11,40, list__w, list__h, 0xFFFFFF, 0x2E74BB, 15, "Fine"); + label.apply_smooth(); + label.show_buf(0,0); */ } diff --git a/programs/cmm/eolite/Eolite.c b/programs/cmm/eolite/Eolite.c index 0eacc3447..798dcc4f0 100644 --- a/programs/cmm/eolite/Eolite.c +++ b/programs/cmm/eolite/Eolite.c @@ -702,7 +702,7 @@ void Line_ReDraw(dword bgcol, filenum){ if (text_col==0xA6A6B7) text_col=0xFFFFFF; } if (file.selected) text_col=0xFF0000; - if (font.size.text==9) || (!font.data) + if (label.size.pt==9) || (!label.font) { if (Form.width>=480) { @@ -717,9 +717,8 @@ void Line_ReDraw(dword bgcol, filenum){ } else { - font.bg_color = bgcol; - font.smooth = smooth_font; - font.write(files.x + 23, files.item_h - font.height / 2 + y, file_name_off); + label.smooth = smooth_font; + label.write(files.x + 23, files.item_h - label.height / 2 + y, bgcol, text_col, label.size.pt, 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 diff --git a/programs/cmm/eolite/include/settings.h b/programs/cmm/eolite/include/settings.h index 45830f971..265111c9d 100644 --- a/programs/cmm/eolite/include/settings.h +++ b/programs/cmm/eolite/include/settings.h @@ -58,8 +58,8 @@ void settings_dialog() else if (id==27) MOUSE_TIME++; else if (id==28) && (MOUSE_TIME>29) MOUSE_TIME--; //else if (id==29) smooth_font ^= true; - else if (id==30) { font.size.text++; IF(!font.changeSIZE()) font.size.text--; BigFontsChange(); } - else if (id==31) { font.size.text--; IF(!font.changeSIZE()) font.size.text++; BigFontsChange(); } + else if (id==30) { label.size.pt++; IF(!label.changeSIZE()) label.size.pt--; BigFontsChange(); } + else if (id==31) { label.size.pt--; IF(!label.changeSIZE()) label.size.pt++; BigFontsChange(); } EventRedrawWindow(Form.left,Form.top); DrawSettingsCheckBoxes(); break; @@ -95,7 +95,7 @@ void DrawSettingsCheckBoxes() //CheckBox2(10, 99, 29, smooth_FONT, smooth_font); MoreLessBox(10, 99, 18, 27, 28, #system.color, MOUSE_TIME, T_DOUBLE_CLICK); MoreLessBox(10, 125, 18, 25, 26, #system.color, files.item_h, LIST_LINE_HEIGHT); - if (font.data) MoreLessBox(10, 152, 18, 30, 31, #system.color, font.size.text, FONT_SIZE_LABEL); + if (label.font) MoreLessBox(10, 152, 18, 30, 31, #system.color, label.size.pt, FONT_SIZE_LABEL); } @@ -107,7 +107,7 @@ void LoadIniSettings() ini_get_int stdcall (eolite_ini_path, #config_section, "ShowDeviceName", 1); show_dev_name = EAX; ini_get_int stdcall (eolite_ini_path, #config_section, "RealFileNamesCase", 0); real_files_names_case = EAX; ini_get_int stdcall (eolite_ini_path, #config_section, "InfoAfterCopy", 0); info_after_copy = EAX; - ini_get_int stdcall (eolite_ini_path, #config_section, "FontSize", 9); font.size.text = EAX; + ini_get_int stdcall (eolite_ini_path, #config_section, "FontSize", 9); label.size.pt = EAX; ini_get_int stdcall (eolite_ini_path, #config_section, "TwoPanels", 0); two_panels = EAX; //ini_get_int stdcall (eolite_ini_path, #config_section, "UseSmoothFont", true);smooth_font = EAX; ini_get_int stdcall (eolite_ini_path, #config_section, "LineHeight", 18); files.item_h = EAX; @@ -118,8 +118,8 @@ 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/"); - 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 file",#temp,4096,DEFAULT_FONT); + label.init(#temp); ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font smoothing",#temp,4096,"on"); if(!strcmp(#temp,"off"))smooth_font = false; else smooth_font = true; @@ -132,7 +132,7 @@ void SaveIniSettings() ini_set_int stdcall (eolite_ini_path, #config_section, "ShowDeviceName", show_dev_name); ini_set_int stdcall (eolite_ini_path, #config_section, "RealFileNamesCase", real_files_names_case); ini_set_int stdcall (eolite_ini_path, #config_section, "InfoAfterCopy", info_after_copy); - ini_set_int stdcall (eolite_ini_path, #config_section, "FontSize", font.size.text); + ini_set_int stdcall (eolite_ini_path, #config_section, "FontSize", label.size.pt); ini_set_int stdcall (eolite_ini_path, #config_section, "TwoPanels", two_panels); //ini_set_int stdcall (eolite_ini_path, #config_section, "UseSmoothFont", smooth_font); ini_set_int stdcall (eolite_ini_path, #config_section, "LineHeight", files.item_h); @@ -147,7 +147,7 @@ void SaveIniSettings() ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "ShowDeviceName", show_dev_name); ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "RealFileNamesCase", real_files_names_case); ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "InfoAfterCopy", info_after_copy); - ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "FontSize", font.size.text); + ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "FontSize", label.size.pt); ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "TwoPanels", two_panels); //ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "UseSmoothFont", smooth_font); ini_set_int stdcall (fd_path_eolite_ini_path, #config_section, "LineHeight", files.item_h); @@ -187,7 +187,7 @@ void SetAppColors() void BigFontsChange() { - files.item_h = font.size.text + 4; + files.item_h = label.size.pt + 4; if (files.item_h<18) files.item_h = 18; files_active.item_h = files_inactive.item_h = files.item_h; } diff --git a/programs/cmm/kolibri font viewer/kolibri font viewer.c b/programs/cmm/kolibri font viewer/kolibri font viewer.c index 600ad32a1..39e60296f 100644 --- a/programs/cmm/kolibri font viewer/kolibri font viewer.c +++ b/programs/cmm/kolibri font viewer/kolibri font viewer.c @@ -8,12 +8,10 @@ void main() { proc_info Form; - word i, y, btn; + int i, y, btn; char line[256], title[4196]; - font.color = 0; - font.bg_color = 0xFFFFFF; if (!param) strcpy(#param, DEFAULT_FONT); - font.load(#param); + label.init(#param); strcpy(#title, "Font preview: "); strcat(#title, #param); loop() @@ -23,32 +21,32 @@ void main() case evButton: btn = GetButtonID(); if (btn==1) ExitProcess(); - if (btn==2) font.bold ^=1; - if (btn==3) font.italic ^=1; - if (btn==4) font.smooth ^=1; + if (btn==2) label.bold ^=1; + if (btn==3) label.italic ^=1; + if (btn==4) label.smooth ^=1; goto _DRAW_WINDOW_CONTENT; case evReDraw: DefineAndDrawWindow(215,100,500,320,0x74,0xFFFFFF,#title); GetProcessInfo(#Form, SelfInfo); + if (Form.status_window>2) break; _DRAW_WINDOW_CONTENT: DrawBar(0, 0, Form.cwidth, PANELH, 0xCCCccc); - CheckBox2(10, 8, 2, "Bold", font.bold); - CheckBox2(70, 8, 3, "Italic", font.italic); - CheckBox2(140, 8, 4, "Smooth", font.smooth); - font.buffer_size = free(font.buffer); - if (!font.data) + CheckBox2(10, 8, 2, "Bold", label.bold); + CheckBox2(70, 8, 3, "Italic", label.italic); + CheckBox2(140, 8, 4, "Smooth", label.smooth); + label.raw_size = free(label.raw); + if (!label.font) { DrawBar(0, PANELH, Form.cwidth, Form.cheight - PANELH, 0xFFFfff); WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded."); } - else for (i=10, y=5; i<22; i++, y+=font.height;) //not flexible, need to calculate font count and max line length + else for (i=10, y=5; i<22; i++, y+=label.height;) //not flexible, need to calculate font count and max line length { - font.size.text = i; sprintf(#line,"Размер шрифта/size font %d пикселей.",i); - font.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, #line); + label.write_buf(10,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, 0, i, #line); } - if (font.smooth) font.apply_smooth(); - font.show_buf(0, PANELH); + if (label.smooth) label.apply_smooth(); + label.show_buf(0, PANELH); } } } diff --git a/programs/cmm/lib/font.h b/programs/cmm/lib/font.h index e4f04638f..da9234801 100644 --- a/programs/cmm/lib/font.h +++ b/programs/cmm/lib/font.h @@ -1,5 +1,5 @@ -#ifndef INCLUDE_FONT_H -#define INCLUDE_FONT_H +#ifndef INCLUDE_LABEL_H +#define INCLUDE_LABEL_H #ifndef INCLUDE_MATH_H #include "../lib/math.h" @@ -11,76 +11,70 @@ #define DEFAULT_FONT "/sys/fonts/Tahoma.kf" -:struct __OFFSET_FONT -{ - signed x,y; -}; :struct __SIZE { dword width,height; - __OFFSET_FONT offset; + signed offset_x, offset_y; float offset_i,w_italic; - byte text; + byte points; byte TMP_WEIGHT; }; -:struct FONT +:struct LABEL { __SIZE size; - int left,top,width,height; + int width,height; byte bold,italic,smooth; - dword bg_color; dword color; - dword file_size; - dword buffer; - dword buffer_size; + dword font,font_begin; word block; - dword data; - dword begin; - byte load(...); + byte init(); byte changeSIZE(); - 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; + byte symbol(); + byte symbol_size(); + dword getsize(); -:byte FONT::changeSIZE() + dword raw; + dword raw_size; + void apply_smooth(); + int write_center(); + int write(); + void write_buf(); + void show_buf(); +} label; + +:byte LABEL::changeSIZE() { + dword file_size; dword TMP_DATA; dword ofs; - IF(size.text<9) size.text = 8; - TMP_DATA = data = begin; - TMP_DATA +=size.text-8*4; + IF(size.pt<9) size.pt = 8; + TMP_DATA = font = font_begin; + TMP_DATA +=size.pt-8*4; ofs = DSDWORD[TMP_DATA]; IF(ofs==-1)return false; - data += ofs + 156; - TMP_DATA = data; + font += ofs + 156; + TMP_DATA = font; file_size = DSDWORD[TMP_DATA]; - TMP_DATA = data + file_size; + TMP_DATA = font + file_size; height = DSBYTE[TMP_DATA - 1]; width = DSBYTE[TMP_DATA - 2]; block = math.ceil(height*width/32); return true; } -:dword FONT::getsize(dword text1) +:dword LABEL::getsize(dword text1) { size.height = size.width = 0; - size.offset.x = size.offset.y = -1; - IF(size.text)IF(!changeSIZE())return 0; + size.offset_x = size.offset_y = -1; + IF(size.pt)IF(!changeSIZE())return 0; WHILE(DSBYTE[text1]) { symbol_size(DSBYTE[text1]); text1++; } - $neg size.offset.y - $neg size.offset.x - size.height += size.offset.y; size.height++; - size.width += size.offset.x; size.width++; + $neg size.offset_y + $neg size.offset_x + size.height += size.offset_y; size.height++; + size.width += size.offset_x; size.width++; IF(italic) { size.w_italic = size.height/3; @@ -90,14 +84,14 @@ FONT font = 0; } return size.width; } -:byte FONT::symbol_size(byte s) +:byte LABEL::symbol_size(byte s) { dword xi,yi; dword tmp,_; dword iii = 0; byte rw=0; byte X; - size.TMP_WEIGHT = math.ceil(size.text/17); + size.TMP_WEIGHT = math.ceil(size.pt/17); IF(s==32) { size.width += width/4; @@ -110,8 +104,8 @@ FONT font = 0; IF(bold) size.width+=size.TMP_WEIGHT; return; } - s = AnsiToCp866(s); - tmp = 4*block*s + data; + s = Cp866ToAnsi(s); + tmp = 4*block*s + font; for(yi=0; yirw)rw=xi; IF(size.heightxi)X = xi; } @@ -137,9 +131,9 @@ FONT font = 0; size.width += rw; IF(bold) size.width+=size.TMP_WEIGHT; IF(s=='_') size.width--; - IF(size.offset.x<0)size.offset.x = X; + IF(size.offset_x<0)size.offset_x = X; } -:byte FONT::symbol(signed x,y;byte s) +:byte LABEL::symbol(signed x,y; byte s; dword image_raw) { dword xi,yi; dword iii = 0; @@ -149,11 +143,12 @@ FONT font = 0; byte rw=0; IF(s==32)return width/4; IF(s==9)return width; - s = AnsiToCp866(s); - EBX = block*s << 2 + data; + debugch(s); + s = Cp866ToAnsi(s); + EBX = block*s << 2 + font; for(yi=0; yi=128)&&(s<=175)s+=64; ELSE IF(s>=224)&&(s<=239)s+=16; ELSE IF(s==241)s=184; //yo @@ -186,15 +181,42 @@ byte AnsiToCp866(byte s) { return s; } +:byte LABEL::init(dword font_path) +{ + lib_init_fs(); + IF(font)free(font); + IF(!fs.read(font_path)) { + debug("Error while loading font: "); + debugln(font_path); + //io.run("/sys/@notify","'Error: Font is not loaded.' -E"); + return false; + } + font_begin = font = EAX; + EBX = font_begin + ECX; + height = DSBYTE[EBX-1]; + width = DSBYTE[EBX-2]; + block = math.ceil(height*width/32); + smooth = true; + return true; +} + + +/*===================================================================================== +=========================== =========================== +=========================== RAW =========================== +=========================== =========================== +=====================================================================================*/ + + inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } -:void FONT::apply_smooth() +:void LABEL::apply_smooth() { dword i,line_w,to; - line_w = font.size.width * 3; - to = font.size.height - 1 * line_w + font.buffer - 3; - for(i=font.buffer; i < to; i+=3) + line_w = size.width * 3; + to = size.height - 1 * line_w + raw - 3; + for(i=raw; i < to; i+=3) { - IF(i-font.buffer%line_w +3 == line_w) continue; + IF(i-raw%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) { ShadowPixel(i+3, 2); @@ -207,101 +229,90 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } } } } -:byte FONT::load(dword path) -{ - lib_init_fs(); - buffer_size = 0; - smooth = true; - IF(data)free(data); - IF(!fs.read(path)) { debug("Error while loading font: "); debugln(path); return false; } - begin = data = EAX; - EBX = begin + ECX; - height = DSBYTE[EBX-1]; - width = DSBYTE[EBX-2]; - block = math.ceil(height*width/32); - return true; -} -:int FONT::write_center(dword x,y,w,h;dword txt) +:int LABEL::write_center(dword x,y,w,h; dword background, color1; byte fontSizePoints; dword txt) { + size.pt = fontSizePoints; getsize(txt); - return write(w-size.width/2+x,y,txt); + return write(w-size.width/2+x,y, background, color1, fontSizePoints, txt); } -:int FONT::write(int x,y; dword text1) +:int LABEL::write(int x,y; dword background, color1; byte fontSizePoints; dword text1) { signed len=0; IF(!text1)return false; - IF(size.text)IF(!changeSIZE())return false; - left = x; + IF(size.pt)IF(!changeSIZE())return false; + size.pt = fontSizePoints; getsize(text1); - y -= size.offset.y; - top = y; + color = color1; + y -= size.offset_y; EDX = size.width*size.height*3; - IF(!buffer_size) + IF(!raw_size) { - buffer_size = EDX; - buffer = malloc(buffer_size); + raw_size = EDX; + raw = malloc(raw_size); } - ELSE IF(buffer_size