相信读者对于画水平方向的文字,应该都了解了。我这里介绍在垂直方向画文字的方法。
垂直分为左边垂直和右边垂直,它们显示文字略有不同。如下图所示:
是输出文字的方向不同。下面介绍具体的代码实现。
第一步:创建字体
HFONT hFont=reinterpret_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT)); assert(hFont); CFontHandler FontHandler = hFont; LOGFONT lf; FontHandler.GetLogFont(&lf); lf.lfOutPrecision = OUT_TT_ONLY_PRECIS; //左边垂直 lf.lfEscapement = 4500; lf.lfOrientation = 4500; //右边垂直 lf.lfEscapement = 2700; lf.lfOrientation = 2700; CFont FontNew; FontNew.Attach( ::CreateFontIndirect(&lf) ); assert(FontNew.m_hFont); HFONT hOldFont = dc.SelectFont(FontNew);
第二步:绘制文字。主要是找准起始的坐标点。CSize TextSize; bool bRet = ::GetTextExtentPoint32(dc, sText, n,&TextSize); assert(bRet); CRect rcTextArea;//只是举例 CPoint pt(rcTextArea.left, rcTextArea.top); if(bHorizontal) { pt.y = rcTextArea.top + (rcTextArea.bottom - rcTextArea.top - TextSize.cy) / 2; } else { //右边垂直 pt.x = rcTextArea.right - (rcTextArea.right - rcTextArea.left - TextSize.cy) / 2; //左边垂直 pt.x = rcTextArea.left + (rcTextArea.right - rcTextArea.left - TextSize.cy) / 2; pt.y = rcTextArea.bottom; } dc.ExtTextOut(pt.x, pt.y, ETO_CLIPPED, rcTextArea, sText, n, NULL); dc.SelectFont(hOldFont);
如何画垂直文字
最新推荐文章于 2020-07-12 19:20:11 发布