在使用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 valueFT_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。

通过这样修改后,上面提到的问题得到解决。

(转载)

最新文章

  1. Ado.net利用反射执行SQL得到实体
  2. sjtu1333 函数时代
  3. WIN7 64位配置Oracle SQL Developer工具
  4. oracle 字段类型详解
  5. UITableView表格操作
  6. 谦先生的程序员日志之我的hadoop大数据生涯一
  7. HTTP面试题都在这里
  8. HTML5VEDIO标签阿里云-微信浏览器兼容性问题
  9. iOS中 百度地图详解 韩俊强的博文
  10. 开发nginx启动脚本及开机自启管理(case)
  11. Bootstrap响应式导航
  12. netframework webapi exceptionless
  13. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
  14. Vue的watch监听事件
  15. [WinCE] [Win10] Win10 Creator 升级后 Windows Mobile Device Center 不能打开
  16. 比较和排序(IComparable和IComparer以及它们的泛型实现)(转)
  17. php自动载方法有两种.
  18. 剑指Offer——连续子数组的最大和
  19. ajax取消重复请求
  20. twitter storm学习 - 安装部署问题汇总

热门文章

  1. redis 哨兵模式 Connection refused
  2. guava collection/cache初探
  3. compose配置文件参数详解
  4. Lazarus 中文汉字解决方案
  5. 一个docker镜像中的目录删除不了问题
  6. ReactiveX 学习笔记(9)工具类操作符
  7. 遍历DOM树,理解更新范围
  8. 12.JDBC-mysql.md
  9. ROC,AUC,Precision,Recall,F1的介绍与计算(转)
  10. tf.identity 个人理解