| Methods Index |
Subclasses: None
CFont is a class that encapsulates the usage of XVT fonts. XVT-Power++ features an encapsulated font model. Under this font model, a CFont object defines a logical font. A logical font is a description of a desired physical font. When your application needs to draw text, the font mapping controller maps (i.e., matches) the specified logical font to the closest available physical font. The physical font is then used for rendering the text.The logical font description is composed of attributes such as the typeface family name, size, and style. The attributes describe the physical font that the application eventually wants to be mapped onto the logical font. All of the following attributes, except the native descriptor, are portable:
XVT_FFN_* constants (shown in Table 8) as a convenience. They represent logical fonts guaranteed to have a good, consistent appearance on all toolkits. Any other logical font families may undergo some mapping substitutions when they are ported across platforms.
XVT_FS_* constants (shown in Table 9), which are used in an XVT_FONT_STYLE_MASK to specify logical font style. You can use the XVT_FS_* constants, combined in bit masks, to specify multiple values. The XVT_FS_WILDCARD logical font style is the only style a logical font has if it was created from an URL font resource with an "any" style.
Usage
The following examples illustrate several uses of CFont:Portably
CFont aFont(XVT_FFN_HELVETICA, XVT_FS_BOLD, 9);
CFont aFont("...native description...");
int anAsc = aFont.GetAscent();
aFont.SetStyle(XVT_FS_NONE);
CFont aFont(FONT_RES_ID);
CText *aText = new CText(itsEnclosure,
CPoint(25, 25), "Hey!");
CEnvironment *anEnv = aText->GetEnvironment();
anEnv->SetFont(aFont);
aText->DoDraw();
void CTestView::Draw(const CRect &theRect)
{
// Call inherited:
CView::Draw(theRect);
// Set units and convert to XVT points:
CUnits::SetGlobalUnits(itsUnits);
PNT aPnt = itsLocation;
// Draw text, uses conversion operator from CFont
// to XVT_FNTID, and CStringRW to const char *:
WINDOW anXVTWin = GetCWindow()->GetXVTWindow();
xvt_dwin_set_font(anXVTWin,
CFont(XVT_FFN_SYSTEM, XVT_FS_BOLD, 9));
xvt_dwin_draw_text(anXVTWin,
aPnt.h,
aPnt.v,
(const char *)itsText,
-1);
}
CFont with XVT Portability Toolkit font functions in the cases described below.If you want a copy of a logical font, use the XVT Portability Toolkit
XVT_FNTID constructor. For instance, you must copy a logical font in the following two cases:
WIN_DEF
CFont aFont(wd->v.tx.font_id);
EVENT
CFont aFont(ep->v.font.font_id);
If you want to consume a logical font, use the XVT Portability Toolkit XVT_FNTID assignment operator. For example, you must consume a logical font in the following five cases:
xvt_font_create()
CFont aFont = xvt_font_create(...);
CFont.
xvt_res_get_font()
CFont aFont = xvt_res_get_font(...);
In the above case, always use CFont.
xvt_dwin_get_font()
CFont aFont = xvt_dwin_get_font(...);
xvt_menu_get_font_sel()
CFont aFont = xvt_menu_get_font_sel(...);
xvt_tx_get_font()
CFont aFont = xvt_tx_get_font(...);
|
|
|
|
XVT_FNTID
|
itsFontId;
| The logical font ID |
static CFontRegistry*
|
itsRegistry
| Global registry of font objects |
static int
|
itsRegistryCreationCount
| Number of registry references |
CFont();
CFont(int theResId);
theResId.
CFont(XVT_FNTID theFontId);
theFontId.
CFont(const CStringRW &theNativeDesc);
theNativeDesc. A native descriptor is a string of data fields, which describes a physical font that resides on your system. The fields in the descriptor represent the internal (native) font selection attributes present on each platform (for example, lfWeight or lfCharSet on MS-Windows and MS-Windows NT). Keep in mind that the created font references theNativeDesc, and you are responsible for maintaining the integrity of that stream.
CFont(const CStringRW &theFamily,
XVT_FONT_STYLE_MASK theStyle,
long theSize);
theFamily specifies the logical font family as a string. theStyle specifies the individual style, such as bold or italic. theSize specifies the logical font size in points.
CFont(const CFont &theFont);
CFont & operator= (const CFont &theFont);
thefont.
~CFont();
void IFont(const CStringRW &theFamily,
XVT_FONT_STYLE_MASK theStyle,
long theSize,
const CStringRW &theNativeDesc = NULLString);
theFamily), style (theStyle), size (theSize), and native descriptor (theNativeDesc).
operator XVT_FNTID (void) const;
CFont object, this operator gets at the logical font ID (see "Using CFont with XVT Portability Toolkit Font Functions"). This operator is used with XVT Portability Toolkit font functions. Since this method returns a direct reference into internal information, use this method carefully. Specifically, do not use this method in cases in which the calling method might destroy or alter the handle.
CFont & operator= (XVT_FNTID theFontId);
friend BOOLEAN operator== (const CFont &theAFont,
const CFont &theBFont);
theAFont to theBFont and determines if they are equal. To use this operator, both fonts must be mapped. For a definition of "mapped," see "Mapped Font Methods," next.
friend BOOLEAN operator!= (const CFont &theAFont, const CFont &theBFont);
theAFont to theBFont and determines if they are not equal. To use this operator, both fonts must be mapped. For a definition of "mapped," see "Mapped Font Methods," next.
CWindow. Font mapping is the process of matching a logical font to the physical font that most closely resembles it. Once this match has been made, the logical font is "mapped."
void GetMetrics(int *theOutLeading,
int *theOutAscent, int *theOutDescent) const;
theOutLeading), ascent (theOutAscent), and descent (theOutDescent).
int GetLeading(void) const;
int GetAscent(void) const;
int GetDescent(void) const;
int GetHeight(void) const;
long GetTextWidth(const CStringRW &theStr) const;
theStr. This method is useful for calculating text layout, especially word wrapping. The text width is not always the sum of the widths of individual characters.
CStringRW GetMappedFamily(void) const;
XVT_FONT_STYLE_MASK GetMappedStyle(void) const;
long GetMappedSize(void) const;
void SetNativeDescription(
const CStringRW &theNativeDesc);
void SetFamily(const CStringRW &theFamily);
theFamily can be any valid string. The font mapper guarantees that the family will be mapped, regardless of what the family name is. However, if the family is the name of a logical font that does not exist as a physical font, is not handled by an application-supplied font mapper, or is not handled by URL extensions to the font mapper, the mapping result may not be a close fit.
void SetStyle(XVT_FONT_STYLE_MASK theStyle);
theStyle. This method overrides any existing style attributes of the specified logical font. If the logical font was previously mapped and the style changes, this method unmaps it.
void SetSize(long theSize);
theSize. If the logical font was previously mapped and the size changes, this method unmaps it.
CStringRW GetNativeDescription(void) const;
CStringRW GetFamily(void) const;
XVT_FONT_STYLE_MASK GetStyle(void) const;
long GetSize(void) const;
CStringRW Serialize(void) const;
void Deserialize(const CStringRW &theSerialStr);
void Map(CWindow *theCWindow);
This method is very useful if you need to set a single logical font in several windows simultaneously. By allowing the logical font to be mapped "up front," the system can avoid having to map several times when text is drawn in the windows.
void MapUsingDefault(void);
void Unmap(void);
BOOLEAN IsMapped(void) const;
TRUE if the logical font is mapped, and it returns FALSE otherwise.
BOOLEAN IsPrint(void) const;
TRUE if the logical font is mapped and the mapping is for a print window font, and it returns FALSE otherwise.
BOOLEAN IsScalable(void) const;
TRUE if the logical font is mapped and the mapped logical font is scalable, and it returns FALSE otherwise.
static const CFont & GetBestCtlFont(void);