如何画垂直文字

相信读者对于画水平方向的文字,应该都了解了。我这里介绍在垂直方向画文字的方法。

垂直分为左边垂直和右边垂直,它们显示文字略有不同。如下图所示:

是输出文字的方向不同。下面介绍具体的代码实现。

第一步:创建字体

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);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值