I'm trying to draw rotated multi-line test in win32. I'm using DrawText with DT_WORDBREAK to break the text into lines within a bounding box, and defining a XFORM transform matrix to manipulate the world transform before drawing so I can draw the text rotated:
/* desiredOrigin - point around which to apply the rotation (rotated text 'topleft' corner)
textboxSize - desired horizontal textbox size (I'm assuming this should get rotated by drawtext)
pDC is setup with a font with lfEscapement = 900 (odd that I have to do this, clearly the transform doesn't work like I expected)
*/
void DrawRotatedText(CDC* pDC, CString text, CPoint desiredOrigin, CSize textboxSize, double rotationRads)
{
XFORM oldTransform;
pDC->GetWorldTransform(&oldTransform);
XFORM textTransform = oldTransform;
float dSin = (float)sin(rotationRads);
float dCos = (float)cos(rotationRads);
//setup rotation components from desired angle
textTransform.eM11 = dCos;
textTransform.eM12 = dSin;
textTransform.eM21 = -dSin;
textTransform.eM22 = dCos;
//setup translation from desiredtext origin
textTransform.eDx = (FLOAT)desiredOrigin.x;
textTransform.eDy = (FLOAT)desiredOrigin.y;
pDC->SetWorldTransform(&textTransform);
CRect bounds(CPoint(0, 0), textboxSize);
pDC->DrawText(text, bounds, DT_TOP | DT_CENTER | DT_WORDBREAK);
pDC->SetWorldTransform(&oldTransform);
}
This isn't working at all, and I'm not sure if it's because I did something wrong or DrawText doesn't work with world transforms..
I'm trying to draw a 90 degrees rotated text starting at the bottom left of the page (along the left edge). What I get is what seems correctly rotated text, but near the top of the page (going off screen). As I expand the window height, the text starts moving right around the x-axis, and stay stationary along the y-axis (well the visible text does change, but that should be the line wrap redrawing at different textbox widths).
Anyone know what I might be doing wrong? I'll gladly provide more detail if needed.