#include #include#include#include#include#include#include#include#include#include"show_font.h"#include#include FT_FREETYPE_H
unsignedchar *hzkmem;
unsignedchar *fbmem;
unsignedintline_width;
unsignedintpixel_width;struct fb_var_screeninfo var;void lcd_put_pixel( int x, int y, unsigned intcolor )
{
unsignedchar *pen_8 = fbmem +y*line_width + x*pixel_width;
unsignedshort *pen_16;
unsignedshort *pen_32;
unsignedcharred,green,blue;
pen_16= (unsigned short *)pen_8;
pen_32= (unsigned short *)pen_8;switch( pixel_width*8)
{case 8:*pen_8 =color;break;case 16:/*565*/red= (color>>16) & 0xff;
green= (color>>8) & 0xff;
blue= (color>>0) & 0xff;
color= ((red>>3)<<11) | ((green>>2)<<5) |((blue>>3));*pen_16 =color;break;case 32:*pen_32 =color;break;default:
printf("can‘t support %ddpp\n",pixel_width*8);break;
}
}void lcd_put_ascii( int x, int y, unsigned charc )
{
unsignedchar *dots = (unsigned char *)&fontdata_8x16[c*16];inti,b;
unsignedchar byte;for( i=0; i< 16; i++)
{byte =dots[i];for( b=7;b>=0;b--)
{if( byte & (1<
{
lcd_put_pixel(x+7-b,y+i, 0xffffff);
}else{
lcd_put_pixel(x+7-b,y+i, 0x000000);
}
}
}
}void lcd_put_chinese( int x, int y, unsigned char *c )
{
unsignedint area = c[0] - 0xa1;
unsignedint where = c[1] - 0xa1;
unsignedchar *dots = hzkmem + (area*94+where)*32;
unsignedchar byte;inti,j,b;for( i=0; i<16; i++)
{for( j=0; j<2; j++)
{byte = dots[i*2+j];for( b=7; b>=0; b--)
{if( byte & (1<
lcd_put_pixel(x+j*8+7-b,y+i, 0xffffff);elselcd_put_pixel(x+j*8+7-b,y+i, 0x000000);
}
}
}
}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>= var.xres || j >= var.yres )continue;//image[j][i] |= bitmap->buffer[q * bitmap->width + p];
lcd_put_pixel(i,j,bitmap->buffer[q * bitmap->width +p]);
}
}
}int main( int argc, char **argv )
{inthzk_fd;intfd_fb;structfb_fix_screeninfo fix;intscreen_size;
FT_Library library;
FT_Error error;
FT_Face face;
FT_Matrix matrix;/*transformation matrix*/FT_Vector pen;/*untransformed origin*/
doubleangle;
wchar_t*chinese_char = L"周zhou";
unsignedchar str[]={0xd6,0xd0};structstat hzk_stat;
fd_fb= open("/dev/fb0", O_RDWR );if( fd_fb<0)
{
perror("oepn failed");return -1;
}if( ioctl( fd_fb, FBIOGET_VSCREENINFO, &var) )
{
printf("can‘t get var\n");return -1;
}if( ioctl( fd_fb, FBIOGET_FSCREENINFO, &fix ) )
{
printf("can‘t get fix\n");return -1;
}
line_width= var.xres * var.bits_per_pixel / 8;
pixel_width= var.bits_per_pixel / 8;
screen_size= var.xres * var.yres * var.bits_per_pixel / 8;
fbmem= (unsigned char *)mmap( NULL, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED,fd_fb,0);if( fbmem == (unsigned char *)-1)
{
printf("mmap is failed\n");return -1;
}
hzk_fd= open("HZK16", O_RDONLY );if( hzk_fd<0)
{
printf("can‘t open hzk\n");return -1;
}if( fstat(hzk_fd, &hzk_stat))
{
printf("can‘t get fstat\n");return -1;
}
hzkmem= (unsigned char *)mmap( NULL, hzk_stat.st_size, PROT_READ, MAP_SHARED,hzk_fd,0);if( hzkmem == (unsigned char *)-1)
{
printf("mmap hzk is failed\n");return -1;
}
memset( fbmem,0, screen_size );
lcd_put_ascii(var.xres/2,var.yres/2,‘A‘);
printf("chinese code : %02x %02x\n", str[0],str[1]);
lcd_put_chinese(var.xres/2 +8 ,var.yres/2, str );if( argc != 2)
{
printf("Usage: %s \n", argv[0]);return -1;
}
error= FT_Init_FreeType( &library ); /*initialize library*/
/*error handling omitted*/error= FT_New_Face( library, argv[1], 0, &face ); /*create face object*/
/*use 50pt at 100dpi*/error= FT_Set_Pixel_Sizes( face, 30, 0 ); /*set character size*/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 (40,0) relative to the upper left corner*/pen.x= (var.xres/2+8+16) * 64;
pen.y= ( var.yres/2 - 16 ) * 64;/*set transformation*/FT_Set_Transform( face,&matrix, &pen );/*load glyph image into the slot (erase previous one)*/error= FT_Load_Char( face, chinese_char[0], FT_LOAD_RENDER );if(error)
{
printf("FT_load_char error\n");return -1;
}
draw_bitmap(&face->glyph->bitmap,
face->glyph->bitmap_left,var.yres - face->glyph->bitmap_top );return 0;
}