数码相框——矢量字体原理(六)
数码相框——矢量字体原理(6)
4、编译:make
来源:
http://liu1227787871.blog.163.com/blog/static/2053631972012628113620362/
前面我们的矢量字体显示的例子是在pc上运行的,这一节里面我们来编写可以再lcd上显示矢量字体的程序,例如显示“hello 嵌入式”
2.3.3节_数码相框_在LCD上显示一个矢量字体
交叉编译:
tar xjf freetype-2.4.10.tar.bz2
./configure --host=arm-linux
make
make DESTDIR=$PWD/tmp install
编译出来的头文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
编译出来的库文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
把tmp/usr/local/lib/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
sudo cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib -d -rf
cp *so* /work/nfs_root/fs_mini_mdev_new/lib -d
把tmp/usr/local/include/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include -rf
cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
mv freetype2/freetype .
//编译
arm-linux-gcc -finput-charset=GBK -o example1 example1.c -lfreetype -lm
arm-linux-gcc -finput-charset=GBK -o show_font show_font.c -lfreetype -lm
arm-linux-gcc -finput-charset=GBK -o chinese_lcd chinese_lcd.c -lfreetype -lm
//修改/ftheader.h的路径
freetype/config/ftheader.h
freetype2/freetype/config/ftheader.h
//制定输入字符charsert
arm-linux-gcc -finput-charset=GBK -fexec-charset=GBK -o show_font show_font.c -lfreetype -lm
arm-linux-gcc -finput-charset=GBK -o chinese_lcd chinese_lcd.c -lfreetype -lm
交叉编译:
tar xjf freetype-2.4.10.tar.bz2
./configure --host=arm-linux
make
make DESTDIR=$PWD/tmp install
编译出来的头文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
编译出来的库文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
把tmp/usr/local/lib/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
sudo cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib -d -rf
cp *so* /work/nfs_root/fs_mini_mdev_new/lib -d
把tmp/usr/local/include/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include -rf
cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
mv freetype2/freetype .
//编译
arm-linux-gcc -finput-charset=GBK -o example1 example1.c -lfreetype -lm
arm-linux-gcc -finput-charset=GBK -o show_font show_font.c -lfreetype -lm
arm-linux-gcc -finput-charset=GBK -o chinese_lcd chinese_lcd.c -lfreetype -lm
//修改/ftheader.h的路径
freetype/config/ftheader.h
freetype2/freetype/config/ftheader.h
//制定输入字符charsert
arm-linux-gcc -finput-charset=GBK -fexec-charset=GBK -o show_font show_font.c -lfreetype -lm
arm-linux-gcc -finput-charset=GBK -o chinese_lcd chinese_lcd.c -lfreetype -lm
一、搭建编译环境
1、解压:tar xvf freetype-2.4.10.tar.bz2
2、cd freetype-2.4.10
3、配置:./configure --host=arm-linux
4、编译:make
5、安装:make DESTDIR=$PWD/tmp install
编译出来的头文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
编译出来的库文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
6、cd tmp/usr/local
7、把tmp/usr/local/lib/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
cp lib/* /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib -d -rf
8、把tmp/usr/local/include/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
cp include/* /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include -rf
cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
mv freetype2/freetype .
9、将动态库拷贝到根文件系统的lib目录下
cp lib/*so* /home/share/jz2440/source/fs_mini_mdev_new/lib -d
10、编译:arm-linux-gcc -finput-charset=GBK -o chinese_lcd chinese_lcd.c -lfreetype -lm
执行文件,在开发板串口控制台输出根pc机一样的汉字!
二:代码修改(参考dot_Font.c 和Example1.c(Freetype))
/*
*功能:在LCD上显示Hello 嵌入式
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
//#include <sys/types.h>
//#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <linux/fb.h>
#include <string.h>
#include <math.h>
#include <wchar.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
int fd_fb = 0;
struct fb_var_screeninfo fb_var;
struct fb_fix_screeninfo fb_fix;
int screen_size = 0;
unsigned char* fb_mem;
int line_width;
int pix_width;
void lcd_put_pixel(int x, int y, unsigned int color)
{
unsigned char *pen_8 = (unsigned char*)(fb_mem+y*line_width+x*pix_width);
unsigned short *pen_16;
unsigned int *pen_32;
pen_16 = (unsigned short*)pen_8;
pen_32 = (unsigned int*)pen_8;
unsigned char red,green,blue;
switch(fb_var.bits_per_pixel)
{
case 8:
*pen_8 = color;
break;
case 16:
red = (color >>16)&0xff;
green = (color>>8)&0xff;
blue = (color>>0)&0xff;
color = ((red>>3)<<11)|((green>>2)<<5)|((blue>>3)<<0);
*pen_16 = color;
break;
case 32:
*pen_32 = color;
break;
default:
printf("Can' support error\n");
break;
}
}
/* Replace this function with something useful. */
void
draw_bitmap( FT_Bitmap* bitmap,
FT_Int x,
FT_Int y)
{
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
for ( i = x, p = 0; i < x_max; i++, p++ )
{
for ( j = y, q = 0; j < y_max; j++, q++ )
{
if ( i < 0 || j < 0 ||
i >= fb_var.xres|| j >= fb_var.yres)
continue;
lcd_put_pixel(i,j, bitmap->buffer[q * bitmap->width + p]);
}
}
}
int main(int argc,char ** argv)
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
double angle;
int target_height;
int n;
wchar_t *chinese_str = L"hello 嵌入式";
fd_fb = open("/dev/fb0",O_RDWR);
if(fd_fb < 0)
{
printf("open /dev/fb0 failed\n");
return -1;
}
if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &fb_var))
{
printf("get var information failed\n");
return -1;
}
if (ioctl(fd_fb, FBIOGET_FSCREENINFO, &fb_fix))
{
printf("get fix information failed\n");
return -1;
}
screen_size = fb_var.xres * fb_var.yres * fb_var.bits_per_pixel /8;
line_width = fb_var.xres * fb_var.bits_per_pixel /8;
pix_width = fb_var.bits_per_pixel /8;
fb_mem =(unsigned char *)mmap(NULL , screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
if(fb_mem == (unsigned char *)-1)
{
printf("fb_mem mmap failed\n ");
return -1;
}
memset(fb_mem, 0, screen_size);
/*Ôö¼ÓFreetype*/
if(argc != 2)
{
printf("Useage: %s <font file>\n",argv[0]);
return -1;
}
error = FT_Init_FreeType( &library ); /* initialize library */
if(error)
{
printf("FT_Init_FreeType failed\n");
return -1;
}
error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
if(error)
{
printf("FT_New_Face failed\n");
return -1;
}
FT_Set_Pixel_Sizes(face, 24, 0);
slot = face->glyph;
angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
/* the pen position in 26.6 cartesian space coordinates; */
/* start at (0,40) relative to the upper left corner */
pen.x = 0 * 64;
pen.y = ( fb_var.yres- 50 ) * 64;
for ( n = 0; n < wcslen(chinese_str); n++ )
{
FT_Set_Transform( face, &matrix, &pen );
error = FT_Load_Char( face, chinese_str[n], FT_LOAD_RENDER );
if(error)
continue;
/* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
fb_var.yres- slot->bitmap_top );
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
FT_Done_Face ( face );
FT_Done_FreeType( library );
return 0;
}
二:代码修改(参考dot_Font.c 和Example1.c(Freetype))
/*
*功能:在LCD上显示Hello 嵌入式
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
//#include <sys/types.h>
//#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <linux/fb.h>
#include <string.h>
#include <math.h>
#include <wchar.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
int fd_fb = 0;
struct fb_var_screeninfo fb_var;
struct fb_fix_screeninfo fb_fix;
int screen_size = 0;
unsigned char* fb_mem;
int line_width;
int pix_width;
void lcd_put_pixel(int x, int y, unsigned int color)
{
unsigned char *pen_8 = (unsigned char*)(fb_mem+y*line_width+x*pix_width);
unsigned short *pen_16;
unsigned int *pen_32;
pen_16 = (unsigned short*)pen_8;
pen_32 = (unsigned int*)pen_8;
unsigned char red,green,blue;
switch(fb_var.bits_per_pixel)
{
case 8:
*pen_8 = color;
break;
case 16:
red = (color >>16)&0xff;
green = (color>>8)&0xff;
blue = (color>>0)&0xff;
color = ((red>>3)<<11)|((green>>2)<<5)|((blue>>3)<<0);
*pen_16 = color;
break;
case 32:
*pen_32 = color;
break;
default:
printf("Can' support error\n");
break;
}
}
/* Replace this function with something useful. */
void
draw_bitmap( FT_Bitmap* bitmap,
FT_Int x,
FT_Int y)
{
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
for ( i = x, p = 0; i < x_max; i++, p++ )
{
for ( j = y, q = 0; j < y_max; j++, q++ )
{
if ( i < 0 || j < 0 ||
i >= fb_var.xres|| j >= fb_var.yres)
continue;
lcd_put_pixel(i,j, bitmap->buffer[q * bitmap->width + p]);
}
}
}
int main(int argc,char ** argv)
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
double angle;
int target_height;
int n;
wchar_t *chinese_str = L"hello 嵌入式";
fd_fb = open("/dev/fb0",O_RDWR);
if(fd_fb < 0)
{
printf("open /dev/fb0 failed\n");
return -1;
}
if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &fb_var))
{
printf("get var information failed\n");
return -1;
}
if (ioctl(fd_fb, FBIOGET_FSCREENINFO, &fb_fix))
{
printf("get fix information failed\n");
return -1;
}
screen_size = fb_var.xres * fb_var.yres * fb_var.bits_per_pixel /8;
line_width = fb_var.xres * fb_var.bits_per_pixel /8;
pix_width = fb_var.bits_per_pixel /8;
fb_mem =(unsigned char *)mmap(NULL , screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
if(fb_mem == (unsigned char *)-1)
{
printf("fb_mem mmap failed\n ");
return -1;
}
memset(fb_mem, 0, screen_size);
/*Ôö¼ÓFreetype*/
if(argc != 2)
{
printf("Useage: %s <font file>\n",argv[0]);
return -1;
}
error = FT_Init_FreeType( &library ); /* initialize library */
if(error)
{
printf("FT_Init_FreeType failed\n");
return -1;
}
error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
if(error)
{
printf("FT_New_Face failed\n");
return -1;
}
FT_Set_Pixel_Sizes(face, 24, 0);
slot = face->glyph;
angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
/* the pen position in 26.6 cartesian space coordinates; */
/* start at (0,40) relative to the upper left corner */
pen.x = 0 * 64;
pen.y = ( fb_var.yres- 50 ) * 64;
for ( n = 0; n < wcslen(chinese_str); n++ )
{
FT_Set_Transform( face, &matrix, &pen );
error = FT_Load_Char( face, chinese_str[n], FT_LOAD_RENDER );
if(error)
continue;
/* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
fb_var.yres- slot->bitmap_top );
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
FT_Done_Face ( face );
FT_Done_FreeType( library );
return 0;
}