home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / font.h < prev    next >
C/C++ Source or Header  |  1995-04-09  |  7KB  |  251 lines

  1. #ifndef _font_h_
  2. #define _font_h_
  3.  
  4.  
  5.  
  6.  
  7.  
  8. /*
  9.  *
  10.  *          Copyright (C) 1994, M. A. Sridhar
  11.  *  
  12.  *
  13.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  14.  *     to copy, modify or distribute this software  as you see fit,
  15.  *     and to use  it  for  any  purpose, provided   this copyright
  16.  *     notice and the following   disclaimer are included  with all
  17.  *     copies.
  18.  *
  19.  *                        DISCLAIMER
  20.  *
  21.  *     The author makes no warranties, either expressed or implied,
  22.  *     with respect  to  this  software, its  quality, performance,
  23.  *     merchantability, or fitness for any particular purpose. This
  24.  *     software is distributed  AS IS.  The  user of this  software
  25.  *     assumes all risks  as to its quality  and performance. In no
  26.  *     event shall the author be liable for any direct, indirect or
  27.  *     consequential damages, even if the  author has been  advised
  28.  *     as to the possibility of such damages.
  29.  *
  30.  */
  31.  
  32.  
  33.  
  34. // Authors:   M. A. Sridhar
  35. //            N. Bhowmik
  36.  
  37. // Modified:  R. Sampath, Dec 1994
  38.  
  39.  
  40.  
  41. // The Font class represents a single font of the underlying windowing
  42. // system, together with point size, type style and other attributes. An
  43. // instance of this class cannot be created independently; it can only be
  44. // created by the VisualObject and DrawingSurface classes. Every Font
  45. // instance is owned by a corresponding VisualObject or DrawingSurface
  46. // instance.
  47.  
  48.  
  49. #if defined(__GNUC__)
  50. #pragma interface
  51. #endif
  52.  
  53.  
  54.  
  55. #include "base/string.h"
  56. #include "base/sequence.h"
  57.  
  58. #include "ui/dsplrsrc.h"
  59. #include "ui/fontdesc.h"
  60.  
  61.  
  62. #if defined(__MS_WINDOWS__)
  63. typedef ulong UI_NativeFontRep;
  64.  
  65. // Definitions of three common font names:
  66. #define UIFont_Times      "Times New Roman"
  67. #define UIFont_Courier    "Courier"
  68. #define UIFont_Helvetica  "Arial"
  69.  
  70. #elif defined (__X_MOTIF__)
  71. typedef CL_String UI_NativeFontRep;
  72.  
  73. // Definitions of three common font names:
  74. #define UIFont_Times      "times"
  75. #define UIFont_Courier    "courier"
  76. #define UIFont_Helvetica  "helvetica"
  77.  
  78. #elif defined (__OS2__)
  79. typedef ulong UI_NativeFontRep;
  80.  
  81. // Definitions of three common font names:
  82. #define UIFont_Times      "Times New Roman"
  83. #define UIFont_Courier    "Courier"
  84. #define UIFont_Helvetica  "Helvetica"
  85.  
  86. #endif
  87.  
  88. class CL_EXPORT UI_VisualObject;
  89.  
  90. class CL_EXPORT UI_Font: public UI_DisplayResource {
  91.  
  92. public:
  93.  
  94.     long Height () const;
  95.     // Return the height of each character, in pixels.
  96.  
  97.     long Width  () const;
  98.     // Return the average width of a character, in pixels.
  99.  
  100.     long Width (const char* string) const;
  101.     // Return the width, in pixels, of the box containing {\tt string}, if
  102.     // it were to be drawn on the DrawingSurface that owns this Font.
  103.     
  104.     short PointSize() const;
  105.     // Return the point size of this font.
  106.  
  107.     CL_String TypeFace() const;
  108.     // Return the name of the type face.
  109.  
  110.     bool IsFixed () const;
  111.     // Return whether this is a fixed-width font (i.e., all characters have
  112.     // the same width).
  113.  
  114.     ulong Style () const {return _style; };
  115.     // Return the style parameters for this Font.
  116.     
  117.     
  118.     bool Italic() const;
  119.     // Return whether this is an italic font.
  120.  
  121.     bool Underline() const;
  122.     // Return whether this font has the underline attribute.
  123.  
  124.     bool BoldFace() const;
  125.     // Return whether this is a boldface font.
  126.  
  127.     bool StrikeOut() const;
  128.     // Return whether this font has the strike-out attribute.
  129.  
  130.     short Ascent ()  const;
  131.     // Return the ascent of this font, in pixels.
  132.  
  133.     short Descent () const;
  134.     // Return the descent of this font, in pixels.
  135.  
  136.     bool IsScalable () const;
  137.     // Return whether this font is scalable to arbitrary point sizes.
  138.     
  139.     void PointSize (short ptSize);
  140.     // Set the point size of this font to the given size.
  141.  
  142.     void TypeFace  (const char* new_type_face);
  143.     // Set the type face name of this font.
  144.  
  145.     void Italic    (bool );
  146.     // Set the italic attribute for this font.
  147.  
  148.     void Underline (bool );
  149.     // Set the underline attribute for this font.
  150.  
  151.     void BoldFace  (bool );
  152.     // Set the boldface attribute for this font.
  153.  
  154.     void StrikeOut (bool );
  155.     // Set the strike-out attribute for this font.
  156.  
  157.     void operator= (const UI_FontDesc& desc);
  158.     // Modify this Font according to the contents of the given descriptor.
  159.  
  160.     void operator= (const CL_Object& o);
  161.     // The parameter is required to be of type {\tt UI_FontDesc}. This
  162.     // method is provided so that the virtual assignment operator does not
  163.     // become hidden.
  164.  
  165. #if defined(__X_MOTIF__)
  166.     void operator= (const char* native_name);
  167.     // [X-windows-specific] Use the font whose fully-qualified name is
  168.     // {\tt native_name}.
  169.  
  170. #endif
  171.     
  172.     static const CL_Sequence<UI_FontInfo>& AvailableFonts ();
  173.     // Return a reference to a sequence containing all available fonts.
  174.     
  175.     const char* ClassName() const { return "UI_Font";};
  176.     // Override the method inherited from {\small\tt CL_Object}.
  177.  
  178. protected:
  179.  
  180.     void    _Setup ();
  181.     // This method is called when any of the Font's attributes changes. It
  182.     // sets up the new font handle.
  183.  
  184.     void _Init (UI_VisualObject* v = NULL);
  185.     
  186. #if defined(__MS_WINDOWS__) || defined(__X_MOTIF__)
  187.     void    _Setup (UI_NativeFontRep nativename);
  188.     
  189. #endif
  190.  
  191.     short             _ptSize;
  192.     CL_String         _typeFace;
  193.     UI_NativeFontRep  _nativeName;
  194.     ulong             _style;
  195.     bool              _stockFont;
  196.     long              _height;
  197.     long              _width;
  198.  
  199.     void* _entry;
  200.  
  201.     static CL_Sequence<UI_FontInfo> _allFonts;
  202.  
  203. #if defined(__MS_WINDOWS__)
  204. private:
  205.     static long _ppi; // Pixels per inch: used during font enumeration
  206. #endif
  207.     
  208. public:
  209. #if defined(__MS_WINDOWS__)
  210.     static void _AddFont (void*, void*, int);
  211.     // [MS-Windows-specific; YACL internal use only]
  212.  
  213. #elif defined(__X_MOTIF__)
  214.     long TextWidth (const CL_String& s) const;
  215.     // [X-windows-specific; YACL internal use only]
  216.  
  217. #endif
  218.  
  219.     void*  NativeFontStruct () const;
  220.     // [YACL internal use only]
  221.     
  222.     UI_Font (UI_VisualObject* client = NULL);
  223.     // [Internal use only] Create the platform's default font for the given
  224.     // client, if any.
  225.  
  226.     UI_Font (const CL_String& typeface, short ptSize, ulong style = 0);
  227.     // [Internal use only] Create a font with the given attributes. The last
  228.     // parameter is a disjunction of {\tt UIFont_Style} elements.
  229.     
  230.     UI_Font (UI_DrawingSurface*);
  231.     // [Internal use only] Create a font for the given surface.
  232.  
  233.     UI_Font (const UI_Font&);
  234.     // [Internal use only] Copy constructor.
  235.  
  236.     ~UI_Font ();
  237.     // [Internal use only] Destructor.
  238.  
  239.     void UseClient (UI_DrawingSurface* sfc);
  240.     // [Internal use only]
  241.     
  242. };
  243.  
  244.  
  245.  
  246.  
  247. #endif
  248.  
  249.  
  250.  
  251.