home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WFONT.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  13KB  |  442 lines

  1. /**********************************************************************
  2.  *
  3.  * wfont.cpp -- Generalized font support.
  4.  *
  5.  **********************************************************************/
  6.  
  7. #ifndef _WFONT_HPP_INCLUDED
  8. #define _WFONT_HPP_INCLUDED
  9.  
  10. #ifndef _WNO_PRAGMA_PUSH
  11. #pragma pack(push,8);
  12. #pragma enum int;
  13. #endif
  14.  
  15. #ifndef _WSTRING_HPP_INCLUDED
  16. #  include "wstring.hpp"
  17. #endif
  18. #ifndef _WCANVAS_HPP_INCLUDED
  19. #  include "wcanvas.hpp"
  20. #endif
  21.  
  22. //
  23. // Stock fonts -- These are system fonts that are always available.
  24. //
  25.  
  26. enum WFStockFont {
  27.     WFInheritedFont             = -1,
  28.     WFNullFont                  = 0,
  29.  
  30.     WFOEMFixedFont              = 10,
  31.     WFFirstStockFont = WFOEMFixedFont,
  32.  
  33.     WFAnsiFixedFont             = 11,
  34.     WFAnsiFont                  = 12,
  35.     WFSystemFont                = 13,
  36.     WFDeviceDefaultFont         = 14,
  37.     WFSystemFixedFont           = 16,
  38.     WFDefaultGUIFont            = 17,
  39.  
  40.     WFLastStockFontPlusOne,
  41.     WFLastStockFont = WFLastStockFontPlusOne - 1
  42. };
  43.  
  44. //
  45. // Boldness values
  46. //
  47.  
  48. enum WFBoldType {
  49.     WFUnknownBold               = 0,
  50.     WFThin                      = 100,
  51.     WFExtraLight                = 200,
  52.     WFLight                     = 300,
  53.     WFNormal                    = 400,
  54.     WFMedium                    = 500,
  55.     WFSemiBold                  = 600,
  56.     WFBold                      = 700,
  57.     WFExtraBold                 = 800,
  58.     WFHeavy                     = 900,
  59. };
  60.  
  61. //
  62. // Character sets
  63. //
  64.  
  65. enum WFCharSetType {
  66.     WFAnsiCharSet               = 0,
  67.     WFDefaultCharSet            = 1,
  68.     WFSymbolCharSet             = 2,
  69.     WFMacCharSet                = 77,
  70.     WFShiftJisCharSet           = 128,
  71.     WFHangeulCharSet            = 129,
  72.     WFJohabCharSet              = 130,
  73.     WFGB2312CharSet             = 134,
  74.     WFChineseBig5CharSet        = 136,
  75.     WFGreekCharSet              = 161,
  76.     WFTurkishCharSet            = 162,
  77.     WFHebrewCharSet             = 177,
  78.     WFArabicCharSet             = 178,
  79.     WFBalticCharSet             = 186,
  80.     WFRussianCharSet            = 204,
  81.     WFThaiCharSet               = 222,
  82.     WFEastEuropeCharSet         = 238,
  83.     WFOEMCharSet                = 255,
  84. };
  85.  
  86. //
  87. // Output precision
  88. //
  89.  
  90. enum WFOutPrecType {
  91.     WFOutDefault                = 0,
  92.     WFOutString                 = 1,
  93.     WFOutCharacter              = 2,
  94.     WFOutStroke                 = 3,
  95.     WFOutTrueType               = 4,
  96.     WFOutDevice                 = 5,
  97.     WFOutRaster                 = 6,
  98.     WFOutTrueTypeOnly           = 7,
  99.     WFOutOutline                = 8,
  100. };
  101.  
  102. //
  103. // Clipping precision
  104. //
  105.  
  106. enum WFClipPrecType {
  107.     WFClipDefault               = 0,
  108.     WFClipCharacter             = 1,
  109.     WFClipStroke                = 2,
  110.     WFClipMask                  = 0xf,
  111.     WFClipLHAngles              = (1<<4),
  112.     WFClipTrueTypeAlways        = (2<<4),
  113.     WFClipEmbedded              = (8<<4),
  114. };
  115.  
  116. //
  117. // Output quality
  118. //
  119.  
  120. enum WFQualityType {
  121.     WFDefaultQuality            = 0,
  122.     WFDraftQuality              = 1,
  123.     WFProofQuality              = 2,
  124. };
  125.  
  126. //
  127. // Font pitch
  128. //
  129.  
  130. enum WFPitchType {
  131.     WFDefaultPitch              = 0,
  132.     WFFixedPitch                = 1,
  133.     WFVariablePitch             = 2,
  134. };
  135.  
  136. //
  137. // Font family
  138. //
  139.  
  140. enum WFFamilyType {
  141.     WFDontCare                  = (0<<4),
  142.     WFRoman                     = (1<<4),
  143.     WFSwiss                     = (2<<4),
  144.     WFModern                    = (3<<4),
  145.     WFScript                    = (4<<4),
  146.     WFDecorative                = (5<<4),
  147. };
  148.  
  149. #ifndef _WIN16
  150. #ifdef UNICODE
  151.     typedef struct tagLOGFONTW WSystemLogicalFont;
  152. #else
  153.     typedef struct tagLOGFONTA WSystemLogicalFont;
  154. #endif
  155. #else
  156. typedef struct tagLOGFONT WSystemLogicalFont;
  157. #endif
  158.  
  159. class WFontReference; // internal use only
  160.  
  161. //
  162. // WFont
  163. //
  164.  
  165. class WCMCLASS WFont : public WObject {
  166.     WDeclareSubclass( WFont, WObject );
  167.     
  168.     public:
  169.  
  170.         /************************************************************
  171.          * Constructors
  172.          ************************************************************/
  173.     
  174.         WFont( WFStockFont fontType=WFNullFont );
  175.         WFont( const WChar *fontDescription,
  176.                const WInfoCanvas *canvas=NULL );
  177.         WFont( const WString & fontDescription,
  178.                const WInfoCanvas *canvas=NULL );
  179.         WFont( const WFont &font );
  180.         WFont( WFontHandle handle, WBool deleteHandle=FALSE );
  181.         WFont( const WSystemLogicalFont *logicalFont, WInt pointsize=0,
  182.                const WInfoCanvas *canvas=NULL );
  183.         WFont( const WString & faceName, WInt pointsize,
  184.                const WInfoCanvas *canvas=NULL,
  185.                WInt cy=0, WInt cx=0, WInt escape=0, WInt orient=0,
  186.                WFBoldType weight=WFNormal, WBool ital=FALSE,
  187.                WBool under=FALSE, WBool strike=FALSE,
  188.                WFCharSetType charset=WFDefaultCharSet,
  189.                WFOutPrecType outprec=WFOutDefault,
  190.                WFClipPrecType clipprec=WFClipDefault,
  191.                WFQualityType qual = WFDefaultQuality,
  192.                WFPitchType ptch=WFDefaultPitch,
  193.                WFFamilyType fmly=WFDontCare );
  194.  
  195.         ~WFont();
  196.  
  197.         WFont& operator=( const WFont & f );
  198.         WFont& operator=( WFStockFont f );
  199.  
  200.         /*******************************************************************
  201.          * Properties
  202.          *******************************************************************/
  203.  
  204.         // Bold
  205.         //
  206.         //    Bold is defined as Weight >= WFBold.  Setting bold on sets
  207.         //    the weight to WFBold, setting it off sets it to WFNormal.
  208.  
  209.         WBool GetBold() const;
  210.         WBool SetBold( WBool on );
  211.  
  212.         // CharacterSet
  213.  
  214.         WFCharSetType GetCharacterSet() const;
  215.         WBool         SetCharacterSet( WFCharSetType characterSet );
  216.  
  217.         // ClipPrecision
  218.  
  219.         WFClipPrecType GetClipPrecision() const;
  220.         WBool          SetClipPrecision( WFClipPrecType clipPrecision );
  221.  
  222.         // FaceName
  223.  
  224.         WString GetFaceName() const;
  225.         WBool   SetFaceName( const WString & name );
  226.  
  227.         // Family
  228.  
  229.         WFFamilyType GetFamily() const;
  230.         WBool        SetFamily( WFFamilyType family );
  231.  
  232.         // Handle
  233.  
  234.         WFontHandle GetHandle( WBool noNullHandle=FALSE ) const;
  235.  
  236.         // Height
  237.  
  238.         WInt  GetHeight() const;
  239.  
  240.         // Italic
  241.  
  242.         WBool GetItalic() const;
  243.         WBool SetItalic( WBool on );
  244.  
  245.         // Name
  246.         //
  247.         //    Returns the full name (i.e. "8.Helv.Bold") of the font.
  248.         //    Use the FaceName property just for the face name.
  249.         //    The extended name includes information useful for
  250.         //    saving a font.
  251.  
  252.         WString GetName( WBool extended=FALSE ) const;
  253.         WBool   SetName( const WChar *name );
  254.  
  255.         // OutputPrecision
  256.  
  257.         WFOutPrecType GetOutputPrecision() const;
  258.         WBool         SetOutputPrecision( WFOutPrecType outputPrecision );
  259.  
  260.         // Pitch
  261.  
  262.         WFPitchType GetPitch() const;
  263.         WBool       SetPitch( WFPitchType pitch );
  264.  
  265.         // PointSize
  266.  
  267.         WInt  GetPointSize() const;
  268.         WBool SetPointSize( WInt pointSize );
  269.  
  270.         // Quality
  271.  
  272.         WFQualityType GetQuality() const;
  273.         WBool         SetQuality( WFQualityType quality );
  274.  
  275.         // Stock
  276.  
  277.         WBool GetStock() const;
  278.  
  279.         // StrikeOut
  280.  
  281.         WBool GetStrikeOut() const;
  282.         WBool SetStrikeOut( WBool on );
  283.  
  284.         // Underline
  285.  
  286.         WBool GetUnderline() const;
  287.         WBool SetUnderline( WBool on );
  288.  
  289.         // Valid
  290.         //
  291.         //    TRUE if font is defined.
  292.  
  293.         WBool GetValid() const;
  294.  
  295.         // Weight
  296.  
  297.         WInt  GetWeight() const;
  298.         WBool SetWeight( WInt weight );
  299.  
  300.         // Width
  301.         //
  302.         //    Calculates the average width of the font based on the
  303.         //    average width of the 52 upper and lowercase English
  304.         //    letters.
  305.  
  306.         WInt GetWidth() const;
  307.  
  308.         /*******************************************************************
  309.          * Methods
  310.          *******************************************************************/
  311.  
  312.         // Clear
  313.  
  314.         WBool Clear();
  315.  
  316.         // CopyToLogicalFont
  317.  
  318.         WBool CopyToLogicalFont( WSystemLogicalFont *copyInto );
  319.  
  320.         // Create
  321.         //
  322.         //    Create a font using a variety of methods....
  323.  
  324.         WBool Create( WFStockFont fontType=WFNullFont );
  325.         WBool Create( const WChar *fontDescription,
  326.                       const WInfoCanvas *canvas=NULL );
  327.         WBool Create( const WString & fontDescription,
  328.                       const WInfoCanvas *canvas=NULL );
  329.         WBool Create( const WFont &font );
  330.         WBool Create( WFontHandle handle, WBool deleteHandle=FALSE );
  331.         WBool Create( const WSystemLogicalFont *logicalFont, WInt pointsize=0,
  332.                       const WInfoCanvas *canvas=NULL );
  333.         WBool Create( const WString & faceName, WInt pointsize,
  334.                       const WInfoCanvas *canvas=NULL,
  335.                       WInt cy=0, WInt cx=0, WInt escape=0, WInt orient=0,
  336.                       WFBoldType weight=WFNormal, WBool ital=FALSE,
  337.                       WBool under=FALSE, WBool strike=FALSE,
  338.                       WFCharSetType charset=WFDefaultCharSet,
  339.                       WFOutPrecType outprec=WFOutDefault,
  340.                       WFClipPrecType clipprec=WFClipDefault,
  341.                       WFQualityType qual = WFDefaultQuality,
  342.                       WFPitchType ptch=WFDefaultPitch,
  343.                       WFFamilyType fmly=WFDontCare );
  344.  
  345.         // HorizDUToPixel
  346.         //
  347.         //     Convert horizontal dialog units into pixels based
  348.         //     on the font.
  349.  
  350.         WLong HorizDUToPixel( WLong dialogUnits ) const;
  351.  
  352.         // VertDUToPixel
  353.         //
  354.         //     Convert vertical dialog units into pixels based
  355.         //     on the font.
  356.  
  357.         WLong VertDUToPixel( WLong dialogUnits ) const;
  358.  
  359.         // PixelToHorizDU
  360.         //
  361.         //     Convert pixels into horizontal dialog units based
  362.         //     on the font.
  363.  
  364.         WLong PixelToHorizDU( WLong pixels ) const;
  365.  
  366.         // PixelToVertDU
  367.         //
  368.         //     Convert pixels into horizontal dialog units based
  369.         //     on the font.
  370.  
  371.         WLong PixelToVertDU( WLong pixels ) const;
  372.  
  373.         /*************************************************************
  374.          * Static Properties
  375.          *************************************************************/
  376.  
  377.         // DefaultGUIFont
  378.  
  379.         static const WFont & GetDefaultGUIFont();
  380.  
  381.         // InheritedFont
  382.  
  383.         static const WFont & GetInheritedFont();
  384.  
  385.         // NullFont
  386.  
  387.         static const WFont & GetNullFont();
  388.  
  389.         // SystemFont
  390.  
  391.         static const WFont & GetSystemFont();
  392.  
  393.         // StandardGUIFont
  394.  
  395.         static const WFont & GetStandardGUIFont();
  396.  
  397.         /************************************************************
  398.          * Static Methods
  399.          ************************************************************/
  400.  
  401.         // IsValidHandle
  402.         //
  403.         //     Returns TRUE if the given handle is valid.  Can
  404.         //     optionally specify whether or not a null handle
  405.         //     is "valid".
  406.  
  407.         static WBool IsValidHandle( WFontHandle handle,
  408.                                     WBool nullValid=FALSE );
  409.  
  410.         /*************************************************************
  411.          * Operator overloads
  412.          *************************************************************/
  413.  
  414.         int operator==( const WFont & f ) const;
  415.         int operator!=( const WFont & f ) const;
  416.  
  417.         /*************************************************************
  418.          * Private
  419.          *************************************************************/
  420.  
  421.     protected:
  422.         WBool PrepareForRead() const;
  423.         WBool PrepareForUpdate() const;
  424.  
  425.     private:
  426.         WFStockFont     _stockFont;
  427.         WFontReference *_fontReference;
  428. };
  429.  
  430. #ifdef _DEBUG
  431. #define W_ISFONTHANDLE(h) CHECKGDI(WFont::IsValidHandle((WFontHandle)h))
  432. #else
  433. #define W_ISFONTHANDLE(h)
  434. #endif
  435.  
  436. #ifndef _WNO_PRAGMA_PUSH
  437. #pragma enum pop;
  438. #pragma pack(pop);
  439. #endif
  440.  
  441. #endif // _WFONT_HPP_INCLUDED
  442.