问题

在 NGUI 中使用 BMFont 生成的字体的时候,发现比美术给的效果图中的字体小很多,而且字体边缘产生了毛边,但是在生成字体时选择的参数与 PhotoShop 中的参数设置相同,都是像素。

解决方法

经过测试发现:用 BMFont 生成中文字体,“Options”->“Font Settings”->“Size (px)”中设置字体为 18 像素,结果生成的字体并没有 18 像素高,只有 11 像素高,而 PhotoShop 中 18 像素的字体就是 18 像素高,可见 BMFont 中生成的字体大小并不正确,后来发现,只要勾选 “Match char height” 选项就可以生成正确大小的字体。

经过 Google,发现了问题的原因:BMFont 中 “Size (px)” 参数使用的是字体的行高,而不是字体的高度!BMFont 直到 1.11 版本才加入对字体高度的支持,而这个支持的选项 “Match char height” 默认是不开启的,实在是太囧了!

参考资料

Andreas Jonsson Moderators - Reputation: 1439 Posted 11 October 2008 – 01:17 PM

BMFont 1.11 is now available, with the option to define the font size by character height rather than line height. Let me know if you find any problems with it.

BMFont font size – AngelCode – GameDev.net

Kartzan Re: Problem with proportional fonts « Reply #6 on: June 12, 2012, 02:15:04 PM »

There appears to be some issues with the way the text is rendered from BMFont and as a result the output varies depending on the size. I decided to check the “Match char height” checkbox in the font settings and now the font seems to be rendering properly. I’ve watched the video on this about 1/2 a dozen times and I think it may just be an issue with the font I am using. At the moment things seems to be working properly. Thank you for all your help and if anyone has a similar problem in the future hopefully they’ll see this post and give “Match char height” a try.

Problem with proportional fonts