⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gu_font.c.svn-base

📁 psp播放器PPA源码,在MSYS/CYGWIN环境下编译(GNU-C)
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
}void sbit_cache_done(void){	int i;	for (i = 0; i < SBIT_HASH_SIZE; ++i) {		if(sbit_hash_root[i].bitmap.buffer) {			free(sbit_hash_root[i].bitmap.buffer);		}		if(sbit_hash_root[i].border_bitmap.buffer) {			free(sbit_hash_root[i].border_bitmap.buffer);		}	}}SBit_HashItem* sbit_cache_find(unsigned long ucs_code, int size, int embolden) {	unsigned long hash_value = ucs_code % SBIT_HASH_SIZE;	if ( (sbit_hash_root[hash_value].ucs_code == ucs_code) &&		(sbit_hash_root[hash_value].size == size)  &&		(sbit_hash_root[hash_value].embolden == embolden) )		return (&sbit_hash_root[hash_value]);	else		return 0;}void sbit_cache_add(unsigned long ucs_code, int glyph_index, int size, int embolden,	FT_Bitmap *bitmap, int left, int top, 	FT_Bitmap *border_bitmap, int border_left, int border_top, int xadvance, int yadvance) {	unsigned long hash_value = ucs_code % SBIT_HASH_SIZE;	SBit_HashItem* item = &sbit_hash_root[hash_value];	if ( item->bitmap.buffer ) {		free(item->bitmap.buffer);		item->bitmap.buffer = 0;	}		if ( item->border_bitmap.buffer ) {		free(item->border_bitmap.buffer);		item->border_bitmap.buffer = 0;	}		item->ucs_code = ucs_code;	item->glyph_index = glyph_index;	item->size = size;	item->embolden = embolden;	item->xadvance  = xadvance;	item->yadvance  = yadvance;	item->bitmap.width     = bitmap->width;	item->bitmap.height    = bitmap->rows;	item->bitmap.pitch     = bitmap->pitch;	item->bitmap.left      = left;	item->bitmap.top       = top;	item->bitmap.format    = bitmap->pixel_mode;	item->bitmap.max_grays = (bitmap->num_grays - 1);		item->border_bitmap.width     = border_bitmap->width;	item->border_bitmap.height    = border_bitmap->rows;	item->border_bitmap.pitch     = border_bitmap->pitch;	item->border_bitmap.left      = border_left;	item->border_bitmap.top       = border_top;	item->border_bitmap.format    = border_bitmap->pixel_mode;	item->border_bitmap.max_grays = (border_bitmap->num_grays - 1);		int pitch = bitmap->pitch;	if( pitch < 0 ) pitch = -pitch;	if ( pitch * bitmap->rows > 0) {		item->bitmap.buffer = malloc_64(pitch * bitmap->rows);		memset(item->bitmap.buffer, 0, pitch * bitmap->rows);		memcpy(item->bitmap.buffer, bitmap->buffer, pitch * bitmap->rows);	}	pitch = border_bitmap->pitch;	if( pitch < 0 ) pitch = -pitch;	if ( pitch * border_bitmap->rows > 0) {		item->border_bitmap.buffer = malloc_64(pitch * border_bitmap->rows);		if ( item->border_bitmap.buffer ) {			memset(item->border_bitmap.buffer, 0, pitch * border_bitmap->rows);			memcpy(item->border_bitmap.buffer, border_bitmap->buffer, pitch * border_bitmap->rows);		}	}}char* gu_font_init()	{	if (gu_font_initialized==1) return(0);		FT_Error error;	error = FT_Init_FreeType( &library );              /* initialize library */  	if(error)		return("FT_Init_FreeType failed");		memset(cache_string, 0, 2048);		sbit_cache_init();		font_stream.read =  gufont_font_stream_io;	font_stream.close = gufont_font_stream_close;		open_args.flags = FT_OPEN_STREAM;	open_args.stream = &font_stream;		gu_font_initialized = 1;	return(0);	}	void gu_font_close()	{	if (gu_font_initialized==0) return;		if( stroker )		FT_Stroker_Done(stroker);			if (face)		FT_Done_Face(face);		FT_Done_FreeType(library);	library = 0;	sbit_cache_done();	gu_font_initialized=0;	}	char* gu_font_load( char* name )	{	if (gu_font_initialized==0) return("initialized : fail");	//*/	if ( strcmp(font_filename, name) == 0) {		return(0);	}		//*/	memset(font_filename, 0, 1024);	FT_Error error;		//error = FT_New_Face(library, name, 0, &face);	font_stream.descriptor.value = sceIoOpen(name, PSP_O_RDONLY, 0777);	if ( ! font_stream.descriptor.value )		{		face = NULL;		return("gu_font_load: FT_New_Face failed");		}	font_stream.base = 0;	font_stream.size = sceIoLseek32(font_stream.descriptor.value,0, PSP_SEEK_END);	font_stream.pos = sceIoLseek32(font_stream.descriptor.value,0, PSP_SEEK_SET);	error = FT_Open_Face(library, &open_args, 0, &face);	if(error)		{		face = NULL;		return("gu_font_load: FT_New_Face failed");		}		error = FT_Stroker_New(face->memory, &stroker);	if(error)		{		FT_Done_Face(face);		face = NULL;		return("gu_font_load: FT_Stroker_New failed");		}		strncpy(font_filename, name, 1023);		gu_font_border_enable( 1 );	gu_font_border_set(1.2);	gu_font_pixelsize_set( 16 );	gu_font_color_set( 0xffffffff );	gu_font_border_color_set( 0xff000000 );	return(0);	}void gu_font_on_suspend()	{	sceIoClose(font_stream.descriptor.value);	font_stream.descriptor.value = 0;	}void gu_font_on_resume()	{	font_stream.descriptor.value = sceIoOpen(font_filename, PSP_O_RDONLY, 0777);	sceIoLseek32(font_stream.descriptor.value, font_stream.pos, PSP_SEEK_SET);	}FT_Face gu_font_getface() 	{	return(face);	}void gu_font_pixelsize_set( int size ) 	{		gufont_pixel_size = size;	gufont_char_width = size;	gufont_char_height = size;		FT_Set_Pixel_Sizes(face, gufont_char_width, gufont_char_height);		}void gu_font_scale_set(float asc_scale, float multcode_scale)	{	gufont_asc_scale = asc_scale;	gufont_multcode_scale = multcode_scale;	}void gu_font_border_enable( int enable )	{	//if (face==0) return;	if (gufont_border_enable==enable) return;	gufont_border_enable = enable;	}	void gu_font_border_set(float border)	{	FT_Stroker_Set( stroker,		(int)(64 * border),		FT_STROKER_LINECAP_ROUND,		FT_STROKER_LINEJOIN_ROUND,		0 );	gufont_border_size = border;	}void gu_font_border_color_set( unsigned int color )	{	//if (face==0) return;	gufont_border_color = 0xff000000 | color;	if (gufont_border_enable==0) return;	}	void gu_font_color_set( unsigned int color )	{	//if (face==0) return;	gufont_color = 0xff000000 | color;		}void gu_font_embolden_enable( int enable )	{	if (gufont_embolden_enable == enable) return;	gufont_embolden_enable = enable;	}void gu_font_align_set(unsigned int align) 	{	gufont_align = align;	}unsigned int gu_font_align_get()	{	return gufont_align;	}void gu_font_distance_set(unsigned int distance) 	{	gufont_distance = distance;	}unsigned int gu_font_distance_get()	{	return gufont_distance;	}int gu_font_line_width_get( char* s )	{	if (s==0) return 0;	char* c = s;	int x = 0;	int style = 0;	int lastcharstyle = 0;	while (*c!='\0' && *c!='\n')		{		if (*c==' ')			{			x += CHARWIDTH('t');			}		else if ((unsigned char)*c>32)			{			if (gu_font_parse_bbcode( &c, &style )==0)				{				x += CHARWIDTH2((unsigned char)*c,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;	x+=8;	return (x);	}	int gu_font_width_get( char* s, int flag )	{	if (s==0 ) return 0;	char* c = s;	int x = 0;	int width = 0;	if (flag == 0) flag--;	int style=0;	int lastcharstyle=0;		while (*c!='\0' && flag!=0)		{		if (*c==' ')			{			flag--;			x += CHARWIDTH('t');			}		else if (*c=='\n')			{			if (lastcharstyle!=0) x+=4;			x+=8;			if (x>width) width=x;			x = 0;			}		else if ((unsigned char)*c>32)			{			if (gu_font_parse_bbcode( &c, &style )==0)				{				x += CHARWIDTH2((unsigned char)*c,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;	x+=8;	return (x>width?x:width);	}	int gu_font_utf8_line_width_get( char* s )	{	if (s==0 ) return 0;	char* c = s;	int x = 0;	int style = 0;	int lastcharstyle = 0;	while (*c!='\0' && *c!='\n')		{		if (*c==' ')			{			x += CHARWIDTH('t');			}		else if ((unsigned char)*c>32)			{			if (gu_font_parse_bbcode( &c, &style )==0)				{				unsigned short ucs = get_next_utf8(&c);				x += CHARWIDTH2(ucs,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;	x+=8;	return (x);	}int gu_font_utf8_width_get( char* s, int flag )	{	if (s==0 ) return 0;	char* c = s;	int x = 0;	int width = 0;	if (flag == 0) flag--;	int style=0;	int lastcharstyle = 0;	unsigned char ch;		while ((ch=(unsigned char)*c)!='\0' && flag!=0)		{		if (ch==' ')			{			flag--;			x += CHARWIDTH('t');			}		else if (ch=='\n')			{			if (lastcharstyle!=0) x+=4;			x+=8;			if (x>width) width=x;			x = 0;			}		else if (ch>32)			{			if (gu_font_parse_bbcode( &c, &style )==0)				{				unsigned short ucs = get_next_utf8(&c);				x += CHARWIDTH2(ucs,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;	x+=8;	return (x>width?x:width);	}int gu_font_utf16le_line_width_get( short* s )	{	if (s==0 ) return 0;	short* c = s;	int x = 0;	int style = 0;	int lastcharstyle = 0;	while (*c!=0 && *c!='\n')		{		if (*c==' ')			{			x += CHARWIDTH('t');			}		else if ((unsigned short)*c>32)			{			if (gu_font_utf16le_parse_bbcode( &c, &style )==0)				{				unsigned short ucs = get_next_utf16le(&c);				x += CHARWIDTH2(ucs,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;	x+=8;	return (x);	}	int gu_font_utf16le_width_get( short* s, int flag )	{	if (s==0 ) return 0;	short* c = s;	int x = 0;	int width = 0;	if (flag == 0) flag--;	int style=0;	int lastcharstyle=0;	unsigned short ch;		while ((ch=(unsigned short)*c)!=0 && flag!=0)		{		if (ch==' ')			{			flag--;			x += CHARWIDTH('t');			}		else if (ch=='\n')			{			if (lastcharstyle!=0) x+=4;			x+=8;			if (x>width) width=x;			x = 0;			}		else if (ch>32)			{			if (gu_font_utf16le_parse_bbcode( &c, &style )==0)				{				unsigned short ucs = ch;				x += CHARWIDTH2(ucs,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -