交叉編譯:tar xjf freetype-2.4.10.tar.bz2 ./configure --host=arm-linuxmakemake DESTDIR=$PWD/tmp install find -name stdio.h 平時使用#include<stdio.h>路徑 ./arm-li ...
交叉編譯:
tar xjf freetype-2.4.10.tar.bz2
./configure --host=arm-linux
make
make DESTDIR=$PWD/tmp install
find -name stdio.h
平時使用#include<stdio.h>路徑 ./arm-linux/include/stdio.h
編譯出來的頭文件應該放入:
/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include
編譯出來的庫文件應該放入:
/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib
把tmp/usr/local/lib/* 複製到 /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib
sudo cp * /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib -d -rf
cp *so* /work/nfs_root/fs_mini_mdev_new/lib –d
cd /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib
把tmp/usr/local/include/* 複製到 /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include
cp * /work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include -rf
cp *so* /work/nfs_root/fs_mini_mdev/lib –d
錯誤
/arm-linux/include/ft2build.h:56:38: freetype/config/ftheader.h
freetype/config/ftheader.h
freetype2/freetype/config/ftheader.h
將freetype2/freetype移動到當前目錄
mv freetype2/freetype .
編譯
arm-linux-gcc -finput-charset=GBK -fexec-charset=GBK -o example1 example1.c -lfreetype -lm
在開發板上運行
用函數轉化文件編碼方式
iconv -f GBK -t UTF-8 show_font.c
查看錯誤
編譯
arm-linux-gcc -finput-charset=GBK -fexec-charset=GBK -o show_font show_font.c -lfreetype -lm
wchar_t * chinese_str = L"陳"; FT_Library library; FT_Face face; FT_Vector pen; /* untransformed origin */ FT_GlyphSlot slot; int error; if(argc != 2) { printf("Usage : %s <font_file>\n",argv[0]); return -1; }
freetype初始化
/* ÏÔʾʸÁ¿ÎÄ×Ö */ error = FT_Init_FreeType( &library ); /* initialize library */ /* error handling omitted */ error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */ /* error handling omitted */ slot = face->glyph; FT_Set_Pixel_Sizes(face, 24, 0); /*È·¶¨×ø±ê *lcd_x = var.xres / 2 + 32 + 32 *lcd_y = var.yres / 2 *µÑ¿¨¶û×ø±ê *x = lcd_x = var.xres / 2 + 32 + 32 *y = var.yres - var.yres / 2 */ pen.x = ( var.xres / 2 + 32 + 32 ) * 64; pen.y = ( var.yres - var.yres / 2 - 16) * 64; /* set transformation */ FT_Set_Transform( face, 0, &pen ); /* load glyph image into the slot (erase previous one) */ error = FT_Load_Char( face, chinese_str[0], FT_LOAD_RENDER ); if ( error ) { printf("FT_Load_Char error\n"); return -1; } /* now, draw to our target surface (convert position) */ draw_bitmap( &slot->bitmap, slot->bitmap_left, var.yres - slot->bitmap_top );
描畫圖
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; printf("x = %d, y = %d\n", x, y); 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]); } } }
旋轉angle角度
第三個參數為角度
添加頭文件 #include <stdlib.h>
angle = ( 1.0 * strtoul(argv[2], NULL, 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 );