C++ CDC::DrawText多行和旋转
我试图在win32中绘制旋转的多行测试。我正在使用带有DT_WORDBREAK的DrawText在边界框中将文本拆分为几行,并定义一个变换矩阵来在绘制之前操纵世界变换,以便可以绘制旋转的文本:C++ CDC::DrawText多行和旋转,c++,windows,winapi,mfc,C++,Windows,Winapi,Mfc,我试图在win32中绘制旋转的多行测试。我正在使用带有DT_WORDBREAK的DrawText在边界框中将文本拆分为几行,并定义一个变换矩阵来在绘制之前操纵世界变换,以便可以绘制旋转的文本: /* desiredOrigin - point around which to apply the rotation (rotated text 'topleft' corner) textboxSize - desired horizontal textbox size (I'm assumin
/* 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轴保持静止(可见文本确实会发生变化,但这应该是以不同文本框宽度重新绘制的换行)
有人知道我可能做错了什么吗?如果需要,我很乐意提供更多细节。请参阅我的答案:。可能您需要先执行一个
DT_calcorrect
。您还需要将设备上下文的图形模式设置为高级:int oldgm=pDC->SetGraphicsMode(GM_advanced);