Displaying Unicode characters with FreeType

Source: Internet
Author: User

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;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.