2016-12-23 03:27:00 +03:00
|
|
|
|
// Сам шрифт представляет.
|
|
|
|
|
|
|
|
|
|
// Голова:
|
|
|
|
|
// [2 байта символы:KF]
|
|
|
|
|
// [4 байта:указатель на название шрифта]
|
|
|
|
|
// [1 байт:размер массива указателей на размеры шрифтов, указатель 4 байта, т.е. размер = размер массива*4]
|
|
|
|
|
// [размер массива*4 байт:указатели..]
|
|
|
|
|
|
|
|
|
|
// Тело файла:
|
|
|
|
|
// [4 байта:масштаб ширина][4 байта:масштаб высота][255*4 байт:указатели на символы][масштаб ширина*масштаб высота байт: данные символов..]
|
|
|
|
|
|
|
|
|
|
// Конец:
|
|
|
|
|
// [Название шрифта:"Times New Roman"]
|
|
|
|
|
|
|
|
|
|
|
2018-05-22 15:04:44 +03:00
|
|
|
|
#ifndef INCLUDE_KFONT_H
|
|
|
|
|
#define INCLUDE_KFONT_H
|
2015-08-17 03:16:17 +03:00
|
|
|
|
|
|
|
|
|
#ifndef INCLUDE_MATH_H
|
|
|
|
|
#include "../lib/math.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-12-04 22:30:30 +03:00
|
|
|
|
#ifndef INCLUDE_IO_H
|
2020-12-13 04:21:31 +03:00
|
|
|
|
#include "../lib/fs.h"
|
2015-08-17 03:16:17 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
2016-01-01 19:51:53 +03:00
|
|
|
|
#include "../lib/patterns/rgb.h"
|
|
|
|
|
|
|
|
|
|
|
2015-12-17 22:15:49 +03:00
|
|
|
|
#define DEFAULT_FONT "/sys/fonts/Tahoma.kf"
|
|
|
|
|
|
2016-12-23 03:27:00 +03:00
|
|
|
|
#ifndef KFONT_BPP
|
|
|
|
|
#define KFONT_BPP 4
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-05-22 15:04:44 +03:00
|
|
|
|
int kfont_char_width[255];
|
|
|
|
|
|
2015-08-20 18:04:18 +03:00
|
|
|
|
:struct __SIZE
|
|
|
|
|
{
|
2015-09-07 16:07:29 +03:00
|
|
|
|
dword width,height;
|
2015-12-19 00:10:45 +03:00
|
|
|
|
signed offset_x, offset_y;
|
2015-12-19 00:13:19 +03:00
|
|
|
|
byte pt;
|
2015-08-20 18:04:18 +03:00
|
|
|
|
};
|
2018-05-22 15:04:44 +03:00
|
|
|
|
:struct KFONT
|
2015-08-17 03:16:17 +03:00
|
|
|
|
{
|
2015-08-20 18:04:18 +03:00
|
|
|
|
__SIZE size;
|
2015-12-19 00:10:45 +03:00
|
|
|
|
int width,height;
|
2016-12-21 13:56:06 +03:00
|
|
|
|
byte bold,smooth;
|
2015-12-21 22:04:39 +03:00
|
|
|
|
dword color, background;
|
2015-12-19 00:10:45 +03:00
|
|
|
|
dword font,font_begin;
|
2015-08-17 03:16:17 +03:00
|
|
|
|
word block;
|
2016-12-21 13:56:06 +03:00
|
|
|
|
dword raw;
|
|
|
|
|
dword raw_size;
|
|
|
|
|
|
2016-12-21 22:50:13 +03:00
|
|
|
|
bool init();
|
2016-12-21 13:56:06 +03:00
|
|
|
|
bool changeSIZE();
|
2015-12-19 00:10:45 +03:00
|
|
|
|
byte symbol();
|
|
|
|
|
byte symbol_size();
|
|
|
|
|
dword getsize();
|
2018-05-22 15:04:44 +03:00
|
|
|
|
int get_label_width();
|
2015-12-19 00:10:45 +03:00
|
|
|
|
|
2016-12-21 13:56:06 +03:00
|
|
|
|
void ApplySmooth();
|
|
|
|
|
int WriteIntoWindow();
|
|
|
|
|
int WriteIntoWindowCenter();
|
2020-05-01 22:10:48 +03:00
|
|
|
|
dword WriteIntoBuffer();
|
2016-12-21 18:40:39 +03:00
|
|
|
|
void ShowBuffer();
|
2016-12-23 03:27:00 +03:00
|
|
|
|
void ShowBufferPart();
|
2016-12-21 22:50:13 +03:00
|
|
|
|
} kfont;
|
2015-12-17 22:15:49 +03:00
|
|
|
|
|
2018-05-22 15:04:44 +03:00
|
|
|
|
:bool KFONT::init(dword font_path)
|
2016-12-23 03:27:00 +03:00
|
|
|
|
{
|
2020-12-13 04:21:31 +03:00
|
|
|
|
dword fsize_notused;
|
2016-12-23 03:27:00 +03:00
|
|
|
|
if(font)free(font);
|
2020-12-13 04:21:31 +03:00
|
|
|
|
read_file(font_path, #font_begin, #fsize_notused);
|
2016-12-23 03:27:00 +03:00
|
|
|
|
if(!EAX) {
|
2020-12-13 04:21:31 +03:00
|
|
|
|
RunProgram("/sys/@notify", "'Error: KFONT is not loaded.' -E");
|
2016-12-23 03:27:00 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
changeSIZE();
|
|
|
|
|
smooth = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 15:04:44 +03:00
|
|
|
|
:bool KFONT::changeSIZE()
|
2015-08-17 19:21:51 +03:00
|
|
|
|
{
|
2018-05-22 15:04:44 +03:00
|
|
|
|
int i;
|
2015-12-19 00:10:45 +03:00
|
|
|
|
dword file_size;
|
2015-08-17 19:21:51 +03:00
|
|
|
|
dword ofs;
|
2016-12-21 18:40:39 +03:00
|
|
|
|
if(size.pt<9) size.pt = 9;
|
2016-12-21 13:56:06 +03:00
|
|
|
|
font = font_begin;
|
|
|
|
|
ofs = DSDWORD[calc(size.pt-8<<2+font_begin)];
|
|
|
|
|
if(ofs==-1)return false;
|
2015-12-19 00:10:45 +03:00
|
|
|
|
font += ofs + 156;
|
2016-12-21 13:56:06 +03:00
|
|
|
|
file_size = DSDWORD[calc(font)];
|
|
|
|
|
height = DSBYTE[calc(font+file_size) - 1];
|
|
|
|
|
width = DSBYTE[calc(font+file_size) - 2];
|
2015-08-20 19:37:49 +03:00
|
|
|
|
block = math.ceil(height*width/32);
|
2018-05-22 15:04:44 +03:00
|
|
|
|
for (i=0; i<256; i++) {
|
|
|
|
|
kfont_char_width[i] = symbol_size((byte) i);
|
|
|
|
|
}
|
2015-08-20 19:37:49 +03:00
|
|
|
|
return true;
|
2015-08-17 19:21:51 +03:00
|
|
|
|
}
|
2016-12-21 22:50:13 +03:00
|
|
|
|
|
2020-04-06 18:22:12 +03:00
|
|
|
|
:dword KFONT::getsize(byte font_size, dword text1)
|
2015-08-17 03:16:17 +03:00
|
|
|
|
{
|
2015-08-20 18:04:18 +03:00
|
|
|
|
size.height = size.width = 0;
|
2015-12-19 00:10:45 +03:00
|
|
|
|
size.offset_x = size.offset_y = -1;
|
2020-04-06 18:22:12 +03:00
|
|
|
|
if (size.pt != font_size) {
|
|
|
|
|
size.pt = font_size;
|
2018-05-22 15:04:44 +03:00
|
|
|
|
if(!changeSIZE())return 0;
|
|
|
|
|
}
|
2015-08-18 13:43:23 +03:00
|
|
|
|
WHILE(DSBYTE[text1])
|
|
|
|
|
{
|
2016-12-21 22:50:13 +03:00
|
|
|
|
size.width += symbol_size(DSBYTE[text1]);
|
2015-08-18 13:43:23 +03:00
|
|
|
|
text1++;
|
|
|
|
|
}
|
2015-12-19 00:10:45 +03:00
|
|
|
|
$neg size.offset_y
|
|
|
|
|
$neg size.offset_x
|
2015-12-21 19:37:24 +03:00
|
|
|
|
size.height += size.offset_y+1;
|
|
|
|
|
size.width += size.offset_x+1;
|
2015-08-20 18:04:18 +03:00
|
|
|
|
return size.width;
|
2015-08-18 13:43:23 +03:00
|
|
|
|
}
|
2016-12-21 22:50:13 +03:00
|
|
|
|
|
2020-04-06 18:22:12 +03:00
|
|
|
|
//WILL NOT WORK if requested font_size
|
2018-05-22 15:04:44 +03:00
|
|
|
|
//is differ from precalculated kfont_char_width[]
|
|
|
|
|
:int KFONT::get_label_width(dword _label)
|
|
|
|
|
{
|
|
|
|
|
int len=0;
|
|
|
|
|
while (ESBYTE[_label]) {
|
|
|
|
|
len += kfont_char_width[ ESBYTE[_label] ];
|
|
|
|
|
_label++;
|
|
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:byte KFONT::symbol_size(byte s)
|
2015-08-18 13:43:23 +03:00
|
|
|
|
{
|
2016-12-21 22:50:13 +03:00
|
|
|
|
int chaw_width;
|
|
|
|
|
chaw_width = symbol(0,0, s, 0);
|
|
|
|
|
if(bold) chaw_width += math.ceil(size.pt/17);
|
|
|
|
|
return chaw_width;
|
2015-08-18 13:43:23 +03:00
|
|
|
|
}
|
2016-12-21 22:50:13 +03:00
|
|
|
|
|
2018-05-22 15:04:44 +03:00
|
|
|
|
:byte KFONT::symbol(signed x,y; byte s; dword image_raw)
|
2015-12-17 22:15:49 +03:00
|
|
|
|
{
|
2016-12-21 18:40:39 +03:00
|
|
|
|
dword xi,yi;
|
|
|
|
|
dword iii = 0;
|
|
|
|
|
dword offs;
|
2016-12-21 22:50:13 +03:00
|
|
|
|
dword tmp, _;
|
|
|
|
|
byte X;
|
|
|
|
|
byte chaw_width=0;
|
2020-04-15 23:55:42 +03:00
|
|
|
|
if(s==32)return width/4+1;
|
2016-12-21 18:40:39 +03:00
|
|
|
|
if(s==9)return width;
|
|
|
|
|
s = Cp866ToAnsi(s);
|
2016-12-21 22:50:13 +03:00
|
|
|
|
tmp = block*s << 2 + font;
|
2016-12-21 18:40:39 +03:00
|
|
|
|
for(yi=0; yi<height; yi++)
|
|
|
|
|
{
|
2016-12-23 03:27:00 +03:00
|
|
|
|
EDI = size.offset_y + yi + y * size.width * KFONT_BPP + image_raw;
|
2016-12-21 18:40:39 +03:00
|
|
|
|
for(xi=0; xi<width; xi++)
|
2015-12-17 22:15:49 +03:00
|
|
|
|
{
|
2016-12-21 22:50:13 +03:00
|
|
|
|
if(iii%32) _ >>= 1;
|
2016-12-21 18:40:39 +03:00
|
|
|
|
else
|
2015-12-17 22:15:49 +03:00
|
|
|
|
{
|
2016-12-21 22:50:13 +03:00
|
|
|
|
tmp += 4;
|
|
|
|
|
_ = DSDWORD[tmp];
|
2016-12-21 18:40:39 +03:00
|
|
|
|
}
|
2016-12-21 22:50:13 +03:00
|
|
|
|
if(_&1) //check does the pixel set
|
2016-12-21 18:40:39 +03:00
|
|
|
|
{
|
2016-12-21 22:50:13 +03:00
|
|
|
|
if(xi>chaw_width)chaw_width=xi;
|
2016-12-23 03:27:00 +03:00
|
|
|
|
//in case of image_raw!=0 draw font into bug
|
|
|
|
|
//in case of image_raw==0 calculate size
|
2016-12-21 22:50:13 +03:00
|
|
|
|
if (image_raw)
|
|
|
|
|
{
|
2016-12-23 03:27:00 +03:00
|
|
|
|
offs = x + xi * KFONT_BPP + EDI;
|
|
|
|
|
DSDWORD[offs] = color;
|
|
|
|
|
if(bold) DSDWORD[offs+KFONT_BPP] = color;
|
2016-12-21 22:50:13 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(size.height<yi)size.height = yi;
|
|
|
|
|
if(size.offset_y<0)size.offset_y = yi; else if(yi<size.offset_y)size.offset_y = yi;
|
|
|
|
|
if(!X) X = xi; else if(X>xi)X = xi;
|
|
|
|
|
if(size.offset_x<0)size.offset_x = X;
|
|
|
|
|
}
|
2015-12-17 22:15:49 +03:00
|
|
|
|
}
|
2016-12-21 18:40:39 +03:00
|
|
|
|
iii++;
|
2015-12-17 22:15:49 +03:00
|
|
|
|
}
|
2016-12-21 18:40:39 +03:00
|
|
|
|
}
|
2016-12-21 22:50:13 +03:00
|
|
|
|
return chaw_width;
|
2015-12-17 22:15:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-21 13:56:06 +03:00
|
|
|
|
inline fastcall Cp866ToAnsi(AL) {
|
|
|
|
|
if (AL>=128)&&(AL<=175) return AL+64;
|
|
|
|
|
if (AL>=224)&&(AL<=239) return AL+16;
|
|
|
|
|
if (AL==241) return 184; //e ruAL with dotAL (yo)
|
|
|
|
|
if (AL==240) return 168; //E ruAL with dotAL (yo)
|
|
|
|
|
if (AL==242) return 'E'; //E ukr (ye)
|
|
|
|
|
if (AL==243) return 186; //e ukr (ye)
|
|
|
|
|
if (AL==244) return 'I'; //I ukr (yi)
|
|
|
|
|
if (AL==245) return 191; //i ukr (yi)
|
|
|
|
|
return AL;
|
2015-12-17 22:15:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-19 00:10:45 +03:00
|
|
|
|
/*=====================================================================================
|
|
|
|
|
=========================== ===========================
|
|
|
|
|
=========================== RAW ===========================
|
|
|
|
|
=========================== ===========================
|
|
|
|
|
=====================================================================================*/
|
|
|
|
|
|
2016-12-23 03:27:00 +03:00
|
|
|
|
inline fastcall dword b32(EAX) { return DSDWORD[EAX]; }
|
2018-05-22 15:04:44 +03:00
|
|
|
|
:void KFONT::ApplySmooth()
|
2015-12-17 22:15:49 +03:00
|
|
|
|
{
|
2016-01-11 01:33:10 +03:00
|
|
|
|
dword i,line_w,to,dark_background;
|
2016-12-23 03:27:00 +03:00
|
|
|
|
line_w = size.width * KFONT_BPP;
|
|
|
|
|
to = size.height - 1 * line_w + raw - KFONT_BPP;
|
|
|
|
|
for(i=raw; i < to; i+=KFONT_BPP)
|
2015-12-18 18:21:19 +03:00
|
|
|
|
{
|
2016-12-23 03:27:00 +03:00
|
|
|
|
if(i-raw%line_w +KFONT_BPP == line_w) continue;
|
2016-01-01 19:51:53 +03:00
|
|
|
|
// pixels position, where b - black, w - write
|
|
|
|
|
// bw
|
|
|
|
|
// wb
|
2016-12-23 03:27:00 +03:00
|
|
|
|
if(b32(i)!=background) {
|
|
|
|
|
if (b32(i+KFONT_BPP)==background)
|
|
|
|
|
&& (b32(i+line_w)==background) && (b32(i+KFONT_BPP+line_w)!=background)
|
|
|
|
|
{
|
|
|
|
|
dark_background = MixColors(background,b32(i),200);
|
|
|
|
|
DSDWORD[i+KFONT_BPP] = dark_background;
|
|
|
|
|
DSDWORD[i+line_w] = dark_background;
|
|
|
|
|
}
|
2015-12-17 22:15:49 +03:00
|
|
|
|
}
|
2016-01-01 19:51:53 +03:00
|
|
|
|
// wb
|
|
|
|
|
// bw
|
2016-12-23 03:27:00 +03:00
|
|
|
|
else if (b32(i+KFONT_BPP)!=background)
|
|
|
|
|
&& (b32(i+line_w)!=background) && (b32(i+KFONT_BPP+line_w)==background)
|
2015-12-17 22:15:49 +03:00
|
|
|
|
{
|
2016-12-23 03:27:00 +03:00
|
|
|
|
dark_background = MixColors(background,b32(i+KFONT_BPP),200);
|
|
|
|
|
DSDWORD[i] = dark_background;
|
|
|
|
|
DSDWORD[i+KFONT_BPP+line_w] = dark_background;
|
2015-12-17 22:15:49 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-01 22:10:48 +03:00
|
|
|
|
:dword KFONT::WriteIntoBuffer(int x,y,w,h; dword _background, _color; byte font_size; dword text1)
|
2015-09-01 16:11:07 +03:00
|
|
|
|
{
|
2015-12-19 00:10:45 +03:00
|
|
|
|
dword new_raw_size;
|
2016-12-21 13:56:06 +03:00
|
|
|
|
if(!text1)return;
|
2015-12-19 00:10:45 +03:00
|
|
|
|
|
2020-04-06 18:22:12 +03:00
|
|
|
|
if (size.pt != font_size) {
|
|
|
|
|
getsize(font_size, text1);
|
2016-01-01 19:51:53 +03:00
|
|
|
|
y -= size.offset_y;
|
|
|
|
|
}
|
2015-12-21 22:04:39 +03:00
|
|
|
|
color = _color;
|
|
|
|
|
background = _background;
|
2015-12-17 22:15:49 +03:00
|
|
|
|
|
2015-09-01 16:11:07 +03:00
|
|
|
|
size.width = w;
|
2015-09-01 16:55:35 +03:00
|
|
|
|
size.height = h;
|
2015-09-02 16:15:32 +03:00
|
|
|
|
|
2016-12-23 03:27:00 +03:00
|
|
|
|
new_raw_size = w*h*KFONT_BPP;
|
2016-12-21 13:56:06 +03:00
|
|
|
|
if(raw_size != new_raw_size)
|
2015-09-01 16:11:07 +03:00
|
|
|
|
{
|
2015-12-19 00:10:45 +03:00
|
|
|
|
raw_size = new_raw_size;
|
|
|
|
|
free(raw);
|
|
|
|
|
raw = malloc(raw_size);
|
2015-12-18 18:21:19 +03:00
|
|
|
|
// Fill background color
|
2015-12-19 00:10:45 +03:00
|
|
|
|
EBX = background;
|
|
|
|
|
EAX = raw_size+raw;
|
2016-12-23 03:27:00 +03:00
|
|
|
|
for (EDI=raw; EDI<EAX; EDI+=KFONT_BPP) ESDWORD[EDI] = EBX;
|
2015-09-01 16:11:07 +03:00
|
|
|
|
}
|
|
|
|
|
WHILE(DSBYTE[text1])
|
|
|
|
|
{
|
2015-12-19 00:10:45 +03:00
|
|
|
|
x+=symbol(x,y,DSBYTE[text1], raw);
|
2016-12-21 13:56:06 +03:00
|
|
|
|
if(bold)x+=math.ceil(size.pt/17);
|
2015-09-01 16:11:07 +03:00
|
|
|
|
text1++;
|
|
|
|
|
}
|
2020-05-01 22:10:48 +03:00
|
|
|
|
return x;
|
2015-09-01 16:11:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 18:22:12 +03:00
|
|
|
|
:int KFONT::WriteIntoWindow(int x,y; dword _background, _color; byte font_size; dword text1)
|
2016-12-21 18:40:39 +03:00
|
|
|
|
{
|
|
|
|
|
if(!text1)return 0;
|
2020-04-06 18:22:12 +03:00
|
|
|
|
getsize(font_size, text1);
|
2016-12-21 18:40:39 +03:00
|
|
|
|
raw_size = NULL;
|
|
|
|
|
WriteIntoBuffer(0, -size.offset_y, size.width-size.offset_x,
|
2020-04-06 18:22:12 +03:00
|
|
|
|
size.height-size.offset_y, _background, _color, font_size, text1);
|
2016-12-21 18:40:39 +03:00
|
|
|
|
if (smooth) ApplySmooth();
|
|
|
|
|
ShowBuffer(x,y);
|
|
|
|
|
return size.offset_x + size.width;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 18:22:12 +03:00
|
|
|
|
:int KFONT::WriteIntoWindowCenter(dword x, _y,w,h, _background, _color; byte font_size; dword text1)
|
2016-12-21 18:40:39 +03:00
|
|
|
|
{
|
2020-04-06 18:22:12 +03:00
|
|
|
|
getsize(font_size, text1);
|
|
|
|
|
return WriteIntoWindow(w-size.width/2+x-1, _y, _background, _color, font_size, text1);
|
2016-12-21 18:40:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 15:04:44 +03:00
|
|
|
|
:void KFONT::ShowBuffer(dword _x, _y)
|
2016-12-23 03:27:00 +03:00
|
|
|
|
{
|
|
|
|
|
if (4==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 32, 0);
|
|
|
|
|
//if (1==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 8, #palette);
|
2015-12-18 18:21:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 15:04:44 +03:00
|
|
|
|
:void KFONT::ShowBufferPart(dword _x, _y, _w, _h, _buf_offset)
|
2016-12-23 03:27:00 +03:00
|
|
|
|
{
|
|
|
|
|
if (4==KFONT_BPP) PutPaletteImage(_buf_offset * KFONT_BPP + raw, _w, _h, _x, _y, 32, 0);
|
|
|
|
|
//if (1==KFONT_BPP) PutPaletteImage(_buf_offset * KFONT_BPP + raw, _w, _h, _x, _y, 8, #palette);
|
|
|
|
|
}
|
2015-12-18 18:21:19 +03:00
|
|
|
|
|
2015-08-17 03:16:17 +03:00
|
|
|
|
#endif
|