[Classes] [Prev] [Next] [Methods]

CFont

Methods Index

Heritage
Description
Usage
Protected Data Members
Public Methods
Constructor, Destructor, and Initializer Methods
Helper Operators
Mapped Font Methods
Font State Methods

CFont


Heritage

Superclass: None

Subclasses: None


Description

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:

The XVT portability Toolkit provides the 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.

Table 8. XVT Portability Toolkit Logical Font Family Name Constants
Constant Font Family Name
#define XVT_FFN_TIMES ... "Times"
#define XVT_FFN_HELVETICA ... "Helvetica"
#define XVT_FFN_COURIER ... "Courier"
#define XVT_FFN_FIXED ... "Fixed"
#define XVT_FFN_SYSTEM ... "System"

The XVT Portability Toolkit supplies the 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.

Table 9. XVT Portability Toolkit Logical Font Style Constants
Constant Font Style
#define XVT_FS_NONE ... None
#define XVT_FS_BOLD ... Bold
#define XVT_FS_ITALIC ... Italic
#define XVT_FS_UNDERLINE ... Underline
#define XVT_FS_OUTLINE ... Outline
#define XVT_FS_SHADOW ... Shadow
#define XVT_FS_INVERSE ... Inverse
#define XVT_FS_BLINK ... Blinking
#define XVT_FS_STRIKEOUT ... Strikeout
#define XVT_FS_USER1 ... For application use
#define XVT_FS_USER2 ... For application use
#define XVT_FS_USER3 ... For application use
#define XVT_FS_USER4 ... For application use
#define XVT_FS_USER5 ... For application use
#define XVT_FS_WILDCARD ... Used only in URL-created logical fonts


Usage

The following examples illustrate several uses of CFont:

Portably

CFont aFont(XVT_FFN_HELVETICA, XVT_FS_BOLD, 9);

Natively

CFont aFont("...native description...");

Generally

int anAsc = aFont.GetAscent();
aFont.SetStyle(XVT_FS_NONE);

From Resources

CFont aFont(FONT_RES_ID);

With Environments

CText *aText = new CText(itsEnclosure,
CPoint(25, 25), "Hey!");
CEnvironment *anEnv = aText->GetEnvironment();
anEnv->SetFont(aFont);
aText->DoDraw();

With Primitives

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

Using CFont with XVT Portability Toolkit Font Functions

You should use 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(...);

Protected Data Members

XVT_FNTID itsFontId; The logical font ID
static CFontRegistry* itsRegistry Global registry of font objects
static int itsRegistryCreationCount Number of registry references


Public Methods

Constructor, Destructor, and Initializer Methods

CFont();
CFont(int theResId);
CFont(XVT_FNTID theFontId);
CFont(const CStringRW &theNativeDesc);
CFont(const CStringRW &theFamily,
XVT_FONT_STYLE_MASK theStyle,
long theSize);
CFont(const CFont &theFont);
CFont & operator= (const CFont &theFont);
~CFont();
void IFont(const CStringRW &theFamily, 
XVT_FONT_STYLE_MASK theStyle,
long theSize,
const CStringRW &theNativeDesc = NULLString);

Helper Operators

operator XVT_FNTID (void) const;																		
CFont & operator= (XVT_FNTID theFontId);
friend BOOLEAN operator== (const CFont &theAFont, 
const CFont &theBFont);
friend BOOLEAN operator!= (const CFont &theAFont,		const CFont &theBFont); 

Mapped Font Methods

For the following methods, the font must be mapped to a 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;
int GetLeading(void) const;
int GetAscent(void) const;
int GetDescent(void) const;
int GetHeight(void) const;
long GetTextWidth(const CStringRW &theStr) const;
CStringRW GetMappedFamily(void) const;
XVT_FONT_STYLE_MASK GetMappedStyle(void) const; 
long GetMappedSize(void) const;

Font State Methods

void SetNativeDescription(
const CStringRW &theNativeDesc);
void SetFamily(const CStringRW &theFamily);
void SetStyle(XVT_FONT_STYLE_MASK theStyle);
void SetSize(long theSize);
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);
void MapUsingDefault(void);
void Unmap(void);
BOOLEAN IsMapped(void) const;
BOOLEAN IsPrint(void) const;
BOOLEAN IsScalable(void) const;
static const CFont & GetBestCtlFont(void);


[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.