这个程序本意是让执行程序+字体+要输出的字,结果可以输出相应的字,但我现在编译通过执行后输出和我输入的差距很大。经我观察,输出和输入字符数有关,输入一个字符,比如a或f等等,输出就是T;输入两个字符,比如tu或dw,输出就是N;三个字符是E;四个字符是G。输入一个汉字输出就是E。不知道哪里出了问题,麻烦帮忙看下程序应该怎么改才能输入需要的字符,先谢了
#include <stdio.h>
#include <string.h>
//加载FreeType头文件
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
void
draw_bitmap( FT_Bitmap bitmap,
FT_Int x,
FT_Int y)
{
for(int i=0;i <bitmap.rows;++i)
{
for(int j=0;j <bitmap.width;++j)
{
printf("%d",bitmap.buffer[i*bitmap.width+j]?1:0);
}
printf("\n");
}
}
int
main (int argc, char** argv)
{
char* filename;
char* text;
FT_Library pFTLib = NULL;
FT_Face pFTFace = NULL;
FT_Error error = 0;
FT_Glyph glyph;
filename = argv[1];
text = argv[2];
int n=10;
//初始化FreeType Lib
error = FT_Init_FreeType( &pFTLib );
if (error)
{
pFTLib = 0;
printf("There is some error when Init Library...");
return -1;
}
//创建font face
error = FT_New_Face(pFTLib,argv[1],0,&pFTFace);
if(!error)
{
FT_Set_Char_Size(pFTFace,0,16*64,200,150);
//加载glyph与文字
FT_Select_Charmap(pFTFace,FT_ENCODING_UNICODE);
//从字符码检索字形索引
FT_UInt glyph_index;
glyph_index=FT_Get_Char_Index(pFTFace,text[n]);
//装载字形图像到字形槽(将抹掉先前的字形图像)
FT_Load_Glyph(pFTFace,glyph_index,FT_LOAD_DEFAULT);
error = FT_Get_Glyph(pFTFace->glyph, &glyph);
if(!error)
{
//转换glyph至bitmap
FT_Render_Glyph(pFTFace->glyph, FT_RENDER_MODE_NORMAL);
FT_Glyph_To_Bitmap(&glyph,FT_RENDER_MODE_NORMAL,0,1);
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
//取位图数据
FT_Bitmap bitmap = bitmap_glyph->bitmap;
//绘制到目标表面
draw_bitmap(bitmap,bitmap.rows,bitmap.width);
}
//释放glyph
FT_Done_Glyph(glyph);
glyph = NULL;
}
//释放face
FT_Done_Face(pFTFace);
pFTFace = NULL;
//释放FreeType Lib
FT_Done_FreeType(pFTLib);
pFTLib = NULL;
}
freetype程序得不到想要结果,请大家帮忙看下
-
- 帖子: 3
- 注册时间: 2009-03-19 11:54
-
- 帖子: 26
- 注册时间: 2008-06-18 9:14
Re: freetype程序得不到想要结果,请大家帮忙看下
我最近也在看freetype的东西,但是对程序的编译一点也不了解,可以告诉我这种freetype程序要如何加什么编译参数么?#include FT_FREETYPE_H
#include FT_GLYPH_H又代表了什么呢,谢谢
#include FT_GLYPH_H又代表了什么呢,谢谢