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

  1.  
  2. #if defined(__GNUC__)
  3. #pragma implementation
  4. #endif
  5.  
  6.  
  7. #include "ui/fontdesc.h"
  8.  
  9.  
  10.  
  11. UI_FontDesc::UI_FontDesc (const char* type_face, short point_size,
  12.                           ulong style_enum)
  13. : _typeFace (type_face), _ptSize (point_size), _style (style_enum)
  14. {
  15. }
  16.  
  17.  
  18. UI_FontDesc::UI_FontDesc ()
  19. {
  20. }
  21.  
  22. void UI_FontDesc::operator= (const CL_Object& o)
  23. {
  24.     if (o.IsA (*this))
  25.         *this = ((const UI_FontInfo&) o);
  26. }
  27.  
  28.  
  29. UI_FontDesc& UI_FontDesc::operator= (const UI_FontDesc& o)
  30. {
  31.     _typeFace    = o._typeFace;
  32.     _ptSize      = o._ptSize;
  33.     _style       = o._style;
  34.     return *this;
  35. }
  36.  
  37.  
  38.  
  39. short UI_FontDesc::Compare (const CL_Object& o) const
  40. {
  41.     if (o.IsA (*this))
  42.         return Compare ((const UI_FontDesc&) o);
  43.     return -1;
  44. }
  45.  
  46. short UI_FontDesc::Compare (const UI_FontDesc& o) const
  47. {
  48.     short cmp = _typeFace.Compare (o._typeFace);
  49.     if (!cmp) {
  50.         if (_ptSize == o._ptSize) {
  51.             if (_style == o._style)
  52.                 return 0;
  53.             return _style < o._style ? -1 : 1;
  54.         }
  55.         return _ptSize < o._ptSize ? -1 : 1;
  56.     }
  57.     return cmp;
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. // -------------------------- UI_FontInfo --------------------------------
  65.  
  66.  
  67. UI_FontInfo::UI_FontInfo ()
  68. {
  69. #if defined(__MS_WINDOWS__)
  70.     _scalable = FALSE;
  71. #endif
  72.  
  73. #if defined(__X_MOTIF__)
  74.     _fixedWidth = TRUE;
  75. #endif
  76. }
  77.  
  78. UI_FontInfo::UI_FontInfo (const char* type_face, short point_size,
  79.                           ulong style_enum, bool f)
  80. : UI_FontDesc (type_face, point_size, style_enum)
  81. {
  82.     _scalable = f;
  83.  
  84. #if defined(__X_MOTIF__)
  85.     _fixedWidth = !f; // ?? FIX THIS
  86. #endif
  87. }
  88.  
  89.  
  90. short UI_FontInfo::Compare (const CL_Object& o) const
  91. {
  92.     if (o.IsA (*this))
  93.         return Compare ((const UI_FontInfo&) o);
  94.     return -1;
  95. }
  96.  
  97. short UI_FontInfo::Compare (const UI_FontInfo& o) const
  98. {
  99.     short cmp = _typeFace.Compare (o._typeFace);
  100.     if (!cmp) {
  101.         if (_ptSize == o._ptSize) {
  102.             if (_style == o._style) {
  103.                 if (_scalable == o._scalable)
  104.                     return 0;
  105.                 return _scalable < o._scalable ? -1 : 1;
  106.             }
  107.             return _style < o._style ? -1 : 1;
  108.         }
  109.         return _ptSize < o._ptSize ? -1 : 1;
  110.     }
  111.     return cmp;
  112. }
  113.  
  114.  
  115. void UI_FontInfo::operator= (const CL_Object& o)
  116. {
  117.     if (o.IsA (*this))
  118.         *this = ((const UI_FontInfo&) o);
  119. }
  120.  
  121.  
  122. UI_FontInfo& UI_FontInfo::operator= (const UI_FontInfo& o)
  123. {
  124.     UI_FontDesc::operator= (o);
  125. #if defined(__MS_WINDOWS__)
  126.     _scalable    = o._scalable;
  127. #endif
  128. #if defined(__X_MOTIF__)
  129.     _fixedWidth  = o._fixedWidth;
  130.     _realName    = o._realName;
  131. #endif
  132.     return *this;
  133. }
  134.  
  135.  
  136. CL_String UI_FontInfo::AsString () const
  137. {
  138.     
  139.     CL_String s = "'" + _typeFace + "'";
  140.     if (_scalable)
  141.         s += " scalable";
  142.     else
  143.         s +=  " " + CL_String(_ptSize) + " points";
  144. #if defined(__X_MOTIF__)
  145.     s += " " + CL_String (_fixedWidth ? "(fixed) " : "(variable)");
  146. #endif
  147.     if (_style & UIFont_Italic)
  148.         s += " italic";
  149.     if (_style & UIFont_Underline)
  150.         s += " underlined";
  151.     if (_style & UIFont_BoldFace)
  152.         s += " bold";
  153.     if (_style & UIFont_StrikeOut)
  154.         s += " strikeout";
  155.     return s;
  156. }
  157.  
  158.