Click to See Complete Forum and Search --> : Controlling vertical text using GDI+


Mike Pliam
September 20th, 2008, 03:46 PM
GDI+ provides for the output of vertical text, as shown by the following code. (CChart is an MFC class derived from CStatic)


void CChart::DrawVLabel(WCHAR * string, RectF layoutRect, HDC hdc)
{
Graphics graphics(hdc);

// Initialize arguments.
FontFamily fontFamily(L"Arial");
Font myFont(&fontFamily, 18, FontStyleBold, UnitPixel);

StringFormat format;
format.SetFormatFlags(StringFormatFlagsDirectionVertical|StringFormatFlagsDirectionRightToLeft);
SolidBrush blackBrush(Color(255, 0, 0, 0));

// Draw string.
graphics.DrawString(string, 11, &myFont, layoutRect, &format, &blackBrush);

// Draw layoutRect.
//graphics.DrawRectangle(&Pen(Color::Black, 3), layoutRect);

}// DrawVLabel(WCHAR * string, RectF layoutRect, HDC hdc)


Now, while this code works, the vertical text is always written from top to bottom (unable to render here). I would prefer the vertical text to be rendered from bottom to top, that is, what is conventionally left to right reading becomes bottom to top. IMHO, it just looks better.

The format flags I have tried here have no effect. Does anyone know how to render vertical text to read bottom to top using GDI+ ?

:wave:

UnfitElf
September 21st, 2008, 06:51 AM
I may be misunderstanding your question (its late here an im tied :))

If your talking about the actual output why not just reverse the string and then pass that to the same vertical text function..?

HTH

Mike Pliam
September 21st, 2008, 02:53 PM
Thankyou for your response.

Good idea. I should have mentioned that I had tried that. It doesnt work. It produces the the reverse string from the top down, so that the letters are backwards, but the output is still top down. If you try it with the code I've provided, you will see what I mean.

I have seen GDI output with vertical text printed 'bottom-up' (I can't think of a better way to describe it), so I am certain that it can be accomplished, but I cannot locate the code.