Subversion Repositories Kolibri OS

Rev

Rev 7160 | Rev 7769 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7160 Rev 7286
Line 11... Line 11...
11
 
11
 
12
// Конец:
12
// Конец:
Line 13... Line 13...
13
// [Название шрифта:"Times New Roman"]
13
// [Название шрифта:"Times New Roman"]
14
 
14
 
Line 15... Line 15...
15
 
15
 
16
#ifndef INCLUDE_LABEL_H
16
#ifndef INCLUDE_KFONT_H
17
#define INCLUDE_LABEL_H
17
#define INCLUDE_KFONT_H
Line 31... Line 31...
31
 
31
 
32
#ifndef KFONT_BPP
32
#ifndef KFONT_BPP
33
#define KFONT_BPP 4
33
#define KFONT_BPP 4
Line -... Line 34...
-
 
34
#endif
-
 
35
 
34
#endif
36
int kfont_char_width[255];
35
 
37
 
36
:struct __SIZE
38
:struct __SIZE
37
{
39
{
38
	dword width,height;
40
	dword width,height;
39
	signed offset_x, offset_y;
41
	signed offset_x, offset_y;
40
	byte pt;
42
	byte pt;
41
};
43
};
42
:struct LABEL
44
:struct KFONT
43
{
45
{
44
	__SIZE size;
46
	__SIZE size;
45
	int width,height;
47
	int width,height;
46
	byte bold,smooth;
48
	byte bold,smooth;
47
	dword color, background;
49
	dword color, background;
48
	dword font,font_begin;
50
	dword font,font_begin;
49
	word block;
51
	word block;
50
	dword raw;
-
 
Line 51... Line 52...
51
	dword raw_size;
52
	dword raw;
52
	//dword palette[256];
53
	dword raw_size;
53
 
54
 
54
	bool init();
55
	bool init();
55
	bool changeSIZE();
56
	bool changeSIZE();
-
 
57
	byte symbol();
Line 56... Line 58...
56
	byte symbol();
58
	byte symbol_size();
57
	byte symbol_size();
59
	dword getsize();
58
	dword getsize();
60
	int get_label_width();
59
 
61
 
60
	void ApplySmooth();
62
	void ApplySmooth();
61
	int WriteIntoWindow();
63
	int WriteIntoWindow();
62
	int WriteIntoWindowCenter();
64
	int WriteIntoWindowCenter();
Line 63... Line 65...
63
	void WriteIntoBuffer();
65
	void WriteIntoBuffer();
64
	void ShowBuffer();
66
	void ShowBuffer();
65
	void ShowBufferPart();
67
	void ShowBufferPart();
66
} kfont;
68
} kfont;
67
 
69
 
68
:bool LABEL::init(dword font_path)
70
:bool KFONT::init(dword font_path)
Line 79... Line 81...
79
	changeSIZE();
81
	changeSIZE();
80
	smooth = true;
82
	smooth = true;
81
	return true;
83
	return true;
82
}
84
}
Line 83... Line 85...
83
 
85
 
84
:bool LABEL::changeSIZE()
86
:bool KFONT::changeSIZE()
-
 
87
{
85
{
88
	int i;
86
	dword file_size;
89
	dword file_size;
87
	dword ofs;
90
	dword ofs;
88
	if(size.pt<9) size.pt = 9;
91
	if(size.pt<9) size.pt = 9;
89
	font = font_begin;
92
	font = font_begin;
Line 92... Line 95...
92
	font += ofs + 156;
95
	font += ofs + 156;
93
	file_size = DSDWORD[calc(font)];
96
	file_size = DSDWORD[calc(font)];
94
	height = DSBYTE[calc(font+file_size) - 1];
97
	height = DSBYTE[calc(font+file_size) - 1];
95
	width =  DSBYTE[calc(font+file_size) - 2];
98
	width =  DSBYTE[calc(font+file_size) - 2];
96
	block = math.ceil(height*width/32);
99
	block = math.ceil(height*width/32);
-
 
100
	for (i=0; i<256; i++) {
-
 
101
		kfont_char_width[i] = symbol_size((byte) i);
-
 
102
	}
97
	return true;
103
	return true;
98
}
104
}
Line 99... Line 105...
99
 
105
 
100
:dword LABEL::getsize(byte fontSizePoints, dword text1)
106
:dword KFONT::getsize(byte fontSizePoints, dword text1)
101
{
107
{
102
	size.height = size.width = 0;
108
	size.height = size.width = 0;
-
 
109
	size.offset_x = size.offset_y = -1;
103
	size.offset_x = size.offset_y = -1;
110
	if (size.pt != fontSizePoints) {
104
	size.pt = fontSizePoints;
111
		size.pt = fontSizePoints;
-
 
112
		if(!changeSIZE())return 0;
105
	if(size.pt)if(!changeSIZE())return 0;
113
	}
106
	WHILE(DSBYTE[text1])
114
	WHILE(DSBYTE[text1])
107
	{
115
	{
108
		size.width += symbol_size(DSBYTE[text1]);
116
		size.width += symbol_size(DSBYTE[text1]);
109
		text1++;
117
		text1++;
Line 113... Line 121...
113
	size.height += size.offset_y+1;
121
	size.height += size.offset_y+1;
114
	size.width += size.offset_x+1;
122
	size.width += size.offset_x+1;
115
	return size.width;
123
	return size.width;
116
}
124
}
Line -... Line 125...
-
 
125
 
-
 
126
//WILL NOT WORK if requested fontSizePoints 
-
 
127
//is differ from precalculated kfont_char_width[]
-
 
128
:int KFONT::get_label_width(dword _label) 
-
 
129
{
-
 
130
	int len=0;
-
 
131
	while (ESBYTE[_label]) {
-
 
132
		len += kfont_char_width[ ESBYTE[_label] ];
-
 
133
		_label++;
-
 
134
	}
-
 
135
	return len;
-
 
136
}
117
 
137
 
118
:byte LABEL::symbol_size(byte s)
138
:byte KFONT::symbol_size(byte s)
119
{
139
{
120
	int chaw_width;
140
	int chaw_width;
121
	chaw_width = symbol(0,0, s, 0);
141
	chaw_width = symbol(0,0, s, 0);
122
	if(bold) chaw_width += math.ceil(size.pt/17);
142
	if(bold) chaw_width += math.ceil(size.pt/17);
123
	return chaw_width;
143
	return chaw_width;
Line 124... Line 144...
124
}
144
}
125
 
145
 
126
:byte LABEL::symbol(signed x,y; byte s; dword image_raw)
146
:byte KFONT::symbol(signed x,y; byte s; dword image_raw)
127
{
147
{
128
	dword xi,yi;
148
	dword xi,yi;
129
	dword iii = 0;
149
	dword iii = 0;
Line 188... Line 208...
188
===========================               RAW               ===========================
208
===========================               RAW               ===========================
189
===========================                                 ===========================
209
===========================                                 ===========================
190
=====================================================================================*/
210
=====================================================================================*/
Line 191... Line 211...
191
 
211
 
192
inline fastcall dword b32(EAX) { return DSDWORD[EAX]; }
212
inline fastcall dword b32(EAX) { return DSDWORD[EAX]; }
193
:void LABEL::ApplySmooth()
213
:void KFONT::ApplySmooth()
194
{
214
{
195
	dword i,line_w,to,dark_background;
215
	dword i,line_w,to,dark_background;
196
	line_w = size.width * KFONT_BPP;
216
	line_w = size.width * KFONT_BPP;
197
	to = size.height - 1 * line_w + raw - KFONT_BPP;
217
	to = size.height - 1 * line_w + raw - KFONT_BPP;
Line 220... Line 240...
220
			DSDWORD[i+KFONT_BPP+line_w] = dark_background;	
240
			DSDWORD[i+KFONT_BPP+line_w] = dark_background;	
221
		}
241
		}
222
	}
242
	}
223
}
243
}
Line 224... Line 244...
224
 
244
 
225
:void LABEL::WriteIntoBuffer(int x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1)
245
:void KFONT::WriteIntoBuffer(int x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1)
226
{
246
{
227
	dword new_raw_size;
247
	dword new_raw_size;
228
	if(!text1)return;
-
 
Line 229... Line 248...
229
	if(size.pt)if(!changeSIZE())return;
248
	if(!text1)return;
230
	
249
	
231
	if (size.pt != fontSizePoints) {
250
	if (size.pt != fontSizePoints) {
232
		getsize(fontSizePoints, text1);
251
		getsize(fontSizePoints, text1);
Line 256... Line 275...
256
		text1++;
275
		text1++;
257
	}
276
	}
258
	return;
277
	return;
259
}
278
}
Line 260... Line 279...
260
 
279
 
261
:int LABEL::WriteIntoWindow(int x,y; dword _background, _color; byte fontSizePoints; dword text1)
280
:int KFONT::WriteIntoWindow(int x,y; dword _background, _color; byte fontSizePoints; dword text1)
262
{
281
{
263
	if(!text1)return 0;
282
	if(!text1)return 0;
264
	getsize(fontSizePoints, text1);
283
	getsize(fontSizePoints, text1);
265
	raw_size = NULL;
284
	raw_size = NULL;
Line 268... Line 287...
268
	if (smooth) ApplySmooth();
287
	if (smooth) ApplySmooth();
269
	ShowBuffer(x,y);
288
	ShowBuffer(x,y);
270
	return size.offset_x + size.width;
289
	return size.offset_x + size.width;
271
}
290
}
Line 272... Line 291...
272
 
291
 
273
:int LABEL::WriteIntoWindowCenter(dword x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1)
292
:int KFONT::WriteIntoWindowCenter(dword x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1)
274
{
293
{
275
	getsize(fontSizePoints, text1);
294
	getsize(fontSizePoints, text1);
276
	return WriteIntoWindow(w-size.width/2+x-1,y, _background, _color, fontSizePoints, text1);
295
	return WriteIntoWindow(w-size.width/2+x-1,y, _background, _color, fontSizePoints, text1);
Line 277... Line 296...
277
}
296
}
278
 
297
 
279
:void LABEL::ShowBuffer(dword _x, _y)
298
:void KFONT::ShowBuffer(dword _x, _y)
280
{
299
{
281
	if (4==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 32, 0);
300
	if (4==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 32, 0);
Line 282... Line 301...
282
	//if (1==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 8, #palette);
301
	//if (1==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 8, #palette);
283
}
302
}
284
 
303
 
285
:void LABEL::ShowBufferPart(dword _x, _y, _w, _h, _buf_offset)
304
:void KFONT::ShowBufferPart(dword _x, _y, _w, _h, _buf_offset)
286
{
305
{