如何在 wxWidgets projet 中包含和使用新字体?
如何在 wxWidgets projet 中包含和使用新字体? 我用的是VS2005。 我只想使用新的 ttf 字体打印文本。 提前致谢!!
How to include and use new fonts in wxWidgets projet?
I am using VS2005.
I just want to print text using new ttf font.
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您愿意链接到 FreeType 之类的内容:
http://en.wikipedia.org/wiki/FreeType
...大多数程序都需要由用户或某些特定于操作系统的脚本将字体安装到操作系统中。您不能直接在应用程序中按文件名加载它。
由于命名和访问自定义字体的平台依赖性,阻力最小的方法不是尝试对字体进行硬编码……而是让用户从对话框中选择一种字体。为此,您可以使用
wxFontDialog
:http://docs.wxwidgets。 org/stable/wx_wxfontdialog.html
它可以让你检索
wxFontData
,从中你可以获取所选的字体wxFont
:http://docs.wxwidgets.org/stable/ wx_wxfontdata.html#wxfontdatagetchosenfont
一旦你有了它,你就可以保存并重新加载字体的标识通过本机字符串接口:
http://docs.wxwidgets.org/stable/wx_wxfont.html #wxfontgetnativefontinfodesc
尝试自己制定这些字符串或使用“面孔名称”是一种小狡猾:
http://docs.wxwidgets.org/stable/wx_wxfont.html#wxfontsetfacename< /a>
一般来说,这里会出现很多与处理 HTML 中的字体相同的问题。如果您对某些文本的跨平台外观有非常具体的想法,那么最好的选择通常是用该文本制作图像并使用它,而不是费尽周折地在应用程序中获取您想要的字体。如果您更灵活并且有很多用户感兴趣的文本,那么他们可能也有兴趣更改字体。因此,只需使用默认值,但让用户可以选择安装在其系统上的任何内容。
(注意:我个人认为几乎每个操作系统或文档系统中的字体处理都是一种耻辱。想象一下这样一个世界:为了在程序中显示图形,您必须将其注册到操作系统通过一个复杂的过程,当您复制嵌入它的文档时,它不会从一台机器复制到另一台机器。我们现在处理的图形比字体文件大几个数量级,但它们在人们看起来时是无缝处理的。将缺乏无缝字体传输视为“正常”。字体供应商陈旧的 DRM 思维方式是问题的一方面,但蹩脚的技术是另一个重要组成部分。)
Unless you're willing to link against something like FreeType:
http://en.wikipedia.org/wiki/FreeType
...most any program is going to require the font to be installed to the operating system, by the user or by some OS-specific script. You can't just load it by filename off the cuff in your app.
Because of the platform dependence of naming and accessing custom fonts, the path of least resistance is not to try and hardcode a font...but to let the user pick one out of a dialog. You would use a
wxFontDialog
for this:http://docs.wxwidgets.org/stable/wx_wxfontdialog.html
It will let you retrieve the
wxFontData
, from which you can get the chosenwxFont
:http://docs.wxwidgets.org/stable/wx_wxfontdata.html#wxfontdatagetchosenfont
Once you have that, you can save and reload an identity of the font via the native string interface:
http://docs.wxwidgets.org/stable/wx_wxfont.html#wxfontgetnativefontinfodesc
Trying to formulate these strings on your own or work with the "face name" is a little dodgier:
http://docs.wxwidgets.org/stable/wx_wxfont.html#wxfontsetfacename
Generally speaking a lot of the same problems arise here as dealing with fonts in HTML. If you have a very specific idea about the cross-platform appearance of some text, your best bet is often to make an image out of that text and use that instead of going through the hoops to get the font you want in the app. If you're more flexible and have a lot of text the user is interested in, then they may be interested in changing the font too. So just use a default but offer the user a choice to pick anything they want which is installed on their system.
(Note: I personally consider the handling of fonts in pretty much every OS or document system to be a disgrace. Imagine a world where in order to get a graphic to display in your program you had to register it with the operating system through a complex process and it would not copy from machine to machine when you copied a document in which it was embedded. We're dealing now with graphics that are orders of magnitude larger than font files, and yet they are handled seamlessly while people seem to accept the lack of seamless font transfer as "normal". Archaic DRM mindsets of font vendors is one side of the problem, but lame technology is another big component.)