LogFont与CharFormat互相转换
way1:
CFontDialog::getcharformat
way2:
void CTextLine::ChangeLogFontToCharFormat(CHARFORMAT &cf, const LOGFONT lf, const COLORREF textcolor)
{
//CFE_AUTOCOLOR
cf.dwMask = CFM_BOLD|CFM_CHARSET|CFM_COLOR|CFM_FACE|CFM_ITALIC|\
CFM_SIZE|CFM_UNDERLINE|CFM_STRIKEOUT;
BOOL bIsItalic = lf.lfItalic ;
BOOL bIsBold = (lf.lfWeight > FW_BOLD);//? FW_NORMAL:FW_BOLD;
BOOL bIsUnderline = lf.lfUnderline ;
BOOL bIsStrickout = lf.lfStrikeOut ;
cf.dwEffects |= CFE_PROTECTED;
cf.dwEffects &= ~CFE_AUTOCOLOR;
if (bIsBold)
{
cf.dwEffects |= CFE_BOLD;
}
else
{
cf.dwEffects &= ~CFE_BOLD;
}
if (bIsItalic)
{
cf.dwEffects |= CFE_ITALIC;
}
else
{
cf.dwEffects &= ~CFE_ITALIC;
}
if (bIsUnderline)
{
cf.dwEffects |= CFE_UNDERLINE;
}
else
{
cf.dwEffects &= ~CFE_UNDERLINE;
}
if (bIsStrickout)
{
cf.dwEffects |= CFM_STRIKEOUT;
}
else
{
cf.dwEffects &= ~CFM_STRIKEOUT;
}
//设置属性
cf.yHeight = -15 * lf.lfHeight;
cf.crTextColor = textcolor;//;//m_Font_Color;
cf.bCharSet = lf.lfCharSet ;
cf.bPitchAndFamily = lf.lfPitchAndFamily ;
sprintf(cf.szFaceName, lf.lfFaceName);
}
void CTextLine::ChangeCharFormatToLogFont(CHARFORMAT cf, LOGFONT &lf, COLORREF &textcolor)
{
lf.lfOutPrecision = 3;
lf.lfClipPrecision =2;
lf.lfQuality = 1;
//粗体
if ((cf.dwEffects &CFE_BOLD )>0)
{
lf.lfWeight = 700;
}
else
{
lf.lfWeight = 400;
}
//斜体
if ((cf.dwEffects &CFE_ITALIC)>0)
{
lf.lfItalic = 1;
}
else
{
lf.lfItalic = 0;
}
//下划线
if ((cf.dwEffects & CFE_UNDERLINE)>0)
{
lf.lfUnderline = 1;
}
else
{
lf.lfUnderline = 0;
}
//删除线
if ((cf.dwEffects & CFE_STRIKEOUT)>0)
{
lf.lfStrikeOut = 1;
}
else
{
lf.lfStrikeOut =0;
}
lf.lfHeight = (-cf.yHeight/15);
textcolor = cf.crTextColor;
lf.lfCharSet = cf.bCharSet;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
sprintf(lf.lfFaceName, cf.szFaceName);
}