Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Chart User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

7.5 Using SRGraphTitle

SRGraphTitle adds text drawing functionality to the basic component class and can display multiple line text. The new line character, \n, can be used to separate lines.

SRGraphTitle can be used in two modes. By default, an SRGraphTitle gets its title text from its parent, the SRGraph object, during every draw cycle by calling GetParentContent().


WARNING: It is critical that the call to SetYMargin() follow the call to SetMeasurement().

Alternatively, it can display its own text, provided by SetText(), if SetUseOwnText(TRUE) is also called. This allows several titles to be used in one chart.

To change the text shown in the title panel:

The code below creates the multiline, autosized title shown in Figure 102.

Figure 102: Multiline title produced by the preceding code

The remainder of this section discusses how the appearance of text can be modified.

7.5.1 Font selection

The SRGraphTitle class also contains the font management functions. All classes that display text are derived from this class, so all the methods described here can be used for text in any other type of Objective Chart component.

Fonts may be selected from any of the available bitmap or TrueType fonts. The following functions specify the appearance of displayed text:

To change text appearance, call the font selection functions defined in SRGraphTitle. For example:

7.5.2 Font sizing

The font size may be specified in two ways:

In the latter case, the font character height is calculated from the absolute number of the given size. For example, SetFontSize(18) sets the font to 18 points, and SetFontSize(-18) sets the height to 18 pixels.

7.5.3 Font style

As shown above, the SetFontStyle() function sets the standard font styles — bold, italic, underline, and strikeover. Use the following symbols to enable the related style. The symbols can be combined with the OR operator (|).

The special font style, CX_FONT_AUTOSIZE, causes the component's own CalcFontAutoSize() function to be called to determine the font size. For a Title component, the font size is selected to fit the text to the component rectangle. For a Legend component, the font height is set to 10% of the rectangle height. You can override CalcFontAutoSize() to select a font size appropriate for your needs.

Figure 103: Title components showing various font styles

7.5.4 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
          }
      


    The LOGFONT structure must have a global lifetime.

7.5.5 Text Alignment

The positioning of the title text within the component rectangle can be changed by calling SRGraphTitle::SetJustication(). To specify the alignment of the annotations within their allotted space:

  1. Call SetJustification(0) for left alignment.

  2. Call SetJustification(1) for right alignment.

  3. Call SetJustification(2) for center alignment.

7.5.6 Word Wrap

If the text is too long for the specified component rectangle (and CX_FONT_AUTOSIZE is not selected), the text will automatically wrap to a second line. You can disable this automatic word-wrapping by including CX_FONT_NOWRAP in the font style.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.