home *** CD-ROM | disk | FTP | other *** search
- #ifndef _IFONTMGR_
- #define _IFONTMGR_
- /*******************************************************************************
- * FILE NAME: IFONTMGR.hpp *
- * *
- * DESCRIPTION: *
- * Declaration of the class(es): *
- * IFontMgr - Class to manage a font. *
- * *
- * COPYRIGHT: *
- * (C) Copyright IBM Corporation 1992 *
- * All Rights Reserved *
- * Licensed Materials * Property of IBM *
- * *
- * HISTORY: *
- *$Log: R:/IBMCLASS/IBASEAPP/VCS/IFONTMGR.HPV $ *
- //
- // Rev 1.3 25 Oct 1992 16:57:14 nunn
- // changed library name to ICLUI
- //
- // Rev 1.2 24 Oct 1992 17:37:52 tsuji
- // Format/documentation in the style of the standard header (by Tim Hertz).
- *******************************************************************************/
- #ifndef _IVBASE_
- #include <ivbase.hpp>
- #endif
- #ifndef _IHANDLE_
- #include <ihandle.hpp>
- #endif
-
- // Forward declarations for other classes:
- class IString;
- class IFontPkg;
-
- const unsigned long IC_DRAW_DEFAULT = 0;
- const unsigned long IC_DRAW_LEFTRIGHT = 1;
- const unsigned long IC_DRAW_TOPBOTTOM = 2;
- const unsigned long IC_DRAW_RIGHTLEFT = 3;
- const unsigned long IC_DRAW_BOTTOMTOP = 4;
-
- class IFontMgr : public IVBase
- /*******************************************************************************
- * This class manages the use of fonts. With it, you can select a font through *
- * its methods or by using the font dialog, you can get font metrics *
- * information, and you can use the font manager to set the font when drawing *
- * text. *
- * *
- * The font manager does its best to match the requested font, however, if *
- * an exact match can't be found, the font manager finds the nearest match. *
- * *
- * EXAMPLE: *
- * // To create the font manager: *
- * pFontMgr = new IFontMgr("Tms Rmn", 24); *
- * // Creates IFontMgr set to 24 point, Times Roman font. *
- * pFontMgr = new IFontMgr(whMyWindow); *
- * // Creates IFontMgr set to same font as used by whMyWindow *
- * pFontMgr = new IFontMgr; *
- * // Creates IFontMgr set to the system default font. *
- * *
- * // To draw using the font manager's font *
- * pfntm->beginUsingFont(evt.presSpaceHandle()); *
- * evt.drawText("Hello", IPoint(10, 50)); *
- * pfntm->endUsingFont(evt.presSpaceHandle()); *
- * *
- *******************************************************************************/
- {
- public :
- /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
- | There are 4 ways to construct instances of this class: |
- | 1. default |
- | Constructs a font manager for the default system font |
- | 2. A window's font |
- | Constructs a font manager with the same font that is being used |
- | in the window (represented by the window handle). |
- | 3. A specific font |
- | Constructs a font manager for font specified in the parameters. The |
- | parameters include the font's face name, its point size, its style |
- | flags, whether the font should be in bitmap form only, and whether |
- | the font should only be non-proportional. |
- | 4. A copy of another font manager |
- | Constructs a font manager with the same specification as the font |
- | manager that is passed in. |
- ------------------------------------------------------------------------------*/
- IFontMgr (IWindowHandle wh = 0);
- IFontMgr (const IFontPkg& fontpkg);
- IFontMgr (const char* const pszFaceName,
- unsigned long ulPointSize,
- unsigned long flStyle = 0,
- Boolean fBitmapOnly = false,
- Boolean fNonPropOnly = false);
- IFontMgr (const IFontMgr& fntmCopy);
-
- virtual
- ~IFontMgr ();
-
- /*-------------------------------- FONT TYPES ----------------------------------
- | These functions provide means of getting and setting the types of fonts |
- | used by the font manager: |
- | useNonPropOnly - Sets whether the font manager should only use non- |
- | proportional fonts only. |
- | useBitmapOnly - Sets whether the font manager should only use bitmap fonts.|
- | useVectorOnly - Sets whether the font manager should only use vector fonts.|
- | isNonPropOnly - Returns true if the font manager only uses non- |
- | proportional fonts. |
- | isBitmapOnly - Returns true if the font manager only uses bitmap fonts. |
- | isVectorOnly - Returns true if the font manager only uses vector fonts. |
- ------------------------------------------------------------------------------*/
- void
- useNonPropOnly (Boolean fDoIt = true),
- useBitmapOnly (Boolean fDoIt = true),
- useVectorOnly (Boolean fDoIt = true);
-
- Boolean
- isNonPropOnly () const,
- isBitmapOnly () const,
- isVectorOnly () const;
-
- /*--------------------- SETTING GENERAL FONT ATTRIBUTES ------------------------
- | Methods to set the attributes of any font being managed by the font manager. |
- | setFaceName - Sets the font's face name. |
- | setPointSize - Sets the font's point size. |
- | setFontDir - Sets which direction to draw the font. |
- | setFontStyle - Sets the font style flags. |
- | setFont - Sets the font and its point size with the font attributes |
- | structure. |
- ------------------------------------------------------------------------------*/
- void
- setFaceName (const char* const pszFaceName),
- setPointSize (unsigned long ulSize),
- setFontDir (long lFontDir),
- setFontStyle (unsigned long flFontStyle),
- setFont (const IFontPkg& fontpkg);
-
- /*---------------------SETTING VECTOR FONT ATTRIBUTES --------------------------
- | Methods to set the attributes of vector fonts. |
- | setCharWidth - Sets the width of the characters. |
- | setCharHeight - Sets the height of the characters. |
- | setFontAngle - Sets which angle to draw the font. |
- | setFontShear - Sets how much shear should be applied to the font. |
- ------------------------------------------------------------------------------*/
- void
- setCharWidth (unsigned long ulWidth),
- setCharHeight (unsigned long ulHeight),
- setFontAngle (long x, long y),
- setFontShear (long x, long y);
-
- /*------------------------- GETTING FONT ATTRIBUTES ----------------------------
- | Methods to get the attributes of the current font |
- | isNonProp - Returns true if the font is non-proportional |
- | isBitmap - Returns true if the font is a bitmap font, false if it is |
- | a vector font. |
- | faceName - Returns the face name of the font. |
- | presParamText - Returns the text needed to set the presentaion |
- | parameters string for a window (works for bitmap fonts only). |
- | pointSize - Returns the point size of the font |
- | fontStyle - Returns the style flags for the font. |
- | avgCharWidth - Returns the average character's width. |
- | maxCharHeight - Returns the height of the highest character. |
- | maxDescender - Returns the height of the largest descender below the |
- | baseline. |
- | externalLeading - Returns the amount of external leading space. |
- | charWidth - Returns the width of a specific character |
- | textWidth - Returns the width of a specific string |
- | textLines - Returns the number of lines required to fit the specified |
- | text, given the maximum width. |
- | minTextWidth - Returns the width of the widest word. |
- | fontAttributes - Returns the font attributes structure. |
- | fontMetrics - Returns the font metrics structure. |
- ------------------------------------------------------------------------------*/
- Boolean
- isNonProp (),
- isBitmap ();
-
- IString
- faceName (),
- presParamText ();
-
- unsigned long
- pointSize () const,
- fontStyle () const,
- avgCharWidth (),
- maxCharHeight (),
- maxDescender (),
- externalLeading (),
- charWidth (char c),
- textWidth (const char* const pszText),
- textLines (const char* const pszLine,
- unsigned long ulLineWidth),
- minTextWidth (const char* const pszLine);
-
- void
- *fontAttributes () const,
- *fontMetrics ();
-
-
- /*--------------------- DRAWING METHODS ----------------------------------------
- | Methods used to draw text using the font. |
- | beginUsingFont - Sets the presentation space to use the font. |
- | endUsingFont - Restore the presentation space to the default font. |
- ------------------------------------------------------------------------------*/
- void
- beginUsingFont (IPresSpaceHandle hps),
- endUsingFont (IPresSpaceHandle hps);
-
- protected:
- /*----------------------------- IMPLEMENTATION ---------------------------------
- | Methods used by the font manager. |
- | 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 manager's variables. |
- | fontChanged - Clears all information tied to a particular font. |
- | mustUseVector - Signals that the font manager must use a vector font |
- | to do what it needs to do. |
- ------------------------------------------------------------------------------*/
- void
- makeFontMetrics (),
- makeCharWidths (),
- checkForMatch (),
- initialize (IPresSpaceHandle hpsInit = 0),
- fontChanged (),
- mustUseVector (Boolean fDoIt = true);
-
- private :
- /*------------------------------ DATA MEMBERS ----------------------------------
- | flClStyle - Font flags for styles. |
- | 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;
-
- void
- *pfontmetCl,
- *pfattrsCl,
- *ptlClShear;
-
- long
- *plClCharWidths,
- fxClPointSize,
- fxClHeight,
- fxClWidth,
- lClFontDir,
- lClXAngle,
- lClYAngle,
- lClLCId;
-
- friend IFontPkg;
-
- };
-
- #endif /* _IFONTMGR_ */