MFC 根据字符宽度居中
Gdiplus::Font font(_T("微软雅黑"), (Gdiplus::REAL)130);
Gdiplus::RectF orgin(0.0f, 100.0f, nWidth, 200.0f);
Gdiplus::StringFormat stringformat;
stringformat.SetAlignment(Gdiplus::StringAlignmentCenter);
//stringformat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 255, 0, 0));
graphics.DrawString(strFailedContent.c_str(), -1, &font, orgin, &stringformat, &solidBrush);
函数如下
float GetTextWidthFloor(const wstring& strText, const Gdiplus::Font& font)
{
Gdiplus::StringFormat stringformat(Gdiplus::StringAlignmentNear); Gdiplus::GraphicsPath graphicsPathObj;
Gdiplus::FontFamily fontfamily;
font.GetFamily(&fontfamily); Gdiplus::RectF rcBound;
graphicsPathObj.AddString(strText.c_str(), -1, &fontfamily, font.GetStyle(), font.GetSize(), Gdiplus::PointF(0, 0), &stringformat);
graphicsPathObj.GetBounds(&rcBound); return (float)(rcBound.Width);
} int GetTextWidth(const wstring& strText, const Gdiplus::Font& font)
{
// calculate spaces width of text head
// due to gdiplus do not care about it
int nHeadSpace = 0;
int nLen = strText.size();
for (int i=0; i<nLen; ++i)
{
if (0x20 == strText.at(i))
nHeadSpace++;
else{
break;
}
} // calculate space width
static float fSpaceWidth = 0.0f;
if ((fSpaceWidth >= -0.00001f && fSpaceWidth <= 0.00001f) && nHeadSpace > 0)
{
fSpaceWidth = GetTextWidthFloor(_T("a b"), font) - GetTextWidthFloor(_T("ab"), font);
} float fResult = GetTextWidthFloor(strText, font) + (float)nHeadSpace * fSpaceWidth; return (int)fResult + 1;
}
MFC 根据字符宽度居中的更多相关文章
- PDF 补丁丁 0.5.0.2713 发布(替换字库功能修正字符宽度问题)
新版本替换字库后,采用新字库的字符宽度.基本上可以满足一般的字库替换需求.请下载新版本测试.
- 获取字符宽度:并非自适应。coretext去计算
获取字符宽度:并非自适应.coretext去计算 UniChar ch = [ns_str characterAtIndex:0]; CGGlyph glyph = 0; CTFontGetGlyph ...
- ZUFE 1035 字符宽度编码(字符串)
Time Limit: 1 Sec Memory Limit: 128 MB Description 你的任务是编写一个程序实现简单的字符宽度编码方法.规则如下:将任何2~9个相同字符的序列编码成2 ...
- 关于Html无宽度居中
代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...
- 小程序 将图片文字变成一整张图片海报(判断其中字符串宽度可通过计算字符串.length*字符宽度)
//test.xml<canvas bindtap='showhaibao' canvas-id="myCanvas" style="width:{{canvasw ...
- js高度line-height及宽度text-align:center居中插件
1.高度居中---在高度设为100%,无法直接使用line-height:100%;会不起效果 这是用于应对height:100%的插件 /** * 高度居中函数,用于应对高度设为100%时的居中 * ...
- 【转】MFC CreateFont 用法
中国人自古就有自右至左.从上到下书写汉字的习惯.而当我们在自己所编写的应用程序中使用输出函数输出的总是自左至右的横排文字.有没有可能在我们的应用程序中实现竖写汉字的效果呢?笔者偶然发现了一种利用VC实 ...
- 通过编写串口助手工具学习MFC过程——(二)通过“打开串口”按钮了解基本操作
通过编写串口助手工具学习MFC过程 因为以前也做过几次MFC的编程,每次都是项目完成时,MFC基本操作清楚了,但是过好长时间不再接触MFC的项目,再次做MFC的项目时,又要从头开始熟悉.这次通过做一个 ...
- EasyPR--开发详解(7)字符分割
大家好,好久不见了. 一转眼距离上一篇博客已经是4个月前的事了.要问博主这段时间去干了什么,我只能说:我去“外面看了看”. 图1 我想去看看 在外面跟几家创业公司谈了谈,交流了一些大数据与机器视觉相关 ...
随机推荐
- JS enter键一键登录
$("body").keydown(function (event) { ) { //enter键键值为13 $('.finish-btn').click(); // $('.fi ...
- Mac如何升级自带的vim
brew install vim --with-lua --with-override-system-vi brew install macvim --with-lua --with-override ...
- 一种新的python局部调试手法
我们都知道,python里面可以用pdb来调试代码.但是pdb往往不大好用.有时候调试代码往往在多重条件里面,直接用pdb需要下条件断点,设定复杂的条件. 一个简单的办法就是这么干. __import ...
- 工作中一些常用的linux命令
问题一: 绝对路径用什么符号表示?当前目录.上层目录用什么表示?主目录用什么表示? 切换目录用什么命令? 答案:绝对路径:如/etc/init.d当前目录和上层目录:./ ../主目录:~/切换目录 ...
- JdbcTemplate常用方法
JdbcTemplate简介 JdbcTemplate是Spring JDBC的核心类,借助该类提供的方法可以很方便的实现数据的增删改查. Spring对数据库的操作在jdbc上面做了深层次的封装,使 ...
- jenkins#安装docker
环境:centos7 安装依赖包 yum install -y yum-utils device-mapper-persistent-data lvm2 添加Docker软件包源 yum-config ...
- Day8 - E - The very same Munchhausen CodeForces - 1120E
A positive integer aa is given. Baron Munchausen claims that he knows such a positive integer nn tha ...
- Day6 - 牛客102C
链接:https://ac.nowcoder.com/acm/contest/102/C来源:牛客网 题目描述 We define a value of an interval is the seco ...
- App与Js交互(三)Android、iOS通用解决方案推荐
https://www.jianshu.com/p/6224f429ce87 window.navigator.userAgent用来区分设备和浏览器 https://blog.csdn.net/li ...
- MapReduce On Yarn的执行流程
1.概述 Yarn是一个资源调度平台,负责为运算程序提供服务器运算资源,相当于一个分布式的操作系统平台,而MapReduce等运算程序则相当于运行于操作系统之上的应用程序. Yarn的架构如下图所示: ...