Drawing strings on GDI+ that are vertical bottom to top aligned!
-
Hi, How can I draw strings with GDI+ that are are vertical bottom to top aligned! I try things as SetFormat(StringFormatFlagsDirectionVertical | StringFormatFlagsDirectionRightToLeft) but the text is always top to bottom oriented.
Yep, that's a serious limitation of GDI+ but it can be easily overpassed by rotating yourself the text:
// defined somewhere
Graphics* m_pGraphics;What you have to do is : 1. translate text to origin, 2. rotate, 3. translate back to position, Let's go: We create a graphic container to apply transformations
graphicsContainer = m_pGraphics->BeginContainer();
Doing steps 1,2,3 the order of matrix multiplication is important !
m\_pGraphics->TranslateTransform(pointF.X,pointF.Y); // angle is the angle you want to rotate your text in CCW turn with 0 = horizontal. Of course, in GDI+, Microsoft uses // CW angle so it is not compatible with trigonometric functions :( m\_pGraphics->RotateTransform(-angle); m\_pGraphics->TranslateTransform(-pointF.X,-pointF.Y);
Draw the string
m\_pGraphics->DrawString(str, -1, &font, pointF, &sf,&solidBrush);
Fold back transformations by getting out of the container
m_pGraphics->EndContainer(graphicsContainer);
Jonathan de Halleux, Belgium.
-
Yep, that's a serious limitation of GDI+ but it can be easily overpassed by rotating yourself the text:
// defined somewhere
Graphics* m_pGraphics;What you have to do is : 1. translate text to origin, 2. rotate, 3. translate back to position, Let's go: We create a graphic container to apply transformations
graphicsContainer = m_pGraphics->BeginContainer();
Doing steps 1,2,3 the order of matrix multiplication is important !
m\_pGraphics->TranslateTransform(pointF.X,pointF.Y); // angle is the angle you want to rotate your text in CCW turn with 0 = horizontal. Of course, in GDI+, Microsoft uses // CW angle so it is not compatible with trigonometric functions :( m\_pGraphics->RotateTransform(-angle); m\_pGraphics->TranslateTransform(-pointF.X,-pointF.Y);
Draw the string
m\_pGraphics->DrawString(str, -1, &font, pointF, &sf,&solidBrush);
Fold back transformations by getting out of the container
m_pGraphics->EndContainer(graphicsContainer);
Jonathan de Halleux, Belgium.