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 我想去看看 在外面跟几家创业公司谈了谈,交流了一些大数据与机器视觉相关 ...
随机推荐
- 洛谷 P1886 滑动窗口 /【模板】单调队列
纯板子题,入队时保证单调性,即单调栈,出队保证题目条件,本题即窗口长度k,在入队出队时都可以维护信息 ; int buf[maxm], maxq[maxm], minq[maxm], ans1[max ...
- img标签无法显示src中名字中带有中文的图片的问题
img: <img src="/upload/${good.photo}" style="width: 120px;height: 120px;" alt ...
- IdentityServer4专题之六:Resource Owner Password Credentials
实现代码: (1)IdentityServer4授权服务器代码: public static class Config { public static IEnumerable<Identity ...
- Vivado ILA观察信号和调试过程
先简单介绍一下ILA(Integrated Logic Analyzer)生成方法.这里有两种办法完成Debug Core的配置和实现. 方法一.mark_debug综合选项+Set Up Debug ...
- firewalld学习--service的使用和配置
service配置文件 firewalld默认给我们提供的ftp的service配置文件ftp.xml <?xml version="1.0" encoding=" ...
- vs2010编译C++ 友元函数
// CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...
- 未知进程问题,process information unavailable
执行jps,有些未知进程: 2690 -- process information unavailable2666 原因:内存不足. cd /tmp/hsperfdata_impala/ 执行ll后, ...
- 使用JS写一个计算器
先上效果图: 简单的加减乘除功能还是有的,所以我们就考虑怎么来实现这个功能. 根据预期效果,可以确定页面中的布局要用到table tr td. 所以先放上页面布局,table的边框宽度border,c ...
- 强大的promise
这个玩意叫做普罗米修斯,希腊神话的盗火英雄 promise只用来包装异步函数,同步的会搞乱执行顺序,生产BUG // 如何使用 function pro(){ return new Promise(f ...
- 洛谷P2089 烤鸡
标签:暴力,枚举 题目背景 猪猪 Hanke 得到了一只鸡. 题目描述 猪猪 Hanke 特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke 吃鸡很特别,为什么特别呢?因为他有 10 种配料(芥末. ...