Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1176 andrew_pro 1
/*
2
	menegement of fonts
3
 */
4
 
5
//---------------------------------------------------------------------------------
6
//			destroy font
7
//---------------------------------------------------------------------------------
8
void DestroyFont(font_t *font)
9
{
10
	font_t	*seek_font;
11
	font_t	*exchange_font;
12
	font_t	*last_font;
13
	font_t	*next_font;
14
 
15
	if (font==(font_t*)NULL) return;
16
 
17
	if (FontsMeneger.fnt_bk==FontsMeneger.fnt_fd)
18
	{
19
		//parent have got alone font
20
		if (FontsMeneger.fnt_bk==(DWORD*)font)
21
		{
22
#ifdef	DEBUG
23
			printf("\ndestroyed font %d font name=%s",(int)font,(char*)font->fnt_name);
24
#endif
25
			free(font);
26
			FontsMeneger.fnt_bk=(DWORD*)NULL;
27
			FontsMeneger.fnt_fd=(DWORD*)NULL;
28
		}
29
		return;
30
	}
31
 
32
	seek_font=(font_t*)FontsMeneger.fnt_bk;
33
	while(seek_font!=(font_t*)NULL)
34
	{
35
		if (seek_font==font)
36
		{
37
			//delete font from fonts's cash
38
			last_font=(font_t*)seek_font->fnt_bk;
39
			next_font=(font_t*)seek_font->fnt_fd;
40
 
41
			if ((last_font!=(font_t*)NULL) && (next_font!=(font_t*)NULL))
42
			{//deliting font isn't first font and isn't endest
43
				next_font->fnt_bk=(DWORD*)last_font;
44
				last_font->fnt_fd=(DWORD*)next_font;
45
			}
46
			else
47
			{
48
				if (last_font==(font_t*)NULL)
49
				{//deliting font is first font of Parend
50
					FontsMeneger.fnt_bk=(DWORD*)next_font;
51
					next_font->fnt_bk=(DWORD*)NULL;
52
					if (next_font->fnt_fd==(DWORD*)NULL)
53
					{
54
						FontsMeneger.fnt_fd=(DWORD*)next_font;
55
						FontsMeneger.fnt_bk=(DWORD*)next_font;
56
					}
57
				}
58
 
59
				if (next_font==(font_t*)NULL)
60
				{
61
					//there isn't next fonts
62
					last_font->fnt_fd=(DWORD*)NULL;
63
					FontsMeneger.fnt_fd=(DWORD*)last_font;
64
				}
65
			}
66
#ifdef	DEBUG
67
			printf("\ndestroyed font %d font name=%s",(int)font,(char*)font->fnt_name);
68
#endif
69
			free(font);
70
			break;
71
		}
72
		exchange_font=(font_t*)seek_font->fnt_fd;
73
		seek_font=exchange_font;
74
	}
75
}
76
 
77
void	*CreateFont(void)
78
{
79
	font_t	*font;
80
	font_t	*backward_font;
81
 
82
	font=malloc(sizeof(struct FONT));
83
 
84
	if (FontsMeneger.fnt_bk==(DWORD*)NULL)
85
	{//not yet fonts
86
		FontsMeneger.fnt_bk=(DWORD*)font;
87
		FontsMeneger.fnt_fd=(DWORD*)font;
88
		font->fnt_bk=(DWORD*)NULL;
89
		font->fnt_fd=(DWORD*)NULL;
90
	}
91
	else
92
	{
93
		backward_font=(font_t*)FontsMeneger.fnt_fd;
94
		FontsMeneger.fnt_fd=(DWORD*)font;
95
		backward_font->fnt_fd=(DWORD*)font;
96
		font->fnt_bk=(DWORD*)backward_font;
97
		font->fnt_fd=(DWORD*)NULL;
98
	}
99
	return(font);
100
}
101
////////////////////////////////////////////////////////////////////////////////
102
//			CHAR.MT and CHAR2.MT fonts unpacker
103
////////////////////////////////////////////////////////////////////////////////
104
void	CHAR_MT_FontsUnpacker(unsigned char *loaded_font,font_t *font,char font_type)
105
{
106
	int		i,j,k;
107
	unsigned char	c;
108
	unsigned char	*p;
109
 
110
	if (font_type==FALSE)
111
	{//CHAR.MT
112
		font->font=malloc(6*9*256);
113
		p=(unsigned char*)font->font;
114
 
115
		for(j=0;j<256;j++)
116
		{
117
			for(i=0;i<9;i++)
118
			{
119
				c=(unsigned char)(*loaded_font);
120
				p[5]=(unsigned char)(c & 0x20);
121
				p[4]=(unsigned char)(c & 0x10);
122
				p[3]=(unsigned char)(c & 0x8);
123
				p[2]=(unsigned char)(c & 0x4);
124
				p[1]=(unsigned char)(c & 0x2);
125
				p[0]=(unsigned char)(c & 0x1);
126
 
127
				p+=6;
128
				loaded_font++;
129
			}
130
		}
131
		font->sizex=6;
132
		font->sizey=9;
133
	}
134
	else
135
	{//CHAR2.MT
136
		font->font=malloc(8*10*256);
137
		p=(unsigned char*)font->font;
138
 
139
		for(j=0;j<256;j++)
140
		{
141
			for(i=0;i<10;i++)
142
			{
143
				c=(unsigned char)(*loaded_font);
144
				p[7]=(unsigned char)(c & 0x80);
145
				p[6]=(unsigned char)(c & 0x40);
146
				p[5]=(unsigned char)(c & 0x20);
147
				p[4]=(unsigned char)(c & 0x10);
148
				p[3]=(unsigned char)(c & 0x8);
149
				p[2]=(unsigned char)(c & 0x4);
150
				p[1]=(unsigned char)(c & 0x2);
151
				p[0]=(unsigned char)(c & 0x1);
152
 
153
				p+=8;
154
				loaded_font++;
155
			}
156
		}
157
		font->sizex=8;
158
		font->sizey=10;
159
	}
160
 
161
	font->size=FONT_CONSTANT_SIZE;
162
	font->type=FONT_TYPE_ASCII;
163
	font->encoding_type=FONT_ENCODING_CYRILLIC_IBM866;
164
}
165
 
166
////////////////////////////////////////////////////////////////////////////////
167
//			CHAR.MT and CHAR2.MT fonts draw
168
////////////////////////////////////////////////////////////////////////////////
169
void	MonofontDraw(finition_t *fin,int fx,int fy,
170
				DWORD color,DWORD background_color,
171
				font_t *font,unsigned char *s)
172
{
173
	unsigned int		i,j,k,step,len;
174
	int		x,y,size_x,save_size_x,save_size_y;
175
	unsigned char	*p,*buf,*save_buf;
176
	unsigned char	c;
177
	DWORD		draw_output;
178
 
179
	step=font->sizex*font->sizey;
180
	len=strlen(s);
181
 
182
	if (font->flags & FONT_FLAG_ORIENTATION_HORIZONTAL_FROM_LEFT_TO_RIGHT_ON)
183
	{
184
		if (font->flags & FONT_FLAG_DRAW_BACKGROUND_ON)
185
		{//there is a fon and not finition for draw
186
			//alocate a buffer for draw text
187
			size_x=font->sizex*len;
188
 
189
			c=screen.bits_per_pixel >> 3;
190
			i=step*c*len;
191
			buf=malloc(i);
192
 
193
			//save current screen parameters
194
			save_buf=screen.buffer;
195
			save_size_x=screen.size_x;
196
			save_size_y=screen.size_y;
197
			draw_output=screen.draw_output;
198
 
199
			//load parameters of local buffer
200
			screen.buffer=buf;
201
			screen.size_x=size_x;
202
			screen.size_y=font->sizey;
203
			screen.draw_output=DRAW_OUTPUT_BUFFER;
204
 
205
			//fill buffer by background color
206
			FillArrea(buf,i,screen.bits_per_pixel,background_color);
207
 
208
			//draw text
209
			x=0;
210
			for(k=0;k
211
			{
212
				c=s[k];
213
				p=font->font+step*c;
214
				for(j=0;jsizey;j++)
215
				{
216
 
217
					for(i=0;isizex;i++)
218
					{
219
						if (*p) DrawPixel(x+i,j,color);
220
						p++;
221
					}
222
				}
223
				x=x+font->sizex;
224
			}
225
 
226
			//restore screen parameters
227
			screen.buffer=save_buf;
228
			screen.size_x=save_size_x;
229
			screen.size_y=save_size_y;
230
			screen.draw_output=draw_output;
231
 
232
			//move text from local buffer to screen
233
			if (fin->flags & FINITION_ON)
234
				DrawImageFinit(fin,fx,fy,size_x,font->sizey,screen.bits_per_pixel,buf);
235
			else
236
				DrawImage(fx,fy,size_x,font->sizey,screen.bits_per_pixel,buf);
237
 
238
			//free local buffer
239
			free(buf);
240
		}
241
		else
242
		{
243
			if (fin->flags & FINITION_ON)
244
			{//not background and finition for draw
245
				x=fx;
246
				y=fy;
247
				for(k=0;k
248
				{
249
					c=s[k];
250
					p=font->font+step*c;
251
					for(j=0;jsizey;j++)
252
					{
253
 
254
						for(i=0;isizex;i++)
255
						{
256
							if (*p) DrawPixelFinit(fin,x+i,y+j,color);
257
							p++;
258
						}
259
					}
260
					x=x+font->sizex;
261
				}
262
			}
263
			else
264
			{//not background and not finition for draw
265
				x=fx;
266
				y=fy;
267
				for(k=0;k
268
				{
269
					c=s[k];
270
					p=font->font+step*c;
271
					for(j=0;jsizey;j++)
272
					{
273
 
274
						for(i=0;isizex;i++)
275
						{
276
							if (*p) DrawPixel(x+i,y+j,color);
277
							p++;
278
						}
279
					}
280
					x=x+font->sizex;
281
				}
282
			}
283
 
284
		}
285
	}
286
}
287
 
288
////////////////////////////////////////////////////////////////////////////////
289
//				fonts loader
290
////////////////////////////////////////////////////////////////////////////////
291
font_t	*LoadFont(char *fullfontname)
292
{
293
	char		*path;
294
	char		*c;
295
	BYTE		*buf;
296
	long		filesize;
297
	int		len1,len2,i;
298
	font_t		*font;
299
	static DWORD	buf_for_size[2];
300
	static DWORD	buf_for_pos[2];
301
 
302
	path=malloc(263);
303
	if (strchr(fullfontname,'/')==NULL)
304
	{
305
		len1=strlen(default_fonts_path);
306
		len2=strlen(fullfontname);
307
		memmove(path,default_fonts_path,len1);
308
		memmove(path+len1,fullfontname,len2);
309
		*(path+len1+len2)='\0';
310
	}
311
	else
312
		memmove(path,fullfontname,strlen(fullfontname));
313
 
314
	if (gui_get_file_size(path,buf_for_size)==KOLIBRIOS_SYS_FILE_ACCESS_SUCCESSFULLY)
315
	{
316
		filesize=buf_for_size[0];
317
		buf=malloc(filesize);
318
		//load fonts in buffer
319
		gui_read_file(path,buf_for_pos,filesize,buf);
320
 
321
		free(path);
322
		//register font
323
		font=CreateFont();
324
		c=strrchr(fullfontname,'/');
325
		if(c==NULL)	font->fnt_name=fullfontname;
326
			else
327
				font->fnt_name=(char*)(c+1);
328
 
329
		//check font type
330
		c=strstr(font->fnt_name,"CHAR.MT");//check standart type of fonts
331
		if (c!=NULL)
332
		{
333
			font->fnt_unpacker=(DWORD*)&CHAR_MT_FontsUnpacker;
334
			font->fnt_draw=(DWORD*)&MonofontDraw;
335
			CHAR_MT_FontsUnpacker(buf,font,FALSE);//CHAR.MT
336
			free(buf);
337
			font->flags=0;
338
			font->flags|=FONT_FLAG_ORIENTATION_HORIZONTAL_FROM_LEFT_TO_RIGHT_ON;
339
		}
340
 
341
		c=strstr(font->fnt_name,"CHAR2.MT");//check standart type of fonts
342
		if (c!=NULL)
343
		{
344
			font->fnt_unpacker=(DWORD*)&CHAR_MT_FontsUnpacker;
345
			font->fnt_draw=(DWORD*)&MonofontDraw;
346
			CHAR_MT_FontsUnpacker(buf,font,TRUE);//CHAR2.MT
347
			free(buf);
348
			font->flags=0;
349
			font->flags|=FONT_FLAG_ORIENTATION_HORIZONTAL_FROM_LEFT_TO_RIGHT_ON;
350
		}
351
		//not other fonts yet
352
 
353
	}
354
	else
355
	{
356
#ifdef	DEBUG
357
		printf("\ncannot load font %s",path);
358
#endif
359
		free(path);
360
		return(NULL);
361
	}
362
 
363
	FontsMeneger.number_fonts++;
364
	return(font);
365
}
366
 
367
void	FreeFont(font_t *font)
368
{
369
	if (font==(font_t*)FontsMeneger.default_font)	return;
370
 
371
	free(font->font);
372
	DestroyFont(font);
373
}