freetype使用日记 -- 解决宋体,楷体中文在某些字号下无法正常显示的问题
2010-03-02 20:59
1131 查看
问题:
在使用freetype过程中发现,从window下拷贝来的simsun.ttc, simkai.ttf两个字体,
在调用
FT_Set_Pixel_Sizes(face, 12, 0);
将字体大小设置为12×12pixels,或者16×16pixels等时,中文无法正常画出,英文可以正常画出。
而设置为10×10pixepixels, 17×17pixels时,却能正常画出中文。
其实解决方法是比较简单的,不过还是贴出来供新手有个参考。
分析:
后来经过跟踪发现在设置为12×12pixels时,
FT_Load_Glyph(face, FT_Get_Char_Index(face, szText), FT_LOAD_DEFAULT);
函数在load时,从字体文件中load的时bitmapped image,而不是outline,而可能是字体中的bitmapped image有问题,从而造成无法正常画出中文。
联想到freetype帮助文档中有如下的描述
Loading a glyph image into the slot is performed by calling FT_Load_Glyph as in
error = FT_Load_Glyph( face, /* handle to face object */ glyph_index, /* glyph index */ load_flags ); /* load flags, see below */
The load_flags value is a set of bit flags used to indicate some special operations. The default value FT_LOAD_DEFAULT is 0.
This function will try to load the corresponding glyph image from the face:
If a bitmap is found for the corresponding glyph and pixel size, it will be loaded into the slot. Embedded bitmaps are always favored over native image formats, because we assume that they are higher-quality versions of the same glyph. This can be changed by using the FT_LOAD_NO_BITMAP flag.
Otherwise, a native image for the glyph will be loaded. It will also be scaled to the current pixel size, as well as hinted for certain formats like TrueType and Type 1.
解决办法:
error = FT_Load_Glyph(face, FT_Get_Char_Index(face, szText), FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
这样强制在load时,loadoutline,然后再根据outline得到bitmapped image。
通过这样修改后,上面提到的问题得到解决。
在使用freetype过程中发现,从window下拷贝来的simsun.ttc, simkai.ttf两个字体,
在调用
FT_Set_Pixel_Sizes(face, 12, 0);
将字体大小设置为12×12pixels,或者16×16pixels等时,中文无法正常画出,英文可以正常画出。
而设置为10×10pixepixels, 17×17pixels时,却能正常画出中文。
其实解决方法是比较简单的,不过还是贴出来供新手有个参考。
分析:
后来经过跟踪发现在设置为12×12pixels时,
FT_Load_Glyph(face, FT_Get_Char_Index(face, szText), FT_LOAD_DEFAULT);
函数在load时,从字体文件中load的时bitmapped image,而不是outline,而可能是字体中的bitmapped image有问题,从而造成无法正常画出中文。
联想到freetype帮助文档中有如下的描述
Loading a glyph image into the slot is performed by calling FT_Load_Glyph as in
error = FT_Load_Glyph( face, /* handle to face object */ glyph_index, /* glyph index */ load_flags ); /* load flags, see below */
The load_flags value is a set of bit flags used to indicate some special operations. The default value FT_LOAD_DEFAULT is 0.
This function will try to load the corresponding glyph image from the face:
If a bitmap is found for the corresponding glyph and pixel size, it will be loaded into the slot. Embedded bitmaps are always favored over native image formats, because we assume that they are higher-quality versions of the same glyph. This can be changed by using the FT_LOAD_NO_BITMAP flag.
Otherwise, a native image for the glyph will be loaded. It will also be scaled to the current pixel size, as well as hinted for certain formats like TrueType and Type 1.
解决办法:
error = FT_Load_Glyph(face, FT_Get_Char_Index(face, szText), FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
这样强制在load时,loadoutline,然后再根据outline得到bitmapped image。
通过这样修改后,上面提到的问题得到解决。
相关文章推荐
- freetype使用日记 -- 解决宋体,楷体中文在某些字号下无法正常显示的问题
- [Android]浮层视频效果,在另外一个Window使用SurfaceView无法正常显示的问题排查与解决
- python2.7:dic2json 解决中文无法正常显示问题
- 自行解决12306页面显示异常的问题(长城宽带下WWW。12306无法正常使用)
- 解决Spring boot中使用Gson,Swagger2 api-docs无法正常显示json问题
- Python利用Seaborn画图中关于中文无法正常显示的问题解决
- 20100722 使用FTP客户端(filezilla)中文目录显示乱码无法正常使用解决
- 解决JFreeChart无法正常显示中文问题
- Android Service中使用Toast无法正常显示问题的解决方法
- 解决JFreeChart无法正常显示中文问题
- Python使用matplotlib绘图无法显示中文问题的解决方法
- python2.7;解决中文无法正常显示问题
- 在使用Gson的toJson()方法转为json字符串的时候无法显示中文和符号的问题(已解决)
- 关于使用Volley下载的json字符串无法显示中文的问题(已解决)
- 解决matplotlib绘制图片时中文无法正常显示的问题
- ubuntu 11.04 gnome3 下的gedit无法正常显示中文,出现乱码问题解决
- Linux相关问题-解决Ubuntu12.04下无法使用中文输入法
- 解决Unity中,使用Ngui 的默认字体Arial,在部分Android设备显示中文不清楚,或者显示不出来问题
- putty连接linux服务器中文无法正确显示问题的解决
- Windows下游戏程序使用32位的dll文件-解决“应用程序无法正常启动0xc000007b”问题