Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw vertical text in Windows GUI?

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?

like image 739
sharptooth Avatar asked Feb 12 '10 08:02

sharptooth


1 Answers

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.

like image 62
9 revs Avatar answered Oct 23 '22 13:10

9 revs