Using LOGFONT

The SRGraphTitle functions described above provide control of most, but not all, font selection parameters. Occasionally, you may need to specify some other parameter, or you may find it more convenient to use a LOGFONT structure to select a font.

To use a LOGFONT structure for font selection:

  1. Create a LOGFONT structure and fill it in.

  2. Call SRGraphTitle::SetLogFont(). For example:

    static LOGFONT lf;

    lf.lfHeight=-13;

    lf.lfWidth=0;

    lf.lfEscapement=0;

    lf.lfOrientation=0;

    lf.lfWeight=400;

    lf.lfItalic=TRUE;

    lf.lfUnderline=FALSE;

    lf.lfStrikeOut=FALSE;

    lf.lfCharSet=ANSI_CHARSET;

    lf.lfOutPrecision=OUT_STROKE_PRECIS;

    lf.lfClipPrecision=CLIP_STROKE_PRECIS;

    lf.lfQuality=DRAFT_QUALITY;

    lf.lfPitchAndFamily=DEFAULT_PITCH;

    _tcsncpy(lf.lfFaceName,(LPCTSTR)_T(“Arial”),6);

    SRGraphTitle* pT = new SRGraphTitle;

    pT->SetLogFont(&lf);

    There is a complication in using SetLogFont() to set font information in Objective Chart. The chart’s font caching system only uses the FaceName, FontSize, FontStyle, and Orientation data to identify individual fonts. The method SetLogFont()sets these parameters from the LOGFONT data, so it works better with the font caching system. You can call SetLogFont() repeatedly to change fonts on the fly, but each time you must make sure that one of the identifying traits is changed. If not, you can use one of the unused bits of FontStyle to flag the change. For example:

    if(bFontChanged)

    {

    int nStyle = pC->GetFontStyle();

    pC->SetFontStyle(nStyle+256); // hack to force a new font

    }

    Note: The LOGFONT structure must have a global lifetime.