Subversion Repositories Kolibri OS

Rev

Rev 5730 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5730 Rev 5736
1
#ifndef INCLUDE_FONT_H
1
#ifndef INCLUDE_FONT_H
2
#define INCLUDE_FONT_H
2
#define INCLUDE_FONT_H
3
 
3
 
4
#ifndef INCLUDE_MATH_H
4
#ifndef INCLUDE_MATH_H
5
#include "../lib/math.h"
5
#include "../lib/math.h"
6
#endif
6
#endif
7
 
7
 
8
#ifndef INCLUDE_IO_H
8
#ifndef INCLUDE_IO_H
9
#include "../lib/io.h"
9
#include "../lib/io.h"
10
#endif
10
#endif
11
 
11
 
12
:struct FONT
12
:struct FONT
13
{
13
{
14
	byte width,height,offsetLine;
14
	byte width,height,offsetLine;
-
 
15
	dword file_size;
15
	word block;
16
	word block;
16
	dword data;
17
	dword data;
-
 
18
	dword begin;
17
	dword size_file;
19
	dword size_file;
18
	byte load(...);
20
	byte load(...);
19
	byte symbol(word x,y;byte s;dword c);
21
	byte symbol(word x,y;byte s;dword c);
20
	dword text(word x,y;dword text,c);
22
	dword text(word x,y;dword text,c;byte size);
21
	dword textarea(word x,y;dword text,c);
23
	dword textarea(word x,y;dword text,c;byte size);
-
 
24
	byte changeSIZE(byte size);
22
};
25
};
23
FONT font = 0;
26
FONT font = 0;
-
 
27
:byte FONT::changeSIZE(byte size)
-
 
28
{
-
 
29
	dword TMP_DATA;
-
 
30
	dword ofs;
-
 
31
	byte s;
-
 
32
	IF(size<9) size = 8;
-
 
33
	IF(size>45)size = 45;
-
 
34
		s = size-8;
-
 
35
		data = begin;
-
 
36
		TMP_DATA = data;
-
 
37
		TMP_DATA +=s*4;
-
 
38
		ofs = DSDWORD[TMP_DATA];
-
 
39
		IF(ofs==-1)return false;
-
 
40
		data += ofs;
-
 
41
		data += 156;
-
 
42
		TMP_DATA = data;
-
 
43
		file_size = DSDWORD[TMP_DATA];
-
 
44
		TMP_DATA += file_size;
-
 
45
		TMP_DATA--;
-
 
46
		height = DSBYTE[TMP_DATA];
-
 
47
		TMP_DATA--;
-
 
48
		width =  DSBYTE[TMP_DATA];
-
 
49
		block = math.ceil(height*width/32);
-
 
50
		return true;
-
 
51
}
24
:dword FONT::text(word x,y;dword text1,c)
52
:dword FONT::text(word x,y;dword text1,c;byte size)
25
{
53
{
26
	dword len=0;
54
	dword len=0;
-
 
55
	if(size)if(!changeSIZE(size))return 0;
-
 
56
	
27
	WHILE(DSBYTE[text1])
57
	WHILE(DSBYTE[text1])
28
	{
58
	{
29
		len += symbol(x+len,y,DSBYTE[text1],c);
59
		len += symbol(x+len,y,DSBYTE[text1],c);
30
		text1++;
60
		text1++;
31
	}
61
	}
32
	return len;
62
	return len;
33
}
63
}
34
:dword FONT::textarea(word x,y;dword text1,c)
64
:dword FONT::textarea(word x,y;dword text1,c;byte size)
35
{
65
{
36
	dword len=0;
66
	dword len=0;
-
 
67
	if(size)if(!changeSIZE(size))return 0;
37
	WHILE(DSBYTE[text1])
68
	WHILE(DSBYTE[text1])
38
	{
69
	{
39
		IF(DSBYTE[text1]=='\r'){ y+=height; len=0;}
70
		IF(DSBYTE[text1]=='\r'){ y+=height; len=0;}
40
		ELSE	len += symbol(x+len,y,DSBYTE[text1],c);
71
		ELSE	len += symbol(x+len,y,DSBYTE[text1],c);
41
		text1++;
72
		text1++;
42
	}
73
	}
43
	return len;
74
	return len;
44
}
75
}
45
:byte FONT::symbol(signed x,y;byte s;dword c)
76
:byte FONT::symbol(signed x,y;byte s;dword c)
46
{
77
{
47
	dword xi,yi;
78
        dword xi,yi;
48
	dword tmp,_;
79
        dword tmp,_;
49
	dword iii;
80
        dword iii;
50
	byte rw=0;
81
        byte rw=0;
51
	IF(offsetLine)y+=offsetLine;
82
        IF(offsetLine)y+=offsetLine;
52
	IF(s==32)return width/4;
83
        IF(s==32)return width/4;
-
 
84
		IF(s==9)return width;
53
	yi = 0;
85
        yi = 0;
54
	iii = 0;
86
        iii = 0;
55
	tmp = 4*block*s;
87
        tmp = 4*block*s;
56
	tmp +=data;
88
        tmp +=data;
57
	while(yi
89
        while(yi
58
	{
90
        {
59
		xi = 0;
91
                xi = 0;
60
		WHILE(xi
92
                WHILE(xi
61
		{
93
                {
62
			IF(!(iii%32))
94
                        IF(!(iii%32))
63
			{
95
                        {
64
				tmp += 4;
96
                                tmp += 4;
65
				_ = DSDWORD[tmp];
97
                                _ = DSDWORD[tmp];
66
			}
98
                        }
67
			ELSE _ >>= 1;
99
                        ELSE _ >>= 1;
68
			IF(_&1)
100
                        IF(_&1)
69
			{
101
                        {
70
				IF(xi>rw)rw=xi;
102
                                IF(xi>rw)rw=xi;
71
				PutPixel(x+xi,y+yi,c);
103
                                PutPixel(x+xi,y+yi,c);
72
			}
104
                        }
73
			xi++;
105
                        xi++;
74
			iii++;
106
                        iii++;
75
		}
107
                }
76
		yi++;
108
                yi++;
77
	}
109
        }
78
	return rw;
110
        return rw;
79
}
111
}
80
:byte FONT::load(dword path)
112
:byte FONT::load(dword path)
81
{
113
{
82
	dword tmp;
114
	dword tmp;
83
	IF(data)free(data);
115
	IF(data)free(data);
84
	tmp = io.read(path);
116
	tmp = io.read(path);
85
	data = tmp;
117
	data = tmp;
-
 
118
	begin = data;
86
	size_file = io.FILES_SIZE;
119
	size_file = io.FILES_SIZE;
87
	tmp +=size_file;
120
	tmp +=size_file;
88
	tmp--;
121
	tmp--;
89
	height = DSBYTE[tmp];
122
	height = DSBYTE[tmp];
90
	tmp--;
123
	tmp--;
91
	width = DSBYTE[tmp];
124
	width = DSBYTE[tmp];
92
	block = math.ceil(height*width/32);
125
	block = math.ceil(height*width/32);
93
}
126
}
94
 
127
 
95
#endif
128
#endif
96
>
129
>
97
>
130
>