From 6f0e6671dbc637fc54b4c463224fb7c6d7b84f14 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 2 Sep 2015 13:15:32 +0000 Subject: [PATCH] CMM. list_box.h: handle incorect values font.h: finally ability to write into a buffer kolibri font viewer.c: write into a buffer git-svn-id: svn://kolibrios.org@5784 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../kolibri font viewer/kolibri font viewer.c | 27 ++++-- programs/cmm/lib/font.h | 95 ++++++++----------- programs/cmm/lib/list_box.h | 4 +- 3 files changed, 60 insertions(+), 66 deletions(-) diff --git a/programs/cmm/kolibri font viewer/kolibri font viewer.c b/programs/cmm/kolibri font viewer/kolibri font viewer.c index 50a62d36ac..eea5741d6a 100644 --- a/programs/cmm/kolibri font viewer/kolibri font viewer.c +++ b/programs/cmm/kolibri font viewer/kolibri font viewer.c @@ -1,10 +1,13 @@ -#define MEMSIZE 0xEE80 +#define MEMSIZE 0x2EE80 #include "../lib/font.h" #include "../lib/gui.h" +#define PANELH 30 + void main() { + proc_info Form; word i, y, btn; char line[256], title[4196]; font.no_bg_copy = true; @@ -23,24 +26,30 @@ void main() if (btn==1) ExitProcess(); if (btn==2) font.weight ^=1; if (btn==3) font.italic ^=1; - if (btn==4) font.no_bg_copy ^=1; + if (btn==4) font.smooth ^=1; + goto _DRAW_WINDOW_CONTENT; case evReDraw: - DefineAndDrawWindow(215,100,500,320,0x33,0xFFFFFF,#title); - DrawBar(0, 0, 500-9, 30, 0xCCCccc); + DefineAndDrawWindow(215,100,500,320,0x74,0xFFFFFF,#title); + GetProcessInfo(#Form, SelfInfo); + _DRAW_WINDOW_CONTENT: + DrawBar(0, 0, Form.cwidth, PANELH, 0xCCCccc); CheckBox2(10, 8, 2, "Bold", font.weight); CheckBox2(70, 8, 3, "Italic", font.italic); - CheckBox2(140, 8, 4, "Smooth", font.no_bg_copy); + CheckBox2(140, 8, 4, "Smooth", font.smooth); + font.buffer_size = free(font.buffer); if (!font.data) { + DrawBar(0, PANELH, Form.cwidth, Form.cheight - PANELH, 0xFFFfff); WriteText(10, 50, 0x82, 0xFF00FF, "Font is not loaded."); - } - else for (i=10, y=40; i<22; i++, y+=font.height;) + } + else for (i=10, y=5; i<22; i++, y+=font.height;) //not flexible, need to calculate font count and max line length { font.size.text = i; sprintf(#line,"Размер шрифта/size font %d пикселей.",i); - font.prepare(10,y,#line); - font.show(10, y); + font.prepare_buf(10,y,Form.cwidth,Form.cheight-PANELH, #line); } + if (font.smooth) SmoothFont(font.buffer, font.size.width, font.size.height); + font.show(0, PANELH); } } } diff --git a/programs/cmm/lib/font.h b/programs/cmm/lib/font.h index cf1a59a17c..905f16d918 100644 --- a/programs/cmm/lib/font.h +++ b/programs/cmm/lib/font.h @@ -20,7 +20,7 @@ :struct FONT { __SIZE size; - byte r,g,b,weight,italic; + byte r,g,b,weight,italic, smooth; byte width,height; byte encoding; dword color; @@ -30,9 +30,8 @@ word block; dword data; dword begin; - dword size_file; byte load(...); - byte symbol(word x;byte s;dword c); + byte symbol(word x,y;byte s;dword c); byte symbol_size(byte s); dword prepare(word x,y;dword text1); void prepare_buf(word x,y,w,h;dword text1); @@ -103,10 +102,8 @@ FONT font = 0; } $neg size.offset_y $neg size.offset_x - size.height++; - size.height += size.offset_y; - size.width += size.offset_x; - size.width++; + size.height += size.offset_y; size.height++; + size.width += size.offset_x; size.width++; IF(italic) { size.w_italic = size.height/3; @@ -142,33 +139,29 @@ FONT font = 0; ELSE IF(s==241)s=184; //yo ELSE IF(s==240)s=168; //YO } - yi = 0; iii = 0; tmp = 4*block*s + data; - while(yi>= 1; - ELSE - { - tmp += 4; - _ = DSDWORD[tmp]; - } - IF(_&1) - { - IF(xi>rw)rw=xi; - IF(size.heightxi)X = xi; - } - xi++; - iii++; + for(xi=0; xi>= 1; + ELSE + { + tmp += 4; + _ = DSDWORD[tmp]; } - yi++; + IF(_&1) + { + IF(xi>rw)rw=xi; + IF(size.heightxi)X = xi; + } + iii++; + } } size.width += rw; IF(weight) size.width+=size.TMP_WEIGHT; @@ -218,7 +211,7 @@ FONT font = 0; WHILE(DSBYTE[text1]) { IF(DSBYTE[text1]=='_') len--; - len+=symbol(len,DSBYTE[text1]); + len+=symbol(len,0,DSBYTE[text1]); IF(weight)len+=math.ceil(size.text/17); text1++; } @@ -250,7 +243,7 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } } } } -:byte FONT::symbol(signed x;byte s) +:byte FONT::symbol(signed x,y;byte s) { dword xi,yi; dword tmp,_; @@ -269,15 +262,12 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } ELSE IF(s==241)s=184; //yo ELSE IF(s==240)s=168; //YO } - yi = 0; iii = 0; - tmp = 4*block*s; - tmp +=data; - while(yi>= 1; ELSE @@ -291,17 +281,13 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } ___x = x+xi; IF(italic)___x+=math.ceil(ital); PixelRGB(___x,TMP); - _TMP_WEIGHT = size.TMP_WEIGHT; - WHILE(_TMP_WEIGHT) + for(_TMP_WEIGHT=size.TMP_WEIGHT; _TMP_WEIGHT; _TMP_WEIGHT--) { IF(weight) PixelRGB(___x+_TMP_WEIGHT,TMP); - _TMP_WEIGHT--; } } - xi++; iii++; } - yi++; IF(italic) ital-=size.offset_i; } return rw; @@ -312,8 +298,7 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } IF(data)free(data); if (!io.readKPACK(path)) { debug("Error while loading font: "); debugln(path); return false; } begin = data = io.buffer_data; - size_file = io.FILES_SIZE; - EBX = begin + size_file; + EBX = begin + io.FILES_SIZE; height = DSBYTE[EBX - 1]; width = DSBYTE[EBX - 2]; block = math.ceil(height*width/32); @@ -322,7 +307,6 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } :void FONT::prepare_buf(word x,y,w,h; dword text1) { - signed len=0; dword c; c = color; IF(!text1)return; @@ -333,14 +317,16 @@ inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; } size.width = w; size.height = h; + EDX = size.width*size.height*3; - IF(!buffer_size) + if(buffer_size!=EDX) { - buffer_size = EDX; - buffer = malloc(buffer_size); - EBX = bg_color; - EDI = buffer; - EAX = buffer_size+EDI; + buffer_size = EDX; + free(buffer); + buffer = malloc(buffer_size); + EBX = font.bg_color; + EDI = font.buffer; + EAX = font.buffer_size+font.buffer; WHILE (EDI count) visible=count; + CheckDoesValuesOkey(); } void llist::SetFont(dword font_ww, font_hh, font_tt) @@ -214,8 +214,8 @@ int llist::KeyPgDown() void llist::CheckDoesValuesOkey() { - if (first < 0) first = 0; if (visible + first > count) first = count - visible; + if (first < 0) first = 0; if (current >= count) current = count - 1; if (current < 0) current = 0; }