2015-08-17 02:16:17 +02:00
|
|
|
#ifndef INCLUDE_FONT_H
|
|
|
|
#define INCLUDE_FONT_H
|
|
|
|
|
|
|
|
#ifndef INCLUDE_MATH_H
|
|
|
|
#include "../lib/math.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INCLUDE_IO_H
|
|
|
|
#include "../lib/io.h"
|
|
|
|
#endif
|
|
|
|
|
2015-08-21 18:16:45 +02:00
|
|
|
|
|
|
|
#define CP866 0
|
|
|
|
#define ANSI 1
|
|
|
|
|
2015-08-20 17:04:18 +02:00
|
|
|
:struct __SIZE
|
|
|
|
{
|
|
|
|
word width,height;
|
|
|
|
signed offset_x,offset_y;
|
2015-08-21 13:03:08 +02:00
|
|
|
float offset_i,w_italic;
|
2015-08-20 17:04:18 +02:00
|
|
|
byte text;
|
2015-08-20 18:37:49 +02:00
|
|
|
byte TMP_WEIGHT;
|
2015-08-20 17:04:18 +02:00
|
|
|
};
|
2015-08-17 02:16:17 +02:00
|
|
|
:struct FONT
|
|
|
|
{
|
2015-08-20 17:04:18 +02:00
|
|
|
__SIZE size;
|
2015-08-21 13:03:08 +02:00
|
|
|
byte width,height,offsetLine,r,g,b,weight,italic;
|
2015-08-21 18:16:45 +02:00
|
|
|
byte encoding;
|
2015-08-20 17:04:18 +02:00
|
|
|
dword color;
|
2015-08-17 18:21:51 +02:00
|
|
|
dword file_size;
|
2015-08-18 03:45:23 +02:00
|
|
|
dword buffer;
|
2015-08-18 11:13:34 +02:00
|
|
|
dword buffer_size;
|
2015-08-17 02:16:17 +02:00
|
|
|
word block;
|
|
|
|
dword data;
|
2015-08-17 18:21:51 +02:00
|
|
|
dword begin;
|
2015-08-17 02:16:17 +02:00
|
|
|
dword size_file;
|
|
|
|
byte load(...);
|
2015-08-18 03:45:23 +02:00
|
|
|
byte symbol(word x;byte s;dword c);
|
2015-08-18 12:43:23 +02:00
|
|
|
byte symbol_size(byte s);
|
2015-08-27 10:33:51 +02:00
|
|
|
dword prepare(word x,y;dword text1);
|
|
|
|
void show(word x,y);
|
2015-08-21 13:03:08 +02:00
|
|
|
byte textcenter(word x,y,w,h;dword txt);
|
2015-08-20 17:04:18 +02:00
|
|
|
dword getsize(dword text1);
|
|
|
|
dword textarea(word x,y;dword text,c);
|
|
|
|
byte changeSIZE();
|
2015-08-18 03:45:23 +02:00
|
|
|
void PixelRGB(word x,y);
|
2015-08-21 13:03:08 +02:00
|
|
|
dword GetPixel(word x,y);
|
2015-08-18 03:45:23 +02:00
|
|
|
dword tmp_y,tmp_height,tmp_x;
|
2015-08-19 13:14:15 +02:00
|
|
|
byte no_bg_copy;
|
|
|
|
dword bg_color;
|
2015-08-17 02:16:17 +02:00
|
|
|
};
|
|
|
|
FONT font = 0;
|
2015-08-18 03:45:23 +02:00
|
|
|
|
2015-08-21 13:03:08 +02:00
|
|
|
:dword FONT::GetPixel(word x,y)
|
|
|
|
{
|
|
|
|
dword tmp;
|
|
|
|
tmp = y*size.width*3;
|
|
|
|
tmp += x*3;
|
|
|
|
tmp += buffer;
|
|
|
|
r = DSBYTE[tmp];
|
|
|
|
tmp++;
|
|
|
|
g = DSBYTE[tmp];
|
|
|
|
tmp++;
|
|
|
|
b = DSBYTE[tmp];
|
|
|
|
}
|
2015-08-18 03:45:23 +02:00
|
|
|
:void FONT::PixelRGB(dword x,y)
|
|
|
|
{
|
|
|
|
dword tmp;
|
2015-08-20 17:04:18 +02:00
|
|
|
tmp = y*size.width*3;
|
2015-08-18 03:45:23 +02:00
|
|
|
tmp += x*3;
|
|
|
|
tmp += buffer;
|
|
|
|
|
|
|
|
DSBYTE[tmp] = r;
|
|
|
|
tmp++;
|
|
|
|
DSBYTE[tmp] = g;
|
|
|
|
tmp++;
|
|
|
|
DSBYTE[tmp] = b;
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
:byte FONT::changeSIZE()
|
2015-08-17 18:21:51 +02:00
|
|
|
{
|
|
|
|
dword TMP_DATA;
|
|
|
|
dword ofs;
|
|
|
|
byte s;
|
2015-08-20 17:04:18 +02:00
|
|
|
IF(size.text<9) size.text = 8;
|
2015-08-20 18:37:49 +02:00
|
|
|
s = size.text-8;
|
|
|
|
data = begin;
|
|
|
|
TMP_DATA = data;
|
|
|
|
TMP_DATA +=s*4;
|
|
|
|
ofs = DSDWORD[TMP_DATA];
|
|
|
|
IF(ofs==-1)return false;
|
|
|
|
data += ofs;
|
|
|
|
data += 156;
|
|
|
|
TMP_DATA = data;
|
|
|
|
file_size = DSDWORD[TMP_DATA];
|
|
|
|
TMP_DATA += file_size;
|
|
|
|
TMP_DATA--;
|
|
|
|
height = DSBYTE[TMP_DATA];
|
|
|
|
TMP_DATA--;
|
|
|
|
width = DSBYTE[TMP_DATA];
|
|
|
|
block = math.ceil(height*width/32);
|
|
|
|
return true;
|
2015-08-17 18:21:51 +02:00
|
|
|
}
|
2015-08-18 03:45:23 +02:00
|
|
|
:proc_info Form_SELF_FONTS;
|
2015-08-21 13:03:08 +02:00
|
|
|
:byte FONT::textcenter(word x,y,w,h;dword txt)
|
|
|
|
{
|
|
|
|
getsize(txt);
|
|
|
|
EDX = w/2;
|
|
|
|
ECX = size.width/2;
|
|
|
|
EDX -= ECX;
|
|
|
|
x += EDX;
|
|
|
|
return text(x,y,txt);
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
:dword FONT::getsize(dword text1)
|
2015-08-17 02:16:17 +02:00
|
|
|
{
|
2015-08-20 17:04:18 +02:00
|
|
|
size.height = size.width = 0;
|
|
|
|
size.offset_x = size.offset_y = -1;
|
|
|
|
IF(size.text)IF(!changeSIZE())return 0;
|
2015-08-18 12:43:23 +02:00
|
|
|
WHILE(DSBYTE[text1])
|
|
|
|
{
|
2015-08-20 17:04:18 +02:00
|
|
|
symbol_size(DSBYTE[text1]);
|
2015-08-18 12:43:23 +02:00
|
|
|
text1++;
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
$neg size.offset_y
|
|
|
|
$neg size.offset_x
|
|
|
|
size.height++;
|
|
|
|
size.height += size.offset_y;
|
|
|
|
size.width += size.offset_x;
|
|
|
|
size.width++;
|
2015-08-21 13:03:08 +02:00
|
|
|
IF(italic)
|
|
|
|
{
|
2015-08-21 13:13:10 +02:00
|
|
|
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;
|
2015-08-21 13:03:08 +02:00
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
return size.width;
|
2015-08-18 12:43:23 +02:00
|
|
|
}
|
|
|
|
:byte FONT::symbol_size(byte s)
|
|
|
|
{
|
|
|
|
dword xi,yi;
|
|
|
|
dword tmp,_;
|
|
|
|
dword iii;
|
|
|
|
byte rw=0;
|
2015-08-20 17:04:18 +02:00
|
|
|
byte X;
|
2015-08-20 18:37:49 +02:00
|
|
|
size.TMP_WEIGHT = math.ceil(size.text/17);
|
2015-08-20 17:04:18 +02:00
|
|
|
IF(s==32)
|
|
|
|
{
|
|
|
|
size.width += width/4;
|
2015-08-20 18:37:49 +02:00
|
|
|
IF(weight) size.width+=size.TMP_WEIGHT;
|
2015-08-20 17:04:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
IF(s==9)
|
|
|
|
{
|
|
|
|
size.width += width;
|
2015-08-20 18:37:49 +02:00
|
|
|
IF(weight) size.width+=size.TMP_WEIGHT;
|
2015-08-20 17:04:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-08-21 18:16:45 +02:00
|
|
|
IF(!encoding){
|
|
|
|
IF(s>=128)&&(s<=175)s+=64;
|
|
|
|
ELSE IF(s>=224)&&(s<=239)s+=16;
|
|
|
|
}
|
2015-08-18 12:43:23 +02:00
|
|
|
yi = 0;
|
|
|
|
iii = 0;
|
|
|
|
tmp = 4*block*s;
|
|
|
|
tmp +=data;
|
2015-08-20 17:04:18 +02:00
|
|
|
while(yi<height)
|
2015-08-18 12:43:23 +02:00
|
|
|
{
|
|
|
|
xi = 0;
|
|
|
|
WHILE(xi<width)
|
|
|
|
{
|
|
|
|
IF(iii%32) _ >>= 1;
|
|
|
|
ELSE
|
|
|
|
{
|
|
|
|
tmp += 4;
|
|
|
|
_ = DSDWORD[tmp];
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
IF(_&1)
|
|
|
|
{
|
|
|
|
IF(xi>rw)rw=xi;
|
|
|
|
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;
|
|
|
|
}
|
2015-08-18 12:43:23 +02:00
|
|
|
xi++;
|
|
|
|
iii++;
|
|
|
|
}
|
|
|
|
yi++;
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
size.width += rw;
|
2015-08-20 18:37:49 +02:00
|
|
|
IF(weight) size.width+=size.TMP_WEIGHT;
|
2015-08-20 17:04:18 +02:00
|
|
|
IF(s=='_') size.width--;
|
|
|
|
IF(size.offset_x<0)size.offset_x = X;
|
2015-08-18 12:43:23 +02:00
|
|
|
}
|
2015-08-27 10:33:51 +02:00
|
|
|
:dword FONT::prepare(word x,y;dword text1)
|
2015-08-18 12:43:23 +02:00
|
|
|
{
|
|
|
|
signed len=0;
|
2015-08-20 17:04:18 +02:00
|
|
|
dword c;
|
|
|
|
word _tmp_h;
|
|
|
|
c = color;
|
2015-08-20 18:37:49 +02:00
|
|
|
IF(!text1)return false;
|
|
|
|
IF(size.text)IF(!changeSIZE())return false;
|
2015-08-18 03:45:23 +02:00
|
|
|
GetProcessInfo(#Form_SELF_FONTS, SelfInfo);
|
2015-08-20 18:37:49 +02:00
|
|
|
IF(y>Form_SELF_FONTS.cheight) return false;
|
|
|
|
IF(x>Form_SELF_FONTS.cwidth) return false;
|
2015-08-18 03:45:23 +02:00
|
|
|
AX = c;
|
|
|
|
r = AL;
|
|
|
|
g = AH;
|
|
|
|
c>>=16;
|
|
|
|
AX = c;
|
|
|
|
b = AL;
|
2015-08-20 17:04:18 +02:00
|
|
|
getsize(text1);
|
2015-08-20 18:37:49 +02:00
|
|
|
y -= size.offset_y;
|
|
|
|
tmp_y = y;
|
|
|
|
|
|
|
|
EDX = size.width*size.height*3;
|
2015-08-19 13:14:15 +02:00
|
|
|
IF(!buffer_size)
|
|
|
|
{
|
2015-08-20 18:37:49 +02:00
|
|
|
buffer_size = EDX;
|
2015-08-19 13:14:15 +02:00
|
|
|
buffer = malloc(buffer_size);
|
|
|
|
}
|
2015-08-20 18:37:49 +02:00
|
|
|
ELSE IF(buffer_size<EDX)
|
2015-08-19 13:14:15 +02:00
|
|
|
{
|
2015-08-20 18:37:49 +02:00
|
|
|
buffer_size = EDX;
|
2015-08-19 13:14:15 +02:00
|
|
|
buffer = realloc(buffer,buffer_size);
|
|
|
|
}
|
|
|
|
IF (no_bg_copy)
|
|
|
|
{
|
|
|
|
EBX = bg_color;
|
|
|
|
EDI = buffer;
|
2015-08-20 18:37:49 +02:00
|
|
|
EAX = buffer_size+EDI;
|
2015-08-19 13:14:15 +02:00
|
|
|
WHILE (EDI<EAX)
|
|
|
|
{
|
|
|
|
ESDWORD[EDI] = EBX;
|
|
|
|
$add edi,3
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 17:04:18 +02:00
|
|
|
ELSE CopyScreen(buffer,x+Form_SELF_FONTS.left+5,y+Form_SELF_FONTS.top+GetSkinHeight(),size.width,size.height);
|
2015-08-21 13:03:08 +02:00
|
|
|
len = size.offset_x;
|
2015-08-17 02:16:17 +02:00
|
|
|
WHILE(DSBYTE[text1])
|
|
|
|
{
|
2015-08-20 17:04:18 +02:00
|
|
|
IF(DSBYTE[text1]=='_') len--;
|
2015-08-20 18:37:49 +02:00
|
|
|
len+=symbol(len,DSBYTE[text1]);
|
|
|
|
IF(weight)len+=math.ceil(size.text/17);
|
2015-08-17 02:16:17 +02:00
|
|
|
text1++;
|
|
|
|
}
|
2015-08-22 15:27:12 +02:00
|
|
|
IF (no_bg_copy) && (!color) SmoothFont(buffer, size.width, size.height);
|
2015-08-17 02:16:17 +02:00
|
|
|
return len;
|
|
|
|
}
|
2015-08-27 10:33:51 +02:00
|
|
|
:void FONT::show(word x,y)
|
|
|
|
{
|
|
|
|
_PutImage(x,y,size.width,size.height,buffer);
|
|
|
|
}
|
2015-08-22 15:27:12 +02:00
|
|
|
inline fastcall dword b24(EBX) { return DSDWORD[EBX] << 8; }
|
2015-08-27 10:33:51 +02:00
|
|
|
:void SmoothFont(dword image, w, h)
|
2015-08-22 15:27:12 +02:00
|
|
|
{
|
|
|
|
byte rr,gg,bb;
|
|
|
|
dword i,line_w,to, pixel;
|
|
|
|
line_w = w * 3;
|
2015-08-27 10:33:51 +02:00
|
|
|
to = w*h*3 + image - line_w - 3;
|
|
|
|
for (i = image; i < to; i+=3) {
|
|
|
|
if (i-image%line_w +3 == line_w) continue;
|
2015-08-22 15:27:12 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-17 18:21:51 +02:00
|
|
|
:dword FONT::textarea(word x,y;dword text1,c;byte size)
|
2015-08-17 02:16:17 +02:00
|
|
|
{
|
2015-08-18 03:45:23 +02:00
|
|
|
|
2015-08-17 02:16:17 +02:00
|
|
|
}
|
2015-08-18 12:43:23 +02:00
|
|
|
|
2015-08-20 18:37:49 +02:00
|
|
|
:byte FONT::symbol(signed x;byte s)
|
2015-08-17 02:16:17 +02:00
|
|
|
{
|
2015-08-17 18:21:51 +02:00
|
|
|
dword xi,yi;
|
|
|
|
dword tmp,_;
|
|
|
|
dword iii;
|
2015-08-21 13:03:08 +02:00
|
|
|
float ital = -size.w_italic;
|
2015-08-18 11:13:34 +02:00
|
|
|
dword ___x;
|
2015-08-20 18:37:49 +02:00
|
|
|
word TMP;
|
|
|
|
byte _TMP_WEIGHT;
|
2015-08-17 18:21:51 +02:00
|
|
|
byte rw=0;
|
|
|
|
IF(s==32)return width/4;
|
|
|
|
IF(s==9)return width;
|
2015-08-21 18:16:45 +02:00
|
|
|
IF(!encoding)
|
|
|
|
{
|
|
|
|
IF(s>=128)&&(s<=175)s+=64;
|
|
|
|
ELSE IF(s>=224)&&(s<=239)s+=16;
|
|
|
|
}
|
2015-08-17 18:21:51 +02:00
|
|
|
yi = 0;
|
|
|
|
iii = 0;
|
|
|
|
tmp = 4*block*s;
|
|
|
|
tmp +=data;
|
2015-08-18 11:13:34 +02:00
|
|
|
while(yi<height)
|
2015-08-17 18:21:51 +02:00
|
|
|
{
|
|
|
|
xi = 0;
|
2015-08-20 18:37:49 +02:00
|
|
|
TMP = size.offset_y+yi;
|
2015-08-20 17:04:18 +02:00
|
|
|
while(xi<width)
|
2015-08-17 18:21:51 +02:00
|
|
|
{
|
2015-08-21 13:03:08 +02:00
|
|
|
IF(iii%32) _ >>= 1;
|
|
|
|
ELSE
|
|
|
|
{
|
|
|
|
tmp += 4;
|
|
|
|
_ = DSDWORD[tmp];
|
|
|
|
}
|
|
|
|
if(_&1)
|
|
|
|
{
|
|
|
|
IF(xi>rw)rw=xi;
|
|
|
|
___x = x+xi;
|
|
|
|
IF(italic)___x+=math.ceil(ital);
|
|
|
|
if(___x<Form_SELF_FONTS.cwidth)&&(tmp_y+yi<Form_SELF_FONTS.cheight)
|
|
|
|
{
|
|
|
|
PixelRGB(___x,TMP);
|
|
|
|
_TMP_WEIGHT = size.TMP_WEIGHT;
|
|
|
|
WHILE(_TMP_WEIGHT)
|
2015-08-20 17:04:18 +02:00
|
|
|
{
|
2015-08-21 13:03:08 +02:00
|
|
|
IF(weight) PixelRGB(___x+_TMP_WEIGHT,TMP);
|
|
|
|
_TMP_WEIGHT--;
|
2015-08-20 17:04:18 +02:00
|
|
|
}
|
2015-08-21 13:03:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xi++;
|
|
|
|
iii++;
|
2015-08-17 18:21:51 +02:00
|
|
|
}
|
|
|
|
yi++;
|
2015-08-21 13:03:08 +02:00
|
|
|
IF(italic) ital-=size.offset_i;
|
2015-08-17 18:21:51 +02:00
|
|
|
}
|
|
|
|
return rw;
|
2015-08-17 02:16:17 +02:00
|
|
|
}
|
|
|
|
:byte FONT::load(dword path)
|
|
|
|
{
|
|
|
|
dword tmp;
|
2015-08-19 13:14:15 +02:00
|
|
|
buffer_size = 0;
|
2015-08-17 02:16:17 +02:00
|
|
|
IF(data)free(data);
|
2015-08-22 19:38:33 +02:00
|
|
|
if (!io.readKPACK(path))
|
2015-08-19 13:14:15 +02:00
|
|
|
{
|
|
|
|
debug("Error while loading font: ");
|
|
|
|
debugln(path);
|
2015-08-20 18:37:49 +02:00
|
|
|
return false;
|
2015-08-19 13:14:15 +02:00
|
|
|
}
|
2015-08-21 13:03:08 +02:00
|
|
|
begin = tmp = data = io.buffer_data;
|
2015-08-17 02:16:17 +02:00
|
|
|
size_file = io.FILES_SIZE;
|
|
|
|
tmp +=size_file;
|
|
|
|
tmp--;
|
|
|
|
height = DSBYTE[tmp];
|
|
|
|
tmp--;
|
|
|
|
width = DSBYTE[tmp];
|
|
|
|
block = math.ceil(height*width/32);
|
2015-08-20 18:37:49 +02:00
|
|
|
return true;
|
2015-08-17 02:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|