如何在Windows GUI中绘制垂直文本? [英] How to draw vertical text in Windows GUI?

查看:298
本文介绍了如何在Windows GUI中绘制垂直文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的本地C ++ Win32 GUI应用程序中绘制一列垂直文本(使用日文 - 从顶部到底部而不是从左到右)。我已经通过MSDN查看,只发现如何绘制从右到左的文本。

除了单独绘制每个字符之外,如何输出从上到下的文本?

解决方案

直接的Win32 API没有办法绘制(未旋转的)垂直文本(使用任意字体),除了1在时间的字符。

您可以使用 GDI +
但是这可能不是你想要的,因为文本是垂直的,但是字符也会被旋转。类似地,你可以使用lfEscapement值为900或2700的CreateFont来获取旋转的文本,但是这将会旋转一切。所以这也没有帮助。为了做日本的顶部到底部的绘制,你希望字符是未旋转的,但是每个字符的位置要在Y中提前,而不是在X中.Windows没有API为所有字体做这个。 (你可以从右到左,从左到右,但不是从上到下)。

理论上创建一个900方向的字体而2700的擒纵机构可以做你想做的,但是如果你设置了擒纵机构,那么对于大多数字体来说这个方向就会被忽略。对于日文字体来说,这可能会有所不同。值得花一些时间玩。 (请参阅附录以了解更多信息)

我认为你最好的选择是一个可能的循环,一次画一个字符, ExtTextOut ,让您完全控制每个字符的位置。



如果您使用ETO_OPAQUE在列中绘制第一个字符,而不是所有其他字符,那么您将被允许在垂直方向。

附录



Roygbiv指出一个有趣的文章,说名字以@开头的字体表现不一样其他字体当您使用CreateFont一个字体的lfEscapement值为2700,这些特殊的字体产生直立的字符,同时仍然向前推进页面。所以,虽然没有办法做任何你想要的任意字体,你也许可以使用某些字体来得到它的工作。



显示文本的选项



输出好奇心,我写了一个小的控制台应用程序枚举字体和列出名称。我的Windows Server 2003计算机没有以@开头的字体。但是我的Windows 7机器有几个。虽然都是中文字体,但在默认的Windows 7旗舰版中没有看到日文字体。

I need to draw a column of vertical text (in Japanese language - it is drawn top-to-bottom instead of left-to-right) in my native C++ Win32 GUI application. I've looked through MSDN and only found how to draw right-to-left text.

How do I output top-to-bottom text except drawing each character separately?

解决方案

The straight Win32 API has no way to draw (unrotated) vertical text (with an arbitrary font) in that way except 1 character at at time.

You can do more complex text output with GDI+ But that probably isn't what you want either, since the text will be vertical, but the characters will also be rotated.

Similarly, you can use CreateFont with an lfEscapement value of 900 or 2700 to get rotated text, but this will rotate everything. So that doesn't help either.

To do Japanese Top to Bottom drawing, you want the characters to be unrotated, but the placment of each character to advance in Y but not in X. Windows has no API that does this for all fonts. (you can do right-to-left and left-to-right, but not top-to-bottom).

In theory creating a font with an Orientation of 900 and an escapement of 2700 would do what you want, but it appears that if you set the escapement, then the orientation is ignored for most fonts. It's possible that for Japanese fonts, this will work differently. It's worth spending some time to play with. (see the addendum for more information on this)

I think your best bet is a probably a loop drawing one character at a time with ExtTextOut which gives you full control over the placement of each character.

If you use ETO_OPAQUE to draw the first character in a column, and not with all of the others, then you will be permitted to kern the characters vertically if you need to.

Addendum

Roygbiv points to an interesting article that says that fonts whose names begin with an @ behave differently then other fonts when you use CreateFont a font with an lfEscapement value of 2700, These special fonts produce upright characters while still advancing down the page. So while there is no way to do what you want for arbitrary fonts, you may be able to get it working using certain fonts.

Options for Displaying Text

Out of curiosity, i wrote a small console app to enum fonts and list the names. My Windows Server 2003 machine has not fonts with names beginning with @. But my Windows 7 machine has a few. All seem to be Chinese fonts though, I see no Japanese fonts in the default Windows 7 Ultimate install.

这篇关于如何在Windows GUI中绘制垂直文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆