-
大小: 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程序
相关资源
- Learning Linux Binary Analysis
- 蓝牙源代码应用于LINUX
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- linux扫雷游戏代码
- CAN Linux驱动代码
- Linux系统教材
- intel 82579LM 网卡驱动Linux系统版 v1.9.
- SA1110处理器掌上电脑液晶显示器设计
评论
共有 条评论