GDI 中的文本渲染控制
我已经在 GDI+ 中的文本渲染上苦苦挣扎了一段时间。 我们正在动态生成头条新闻的图像,但库中似乎有很多东西值得期待。 我可以设置字体、字体大小和其他一些东西,但我无法控制行高或字母间距。
我已经构建了自己的类,它采用生成的文本图像,剪切出单独的文本行(每种字体的设置手动编码到设置文件中)并用我想要的行高重新组装它们。 不过,我无法解决字母间距的相同问题。
有没有人有解决这个问题的解决方案或推荐解决这个问题的库(操作系统或商业)?
I've been struggling for a while with the text rendering in GDI+. We are dynamically generating images of headlines but there seems to be a lot to whish for in the library. I can set the font, font size and a few other things but I cannot control row height or letter spacing.
I have built my own class that takes a generated text image, cuts out the individual rows of text (the settings for each font is manually encoded into settings files) and reassembles them with a the row height I want. I haven't been able to solve the same problem for letter spacing though.
Does anyone have a solution for this or a recommendation of a library (OS or commercial) that solves this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这是否适用于您的解决方案,但在过去,当我需要渲染一些更复杂的文本并且我希望在渲染方式上有相当大的灵活性时,我使用了这个库:
http://www.terrainformatica.com/htmlayout/main.whtm
未开放源,但它是免费的...
或者,在游戏空间中,我广泛使用了位图字体 - 如果您存储字符间距等信息,它可能看起来与 TTF 完全相同,但您失去了在不引入一些像样的工件的情况下大幅扩展它。 为了更好地体验这种方法,这里有一个用于构建字体的工具:
http://www. angelcode.com/products/bmfont/
希望其中之一能给您一些帮助 - 任何一个都可以让您控制字符间距和行高,但它们也有其局限性。
I don't know if this will be applicable to your solution, but in the past when I needed to render out some more sophisticated text and I wanted to have a fair amount of flexibility in how it would be rendered, I used this library:
http://www.terrainformatica.com/htmlayout/main.whtm
It's not open source, but it is free...
Alternatively, in the game space I've used bitmap fonts extensively - if you store out information such as character spacing, etc it can look exactly the same as a TTF, but you loose the ability to scale it much without introducing some decent artifacts. To get a better feel for this approach, here's a tool for building the fonts:
http://www.angelcode.com/products/bmfont/
Hopefully one of those gives you some help - either one will give you control over character spacing and row height, but they also have their limitations.