我正在尝试在win32中绘制旋转多行测试。我正在使用带有DT_WORDBREAK的DrawText将文本分解为边界框内的线条,并定义XFORM变换矩阵以在绘制之前操纵世界变换,以便我可以绘制旋转的文本:
/* 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);
}
这根本不起作用,我不确定是不是因为我做错了什么,或者DrawText不能用于世界变换..
我正在尝试从页面左下角(沿着左边缘)绘制一个90度旋转的文本。我得到的是正确旋转的文字,但靠近页面顶部(离开屏幕)。当我扩展窗口高度时,文本开始围绕x轴移动,并沿y轴保持静止(可见文本确实会发生变化,但应该是在不同文本框宽度处重新绘制的换行符。)
任何人都知道我可能做错了什么?如果需要,我很乐意提供更多细节。