• 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);
    }

  • 相关阅读:
    flash播放器插件与flash播放器的区别
    FLASH动作脚本详解
    flash代码
    LitJson使用中需要注意的一些问题(转)
    AS3中ASCII码和字符互转函数
    JQuery直接调用asp.net后台WebMethod方法(转)
    C#文件操作
    js延迟执行
    js操作表格、table、
    定时任务、js定时任务
  • 原文地址:https://www.cnblogs.com/carl2380/p/1924661.html
Copyright © 2020-2023  润新知