Use FreeType to load vector fonts, TTF font files, through the character's unicode,load a character's dot matrix. Unicode use of Chinese characters can be expressed in 32bit, such as ' I ' Unicode is 0x6211
Defining Global Variables
Static Ft_library G_lib;
Static Ft_face G_face;
Initialize FreeType
<pre name= "code" class= "CPP" >pshowscreen<span style= "font-family:arial, Helvetica, Sans-serif;" > is Frambuffer's mapped memory address. </span>
int Show_char (int unicode,int fontsizepixel,mid_font_color fontcolor,int startx,int starty) {int charUnicode = Un
Icode;
int index,x,y;
Ft_glyph Glyph;
unsigned short int *pshowline;
int error;
Index =0;x=0;y = 0; if (Pshowscreen = = NULL) {printf ("<use osd_init not yet!!!
> \ n "); return-1;}
Pshowline = (unsigned short int*) (Pshowscreen);
Error = ft_set_pixel_sizes (g_face,fontsizepixel,fontsizepixel);
if (Error!= 0) {return hi_failure;
index = Ft_get_char_index (G_face,charunicode);
Error = Ft_load_glyph (G_face,index, Ft_load_default);
Error = Ft_get_glyph (g_face->glyph, &glyph);
if (!error) {error = Ft_glyph_to_bitmap (&glyph, Ft_render_mode_normal, 0, 1);
Ft_bitmapglyph bitmap_glyph = (ft_bitmapglyph) glyph;
Ft_bitmap *bitmap = &bitmap_glyph-> Bitmap; for (y = Starty y < bitmap->rows + starty, ++y) {for (x = startx; x < Bitmap->width +StartX;
++X) {if (x < 0 | | | y < 0) continue; if (bitmap->buffer[(y-starty) * bitmap->width + (X-STARTX)]) {* (Pshowline + y * var.xres + x) =
FontColor;
}else{}} ft_done_glyph (Glyph);
Glyph = NULL;
}else return-1;
return 0; }
Msg_print ("init error:%d,errno:%d \ n", Error,errno);} Error = Ft_new_face (g_lib,fontfile, 0, &g_face); if (Error!= 0) {msg_print ("Init FreeType error, please check font fil e \ n "); return-1;} Error = Ft_select_charmap (G_face, Ft_encoding_unicode); if (Error!= 0) {return-1;}
Load Unicode
Release FreeType
int Freetype_realse () {
ft_done_face (g_face);
Ft_done_freetype (g_lib);
return 0;
}