赞
踩
- void SetTextFont(bool bold, bool italic, bool underline, CString strFont, COLORREF color, int size)
- {
- CHARFORMAT2 cf,oldCf;
- GetSelectionCharFormat(oldCf);
- GetSelectionCharFormat(cf);
- if (bold)
- {
- cf.dwMask|=CFM_BOLD;
- cf.dwEffects|=CFE_BOLD; //设置粗体,取消用cf.dwEffects&=~CFE_BOLD;
- }
- if (italic)
- {
- cf.dwMask|=CFM_ITALIC;
- cf.dwEffects|=CFE_ITALIC; //设置斜体,取消用cf.dwEffects&=~CFE_ITALIC;
- }
- if (underline)
- {
- cf.dwMask|=CFM_UNDERLINE;
- cf.dwEffects|=CFE_UNDERLINE; //设置下划线,取消用cf.dwEffects&=~CFE_UNDERLINE;
- }
- if (color)
- {
- cf.dwEffects &= ~CFE_AUTOCOLOR; //这个最重要,设选中文字颜色的时候也要注意,dwEffects一定不能有CEF_AUTOCOLOR的属性
- cf.dwMask|=CFM_COLOR;
- cf.crTextColor = color; //设置颜色
- }
- if (size)
- {
- cf.dwMask|=CFM_SIZE;
- cf.yHeight =200; //设置高度
- }
- cf.dwMask|=CFM_FACE;
- wcscpy(cf.szFaceName , strFont.GetBuffer(0));//设置字体
- SetSelectionCharFormat(cf);
- SetSel(-1,-1);
- SetSelectionCharFormat(oldCf);
- }
CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, m_iFont, DT_SINGLELINE | m_uTextStyle);使用DrawText的缺陷是无法精确的计算字符串的宽度,比如一个字符串为“abc”,我想让b高亮的话,就会绘制三次来达到效果, a、 b(使用不同的样式)、 c、;但是问题就出在这里,不能精确计算字符串a、b、c、的宽度无法完成后面字符串的绘制,不是覆盖就是有空隙。。。。。。
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_strTextValue.c_str(), m_dwTextColor, NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle);
// Bold: <b>text</b> // Color: <c #xxxxxx>text</c> where x = RGB in hex // Font: <f x>text</f> where x = font id // Italic: <i>text</i> // Image: <i x y z> where x = image name and y = imagelist num and z(optional) = imagelist id // Link: <a x>text</a> where x(optional) = link content, normal like app:notepad or http:www.xxx.com // NewLine <n> // Paragraph: <p x>text</p> where x = extra pixels indent in p // Raw Text: <r>text</r> // Selected: <s>text</s> // Underline: <u>text</u> // X Indent: <x i> where i = hor indent in pixels // Y Indent: <y i> where i = ver indent in pixels按照上述样式,可进行绘制操作。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。