home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / ifontmgr.hp_ / IFONTMGR.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  13.8 KB  |  262 lines

  1. #ifndef _IFONTMGR_
  2. #define _IFONTMGR_
  3. /*******************************************************************************
  4. * FILE NAME: IFONTMGR.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IFontMgr - Class to manage a font.                                       *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   (C) Copyright IBM Corporation 1992                                         *
  12. *   All Rights Reserved                                                        *
  13. *   Licensed Materials * Property of IBM                                       *
  14. *                                                                              *
  15. * HISTORY:                                                                     *
  16. *$Log:   R:/IBMCLASS/IBASEAPP/VCS/IFONTMGR.HPV  $                                                                         *
  17. // 
  18. //    Rev 1.3   25 Oct 1992 16:57:14   nunn
  19. // changed library name to ICLUI
  20. // 
  21. //    Rev 1.2   24 Oct 1992 17:37:52   tsuji
  22. // Format/documentation in the style of the standard header (by Tim Hertz).
  23. *******************************************************************************/
  24. #ifndef _IVBASE_
  25.   #include <ivbase.hpp>
  26. #endif
  27. #ifndef _IHANDLE_
  28.   #include <ihandle.hpp>
  29. #endif
  30.  
  31. // Forward declarations for other classes:
  32. class   IString;
  33. class   IFontPkg;
  34.  
  35. const unsigned long IC_DRAW_DEFAULT = 0;
  36. const unsigned long IC_DRAW_LEFTRIGHT = 1;
  37. const unsigned long IC_DRAW_TOPBOTTOM = 2;
  38. const unsigned long IC_DRAW_RIGHTLEFT = 3;
  39. const unsigned long IC_DRAW_BOTTOMTOP = 4;
  40.  
  41. class IFontMgr : public IVBase
  42. /*******************************************************************************
  43. * This class manages the use of fonts.  With it, you can select a font through *
  44. * its methods or by using the font dialog, you can get font metrics            *
  45. * information, and you can use the font manager to set the font when drawing   *
  46. * text.                                                                        *
  47. *                                                                              *
  48. * The font manager does its best to match the requested font, however, if      *
  49. * an exact match can't be found, the font manager finds the nearest match.     *
  50. *                                                                              *
  51. * EXAMPLE:                                                                     *
  52. *    // To create the font manager:                                            *
  53. *    pFontMgr = new IFontMgr("Tms Rmn", 24);                                   *
  54. *         // Creates IFontMgr set to 24 point, Times Roman font.               *
  55. *    pFontMgr = new IFontMgr(whMyWindow);                                      *
  56. *         // Creates IFontMgr set to same font as used by whMyWindow           *
  57. *    pFontMgr = new IFontMgr;                                                  *
  58. *         // Creates IFontMgr set to the system default font.                  *
  59. *                                                                              *
  60. *    // To draw using the font manager's font                                  *
  61. *    pfntm->beginUsingFont(evt.presSpaceHandle());                             *
  62. *    evt.drawText("Hello", IPoint(10, 50));                                    *
  63. *    pfntm->endUsingFont(evt.presSpaceHandle());                               *
  64. *                                                                              *
  65. *******************************************************************************/
  66. {
  67. public :
  68. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  69. | There are 4 ways to construct instances of this class:                       |
  70. |   1. default                                                                 |
  71. |      Constructs a font manager for the default system font                   |
  72. |   2. A window's font                                                         |
  73. |      Constructs a font manager with the same font that is being used         |
  74. |      in the window (represented by the window handle).                       |
  75. |   3. A specific font                                                         |
  76. |      Constructs a font manager for font specified in the parameters.  The    |
  77. |      parameters include the font's face name, its point size, its style      |
  78. |      flags, whether the font should be in bitmap form only, and whether      |
  79. |      the font should only be non-proportional.                               |
  80. |   4. A copy of another font manager                                          |
  81. |     Constructs a font manager with the same specification as the font        |
  82. |     manager that is passed in.                                               |
  83. ------------------------------------------------------------------------------*/
  84.     IFontMgr         (IWindowHandle wh = 0);
  85.     IFontMgr         (const IFontPkg& fontpkg);
  86.     IFontMgr         (const char* const pszFaceName,
  87.                       unsigned long ulPointSize,
  88.                       unsigned long flStyle = 0,
  89.                       Boolean fBitmapOnly = false,
  90.                       Boolean fNonPropOnly = false);
  91.     IFontMgr         (const IFontMgr& fntmCopy);
  92.  
  93. virtual
  94.     ~IFontMgr        ();
  95.  
  96. /*-------------------------------- FONT TYPES ----------------------------------
  97. | These functions provide means of getting and setting the types of fonts      |
  98. | used by the font manager:                                                    |
  99. |   useNonPropOnly - Sets whether the font manager should only use non-        |
  100. |      proportional fonts only.                                                |
  101. |   useBitmapOnly - Sets whether the font manager should only use bitmap fonts.|
  102. |   useVectorOnly - Sets whether the font manager should only use vector fonts.|
  103. |   isNonPropOnly - Returns true if the font manager only uses non-            |
  104. |      proportional fonts.                                                     |
  105. |   isBitmapOnly - Returns true if the font manager only uses bitmap fonts.    |
  106. |   isVectorOnly - Returns true if the font manager only uses vector fonts.    |
  107. ------------------------------------------------------------------------------*/
  108. void
  109.    useNonPropOnly   (Boolean fDoIt = true),
  110.    useBitmapOnly    (Boolean fDoIt = true),
  111.    useVectorOnly    (Boolean fDoIt = true);
  112.  
  113. Boolean
  114.    isNonPropOnly    () const,
  115.    isBitmapOnly     () const,
  116.    isVectorOnly     () const;
  117.  
  118. /*--------------------- SETTING GENERAL FONT ATTRIBUTES ------------------------
  119. | Methods to set the attributes of any font being managed by the font manager. |
  120. |   setFaceName - Sets the font's face name.                                   |
  121. |   setPointSize - Sets the font's point size.                                 |
  122. |   setFontDir - Sets which direction to draw the font.                        |
  123. |   setFontStyle - Sets the font style flags.                                  |
  124. |   setFont - Sets the font and its point size with the font attributes        |
  125. |      structure.                                                              |
  126. ------------------------------------------------------------------------------*/
  127. void
  128.    setFaceName      (const char* const pszFaceName),
  129.    setPointSize     (unsigned long ulSize),
  130.    setFontDir       (long lFontDir),
  131.    setFontStyle     (unsigned long flFontStyle),
  132.    setFont          (const IFontPkg& fontpkg);
  133.  
  134. /*---------------------SETTING VECTOR FONT ATTRIBUTES --------------------------
  135. | Methods to set the attributes of vector fonts.                               |
  136. |   setCharWidth - Sets the width of the characters.                           |
  137. |   setCharHeight - Sets the height of the characters.                         |
  138. |   setFontAngle - Sets which angle to draw the font.                          |
  139. |   setFontShear - Sets how much shear should be applied to the font.          |
  140. ------------------------------------------------------------------------------*/
  141. void
  142.    setCharWidth     (unsigned long ulWidth),
  143.    setCharHeight    (unsigned long ulHeight),
  144.    setFontAngle     (long x, long y),
  145.    setFontShear     (long x, long y);
  146.  
  147. /*------------------------- GETTING FONT ATTRIBUTES ----------------------------
  148. | Methods to get the attributes of the current font                            |
  149. |   isNonProp - Returns true if the font is non-proportional                   |
  150. |   isBitmap - Returns true if the font is a bitmap font, false if it is       |
  151. |      a vector font.                                                          |
  152. |   faceName - Returns the face name of the font.                              |
  153. |   presParamText - Returns the text needed to set the presentaion             |
  154. |      parameters string for a window (works for bitmap fonts only).           |
  155. |   pointSize - Returns the point size of the font                             |
  156. |   fontStyle - Returns the style flags for the font.                          |
  157. |   avgCharWidth - Returns the average character's width.                      |
  158. |   maxCharHeight - Returns the height of the highest character.               |
  159. |   maxDescender - Returns the height of the largest descender below the       |
  160. |      baseline.                                                               |
  161. |   externalLeading - Returns the amount of external leading space.            |
  162. |   charWidth - Returns the width of a specific character                      |
  163. |   textWidth - Returns the width of a specific string                         |
  164. |   textLines - Returns the number of lines required to fit the specified      |
  165. |      text, given the maximum width.                                          |
  166. |   minTextWidth - Returns the width of the widest word.                       |
  167. |   fontAttributes - Returns the font attributes structure.                    |
  168. |   fontMetrics - Returns the font metrics structure.                          |
  169. ------------------------------------------------------------------------------*/
  170. Boolean
  171.    isNonProp        (),
  172.    isBitmap         ();
  173.  
  174. IString
  175.    faceName         (),
  176.    presParamText    ();
  177.  
  178. unsigned long
  179.    pointSize        () const,
  180.    fontStyle        () const,
  181.    avgCharWidth     (),
  182.    maxCharHeight    (),
  183.    maxDescender     (),
  184.    externalLeading  (),
  185.    charWidth        (char c),
  186.    textWidth        (const char* const pszText),
  187.    textLines        (const char* const pszLine,
  188.                      unsigned long ulLineWidth),
  189.    minTextWidth     (const char* const pszLine);
  190.  
  191. void
  192.    *fontAttributes   () const,
  193.    *fontMetrics      ();
  194.  
  195.  
  196. /*--------------------- DRAWING METHODS ----------------------------------------
  197. | Methods used to draw text using the font.                                    |
  198. |   beginUsingFont - Sets the presentation space to use the font.              |
  199. |   endUsingFont - Restore the presentation space to the default font.         |
  200. ------------------------------------------------------------------------------*/
  201. void
  202.    beginUsingFont   (IPresSpaceHandle hps),
  203.    endUsingFont     (IPresSpaceHandle hps);
  204.  
  205. protected:
  206. /*----------------------------- IMPLEMENTATION ---------------------------------
  207. | Methods used by the font manager.                                            |
  208. |   makeFontMetrics - Loads the font metrics for the selected font.            |
  209. |   makeCharWidths - Loads the widths of all the characters in the font.       |
  210. |   checkForMatch - Finds the best match for the desired font.                 |
  211. |   initialize - Initializes all the font manager's variables.                 |
  212. |   fontChanged - Clears all information tied to a particular font.            |
  213. |   mustUseVector - Signals that the font manager must use a vector font       |
  214. |      to do what it needs to do.                                              |
  215. ------------------------------------------------------------------------------*/
  216. void
  217.    makeFontMetrics  (),
  218.    makeCharWidths   (),
  219.    checkForMatch    (),
  220.    initialize       (IPresSpaceHandle hpsInit = 0),
  221.    fontChanged      (),
  222.    mustUseVector    (Boolean fDoIt = true);
  223.  
  224. private :
  225. /*------------------------------ DATA MEMBERS ----------------------------------
  226. |   flClStyle - Font flags for styles.                                         |
  227. |   pfontmetCl - Holds the font metrics for the font.                          |
  228. |   plClCharWidths - Holds the array of character widths for the font.         |
  229. |   pfattrsCl - Holds the font attributes structure.                           |
  230. |   fxClPointSize - Holds the point size for the font.                         |
  231. |   fxClHeight - Holds the character height.                                   |
  232. |   fxClWidth - Holds the character width.                                     |
  233. |   lClFontDir - Holds the direction to draw the font.                         |
  234. |   lClXAngle - Holds the X portion of the font angle                          |
  235. |   lClYAngle - Holds the Y portion of the font angle                          |
  236. |   ptlClShear - Holds the font shear.                                         |
  237. |   lClLCId - Holds the id uses for the logical font.                          |
  238. ------------------------------------------------------------------------------*/
  239. unsigned long
  240.    flClStyles;
  241.  
  242. void
  243.    *pfontmetCl,
  244.    *pfattrsCl,
  245.    *ptlClShear;
  246.  
  247. long
  248.    *plClCharWidths,
  249.    fxClPointSize,
  250.    fxClHeight,
  251.    fxClWidth,
  252.    lClFontDir,
  253.    lClXAngle,
  254.    lClYAngle,
  255.    lClLCId;
  256.  
  257. friend IFontPkg;
  258.  
  259. };
  260.  
  261. #endif /* _IFONTMGR_ */
  262.