TTFont.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /************************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ************************************************************************************************
  21. * *
  22. * Project Name: Setup *
  23. * *
  24. * Archive: ttfont.h *
  25. * *
  26. * Author: Joe_b *
  27. * *
  28. * Modtime: 6/23/97 3:14p *
  29. * *
  30. * Updated: 08/01/2000 [MML] *
  31. * *
  32. * Revision: 22 *
  33. * *
  34. *----------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  37. #pragma once
  38. #ifndef TTFONT_H
  39. #define TTFONT_H
  40. #include <stddef.h>
  41. #include "point.h"
  42. #include "rect.h"
  43. /******************************************************************************
  44. ** These are the control flags for Fancy_Text_Print function.
  45. */
  46. typedef enum TextPrintType {
  47. TPF_LASTPOINT = 0x0000, // Use previous font point value.
  48. TPF_TT_10POINT = 0x0001, // True Type Font - 10 point
  49. TPF_TT_12POINT = 0x0002, // True Type Font - 12 point
  50. TPF_TT_14POINT = 0x000A, // True Type Font - 14 point
  51. TPF_TT_16POINT = 0x000B, // True Type Font - 16 point
  52. TPF_TT_18POINT = 0x000C, // True Type Font - 18 point
  53. TPF_TT_20POINT = 0x000D, // True Type Font - 20 point
  54. TPF_TT_22POINT = 0x000E, // True Type Font - 22 point
  55. TPF_TT_24POINT = 0x000F, // True Type Font - 24 point
  56. TPF_BUTTON_FONT = 0x0010,
  57. TPF_TEXT_FONT = 0x0020,
  58. } TextPrintType;
  59. typedef enum TextShadowType {
  60. TPF_NOSHADOW = 0x0000,
  61. TPF_DROPSHADOW = 0x0001, // Use a simple drop shadow.
  62. TPF_LIGHTSHADOW = 0x0002,
  63. TPF_FULLSHADOW = 0x0004, // Use a full outline shadow.
  64. TPF_DOUBLESHADOW = 0x0008, // Use a simple drop shadow.
  65. TPF_SHADOW = 0x0010, // Print twice, using backcolor.
  66. } TextShadowType;
  67. typedef enum TextFormatType {
  68. TPF_TOP = DT_TOP, // Use with DT_SINGLELINE. Top-justifies text.
  69. TPF_VCENTER = DT_VCENTER, // Use with DT_SINGLELINE. Centers text vertically.
  70. TPF_BOTTOM = DT_BOTTOM, // Use with DT_SINGLELINE. Justifies test to the bottom of the rectangle.
  71. TPF_LEFT = DT_LEFT, // Aligns text to the left.
  72. TPF_CENTER = DT_CENTER, // Centers text horizontally in the rectangle.
  73. TPF_RIGHT = DT_RIGHT, // Right justify text.
  74. TPF_WORDBREAK = DT_WORDBREAK, // Lines are automatically broken between words.
  75. TPF_SINGLE_LINE = DT_SINGLELINE, // All text on one line only.
  76. TPF_NO_PREFIX = DT_NOPREFIX, // Turns off processing of prefix characters.
  77. TPF_PATH_ELLIPSIS = DT_PATH_ELLIPSIS, // For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified rectangle.
  78. } TextFormatType;
  79. /******************************************************************************
  80. ** Standard button text print flags.
  81. */
  82. //#define TPF_BUTTON (TextFormatType)( DT_VCENTER | DT_CENTER | DT_SINGLELINE )
  83. //#define TPF_CENTER_FORMAT (TextFormatType)( DT_VCENTER | DT_CENTER | DT_WORDBREAK )
  84. //#define TPF_CHECKBOX (TextFormatType)( DT_LEFT | DT_VCENTER | DT_WORDBREAK )
  85. //#define TPF_EDIT (TextFormatType)( DT_LEFT | DT_VCENTER )
  86. //#define TPF_DEFAULT (TextFormatType)( DT_LEFT | DT_WORDBREAK )
  87. #define TPF_BUTTON (TextFormatType)( DT_CENTER | DT_VCENTER | DT_SINGLELINE )
  88. #define TPF_EDITBOX (TextFormatType)( DT_LEFT | DT_VCENTER | DT_SINGLELINE )
  89. #define TPF_RADIO (TextFormatType)( DT_LEFT | DT_WORDBREAK )
  90. #define TPF_CHECKBOX (TextFormatType)( DT_LEFT | DT_WORDBREAK )
  91. #define TPF_OUTER_SCROLL (TextFormatType)( DT_LEFT | DT_WORDBREAK )
  92. #define TPF_INNER_SCROLL (TextFormatType)( DT_LEFT | DT_SINGLELINE )
  93. #define TPF_LEFT_TEXT (TextFormatType)( DT_LEFT | DT_WORDBREAK )
  94. #define TPF_CENTER_TEXT (TextFormatType)( DT_CENTER | DT_WORDBREAK )
  95. #define TPF_RIGHT_TEXT (TextFormatType)( DT_RIGHT | DT_WORDBREAK )
  96. #define TPF_LEFT_TOP_ALIGNMENT (TextFormatType)( DT_LEFT | DT_TOP | DT_SINGLELINE )
  97. #define TPF_LEFT_BOTTOM_ALIGNMENT (TextFormatType)( DT_LEFT | DT_BOTTOM | DT_SINGLELINE )
  98. #define TPF_LEFT_JUSTIFY (TextFormatType)( DT_LEFT | DT_VCENTER | DT_SINGLELINE )
  99. #define TPF_RIGHT_TOP_ALIGNMENT (TextFormatType)( DT_RIGHT | DT_TOP | DT_SINGLELINE )
  100. #define TPF_RIGHT_BOTTOM_ALIGNMENT (TextFormatType)( DT_RIGHT | DT_BOTTOM | DT_SINGLELINE )
  101. #define TPF_RIGHT_JUSTIFY (TextFormatType)( DT_RIGHT | DT_VCENTER | DT_SINGLELINE )
  102. #define TPF_CENTER_TOP_ALIGNMENT (TextFormatType)( DT_CENTER | DT_TOP | DT_SINGLELINE )
  103. #define TPF_CENTER_BOTTOM_ALIGNMENT (TextFormatType)( DT_CENTER | DT_BOTTOM | DT_SINGLELINE )
  104. #define TPF_CENTER_JUSTIFY (TextFormatType)( DT_CENTER | DT_VCENTER | DT_SINGLELINE )
  105. /******************************************************************************
  106. ** These are the control flags for Fancy_Text_Print function.
  107. */
  108. typedef enum SpecialEffectType {
  109. TPF_NONE =0x0000, // No special effects needed.
  110. TPF_CUTOFF_AT_WIDTH =0x0001, // Don't print past the allowed width.
  111. TPF_BURST_MODE =0x0002, // Print text one letter at a time like a typewriter.
  112. TPF_SPECIAL_WRAP =0x0003, // Begin at a specified point but start next line at a point before the starting point.
  113. } SpecialEffectType;
  114. /******************************************************************************
  115. ** Global DC. Use it or create your own!
  116. */
  117. extern HDC BackBufferDC;
  118. /******************************************************************************
  119. ** Global Colors for use throughout program.
  120. */
  121. extern unsigned long TEXT_COLOR;
  122. extern unsigned long SHADOW_COLOR;
  123. extern unsigned long TEXT_NORMAL_COLOR;
  124. extern unsigned long TEXT_FOCUSED_COLOR;
  125. extern unsigned long TEXT_PRESSED_COLOR;
  126. extern unsigned long TEXT_NORMAL_SHADOW_COLOR;
  127. extern unsigned long TEXT_FOCUSED_SHADOW_COLOR;
  128. extern unsigned long TEXT_PRESSED_SHADOW_COLOR;
  129. extern unsigned long WHITE_COLOR;
  130. extern unsigned long BLACK_COLOR;
  131. extern unsigned long RED_COLOR;
  132. extern unsigned long ORANGE_COLOR;
  133. extern unsigned long YELLOW_COLOR;
  134. extern unsigned long GREEN_COLOR;
  135. extern unsigned long BLUE_COLOR;
  136. extern unsigned long INDIGO_COLOR;
  137. extern unsigned long VIOLET_COLOR;
  138. /******************************************************************************
  139. ** This is a True Type Font class object to create and use True Type fonts.
  140. ******************************************************************************/
  141. // Font Weight - Specifies the weight of the font in the range 0 through 1000.
  142. // For example, 400 is normal and 700 is bold.
  143. // If this value is zero, a default weight is used.
  144. //
  145. // The following values are defined for convenience:
  146. // FW_DONTCARE 0 FW_SEMIBOLD 600
  147. // FW_THIN 100 FW_DEMIBOLD 600
  148. // FW_EXTRALIGHT 200 FW_BOLD 700
  149. // FW_ULTRALIGHT 200 FW_EXTRABOLD 800
  150. // FW_LIGHT 300 FW_ULTRABOLD 800
  151. // FW_NORMAL 400 FW_HEAVY 900
  152. // FW_REGULAR 400 FW_BLACK 900
  153. // FW_MEDIUM 500
  154. //-----------------------------------------------------------------------------
  155. class TTFontClass
  156. {
  157. public:
  158. TTFontClass (
  159. HDC hdc,
  160. char * filename,
  161. char * facename,
  162. int height,
  163. int weight = FW_NORMAL,
  164. BYTE charset = ANSI_CHARSET,
  165. int width = 0,
  166. int escapement = 0,
  167. int orientation = 0,
  168. BYTE italic = FALSE,
  169. BYTE underline = FALSE,
  170. BYTE strikeout = FALSE,
  171. BYTE outputPrecision = OUT_TT_ONLY_PRECIS,
  172. BYTE clipPrecision = CLIP_DEFAULT_PRECIS,
  173. BYTE quality = PROOF_QUALITY,
  174. BYTE pitchAndFamily = FF_DONTCARE );
  175. virtual ~TTFontClass(void)
  176. {
  177. if ( Font != NULL ) {
  178. DeleteObject( Font );
  179. Font = NULL;
  180. }
  181. RemoveFontResource( szFilename );
  182. };
  183. virtual int Char_Pixel_Width ( HDC hdc, UINT c ) const;
  184. virtual int Char_Pixel_Width ( HDC hdc, char const * string, int *num_bytes=NULL ) const;
  185. virtual int String_Pixel_Width ( HDC hdc, char const * string ) const;
  186. virtual void String_Pixel_Bounds ( HDC hdc, const char * string, Rect& bounds ) const;
  187. virtual int Get_Width ( void ) const;
  188. virtual int Get_Height ( void ) const;
  189. virtual int Set_XSpacing ( HDC hdc, int x );
  190. virtual int Set_YSpacing ( int y );
  191. virtual int Find_Text_VLength ( HDC hdc, char *str, int width );
  192. virtual HFONT Get_Font_Ptr ( void ) { return Font; };
  193. virtual int IsFontDBCS ( void ) const { return ((CharSet==SHIFTJIS_CHARSET)||(CharSet==HANGEUL_CHARSET)||(CharSet==CHINESEBIG5_CHARSET)); }; // [OYO]
  194. virtual UINT Get_Double_Byte_Char ( const char *string, int *num_bytes=NULL ) const;
  195. virtual Point2D Print(
  196. HDC hdc,
  197. char const * string,
  198. Rect const & cliprect,
  199. COLORREF forecolor = TEXT_COLOR,
  200. COLORREF backcolor = TEXT_NORMAL_SHADOW_COLOR,
  201. TextFormatType flag = TPF_LEFT_TEXT,
  202. TextShadowType shadow = TPF_NOSHADOW );
  203. virtual Point2D Print(
  204. HDC hdc,
  205. wchar_t const * string,
  206. Rect const & cliprect,
  207. COLORREF forecolor = TEXT_COLOR,
  208. COLORREF backcolor = TEXT_NORMAL_SHADOW_COLOR,
  209. TextFormatType flag = TPF_LEFT_TEXT,
  210. TextShadowType shadow = TPF_NOSHADOW );
  211. private:
  212. HFONT Font;
  213. long Height;
  214. long Ascent;
  215. long Descent;
  216. long InternalLeading;
  217. long ExternalLeading;
  218. long AveCharWidth;
  219. long MaxCharWidth;
  220. long Overhang;
  221. long Italic;
  222. long Underlined;
  223. long StruckOut;
  224. int CharSet; // [OYO]
  225. int FontXSpacing; // GetTextCharacterExtra;
  226. int FontYSpacing;
  227. char szFacename[ MAX_PATH ];
  228. char szFilename[ MAX_PATH ];
  229. };
  230. //-------------------------------------------------------------------------
  231. // Global functions.
  232. //-------------------------------------------------------------------------
  233. TTFontClass * Font_From_TPF ( TextPrintType flags ); // Returns FontPtr based on flags passed in.
  234. bool Is_True_Type_Font ( TextPrintType flags ); // True Type???
  235. //-------------------------------------------------------------------------
  236. // This class is a wrapper around all the fonts that we want to be available.
  237. // The constructer will make them, and the destructor will remove them for us.
  238. //-------------------------------------------------------------------------
  239. class FontManagerClass
  240. {
  241. public:
  242. FontManagerClass ( HDC hdc );
  243. ~FontManagerClass ( void );
  244. TTFontClass * Get_Font ( TextPrintType flags ) { return( Font_From_TPF( flags )); };
  245. };
  246. /******************************************************************************
  247. ** FontManager Class Pointer.
  248. */
  249. extern FontManagerClass *FontManager;
  250. /******************************************************************************
  251. ** Loaded data file pointers.
  252. */
  253. extern TTFontClass *TTButtonFontPtr;
  254. extern TTFontClass *TTButtonFontPtrSmall;
  255. extern TTFontClass *TTTextFontPtr;
  256. extern TTFontClass *TTTextFontPtr640;
  257. extern TTFontClass *TTTextFontPtr800;
  258. extern TTFontClass *TTLicenseFontPtr;
  259. #endif