freetype不能显示字母、数字、标点符号,可以显示汉字是怎么回事?
Qt下使用freetype显示字符串,但是不能显示字母、数字、标点符号,可以显示汉字是怎么回事?wchar_t lenWord[] = L"1a";//上海欢迎您!2,需要打印的字符串
int ledWordLen =wcslen(str16);
int size_face=16;
FT_Library ftLibrary;
FT_Error ftError = FT_Init_FreeType(&ftLibrary);
if(ftError)
qDebug()<<"Init freetype library fail!\n";
FT_Face ftFace;
ftError = FT_New_Face( ftLibrary, "./fonts/simsun.ttf", 0, &ftFace );//ttc
if(ftError == FT_Err_Unknown_File_Format)
qDebug()<<"Error! Could not support this format!\n";
else if(ftError)
qDebug()<<"Error! Could not open file simsun.ttc!\n";
ftError = FT_Set_Pixel_Sizes(ftFace, size_face, 0);//size_face
if(ftError)
qDebug()<<"Set pixel sizes to %d*%d error!\n"<<size_face;
if (FT_Select_Charmap(ftFace, FT_ENCODING_UNICODE))
qDebug()<<"设定字符编码失败!";
for (int j=0;j<lenWordLen;j++)
{
FT_UInt glyph_index;
glyph_index = FT_Get_Char_Index( ftFace,lenWord[j]);//lenWord[j]
if ( glyph_index == 0 )
qDebug()<<"SOFTERR: FT_Get_Char_Index fail.";
if(FT_Load_Char(ftFace, glyph_index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME))
qDebug()<<"FT_Load_Char error";
if (FT_Load_Glyph( ftFace, glyph_index, FT_LOAD_RENDER))//|FT_LOAD_DEFAULT))//FT_LOAD_RENDER ))
qDebug()<<"SOFTERR: FT_Load_Glyph fail";
FT_GlyphSlot slot;
slot = ftFace->glyph;
FT_Render_Glyph( slot,FT_RENDER_MODE_MONO ); /* render mode */
bitmapData[j] = new Bitmap;
if(bitmapData[j] == NULL)
qDebug()<<"SOFTERR: fail to new a Bitmap";
unsigned char data[size_face][size_face];
qDebug()<<"slot->bitmap.pitch="<<slot->bitmap.pitch;
memset(data,0,size_face*size_face);
for(int i=0;i<slot->bitmap.rows;i++)
{
for(int k=0;k<slot->bitmap.width;k++)
{
data[i][k]= slot->bitmap.buffer[i*slot->bitmap.width+k];
unsigned char pixelclr = (slot->bitmap.buffer[i *slot->bitmap.pitch + (k/8)]<<(k%8))&0x80;//(slot->bitmap.buffer[m * slot->bitmap.pitch + (n/8)]<<(n%8))&0x80;
if(pixelclr>=128)
printf("*");
else
printf(" ");
}
printf("\n");
}
}
--------------------编程问答--------------------
补充:移动开发 , Qt