Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. bltfont.hxx
  7. This file contains the definition for the BLT FONT class.
  8. FILE HISTORY:
  9. Johnl 03-Apr-1991 Created
  10. beng 14-May-1991 Made depend on blt.hxx for clients
  11. terryk 26-Nov-1991 Added FONT_DEFAULT_FIXED_PITCH
  12. */
  13. #ifndef _BLT_HXX_
  14. #error "Don't include this file directly; instead, include it through blt.hxx"
  15. #endif // _BLT_HXX_
  16. #ifndef _BLTFONT_HXX_
  17. #define _BLTFONT_HXX_
  18. /* Default fonts (will currently resolve to Helv. 8).
  19. */
  20. enum FontType { FONT_DEFAULT,
  21. FONT_DEFAULT_FIXED_PITCH,
  22. FONT_DEFAULT_BOLD,
  23. FONT_DEFAULT_ITALIC,
  24. FONT_DEFAULT_BOLD_ITALIC
  25. };
  26. /* Font attributes. Note that FONT_ATT_DEFAULT is mututally exclusive
  27. * from all other attributes.
  28. */
  29. enum FontAttributes { FONT_ATT_DEFAULT = 0x0000, // Use default attributes
  30. FONT_ATT_ITALIC = 0x0001,
  31. FONT_ATT_BOLD = 0x0002,
  32. FONT_ATT_UNDERLINE = 0x0004,
  33. FONT_ATT_STRIKEOUT = 0x0008
  34. };
  35. /*************************************************************************
  36. NAME: FONT
  37. SYNOPSIS: The FONT class is a wrapper for the Windows font creation
  38. and deletion process. It can be very complex so it is
  39. worth wrapping in a class.
  40. INTERFACE:
  41. FONT( )
  42. Constructor, where FontType is one of the default fonts
  43. (FONT_DEFAULT, FONT_DEFAULT_BOLD, FONT_DEFAULT_ITALIC,
  44. or FONT_DEFAULT_BOLD_ITALIC).
  45. FONT()
  46. Constructor, where LOGFONT is a filled in LOGFONT structure
  47. FONT()
  48. Constructor, where:
  49. pchFaceName is the name of the font ("Helv", TmsRmn" etc.)
  50. lfPitchAndFamily is the as in the LOGFONT documentation
  51. nPointSize is the point size of the font.
  52. FontAttributes is a combination of the FontAttributes
  53. enum, "|"ed together.
  54. ~FONT()
  55. Destructor, deletes the font
  56. HFONT QueryFontHandle()
  57. Retrieves the handle to the requested font. Will assert out
  58. under debug if an error has occurred.
  59. SetFont()
  60. Takes a handle to a new font. Must already created be created.
  61. Can use this method to prevent deleting of the font if you
  62. the set the HFONT to NULL.
  63. SetFont()
  64. Takes a LOGFONT. Will delete the old font (if there is one)
  65. and creates a new font based on the LOGFONT structure.
  66. QueryError()
  67. Returns NERR_Success if construction was successful
  68. CAVEATS:
  69. NOTES: SetXxx methods should be avoided because they require the FONT
  70. class to regenerate the font. It is generally better to
  71. simply declare a new FONT object with the desired attributes.
  72. HISTORY:
  73. Johnl 03-Apr-1991 Created
  74. beng 04-Oct-1991 Correct data types
  75. **************************************************************************/
  76. DLL_CLASS FONT : public BASE
  77. {
  78. private:
  79. HFONT _hFont;
  80. public:
  81. FONT( enum FontType );
  82. FONT( const LOGFONT & logfont );
  83. FONT( const TCHAR * pchFaceName, BYTE lfPitchAndFamily,
  84. INT nPointSize, enum FontAttributes fontatt );
  85. ~FONT();
  86. HFONT QueryHandle() const
  87. { return _hFont; }
  88. APIERR SetFont( HFONT hNewFont );
  89. APIERR SetFont( const LOGFONT & logFont );
  90. };
  91. /*******************************************************************
  92. NAME: BLTLogUnits2Points
  93. SYNOPSIS: Converts a number of logical units to the corresponding
  94. Point size
  95. ENTRY: nLogUnits - Count of logical units to convert to points
  96. EXIT: Returns the number of points
  97. NOTES: We are assuming that the default mapping mode (MM_TEXT) is
  98. used. In this mapping mode, one logical unit is one
  99. pixel. We grab the desktop's pixels per logical inch.
  100. A point is 1/72 of an inch.
  101. See Petzold's chapter on fonts for a discussion of fonts.
  102. HISTORY:
  103. Johnl 05-Apr-1991 Created
  104. ********************************************************************/
  105. inline INT BLTLogUnits2Points( INT nLogUnits )
  106. {
  107. SCREEN_DC dcScreen;
  108. INT nLogUnitsPerInch = GetDeviceCaps( dcScreen.QueryHdc(), LOGPIXELSY );
  109. return ( (72 * nLogUnits)/nLogUnitsPerInch );
  110. }
  111. /*******************************************************************
  112. NAME: BLTPoints2LogUnits
  113. SYNOPSIS: Converts a point size to a count of logical units.
  114. ENTRY: nPoints is the font point size
  115. EXIT: Returns the logical units
  116. NOTES: See BLTLogUnits2Points for a discussion
  117. HISTORY:
  118. Johnl 05-Apr-1991 Created
  119. ********************************************************************/
  120. inline INT BLTPoints2LogUnits( INT nPoints )
  121. {
  122. SCREEN_DC dcScreen;
  123. INT nLogUnitsPerInch = GetDeviceCaps( dcScreen.QueryHdc(), LOGPIXELSY );
  124. return ( (nPoints * nLogUnitsPerInch)/72 );
  125. }
  126. #endif // _BLTFONT_HXX_ - end of file