-
大小: 25KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-06-13
- 語言: 其他
- 標簽: linux??frambuffer??freetype2??漢字??
資源簡介
本人在工作實踐中寫的一個漢字顯示程序,在linux平臺下,利用frambuffer顯示設備來顯示。用freetype2庫來顯示矢量漢字。程序帶有漢字對齊、加粗、自動換行等功能。對于freetype2和frambuffer入門很有幫助。本程序已經經過試驗驗證。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?FT_FREETYPE_H
#include?FT_GLYPH_H
#include?FT_OUTLINE_H
typedef?struct?fbdev
{
????int?fdfd;?//open?“dev/fb0“
????struct?fb_var_screeninfo?vinfo;
????struct?fb_fix_screeninfo?finfo;
????long?int?screensize;
????char?*map_fb;?
}FBDEV;
FBDEV?fr_dev;
void?init_dev(FBDEV?*dev)
{
????FBDEV?*fr_dev=dev;
????fr_dev->fdfd=open(“/dev/fb0“O_RDWR);
????printf(“the?framebuffer?device?was?opended?successfully.\n“);
????ioctl(fr_dev->fdfdFBIOGET_FSCREENINFO&(fr_dev->finfo));?//獲取?固定參數
????ioctl(fr_dev->fdfdFBIOGET_VSCREENINFO&(fr_dev->vinfo));?//獲取可變參數
????fr_dev->screensize=fr_dev->vinfo.xres*fr_dev->vinfo.yres*fr_dev->vinfo.bits_per_pixel/8;?
????fr_dev->map_fb=(char?*)mmap(NULLfr_dev->screensizePROT_READ|PROT_WRITEMAP_SHAREDfr_dev->fdfd0);
????printf(“init_dev?successfully.\n“);
}
void?clean_lcd()
{
int?i;
for(i=0;i *((unsigned?short?int*)(fr_dev.map_fb+i))?=?255<<11|255<<5|255;
}
void?draw_dot(FBDEV?*devint?xint?y)?//(x.y)?是坐標
{
????FBDEV?*fr_dev=dev;
????int?*xx=&x;
????int?*yy=&y;????
????long?int?location=0;
????location=location=(*xx+fr_dev->vinfo.xoffset)*(fr_dev->vinfo.bits_per_pixel/8)+(*yy+fr_dev->vinfo.yoffset)*fr_dev->finfo.line_length;
????int?b=0;
????int?g=0;
????int?r=0;
????unsigned?short?int?t=r<<11|g<<5|b;
????*((unsigned?short?int?*)(fr_dev->map_fb+location))=t;
}
FT_Face??face;
FT_Library????library;
int?size;
FT_UInt???????now_index;
FT_UInt???????old_index;
void?freetype_init()
{
????//FT_Library????library;
????//FT_Face???????face;
????int?err?=?FT_Init_FreeType(&library);
????if(err)
????{
????????printf(“Init?library?failed\n“);
????????return;
????}
????err?=?FT_New_Face(library“simsun.ttc“0&face);
????if(err?==?FT_Err_Unknown_File_Format)
????{
????????printf(“the?font?is?not?supported\n“);
????????return;
????}
????else?if(err)
????{
????????printf(“the?font?file?can‘t?open\n“);
????????return;???
????}
}
void?freetype_draw(wchar_t?chint?xint?yint?xwidthint?xheight)
{
FT_Vector??delta;
now_index?=?FT_Get_Char_Index(facech);
????int?err?=?FT_Load_Glyph(faceFT_Get_Char_Index(facech)FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
????if(err)
????{
????????printf(“FT_Load_Glyph?failed\n“);
????????return;
????}
????FT_Outline_EmboldenXY(&face->glyph->outline?xwidth*1.50);
????FT_Glyph?glyph;
????err?=?FT_Get_Glyph(face->glyph&glyph);
????if(err)
????{
????????printf(“FT_Get_Glyph?failed\n“);
????????return;
????}
????FT_Render_Glyph(face->glyph?FT_RENDER_MODE_NORMAL);?
????FT_Glyph_To_Bitmap(&glyphFT_RENDER_MODE_NORMAL01);
????FT_BitmapGlyph?bitmap_glyph?=?(FT_BitmapGlyph)glyph;
????FT_Bitmap?bitmap=bitmap_glyph->bitmap;
????
FT_BBox??bbox;
FT_Glyph_Get_CBox(glyph3&bbox);
FT_Get_Kerning(face?old_index?now_indexFT_KERNING_DEFAULT&delta);
x?+=?delta.x>>6;
FT_Glyph_Metr
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5115??2012-08-23?18:00??ft_word\freetype_word.c
?????文件??????25700??2012-08-23?18:00??ft_word\main.o
?????文件????????281??2012-08-23?18:00??ft_word\Makefile
?????文件??????27968??2012-08-23?18:00??ft_word\test
????I..D...?????????0??2012-08-23?16:59??ft_word
-----------?---------??----------?-----??----
????????????????59064????????????????????5
- 上一篇:《VHDL基礎及經典開發》源程序
- 下一篇:基于51單片機的MPU6050程序
評論
共有 條評論