www.pudn.com > freetype.rar > ftsample.cpp


#if 0//本文件是freetype模块的调用例子 
 
//#include "kstdiodm.h" 
#include "stdio.h" 
 
#include "ft2build.h" 
#include "freetype/freetype.h" 
 
#include "freetype/ftoutln.h" 
#include "freetype/ftbbox.h" 
 
int main() 
{ 
	/* test bbox computations */ 
	#define  XSCALE    65536 
	#define  XX(x)     ((FT_Pos)(x*XSCALE)) 
	#define  XVEC(x,y)  { XX(x), XX(y) } 
	#define  XVAL(x)   ((x)/(1.0*XSCALE)) 
 
	#define Panic(s) {printf(s);exit(1);} 
 
	char*  filename = "c:/winnt/fonts/simhei.ttf"; 
 
	FT_Library    freetype; 
	FT_Face       face; 
	FT_Error      error; 
 
	error = FT_Init_FreeType( &freetype ); 
	if (error) Panic( "could not initialise FreeType" ); 
 
	error = FT_New_Face( freetype, filename, 0, &face ); 
	if (error) Panic( "could not open font face" ); 
 
	printf( "font name : %s (%s)", face->family_name, face->style_name ); 
 
	/* compute font units -> grid pixels scale factor */ 
	face->units_per_EM; 
	 
	/* setup subpixels -> grid pixels transform */ 
	face->size->metrics; 
	 
	//FT_Set_Pixel_Sizes( face, pixel_size, pixel_size ); 
 
 
    int glyph_index; 
    for ( glyph_index = 0; glyph_index < face->num_glyphs; glyph_index++) 
    { 
	    char  temp2[64]; 
	    FT_Get_Glyph_Name( face, glyph_index, temp2, 63 ); 
	    temp2[63] = 0; 
	     
		error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_BITMAP ); 
		if (error) Panic( "could not load glyph" ); 
 
		if ( face->glyph->format != FT_GLYPH_FORMAT_OUTLINE ) 
			Panic( "could not load glyph outline" ); 
 
		FT_Outline*  outline = &face->glyph->outline; 
		FT_BBox  bbox; 
 
		/* compute and display cbox */ 
		FT_Outline_Get_CBox( outline, &bbox ); 
		printf( "cbox = [%.2f %.2f %.2f %.2f]\n", 
		         XVAL( bbox.xMin ), 
		         XVAL( bbox.yMin ), 
		         XVAL( bbox.xMax ), 
		         XVAL( bbox.yMax ) ); 
 
		/* compute and display bbox */ 
		FT_Outline_Get_BBox( outline, &bbox ); 
		printf( "bbox = [%.2f %.2f %.2f %.2f]\n", 
		         XVAL( bbox.xMin ), 
		         XVAL( bbox.yMin ), 
		         XVAL( bbox.xMax ), 
		         XVAL( bbox.yMax ) ); 
 
		//error = nv_path_new_from_outline( renderer, 
		//	(NV_Outline*)&face->glyph->outline, &size_transform, &path ); 
		if (error) Panic( "could not create glyph path" ); 
    } 
    FT_Done_Face(face); 
    FT_Done_FreeType( freetype ); 
 
	return 0; 
} 
#endif//本文件是freetype模块的调用例子