使用 Win32 TextOut 以一定角度绘制文本
我正在使用 GDI 将文本绘制到设备上下文上,并且我注意到,如果角度恰好为 0、90、180 或 270,则字距调整或字符位置会有所不同。一旦我将角度增加 1,字符就会放置位置明显不同。
我没有使用角度创建 HFONT
,而是使用 ModifyWorldTransform
来转换设备上下文的世界坐标,然后使用 TextOut
绘制文本到设备上下文中。
我认为当文本以 90 度的精确倍数绘制时,GDI 正在使用字体提示或其他一些特殊技术,但不是针对任何其他角度。
有没有办法禁用此提示,以便在 0 度渲染的文本与在 1 度渲染的文本没有显着差异?
以下是我的意思的示例(Monotype Corsiva 字体):
0 度:
1 度:
对于某些字体,例如 Arial 或 Tahoma,它并不那么明显,但我想摆脱完全不同,即使这意味着文本没有得到最好的渲染。
I'm using GDI to draw text onto a device context, and I noticed that the kerning or character placement is different if the angle is exactly 0, 90, 180, or 270. As soon as I increase the angle by 1, the character placement differs noticeably.
Rather than creating an HFONT
with the angle, I am using ModifyWorldTransform
to transform the device context's world coordinates, and then I use TextOut
to draw the text onto the device context.
I think that GDI is using font hints or some other special technique when the text is being drawn at exact multiples of 90 degrees, but not for any other angle.
Is there a way to disable this hinting, so that text rendered at 0 degrees does not differ significantly from text rendered at 1 degree?
Here's an example of what I mean (Monotype Corsiva font):
0 degrees:
1 degree:
For some fonts, such as Arial or Tahoma, it is not as noticeable, but I would like to get rid of the difference entirely, even if it means the text is not rendered as best it can.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是由于抗锯齿而不是字体提示。您可以尝试以下操作:
CreateFont()
中使用fdwOutputPrecision
和fdwQuality
。这可能是最简单的解决方案,但我想你必须进行一些实验。哈
I think this is due to anti-aliasing rather than font hints. You could try the following:
CreateCompatibleBitmap()
) render the text to it and then render the rotated bitmap. This depends on how often you need different rotations / different text.fdwOutputPrecision
andfdwQuality
inCreateFont()
. This could be the easiest solution, but you'd have to experiment a little bit I guess.hth