home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IFONT.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
24KB
|
433 lines
#ifndef _IFONT_
#define _IFONT_
/*******************************************************************************
* FILE NAME: IFONT.HPP *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* IFont - Class to manage a font. *
* *
* COPYRIGHT: *
* (C) Copyright IBM Corporation 1992 *
* All Rights Reserved *
* Licensed Materials * Property of IBM *
* *
* HISTORY: *
*******************************************************************************/
#ifndef _IVBASE_
#include <ivbase.hpp>
#endif
#ifndef _IHANDLE_
#include <ihandle.hpp>
#endif
#ifndef _IPOINT_
#include <ipoint.hpp>
#endif
#ifndef _ICONTROL_
#include <icontrol.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
// Forward declarations for other classes:
class IString;
class IWindow;
class IFontDialog;
struct _FATTRS;
struct _FONTMETRICS;
class IFont : public IVBase {
typedef IVBase Inherited;
/*******************************************************************************
* The IFont class manages the use of fonts. You can use it to select a font *
* through its functions. You can also use the font dialog to get font *
* information and set the font when drawing text. *
* *
* The font attempts to match the requested font. If an exact match cannot be *
* found, the font uses the nearest match. *
* *
* NOTE: Many of the set functions (such as setName and setPoint) have an *
* optional final argument of type IPresSpaceHandle. You should supply *
* this argument if you want IFont to use a presentation space other *
* than that associated with the desktop. This is needed when the *
* instantiated IFont object is for handling printer fonts. *
* *
* Example: *
* // To create the font *
* pFont = new IFont("Tms Rmn", 24); *
* // Creates IFont set to 24 point, Times Roman font. *
* pFont = new IFont(myWindow); *
* // Creates IFont set to same font as used by whMyWindow *
* pFont = new IFont; *
* // Creates IFont set to the system default font. *
* *
* // To draw using the font inside an IPaintHandler *
* *
* MyPaintHandler::paintWindow(IPaintEvt& evt) *
* { *
* pFont->beginUsingFont(evt.presSpaceHandle()); *
* evt.drawText("Hello", IPoint(10, 50)); *
* pFont->endUsingFont(evt.presSpaceHandle()); *
* } *
* *
*******************************************************************************/
public :
/*------------------------ Constructors/Destructor -----------------------------
| You can construct instances of this class in the following ways: |
| - Using a window's font. This constructs a font with the same font that |
| is being used in the window. If no window is specified, then the |
| system default font is used. |
| - Using a specific font. This constructs a font specified in the |
| arguments. |
| - From a presentation space. This constructs a font that corresponds to |
| the one being used in the passed-in presentation space. |
| - From a copy of another font. This constructs a font with the same |
| specification as the font that is passed in. |
------------------------------------------------------------------------------*/
IFont (const IWindow* window = 0);
IFont (const char* faceName,
unsigned long ulPointSize = 0,
Boolean useFixedFont = false,
Boolean useVectorFont = false,
IPresSpaceHandle hpsInit = 0);
IFont (const IPresSpaceHandle& presSpace);
IFont (const IFont& fntCopy);
virtual
~IFont ();
/*--------------------- Enumerator ---------------------------------------------
| Direction - Returns the direction in which the font is drawn. This value |
| is used as input to the setDirection function. The valid |
| directions are: |
| - defaultDir (the default direction) |
| - leftRight (left-to-right) |
| - topBottom (top-to-bottom) |
| - rightLeft (right-to-left) |
| - bottomTop (bottom-to-top) |
------------------------------------------------------------------------------*/
enum Direction {defaultDir, leftRight, topBottom, rightLeft, bottomTop};
/*--------------------- Setting General Font Attributes ------------------------
| The following functions are used to set the attributes of any font being |
| managed by the IFont class: |
| setDirection - Sets the direction in which to draw the font. Valid |
| values, as specified by the Direction enumeration, are: |
| - defaultDir (the default direction) |
| - leftRight (left-to-right) |
| - topBottom (top-to-bottom) |
| - rightLeft (right-to-left) |
| - bottomTop (bottom-to-top) |
| setName - Sets the font's face name. |
| setPointSize - Sets the font's point size. |
------------------------------------------------------------------------------*/
IFont
&setDirection (Direction direction),
&setName (const char* name,
IPresSpaceHandle hpsInit = 0),
&setPointSize (unsigned long size,
IPresSpaceHandle hpsInit = 0);
/*------------------- Setting Font Style ---------------------------------------
| The following functions are used to change the appearance of a font: |
| setBold - Changes to bold font. |
| setItalic - Changes to italic font. |
| setUnderscore - Causes a line to appear under the characters. |
| setStrikeout - Puts a line through the characters. |
| setOutline - Causes the font to appear hollow. |
| setAllEmphasis - If true is passed in, all of the styles are set on. |
| If false is passed in, all of the styles are set off. |
------------------------------------------------------------------------------*/
IFont
&setBold (Boolean bold = true),
&setItalic (Boolean italics = true),
&setUnderscore (Boolean underscore = true),
&setStrikeout (Boolean strikeout = true),
&setOutline (Boolean outline = true),
&setAllEmphasis (Boolean turnOn = true);
/*------------------- Getting Font Style ---------------------------------------
| The following functions are used to query the appearance of a font: |
| isBold - Queries whether the font is bold. |
| isItalic - Queries whether the font is italic. |
| isUnderscore - Queries whether a line appears under the characters. |
| isStrikeout - Queries whether a line is drawn through the characters. |
| isOutline - Queries whether the font appears hollow. |
------------------------------------------------------------------------------*/
Boolean
isBold ( ) const,
isItalic ( ) const,
isUnderscore ( ) const,
isStrikeout ( ) const,
isOutline ( ) const;
/*------------------------- Getting Font Attributes ----------------------------
| The following functions are used to get the attributes of the current font: |
| isBitmap - Returns true for a bit-map font, and false for a vector font. |
| isFixed - Returns true if the font is fixed size (non-proportional). |
| name - Returns the face name of the font. |
| pointSize - Returns the point size of the font. |
------------------------------------------------------------------------------*/
Boolean
isBitmap () const,
isFixed () const;
IString
name () const;
unsigned long
pointSize () const;
/*------------------------ Geometry Accessors-----------------------------------
| The following functions return information about size of the font: |
| maxSize - Returns the maximum width and height. |
| maxCharHeight - Returns the height portion of maxSize. |
| maxUppercaseSize - Returns the maximum size for an uppercase |
| character. |
| superscriptSize - Returns the recommended size for superscripts. |
| subscriptSize - Returns the recommended size for subscripts. |
| superscriptOffset - Returns the recommended size of the baseline X-Y |
| offset for superscripts. |
| subscriptOffset - Returns the recommended size of the baseline X-Y |
| offset for subscripts. |
| avgCharWidth - Returns the average character's width. |
| avgLowercase - Returns the nominal height above the baseline for |
| lowercase characters. |
| avgUppercase - Returns the height of the Em square. This |
| corresponds to the point size. |
| maxAscender - Returns the height of the largest ascender above |
| the baseline. |
| maxDescender - Returns the height of the largest descender below |
| the baseline. |
| maxLowercaseAscender - Returns the height of the largest lowercase |
| ascender. |
| maxLowercaseDescender - Returns the height of the largest lowercase |
| descender. |
| internalLeading - Returns the approximate visual top to a row of |
| characters. The recommended use of this value is |
| to position the first line of a block of text by |
| subtracting it from the value returned by the |
| maxAscender function and positioning the baseline |
| that distance below whatever is above the text. |
| externalLeading - Returns the amount of white space that should |
| appear between adjacent rows of text. |
| charWidth - Returns the width of a specific single-byte |
| character. The c argument can only be an SBCS |
| character. This member function is not |
| DBCS-enabled. |
| textWidth - Returns the width of a specific string. The text |
| argument can only point to an SBCS string. This |
| member function is not DBCS-enabled. |
| textLines - Returns the number of lines required to fit the |
| specified text, given the maximum width. The |
| text argument can only point to an SBCS string. |
| This member function is not DBCS-enabled. |
| minTextWidth - Returns the width of the widest word. The line |
| argument can only point to an SBCS string. This |
| member function is not DBCS-enabled. |
------------------------------------------------------------------------------*/
ISize
maxSize ( ) const,
maxUppercaseSize ( ) const,
superscriptSize ( ) const,
subscriptSize ( ) const,
superscriptOffset ( ) const,
subscriptOffset ( ) const;
unsigned long
maxCharHeight ( ) const,
avgCharWidth ( ) const,
avgLowercase ( ) const,
avgUppercase ( ) const,
maxAscender () const,
maxDescender () const,
maxLowercaseAscender ( ) const,
maxLowercaseDescender ( ) const,
internalLeading ( ) const,
externalLeading () const,
charWidth (char c) const,
textWidth (const char* text) const,
textLines (const char* text,
unsigned long lineWidth) const,
minTextWidth (const char* line) const;
/*-------------- Applying the Current Font to a Window -------------------------
| The following function is used to apply the current font: |
| setWindowFont - Sets the specified IWindow's font to the current font. |
| This returns true if the font was successfully changed. |
------------------------------------------------------------------------------*/
Boolean
setWindowFont (IWindow* window) const;
/*--------------------- Setting Vector Font Attributes -------------------------
| The following functions are used to set the attributes of vector fonts. |
| These functions have no effect when applied to a bit-map font. |
| setCharWidth - Sets the width of the characters. |
| setCharHeight - Sets the height of the characters. |
| setCharSize - Sets the size of the characters. |
| setFontAngle - Sets the angle with which to draw the font. |
| setFontShear - Sets how much shear should be applied to the font. |
------------------------------------------------------------------------------*/
IFont
&setCharWidth (unsigned long width,
IPresSpaceHandle hpsInit = 0),
&setCharHeight (unsigned long height,
IPresSpaceHandle hpsInit = 0),
&setCharSize (const ISize& size,
IPresSpaceHandle hpsInit = 0),
&setFontAngle (const IPoint& point,
IPresSpaceHandle hpsInit = 0),
&setFontShear (const IPoint& point,
IPresSpaceHandle hpsInit = 0);
/*--------------------- Drawing Functions --------------------------------------
| The following functions are used to draw text using the font: |
| beginUsingFont - Sets the presentation space to use the font. |
| endUsingFont - Restores the presentation space to the default font. |
------------------------------------------------------------------------------*/
IFont
&beginUsingFont (IPresSpaceHandle hps),
&endUsingFont (IPresSpaceHandle hps);
/*-------------------------------- Font Types ----------------------------------
| These functions provide means of getting and setting the types of fonts |
| used by the IFont object: |
| useNonPropOnly - Sets whether the IFont object should use only |
| nonproportional fonts. |
| useBitmapOnly - Sets whether the IFont object should use only bit-map |
| fonts. |
| useVectorOnly - Sets whether the IFont object should use only vector |
| fonts. |
| isNonPropOnly - Returns true if the IFont object uses only |
| nonproportional fonts. |
| isBitmapOnly - Returns true if the IFont object uses only bit-map fonts. |
| isVectorOnly - Returns true if the IFont object uses only vector fonts. |
------------------------------------------------------------------------------*/
IFont
&useNonPropOnly (Boolean fDoIt = true,
IPresSpaceHandle hpsInit = 0),
&useBitmapOnly (Boolean fDoIt = true,
IPresSpaceHandle hpsInit = 0),
&useVectorOnly (Boolean fDoIt = true,
IPresSpaceHandle hpsInit = 0);
Boolean
isNonPropOnly () const,
isBitmapOnly () const,
isVectorOnly () const;
/*---------- Accessing Presentation Manager Structures Related to Font ---------
| The following functions are used to access Presentation Manager structures: |
| fattrs - Returns a pointer to the font's Presentation Manager FATTRS |
| structure. |
| fontmetrics - Returns a pointer to the font's Presentation Manager |
| FONTMETRICS structure. |
------------------------------------------------------------------------------*/
const struct _FATTRS*
fattrs () const;
const struct _FONTMETRICS*
fontmetrics () const;
private : /*------------------------------------------------------------------*/
// calls setFontFromDialog()
friend void* _System
_IFontDlgProc(unsigned long hwnd, unsigned long ulMsg, void* mp1, void* mp2);
/*----------------------------- Implementation ---------------------------------
| The following functions are used by the font: |
| copyWidthsArray - used by IControl to cache widths array. Helps improve |
| canvas performance. |
| makeFontMetrics - Loads the font metrics for the selected font. |
| makeCharWidths - Loads the widths of all the characters in the font. |
| checkForMatch - Finds the best match for the desired font. |
| initialize - Initializes all the font's variables. |
| fontChanged - Clears all information tied to a particular font. |
| mustUseVector - Signals that the font must use a vector font |
| to do what it needs to do. |
------------------------------------------------------------------------------*/
IFont
©WidthsArray (char * buf, unsigned long length),
&setFontFromDialog (IFontDialog& fontDlg,
IPresSpaceHandle hpsInit = 0),
&makeFontMetrics (IPresSpaceHandle hpsInit = 0),
&makeCharWidths (IPresSpaceHandle hpsInit = 0),
&checkForMatch (IPresSpaceHandle hpsInit = 0),
&initialize (IPresSpaceHandle hpsInit = 0),
&fontChanged (),
&mustUseVector (Boolean fDoIt = true),
&setWidthHeight (unsigned long ulPointSize,
IPresSpaceHandle hpsInit = 0),
&setSizeFromHps (unsigned long ulSize,
IPresSpaceHandle hpsInit = 0);
/*------------------------------ Data Members ----------------------------------
| The following data members are used to different font values: |
| pfontmetCl - Holds the font metrics for the font. |
| plClCharWidths - Holds the array of character widths for the font. |
| pfattrsCl - Holds the font attributes structure. |
| fxClPointSize - Holds the point size for the font. |
| fxClHeight - Holds the character height. |
| fxClWidth - Holds the character width. |
| lClFontDir - Holds the direction to draw the font. |
| lClXAngle - Holds the X portion of the font angle. |
| lClYAngle - Holds the Y portion of the font angle. |
| ptlClShear - Holds the font shear. |
| lClLCId - Holds the ID uses for the logical font. |
------------------------------------------------------------------------------*/
unsigned long
flClStyles;
struct _FONTMETRICS
*pfontmetCl;
struct _FATTRS
*pfattrsCl;
IPoint
pntClAngle,
pntClShear;
long
*plClCharWidths,
fxClPointSize,
fxClHeight,
fxClWidth,
lClFontDir,
lClLCId;
};
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
// Because of ToolKit dependencies, none of the inlineable stuff can be
// inlined right now...
#ifndef I_NO_INLINES
#include <ifont.inl>
#endif
#endif /* _IFONT_ */