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

📄 gu_font.c.svn-base

📁 psp播放器PPA源码,在MSYS/CYGWIN环境下编译(GNU-C)
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
	x+=8;	return (x>width?x:width);	}int gu_font_utf16be_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 && SWAPBYTES(*c)!='\n')		{		if (SWAPBYTES(*c)==' ')			{			x += CHARWIDTH('t');			}		else if ((unsigned short)SWAPBYTES(*c)>32)			{			if (gu_font_utf16be_parse_bbcode( &c, &style )==0)				{				unsigned short ucs = get_next_utf16be(&c);				x += CHARWIDTH2(ucs,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;	x+=8;	return (x);	}int gu_font_utf16be_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)SWAPBYTES((*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_utf16be_parse_bbcode( &c, &style )==0)				{				unsigned short ucs = ch;				x += CHARWIDTH2(ucs,style);				lastcharstyle = style;				}			}		c++;		}	if (lastcharstyle!=0) x+=4;	x+=8;	return (x>width?x:width);	}int gu_font_height_get( char* s )	{	if (s == 0 ) return 0;	char* c = s;	int height = gufont_char_height;//FONTHEIGHT;		while (*c!='\0')		{		if (*c=='\n')			{			height += gufont_char_height;//FONTHEIGHT;			}		c++;		}	return (height);	}int gu_font_utf16be_height_get( short* s )	{	if (s == 0 ) return 0;	short* c = s;	int height = gufont_char_height;//FONTHEIGHT;		while (*c!=0)		{		if (*c=='\n')			{			height += gufont_char_height;//FONTHEIGHT;			}		c++;		}	return (height);	}int gu_font_utf16le_height_get( short* s )	{	if (s == 0 ) return 0;	short* c = s;	int height = gufont_char_height;//FONTHEIGHT;		while (*c!=0)		{		if ((*c>>8)=='\n')			{			height += gufont_char_height;//FONTHEIGHT;			}		c++;		}	return (height);	}inline int gu_font_height()	{	return gufont_char_height;//FONTHEIGHT;	}void render_string(int x, int y, char* s, int flags){		int (*gu_font_line_width)( char* );	int (*gu_font_width)( char* s, int flag );		if (IsSet(flags,FLAG_UTF8)) {		gu_font_line_width = gu_font_utf8_line_width_get;		gu_font_width = gu_font_utf8_width_get;	}	else {		gu_font_line_width = gu_font_line_width_get;		gu_font_width = gu_font_width_get;	}		int max_width = gu_font_width( s, 0 );		int x_x, y_y;		if (IsSet(flags,FLAG_ALIGN_CENTER)){		x_x = x + ((max_width-gu_font_line_width( s ))/2);	}	else if (IsSet(flags,FLAG_ALIGN_RIGHT)){		x_x = x + (max_width-gu_font_line_width( s ));	}	else		x_x = x;		y_y = y;		int width = SUB_SCREEN_WIDTH;	int height = SUB_SCREEN_HEIGHT;		int style = 0;		FT_Error error;	FT_GlyphSlot slot;	FT_UInt glyph_index;		FT_Bool use_kerning; 	FT_UInt previous; 		use_kerning = FT_HAS_KERNING( gu_font_getface() ); 	previous = 0;	//*/	while (*s!='\0') {		if (*s=='\n') {			if (IsSet(flags,FLAG_ALIGN_CENTER)){				x_x = x + ((max_width-gu_font_line_width( &s[1] ))/2);			}			else if (IsSet(flags,FLAG_ALIGN_RIGHT)){				x_x = x + (max_width-gu_font_line_width( &s[1] ));			}			else				x_x = x;			y_y += gufont_char_height + 2;			previous = 0;		}		else if ((unsigned char)*s>=32) {			if (gu_font_parse_bbcode( &s, &style )==0) {				unsigned short ucs;				if (IsSet(flags,FLAG_UTF8)){					ucs = get_next_utf8(&s);					}				else{					ucs = *s;				}				//*/				SBit_HashItem* cache_item =  sbit_cache_find(ucs, gufont_pixel_size, gufont_embolden_enable);				if ( cache_item ) {					if ( use_kerning && previous && cache_item->glyph_index ) { 						FT_Vector delta; 						FT_Get_Kerning( gu_font_getface(), previous, cache_item->glyph_index, FT_KERNING_DEFAULT, &delta ); 						x_x += delta.x >> 6; 					}					draw_cachedbitmap(sub_8888, &cache_item->bitmap, x_x + cache_item->bitmap.left,						y_y - cache_item->bitmap.top, width,						height, gufont_color);					draw_cachedbitmap(border_sub_8888, &cache_item->border_bitmap, x_x + cache_item->border_bitmap.left,						y_y - cache_item->border_bitmap.top, width,						height, gufont_border_color);												x_x += cache_item->xadvance >> 6;					previous = cache_item->glyph_index;					//x_x += DIVWIDTH;					//y_y += cache_item->yadvance >> 6;				}				else { 					FT_Int glyph_index = FT_Get_Char_Index( gu_font_getface(), ucs);					error = FT_Load_Glyph( gu_font_getface(), glyph_index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP );					if (error)						goto render_next;					FT_Glyph glyph;					error = FT_Get_Glyph(gu_font_getface()->glyph, &glyph);					if (error)						goto render_next;					error = FT_Glyph_Stroke( &glyph, stroker, 1 );					if (error) {						FT_Done_Glyph(glyph);						goto render_next;					}					error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1);					if (error) {						FT_Done_Glyph(glyph);						goto render_next;					}					error = FT_Render_Glyph(gu_font_getface()->glyph, FT_RENDER_MODE_NORMAL);					if (error) {						FT_Done_Glyph(glyph);						goto render_next;					}					slot = gu_font_getface()->glyph;										if ( gufont_embolden_enable )						FT_GlyphSlot_Embolden(slot);										if ( use_kerning && previous && glyph_index ) { 						FT_Vector delta; 						FT_Get_Kerning( gu_font_getface(), previous, glyph_index, FT_KERNING_DEFAULT, &delta ); 						x_x += delta.x >> 6; 					}										FT_BitmapGlyph bit = (FT_BitmapGlyph)glyph;					draw_bitmap(sub_8888, &slot->bitmap, x_x + slot->bitmap_left,						y_y - slot->bitmap_top, width,						height, gufont_color);					draw_bitmap(border_sub_8888, &bit->bitmap, x_x + bit->left,						y_y - bit->top, width,						height, gufont_border_color);															x_x += slot->advance.x >> 6;					previous = glyph_index;					//x_x += DIVWIDTH;					//y_y += slot->advance.y >> 6;					sbit_cache_add(ucs, glyph_index, gufont_pixel_size, gufont_embolden_enable, 						&slot->bitmap, slot->bitmap_left, slot->bitmap_top,  						&bit->bitmap, bit->left, bit->top, slot->advance.x, slot->advance.y);										FT_Done_Glyph(glyph);															/*/					error = FT_Load_Char( gu_font_getface(), ucs, FT_LOAD_RENDER);					if (error)						goto render_next;					slot = gu_font_getface()->glyph;					draw_bitmap(image, &slot->bitmap, x_x + slot->bitmap_left,						y_y - slot->bitmap_top, width,						height, gufont_color);					x_x += slot->advance.x >> 6;					y_y += slot->advance.y >> 6;					sbit_cache_add(ucs, gufont_pixel_size, gufont_border_enable,  						&slot->bitmap, slot->bitmap_left, slot->bitmap_top, slot->advance.x, slot->advance.y);					//*/									}				//*/			}		}render_next:		s++;	}	//*/}static void load_subtitle_texture(void *image)	{	sceGuEnable(GU_BLEND);	//sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xffffff, 0xffffff);	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);	sceGuTexMode(GU_PSM_8888, 0, 0, 0);	sceGuTexImage(0, SUB_SCREEN_TEXTURE_WIDTH, SUB_SCREEN_HEIGHT, SUB_SCREEN_TEXTURE_WIDTH, image);	//sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);	sceGuTexFilter(GU_NEAREST, GU_NEAREST);	sceGuTexWrap(GU_CLAMP, GU_CLAMP);	}static void gu_font_draw_sprite(struct texture_subdivision_struct *t)	{	struct vertex_struct *v = sceGuGetMemory(2 * sizeof(struct vertex_struct));	v[0].texture_x = t->output_texture_x_start;	v[0].texture_y = t->output_texture_y_start;	v[0].vertex_x  = (int) t->output_vertex_x_start;	v[0].vertex_y  = t->output_vertex_y_start;	v[0].vertex_z  = 0.0;	v[1].texture_x = t->output_texture_x_end;	v[1].texture_y = t->output_texture_y_end;	v[1].vertex_x  = (int) t->output_vertex_x_end;	v[1].vertex_y  = t->output_vertex_y_end;	v[1].vertex_z  = 0.0;	sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, v);	}static void gu_font_draw_sprite_180(struct texture_subdivision_struct *t, int w, int h)	{	struct vertex_struct *v = sceGuGetMemory(2 * sizeof(struct vertex_struct));	v[0].texture_x = t->output_texture_x_start;	v[0].texture_y = t->output_texture_y_start;	v[0].vertex_x  = (w) - (int) t->output_vertex_x_start;	v[0].vertex_y  = (h) - t->output_vertex_y_start;	v[0].vertex_z  = 0.0;	v[1].texture_x = t->output_texture_x_end;	v[1].texture_y = t->output_texture_y_end;	v[1].vertex_x  = (w) - (int) t->output_vertex_x_end;	v[1].vertex_y  = (h) - t->output_vertex_y_end;	v[1].vertex_z  = 0.0;	sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, v);	}void gu_font_printf( int x, int y, int flags, int output_inversion, char* fmt, ... )	{			va_list         ap;	char   p[512];	va_start( ap,fmt );	vsnprintf( p,512,fmt,ap );	va_end( ap );	gu_font_print(x, y, flags, p, output_inversion );	}void gu_font_print( int x, int y, int flags, char* s , int output_inversion)	{	if (face==NULL) return;		if (s==0) return;		if (!IsSet(gufont_haveflags,GU_FONT_HAS_UNICODE_CHARMAP))		{		flags &= ~FLAG_UTF8;		flags &= ~FLAG_UTF16BE;		flags &= ~FLAG_UTF16LE;		}		/*/	int width, height;	if (IsSet(flags,FLAG_UTF16BE))		{		if (s[0]=='\0'&&s[1]==0) return;		width = gu_font_utf16be_width_get( (short*)s, 0 );		height = gu_font_utf16be_height_get( (short*)s );		}	else	if (IsSet(flags,FLAG_UTF16LE))		{		if (s[0]=='\0'&&s[1]==0) return;		width = gu_font_utf16le_width_get( (short*)s, 0 );		height = gu_font_utf16le_height_get( (short*)s );		}	else	if (IsSet(flags,FLAG_UTF8))		{		if (s[0]=='\0') return;		width = gu_font_utf8_width_get( s, 0 );		height = gu_font_height_get( s );		}	else		{		if (s[0]=='\0') return;		width = gu_font_width_get( s, 0 );		height = gu_font_height_get( s );		}	if (height>512) height=512;	//*/			if (IsSet(flags,FLAG_UTF16BE)||IsSet(flags,FLAG_UTF16LE))		;	else {		//render_string( 0, x, y, s, flags );		if ( strcmp(s, cache_string) != 0) {			memset(sub_8888, 0, DRAW_BUFFER_SIZE);			memset(border_sub_8888, 0, DRAW_BUFFER_SIZE);			memset(cache_string, 0, 2048);			strncpy(cache_string, s, 2047);			render_string(x, gu_font_height(), cache_string, flags);			sceKernelDcacheWritebackInvalidateAll();			sceGuTexFlush();		}			}		int status = sceGuGetAllStatus();	sceGuEnable(GU_TEXTURE_2D);		struct texture_subdivision_struct texture_subdivision;		if (gufont_border_enable) {		load_subtitle_texture(border_sub_8888);		texture_subdivision_constructor(&texture_subdivision, SUB_SCREEN_WIDTH, SUB_SCREEN_HEIGHT, 16, gufont_output_sub_width, gufont_output_sub_height, gufont_output_x, gufont_output_y + y*gufont_output_height/272);		do			{			texture_subdivision_get(&texture_subdivision);			if ( output_inversion )				gu_font_draw_sprite_180(&texture_subdivision, 480, 272);			else				gu_font_draw_sprite(&texture_subdivision);			}		while (texture_subdivision.output_last == 0);	}	//*/	load_subtitle_texture(sub_8888);	texture_subdivision_constructor(&texture_subdivision, SUB_SCREEN_WIDTH, SUB_SCREEN_HEIGHT, 16, gufont_output_sub_width, gufont_output_sub_height, gufont_output_x, gufont_output_y + y*gufont_output_height/272);	do		{		texture_subdivision_get(&texture_subdivision);		if ( output_inversion )			gu_font_draw_sprite_180(&texture_subdivision, 480, 272);		else			gu_font_draw_sprite(&texture_subdivision);		}	while (texture_subdivision.output_last == 0);	//*/		sceGuSetAllStatus(status);			}	void gu_font_output_set(int x, int y, int w, int h)	{	gufont_output_width = w;	gufont_output_height = h;	gufont_output_sub_width = w*SUB_SCREEN_WIDTH/480;	gufont_output_sub_height = h*SUB_SCREEN_HEIGHT/272;	gufont_output_x = x;	gufont_output_y = y;	}

⌨️ 快捷键说明

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