TTFont.cpp 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  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.cpp *
  25. * *
  26. * Author: Maria del Mar McCready Legg *
  27. * *
  28. * Modtime: 8/24/99 3:44pm *
  29. * *
  30. * Revision: 01 *
  31. * *
  32. *----------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * TTFontClass::TTFontClass -- Constructor for a font class object. *
  35. * TTFontClass::Char_Pixel_Width -- Fetch the pixel width of the character specified. *
  36. * TTFontClass::Find_Text_VLength -- Finds length of text in pixels *
  37. * TTFontClass::Get_Height -- Fetch the normalized height of the nominal font character. *
  38. * TTFontClass::Get_Width -- Get normalized width of the nominal font character. *
  39. * TTFontClass::Print -- Print text to the surface specified. *
  40. * TTFontClass::Raw_Height -- Fetch the height of the font. *
  41. * TTFontClass::Raw_Width -- Fetch the raw width of a character. *
  42. * TTFontClass::Set_XSpacing -- Set the X spacing override value. *
  43. * TTFontClass::Set_YSpacing -- Set the vertical (Y) spacing override value. *
  44. * TTFontClass::String_Pixel_Width -- Determines the width of the string in pixels. *
  45. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  46. #define STRICT
  47. #include <windows.h>
  48. #include <windowsx.h>
  49. #include <assert.h>
  50. #include <ctype.h>
  51. #include <stdlib.h>
  52. #include "args.h"
  53. #include "autorun.h"
  54. #include "rect.h"
  55. #include "wnd_file.h"
  56. #include "ttfont.h"
  57. #include "jsupport.h" // [OYO]
  58. #include "locale_api.h"
  59. #define FONTINFOMAXHEIGHT 4
  60. #define FONTINFOMAXWIDTH 5
  61. #define FUDGEDIV 16
  62. //-------------------------------------------------------------------------
  63. // Text Fonts.
  64. //-------------------------------------------------------------------------
  65. TTFontClass *TTButtonFontPtr = NULL;
  66. TTFontClass *TTButtonFontPtrSmall = NULL;
  67. TTFontClass *TTTextFontPtr = NULL;
  68. TTFontClass *TTTextFontPtr640 = NULL;
  69. TTFontClass *TTTextFontPtr800 = NULL;
  70. TTFontClass *TTLicenseFontPtr = NULL;
  71. FontManagerClass * FontManager = NULL;
  72. //unsigned long TEXT_COLOR = RGB( 247, 171, 11 );
  73. //unsigned long SHADOW_COLOR = RGB( 40, 8, 8 );
  74. unsigned long TEXT_COLOR = RGB( 255, 204, 51 );
  75. unsigned long SHADOW_COLOR = RGB( 40, 8, 8 );
  76. unsigned long TEXT_NORMAL_COLOR = RGB( 255, 204, 51 );
  77. unsigned long TEXT_NORMAL_SHADOW_COLOR = RGB( 40, 8, 8 );
  78. unsigned long TEXT_FOCUSED_COLOR = RGB( 255, 204, 51 );
  79. unsigned long TEXT_FOCUSED_SHADOW_COLOR = RGB( 40, 8, 8 );
  80. unsigned long TEXT_PRESSED_COLOR = RGB( 194, 79, 32 );
  81. unsigned long TEXT_PRESSED_SHADOW_COLOR = RGB( 70, 55, 49 );
  82. unsigned long BLACK_COLOR = RGB( 0, 0, 0 );
  83. unsigned long WHITE_COLOR = RGB( 255, 255, 255 );
  84. unsigned long RED_COLOR = RGB( 255, 0, 0 );
  85. unsigned long ORANGE_COLOR = RGB( 199, 91, 0 );
  86. unsigned long YELLOW_COLOR = RGB( 255, 247, 0 );
  87. unsigned long GREEN_COLOR = RGB( 0, 255, 0 );
  88. unsigned long BLUE_COLOR = RGB( 0, 0, 255 );
  89. unsigned long INDIGO_COLOR = RGB( 90, 2, 253 );
  90. unsigned long VIOLET_COLOR = RGB( 128, 0, 255 );
  91. /************************************************************************************
  92. * TTFontClass::TTFontClass -- Constructor for a font class object. *
  93. * *
  94. * This constructs a font object as it is based upon the true type windows fonts. *
  95. * *
  96. * INPUT: char *filename -- True Type Windows font file to open. *
  97. * char *facename -- It's face name. *
  98. * int height -- The height requested. *
  99. * *
  100. * OUTPUT: none *
  101. * *
  102. * WARNINGS: none *
  103. * *
  104. * HISTORY: *
  105. * 08/24/1999 MML : Created. *
  106. *==================================================================================*/
  107. TTFontClass::TTFontClass(
  108. HDC hdc,
  109. char *filename,
  110. char *facename,
  111. int height,
  112. int weight,
  113. BYTE charset,
  114. int width,
  115. int escapement,
  116. int orientation,
  117. BYTE italic,
  118. BYTE underline,
  119. BYTE strikeout,
  120. BYTE outputPrecision,
  121. BYTE clipPrecision,
  122. BYTE quality,
  123. BYTE pitchAndFamily )
  124. {
  125. HGDIOBJ old_object;
  126. TEXTMETRIC tm;
  127. char real_facename[MAX_PATH];
  128. //--------------------------------------------------------------------------
  129. // Get or Set a Font filename.
  130. //--------------------------------------------------------------------------
  131. if (( filename == NULL ) || ( filename[0] == '\0' )) {
  132. strcpy( szFilename, "Arial.ttf" );
  133. } else {
  134. strcpy( szFilename, filename );
  135. }
  136. //--------------------------------------------------------------------------
  137. // Get or Set a Font facename.
  138. //--------------------------------------------------------------------------
  139. if (( facename == NULL ) || ( facename[0] == '\0' )) {
  140. strcpy( szFacename, "Arial" );
  141. } else {
  142. strcpy( szFacename, facename );
  143. }
  144. real_facename[0] = '\0';
  145. Msg( __LINE__, __FILE__, "TTFontClass -- filename=%s, facename=%s, height=%d.", filename, facename, height );
  146. //--------------------------------------------------------------------------
  147. // Make sure the font file is "Registered". Then create the font.
  148. //--------------------------------------------------------------------------
  149. AddFontResource( szFilename );
  150. Font = CreateFont(
  151. height,
  152. width,
  153. escapement,
  154. orientation,
  155. weight,
  156. italic,
  157. underline,
  158. strikeout,
  159. charset,
  160. outputPrecision,
  161. clipPrecision,
  162. quality,
  163. pitchAndFamily,
  164. szFacename );
  165. if ( hdc && ( Font != NULL )) {
  166. //----------------------------------------------------------------------
  167. // The GetTextFace function lets a program determine the face name of
  168. // THE font currently selected in the device context:
  169. //----------------------------------------------------------------------
  170. old_object = SelectObject( hdc, Font );
  171. GetTextFace( hdc, ( sizeof( real_facename ) / sizeof( TCHAR )), real_facename );
  172. if( _stricmp( real_facename, szFacename ) != 0 ) {
  173. strcpy( szFilename, "Arial.ttf" );
  174. strcpy( szFacename, "Arial" );
  175. SelectObject( hdc, old_object );
  176. DeleteObject( Font );
  177. Font = NULL;
  178. Font = CreateFont(
  179. height, // height of font
  180. width, // average character width
  181. escapement, // angle of escapement
  182. orientation, // base-line orientation angle
  183. weight, // font weight
  184. italic, // italic attribute option
  185. underline, // underline attribute option
  186. strikeout, // strikeout attribute option
  187. charset, // character set identifier
  188. outputPrecision, // output precision
  189. clipPrecision, // clipping precision
  190. quality, // output quality
  191. pitchAndFamily, // pitch and family
  192. szFacename ); // typeface name
  193. real_facename[0] = '\0';
  194. old_object = SelectObject( hdc, Font );
  195. GetTextFace( hdc, ( sizeof( real_facename ) / sizeof( TCHAR )), real_facename );
  196. }
  197. }
  198. //--------------------------------------------------------------------------
  199. // Save off the height.
  200. //--------------------------------------------------------------------------
  201. Height = height;
  202. if ( hdc ) {
  203. //-----------------------------------------------------------------------
  204. // Get info from the font in BackBuffer's DC.
  205. //-----------------------------------------------------------------------
  206. old_object = SelectObject( hdc, Font );
  207. GetTextMetrics( hdc, &tm );
  208. FontXSpacing = GetTextCharacterExtra( hdc );
  209. Ascent = tm.tmAscent;
  210. Descent = tm.tmDescent;
  211. InternalLeading = tm.tmInternalLeading;
  212. ExternalLeading = tm.tmExternalLeading;
  213. AveCharWidth = tm.tmAveCharWidth;
  214. MaxCharWidth = tm.tmMaxCharWidth;
  215. Overhang = tm.tmOverhang;
  216. Italic = tm.tmItalic;
  217. Underlined = tm.tmUnderlined;
  218. StruckOut = tm.tmStruckOut;
  219. CharSet = tm.tmCharSet; // [OYO] It is important to support Double Byte Chars
  220. SelectObject( hdc, old_object );
  221. } else {
  222. //-----------------------------------------------------------------------
  223. // Set default values.
  224. //-----------------------------------------------------------------------
  225. Ascent = 0;
  226. Descent = 0;
  227. InternalLeading = 0;
  228. ExternalLeading = 0;
  229. AveCharWidth = 0;
  230. MaxCharWidth = 0;
  231. Overhang = 0;
  232. Italic = 0;
  233. Underlined = 0;
  234. StruckOut = 0;
  235. CharSet = 0; // [OYO]
  236. FontXSpacing = 0;
  237. }
  238. }
  239. /***********************************************************************************************
  240. * TTFontClass::Char_Pixel_Width -- Fetch the pixel width of the character specified. *
  241. * *
  242. * This will return with the pixel width of the character specified. *
  243. * *
  244. * INPUT: c -- The character to determine the pixel width for. *
  245. * *
  246. * OUTPUT: Returns with the pixel width of the character. *
  247. * *
  248. * WARNINGS: The return width is the screen real estate width which may differ from the *
  249. * actual pixels of the character. This difference is controlled by the font *
  250. * X spacing. *
  251. * *
  252. * HISTORY: *
  253. * 05/26/1997 JLB : Created. *
  254. *=============================================================================================*/
  255. int TTFontClass::Char_Pixel_Width( HDC hdc, UINT c ) const
  256. {
  257. HGDIOBJ old_object;
  258. ABC abc;
  259. abc.abcA = 0;
  260. abc.abcB = 0;
  261. abc.abcC = 0;
  262. if ( hdc ) {
  263. old_object = SelectObject( hdc, Font );
  264. GetCharABCWidths( hdc, c, c, &abc );
  265. SelectObject( hdc, old_object );
  266. }
  267. return( abc.abcA + abc.abcB + abc.abcC );
  268. }
  269. /************************************************************************************************
  270. * TTFontClass::Char_Pixel_Width -- Fetch the pixel width of the character specified.
  271. *
  272. * This will return with the pixel width of the character specified.
  273. *
  274. * INPUT: HDC hdc -- must be passed in from calling function.
  275. * char const * string -- the pointer to the character in the string.
  276. * int *num_bytes -- return number of bytes this character has: 1 or 2.
  277. *
  278. * OUTPUT: Returns with the pixel width of the character.
  279. *
  280. * WARNINGS: The return width is the screen real estate width which may differ from the
  281. * actual pixels of the character. This difference is controlled by the font
  282. * X spacing.
  283. *
  284. * NOTE: This is function determines if the character is a double-byte or single-byte
  285. * character, then calls the standard Char_Pixel_Width.
  286. *
  287. * HISTORY:
  288. * 05/26/1997 JLB : Created.
  289. *==============================================================================================*/
  290. //
  291. // [OYO] Supports DBCS ( multi-byte characters ).
  292. //
  293. int TTFontClass::Char_Pixel_Width ( HDC hdc, char const * string, int *num_bytes ) const
  294. {
  295. char const *letter = string;
  296. int length = 0;
  297. UINT c;
  298. //--------------------------------------------------------------------------
  299. // These values must be passed in.
  300. //--------------------------------------------------------------------------
  301. if ( string == NULL || *string == '\0' || hdc == NULL ) {
  302. return( 0 );
  303. }
  304. //--------------------------------------------------------------------------
  305. // If this value is passed in, the set the default value (1=single).
  306. //--------------------------------------------------------------------------
  307. if ( num_bytes!= NULL ) {
  308. *num_bytes = 1;
  309. }
  310. //--------------------------------------------------------------------------
  311. // Get the pixel width of the character. If it is a double-byte character,
  312. // then num_bytes will come back as '2'.
  313. //--------------------------------------------------------------------------
  314. if( IsFontDBCS() && IsDBCSLeadByte( *letter )){
  315. c = Get_Double_Byte_Char( letter, num_bytes );
  316. length += Char_Pixel_Width( hdc, c ); // pixel length of double-byte character.
  317. } else {
  318. length += Char_Pixel_Width( hdc, *letter ); // pixel length of single-byte character.
  319. }
  320. return( length );
  321. }
  322. /************************************************************************************************
  323. * TTFontClass::String_Pixel_Width -- Determines the width of the string in pixels. *
  324. * *
  325. * This routine is used to determine how many pixels wide the string will be if it were *
  326. * printed. *
  327. * *
  328. * INPUT: string -- The string to convert into its pixel width. *
  329. * *
  330. * OUTPUT: Returns with the number of pixels the string would span if it were printed. *
  331. * *
  332. * WARNINGS: This routine does not take into account clipping. *
  333. * *
  334. * HISTORY: *
  335. * 05/26/1997 JLB : Created. *
  336. *==============================================================================================*/
  337. int TTFontClass::String_Pixel_Width( HDC hdc, char const * string ) const
  338. {
  339. if ( string == NULL ) {
  340. return(0);
  341. }
  342. int largest = 0; // Largest recorded width of the string.
  343. int width = 0;
  344. HGDIOBJ old_object;
  345. int length;
  346. SIZE size;
  347. bool make_dc = FALSE;
  348. HDC localDC = hdc;
  349. size.cx = 0;
  350. if ( localDC == NULL ) {
  351. return( size.cx );
  352. }
  353. if ( localDC ) {
  354. length = strlen( string );
  355. old_object = SelectObject( localDC, Font );
  356. GetTextExtentPoint32( localDC, string, length, &size );
  357. SelectObject( localDC, old_object );
  358. }
  359. return( size.cx );
  360. }
  361. /****************************************************************************
  362. *
  363. * NAME
  364. * String_Pixel_Bounds(String, Bounds)
  365. *
  366. * DESCRIPTION
  367. * Calculate the bounding box for the specified string.
  368. *
  369. * INPUTS
  370. * String - String to calculate bounds for
  371. * Bounds - Rect to fill with bounds
  372. *
  373. * RESULT
  374. * NONE
  375. *
  376. ****************************************************************************/
  377. //
  378. // [OYO] Supports DBCS ( multi-byte characters ).
  379. //
  380. void TTFontClass::String_Pixel_Bounds( HDC hdc, const char* string, Rect& bounds ) const
  381. {
  382. int width;
  383. int height;
  384. bounds.Width = 0;
  385. bounds.Height = 0;
  386. if ( string == NULL ) {
  387. return;
  388. }
  389. if ( hdc == NULL ) {
  390. return;
  391. }
  392. width = 0;
  393. height = Get_Height();
  394. while ( *string != 0 ) {
  395. if (( *string == '\r' ) || ( *string == '\n' )) {
  396. string++;
  397. height += Get_Height();
  398. bounds.Width = max( bounds.Width, width );
  399. width = 0;
  400. } else if( IsFontDBCS()){
  401. #if(0)
  402. //--------------------------------------------------------------------
  403. // Using one of those _tc functions:
  404. // Get a character, get the width of that character, then
  405. // move the pointer to the next character.
  406. //--------------------------------------------------------------------
  407. UINT c = Get_Double_Byte_Char( string );
  408. width += Char_Pixel_Width( hdc, c );
  409. string = _tcsinc( string );
  410. #else
  411. //--------------------------------------------------------------------
  412. // MBCS way: Get a byte. If byte is a "Lead" byte, get the second half,
  413. // combine them into one character, then get the width of that character.
  414. //--------------------------------------------------------------------
  415. UINT c = *(BYTE*)string++;
  416. if( IsDBCSLeadByte( c )&& *string ) {
  417. c = ( c << 8 ) | *(BYTE *)string++;
  418. }
  419. width += Char_Pixel_Width( hdc, c );
  420. #endif
  421. } else {
  422. width += Char_Pixel_Width( hdc, *string++ );
  423. }
  424. }
  425. bounds.Width = max( bounds.Width, width );
  426. bounds.Height = height;
  427. }
  428. /***********************************************************************************************
  429. * TTFontClass::Get_Double_Byte_Char -- Get the first character even if DBSC.
  430. *
  431. * INPUT: char * -- string to look at.
  432. *
  433. * OUTPUT: Returns with the normalized width of the character in the font.
  434. *
  435. * WARNINGS: I added this function based on code provided by Ikeda-san.
  436. *
  437. * HISTORY:
  438. * 06/05/2000 MML : Created.
  439. *=============================================================================================*/
  440. //
  441. // [OYO] Supports DBCS ( multi-byte characters ).
  442. //
  443. UINT TTFontClass::Get_Double_Byte_Char ( const char *string, int *num_bytes ) const
  444. {
  445. if ( string == NULL || *string == '\0' ) {
  446. return( 0 );
  447. }
  448. const char *ptr = string;
  449. UINT c = *(BYTE *)ptr++;
  450. if ( num_bytes != NULL ) {
  451. *num_bytes = 1;
  452. }
  453. //--------------------------------------------------------------------------
  454. // The IsDBCSLeadByte function determines whether a character is a
  455. // lead byte — that is, the first byte of a character in a double-byte
  456. // character set (DBCS).
  457. //
  458. // BOOL IsDBCSLeadByte( BYTE TestChar /* character to test */ );
  459. //
  460. // TestChar -- Specifies the character to be tested.
  461. //
  462. // Return Values
  463. // If the character is a lead byte, the return value is nonzero.
  464. // If the character is not a lead byte, the return value is zero.
  465. // To get extended error information, call GetLastError.
  466. // Remarks
  467. // Lead bytes are unique to double-byte character sets.
  468. // A lead byte introduces a double-byte character. Lead bytes
  469. // occupy a specific range of byte values. The IsDBCSLeadByte
  470. // function uses the ANSI code page to check lead-byte ranges.
  471. // To specify a different code page, use the IsDBCSLeadByteEx function.
  472. //
  473. // Declared in winnls.h.
  474. //--------------------------------------------------------------------------
  475. if( IsDBCSLeadByte( c )&& *ptr ) { // [OYO]
  476. c = ( c << 8 ) | *(BYTE *)ptr++;
  477. if ( num_bytes != NULL ) {
  478. *num_bytes = 2;
  479. }
  480. }
  481. return( c );
  482. }
  483. /***********************************************************************************************
  484. * TTFontClass::Get_Width -- Get normalized width of the nominal font character. *
  485. * *
  486. * This routine is used to fetch the width of the widest character in the font but the *
  487. * width has been biased according to any X spacing override present. *
  488. * *
  489. * INPUT: none *
  490. * *
  491. * OUTPUT: Returns with the normalized width of the widest character in the font. *
  492. * *
  493. * WARNINGS: none *
  494. * *
  495. * HISTORY: *
  496. * 05/26/1997 JLB : Created. *
  497. *=============================================================================================*/
  498. int TTFontClass::Get_Width( void ) const
  499. {
  500. return( MaxCharWidth - Overhang );
  501. }
  502. /***********************************************************************************************
  503. * TTFontClass::Get_Height -- Fetch the normalized height of the nominal font character. *
  504. * *
  505. * This will return the height of the font but the returned height will be adjusted by any *
  506. * Y spacing override present. *
  507. * *
  508. * INPUT: none *
  509. * *
  510. * OUTPUT: Returns with the height of the font normalized by any spacing overrides. *
  511. * *
  512. * WARNINGS: none *
  513. * *
  514. * HISTORY: *
  515. * 05/26/1997 JLB : Created. *
  516. *=============================================================================================*/
  517. int TTFontClass::Get_Height( void ) const
  518. {
  519. return( Height );
  520. }
  521. /***********************************************************************************************
  522. * TTFontClass::Set_XSpacing -- Set the X spacing override value. *
  523. * *
  524. * Use this routine to control the horizontal spacing override for this font. If the value *
  525. * is negative, the font becomes compressed. If the value is positive, then the font *
  526. * becomes expanded. *
  527. * *
  528. * INPUT: x -- The X spacing override to use for this font. *
  529. * *
  530. * OUTPUT: Returns with the old X spacing override value. *
  531. * *
  532. * WARNINGS: none *
  533. * *
  534. * HISTORY: *
  535. * 05/26/1997 JLB : Created. *
  536. *=============================================================================================*/
  537. int TTFontClass::Set_XSpacing( HDC hdc, int x )
  538. {
  539. // HGDIOBJ old_object;
  540. // int answer = 0;
  541. // if ( hdc ) {
  542. // old_object = SelectObject( hdc, Font );
  543. // answer = SetTextCharacterExtra( hdc, x );
  544. // SelectObject( hdc, old_object );
  545. // }
  546. FontXSpacing = x;
  547. return( x );
  548. }
  549. /***********************************************************************************************
  550. * TTFontClass::Set_YSpacing -- Set the vertical (Y) spacing override value. *
  551. * *
  552. * Use this routine to control the "line spacing" of a font. If the Y spacing is negative *
  553. * then the font becomes closer to the line above it. If value is positive, then more *
  554. * space occurs between lines. *
  555. * *
  556. * INPUT: y -- The Y spacing override to use for this font. *
  557. * *
  558. * OUTPUT: Returns with the old Y spacing override value. *
  559. * *
  560. * WARNINGS: none *
  561. * *
  562. * HISTORY: *
  563. * 05/26/1997 JLB : Created. *
  564. *=============================================================================================*/
  565. int TTFontClass::Set_YSpacing( int y )
  566. {
  567. FontYSpacing = y;
  568. return(y);
  569. }
  570. /***********************************************************************************************
  571. * TTFontClass::Print -- Print text to the surface specified. WCHAR Version. *
  572. * *
  573. * This displays text to the surface specified and with the attributes specified. *
  574. * *
  575. * INPUT: string -- The string to display to the surface. *
  576. * surface -- The surface to display the text upon. *
  577. * cliprect -- The clipping rectangle that both clips the text and biases the print *
  578. * location to. *
  579. * point -- The draw position for the upper left corner of the first character. *
  580. * convert -- The pixel convert object that is used to draw the correct colors to *
  581. * the destination surface. *
  582. * remap -- Auxiliary remap table for font colors. *
  583. * *
  584. * OUTPUT: Returns with the point where the next print should begin if it is to smoothly *
  585. * continue where this print operation left off. *
  586. * *
  587. * WARNINGS: There are two separate drawing routines; one for old fonts and one for new fonts. *
  588. * *
  589. * HISTORY: *
  590. * 05/26/1997 JLB : Created. *
  591. * 06/20/1887 BNA : Modified to handle new fonts. *
  592. *=============================================================================================*/
  593. #if(NDEBUG)
  594. Point2D TTFontClass::Print(
  595. HDC hdc,
  596. wchar_t const * string,
  597. Rect const & cliprect,
  598. COLORREF forecolor, /* = TEXT_COLOR, */
  599. COLORREF backcolor, /* = TEXT_SHADOW_COLOR, */
  600. TextFormatType flag, /* = TPF_DEFAULT, */
  601. TextShadowType shadow ) /* = TPF_FULLSHADOW */
  602. {
  603. char buffer[ _MAX_PATH ];
  604. int length = wcslen( string );
  605. memset( buffer, '\0', _MAX_PATH );
  606. WideCharToMultiByte( CodePage, 0, string, length, buffer, _MAX_PATH, NULL, NULL );
  607. return( Print( hdc, buffer, cliprect, forecolor, backcolor, flag, shadow ));
  608. }
  609. #else
  610. Point2D TTFontClass::Print(
  611. HDC hdc,
  612. wchar_t const * string,
  613. Rect const & cliprect,
  614. COLORREF forecolor, /* = TEXT_COLOR, */
  615. COLORREF backcolor, /* = TEXT_SHADOW_COLOR, */
  616. TextFormatType flag, /* = TPF_DEFAULT, */
  617. TextShadowType shadow ) /* = TPF_FULLSHADOW */
  618. {
  619. Point2D point( cliprect.X, cliprect.Y );
  620. RECT rect;
  621. HGDIOBJ old_object;
  622. SIZE size;
  623. int length = 0;
  624. int result = 0;
  625. //--------------------------------------------------------------------------
  626. // If no string, why continue?
  627. //--------------------------------------------------------------------------
  628. assert( string != NULL );
  629. assert( hdc != NULL );
  630. if (( string == NULL ) || ( string[0] == '\0' )) {
  631. return( point );
  632. }
  633. //--------------------------------------------------------------------------
  634. // Set up rectangle print regions for the "shadow" and the main color.
  635. //--------------------------------------------------------------------------
  636. length = wcslen( string );
  637. rect.left = cliprect.X;
  638. rect.top = cliprect.Y;
  639. rect.right = cliprect.X + cliprect.Width;
  640. rect.bottom = cliprect.Y + cliprect.Height;
  641. Msg( __LINE__, __FILE__, "TTFontClass::Print -- string = %s.", string );
  642. Msg( __LINE__, __FILE__, "TTFontClass::Print -- strlen = %d.", length );
  643. Msg( __LINE__, __FILE__, "TTFontClass::Print -- rect = [%d, %d, %d, %d].", rect.left, rect.top, rect.right, rect.bottom );
  644. // Msg( __LINE__, __FILE__, "TTFontClass::Print -- rect2 = [%d, %d, %d, %d].", rect.left, rect.top, rect.right, rect.bottom );
  645. //--------------------------------------------------------------------------
  646. // Print the "Shadow" depending on style desired, then the text in the requested color.
  647. //--------------------------------------------------------------------------
  648. if ( hdc ) {
  649. assert( Font != NULL );
  650. old_object = SelectObject( hdc, Font );
  651. SetTextCharacterExtra( hdc, FontXSpacing );
  652. SetTextAlign( hdc, TA_LEFT | TA_TOP );
  653. SetBkMode( hdc, TRANSPARENT );
  654. SetTextColor( hdc, forecolor );
  655. // result = ExtTextOutW(
  656. // hdc, // handle to DC
  657. // rect.left, // x-coordinate of reference point
  658. // rect.top, // y-coordinate of reference point
  659. // ETO_CLIPPED, // text-output options
  660. // &rect, // optional dimensions
  661. // string, // string
  662. // length, // number of characters in string
  663. // NULL // array of spacing values
  664. // );
  665. // result = TextOutW(
  666. // hdc, // handle to DC
  667. // rect.left, // x-coordinate of starting position
  668. // rect.top, // y-coordinate of starting position
  669. // string, // character string
  670. // length // number of characters
  671. // );
  672. result = DrawTextW(
  673. hdc,
  674. string,
  675. length,
  676. &rect,
  677. flag );
  678. GetTextExtentPointW( hdc, string, length, &size );
  679. SelectObject( hdc, old_object );
  680. }
  681. point.X += size.cx;
  682. return( point );
  683. }
  684. #endif
  685. /***********************************************************************************************
  686. * TTFontClass::Print -- Print text to the surface specified. CHAR version. *
  687. * *
  688. * This displays text to the surface specified and with the attributes specified. *
  689. * *
  690. * INPUT: string -- The string to display to the surface. *
  691. * surface -- The surface to display the text upon. *
  692. * cliprect -- The clipping rectangle that both clips the text and biases the print *
  693. * location to. *
  694. * point -- The draw position for the upper left corner of the first character. *
  695. * convert -- The pixel convert object that is used to draw the correct colors to *
  696. * the destination surface. *
  697. * remap -- Auxiliary remap table for font colors. *
  698. * *
  699. * OUTPUT: Returns with the point where the next print should begin if it is to smoothly *
  700. * continue where this print operation left off. *
  701. * *
  702. * WARNINGS: There are two separate drawing routines; one for old fonts and one for new fonts. *
  703. * *
  704. * HISTORY: *
  705. * 05/26/1997 JLB : Created. *
  706. * 06/20/1887 BNA : Modified to handle new fonts. *
  707. *=============================================================================================*/
  708. Point2D TTFontClass::Print(
  709. HDC hdc,
  710. char const * string,
  711. Rect const & cliprect,
  712. COLORREF forecolor, /* = TEXT_COLOR, */
  713. COLORREF backcolor, /* = TEXT_SHADOW_COLOR, */
  714. TextFormatType flag, /* = TPF_DEFAULT, */
  715. TextShadowType shadow ) /* = TPF_FULLSHADOW */
  716. {
  717. Point2D point( cliprect.X, cliprect.Y );
  718. RECT rect, rect2;
  719. HGDIOBJ old_object;
  720. SIZE size;
  721. int length = 0;
  722. int result = 0;
  723. //--------------------------------------------------------------------------
  724. // If no string, why continue?
  725. //--------------------------------------------------------------------------
  726. assert( string != NULL );
  727. assert( hdc != NULL );
  728. if (( string == NULL ) || ( string[0] == '\0' )) {
  729. return( point );
  730. }
  731. //--------------------------------------------------------------------------
  732. // Set up rectangle print regions for the "shadow" and the main color.
  733. //--------------------------------------------------------------------------
  734. length = strlen( string );
  735. rect.left = cliprect.X;
  736. rect.top = cliprect.Y;
  737. rect.right = cliprect.X + cliprect.Width;
  738. rect.bottom = cliprect.Y + cliprect.Height;
  739. // Shadow
  740. rect2.left = rect.left - 1;
  741. rect2.top = rect.top - 1;
  742. rect2.right = rect.right - 1;
  743. rect2.bottom= rect.bottom - 1;
  744. // Msg( __LINE__, __FILE__, "TTFontClass::Print -- strlen = %d.", length );
  745. // Msg( __LINE__, __FILE__, "TTFontClass::Print -- rect = [%d, %d, %d, %d].", rect.left, rect.top, rect.right, rect.bottom );
  746. // Msg( __LINE__, __FILE__, "TTFontClass::Print -- rect2 = [%d, %d, %d, %d].", rect.left, rect.top, rect.right, rect.bottom );
  747. //--------------------------------------------------------------------------
  748. // Print the "Shadow" depending on style desired, then the text in the requested color.
  749. //--------------------------------------------------------------------------
  750. if ( hdc ) {
  751. assert( Font != NULL );
  752. old_object = SelectObject( hdc, Font );
  753. SetTextCharacterExtra( hdc, FontXSpacing );
  754. SetTextAlign( hdc, TA_LEFT | TA_TOP );
  755. SetBkMode( hdc, TRANSPARENT );
  756. SetTextColor( hdc, backcolor );
  757. if ( shadow == TPF_SHADOW ) {
  758. // One left, One up.
  759. result = DrawText( hdc, string, length, &rect2, flag );
  760. assert( result != 0 );
  761. // One left.
  762. rect2.left = rect.left - 1;
  763. rect2.top = rect.top;
  764. rect2.right = rect.right - 1;
  765. rect2.bottom = rect.bottom;
  766. result = DrawText( hdc, string, length, &rect2, flag );
  767. assert( result != 0 );
  768. // One up.
  769. rect2.left = rect.left;
  770. rect2.top = rect.top - 1;
  771. rect2.right = rect.right;
  772. rect2.bottom = rect.bottom - 1;
  773. result = DrawText( hdc, string, length, &rect2, flag );
  774. assert( result != 0 );
  775. } else if ( shadow == TPF_DOUBLESHADOW ) {
  776. // One left, One up.
  777. result = DrawText( hdc, string, length, &rect2, flag );
  778. assert( result != 0 );
  779. // One left.
  780. rect2.left = rect.left - 1;
  781. rect2.top = rect.top;
  782. result = DrawText( hdc, string, length, &rect2, flag );
  783. assert( result != 0 );
  784. // One up.
  785. rect2.left = rect.left;
  786. rect2.top = rect.top - 1;
  787. result = DrawText( hdc, string, length, &rect2, flag );
  788. assert( result != 0 );
  789. // Two left, Two up.
  790. rect2.left = rect.left - 2;
  791. rect2.top = rect.top - 2;
  792. result = DrawText( hdc, string, length, &rect2, flag );
  793. assert( result != 0 );
  794. // Two left.
  795. rect2.left = rect.left - 2;
  796. rect2.top = rect.top;
  797. result = DrawText( hdc, string, length, &rect2, flag );
  798. assert( result != 0 );
  799. // Two up.
  800. rect2.left = rect.left;
  801. rect2.top = rect.top - 2;
  802. result = DrawText( hdc, string, length, &rect2, flag );
  803. assert( result != 0 );
  804. } else if ( shadow == TPF_FULLSHADOW ) {
  805. // One left, One up.
  806. result = DrawText( hdc, string, length, &rect2, flag );
  807. assert( result != 0 );
  808. // One right, One up.
  809. rect2.left = rect.left + 1;
  810. rect2.top = rect.top - 1;
  811. result = DrawText( hdc, string, length, &rect2, flag );
  812. assert( result != 0 );
  813. // One left, One down.
  814. rect2.left = rect.left - 1;
  815. rect2.top = rect.top + 1;
  816. result = DrawText( hdc, string, length, &rect2, flag );
  817. assert( result != 0 );
  818. // One right, One down.
  819. rect2.left = rect.left + 1;
  820. rect2.top = rect.top + 1;
  821. result = DrawText( hdc, string, length, &rect2, flag );
  822. assert( result != 0 );
  823. // One left.
  824. rect2.left = rect.left - 1;
  825. rect2.top = rect.top;
  826. result = DrawText( hdc, string, length, &rect2, flag );
  827. assert( result != 0 );
  828. // One right.
  829. rect2.left = rect.left + 1;
  830. rect2.top = rect.top;
  831. result = DrawText( hdc, string, length, &rect2, flag );
  832. assert( result != 0 );
  833. // One up.
  834. rect2.left = rect.left;
  835. rect2.top = rect.top - 1;
  836. result = DrawText( hdc, string, length, &rect2, flag );
  837. assert( result != 0 );
  838. // One down.
  839. rect2.left = rect.left;
  840. rect2.top = rect.top + 1;
  841. result = DrawText( hdc, string, length, &rect2, flag );
  842. assert( result != 0 );
  843. // Two right.
  844. rect2.left = rect.left + 2;
  845. rect2.top = rect.top;
  846. result = DrawText( hdc, string, length, &rect2, flag );
  847. assert( result != 0 );
  848. // Two down.
  849. rect2.left = rect.left;
  850. rect2.top = rect.top + 2;
  851. result = DrawText( hdc, string, length, &rect2, flag );
  852. assert( result != 0 );
  853. // Two right, One up.
  854. rect2.left = rect.left + 2;
  855. rect2.top = rect.top - 2;
  856. result = DrawText( hdc, string, length, &rect2, flag );
  857. assert( result != 0 );
  858. // Two right, One down.
  859. rect2.left = rect.left + 2;
  860. rect2.top = rect.top + 2;
  861. result = DrawText( hdc, string, length, &rect2, flag );
  862. assert( result != 0 );
  863. // Three right.
  864. rect2.left = rect.left + 3;
  865. rect2.top = rect.top;
  866. result = DrawText( hdc, string, length, &rect2, flag );
  867. assert( result != 0 );
  868. // Three down.
  869. rect2.left = rect.left;
  870. rect2.top = rect.top + 3;
  871. result = DrawText( hdc, string, length, &rect2, flag );
  872. assert( result != 0 );
  873. // Three right, One up.
  874. rect2.left = rect.left + 3;
  875. rect2.top = rect.top - 3;
  876. result = DrawText( hdc, string, length, &rect2, flag );
  877. assert( result != 0 );
  878. // Three right, One down.
  879. rect2.left = rect.left + 3;
  880. rect2.top = rect.top + 3;
  881. result = DrawText( hdc, string, length, &rect2, flag );
  882. assert( result != 0 );
  883. }
  884. SetTextColor( hdc, forecolor );
  885. result = DrawText( hdc, string, length, &rect, flag );
  886. assert( result != 0 );
  887. GetTextExtentPoint( hdc, string, length, &size );
  888. SelectObject( hdc, old_object );
  889. }
  890. point.X += size.cx;
  891. return( point );
  892. }
  893. /***************************************************************************
  894. * TTFontClass::FIND_TEXT_VLENGTH -- Finds length of text in pixels *
  895. * *
  896. * INPUT: BYTE *string - the strength to find the vertical length of *
  897. * int width - the width of the region to fit it in *
  898. * *
  899. * OUTPUT: int -- the number of pixels it takes up veritcally. *
  900. * *
  901. * HISTORY: *
  902. * 09/27/1994 PWG : Created. *
  903. *=========================================================================*/
  904. //
  905. // [OYO] Supports DBCS ( multi-byte characters ).
  906. //
  907. int TTFontClass::Find_Text_VLength( HDC hdc, char *str, int width )
  908. {
  909. int curlen = 0;
  910. int lastlen = 0;
  911. int lines = Get_Height();
  912. char *letter = str;
  913. bool make_dc = FALSE;
  914. HDC localDC = hdc;
  915. if ( *str == '\0' || str == NULL ) {
  916. return( 0 );
  917. }
  918. //--------------------------------------------------------------------------
  919. // If no DC was passed in, then we need to get one.
  920. //--------------------------------------------------------------------------
  921. if ( localDC == NULL ) {
  922. return( 0 );
  923. }
  924. //==========================================================================
  925. // Process languages EXCEPT Double-byte languages.
  926. //==========================================================================
  927. if( !(IS_LANGUAGE_DBCS( LanguageID ))) {
  928. //-----------------------------------------------------------------------
  929. // Get the pixel length of the string.
  930. //-----------------------------------------------------------------------
  931. curlen = String_Pixel_Width( localDC, str );
  932. lines = 0;
  933. //-----------------------------------------------------------------------
  934. // If the string in longer than the width given, calculate the number of
  935. // lines needed in pixels (height of string in pixels ).
  936. //-----------------------------------------------------------------------
  937. if ( curlen > width ) {
  938. while( curlen > 0 ) {
  939. if ( curlen > width ) {
  940. curlen -= width;
  941. } else {
  942. curlen = 0;
  943. }
  944. lines += Get_Height();
  945. }
  946. } else {
  947. lines = Get_Height();
  948. }
  949. //-----------------------------------------------------------------------
  950. // Check for any newlines. Add one line per newline.
  951. //-----------------------------------------------------------------------
  952. letter = str;
  953. while ( *letter ) {
  954. if ( *letter == '\n') {
  955. lines += Get_Height();
  956. }
  957. letter++;
  958. }
  959. } else {
  960. //=======================================================================
  961. // Process Double-Byte language text.
  962. //=======================================================================
  963. int i, n, wspc;
  964. UINT c;
  965. int fdbcs = IsFontDBCS();
  966. lines = 0;
  967. //-----------------------------------------------------------------------
  968. // For each word...
  969. //-----------------------------------------------------------------------
  970. while ( n = nGetWord( letter, fdbcs )) {
  971. //--------------------------------------------------------------------
  972. // For each character in the word...
  973. //--------------------------------------------------------------------
  974. for ( c=0, wspc=0, curlen=0, i=0; i < n; i++ ) {
  975. if ( c ) {
  976. //--------------------------------------------------------------
  977. // Double-byte character.
  978. //--------------------------------------------------------------
  979. c = ( c<<8 )|(UINT)(BYTE)letter[i];
  980. curlen += Char_Pixel_Width( localDC, c ) + wspc;
  981. c = 0;
  982. wspc = 0;
  983. } else if( fdbcs && IsDBCSLeadByte((BYTE)letter[i])) {
  984. //--------------------------------------------------------------
  985. // First half of a Double-byte character.
  986. //--------------------------------------------------------------
  987. c = (UINT)(BYTE)letter[i];
  988. } else if((BYTE)letter[i] > ' ' ) {
  989. //--------------------------------------------------------------
  990. // Single-byte character.
  991. //--------------------------------------------------------------
  992. curlen += Char_Pixel_Width( localDC, (UINT)(BYTE)letter[i] ) + wspc;
  993. wspc = 0;
  994. } else if( letter[i] == ' ') {
  995. //--------------------------------------------------------------
  996. // Space character.
  997. //--------------------------------------------------------------
  998. wspc += Char_Pixel_Width( localDC, ' ' );
  999. }
  1000. } // end-of-for
  1001. //--------------------------------------------------------------------
  1002. //
  1003. //--------------------------------------------------------------------
  1004. if( lastlen + curlen > width ) {
  1005. lines += Get_Height();
  1006. lastlen = 0;
  1007. }
  1008. //--------------------------------------------------------------------
  1009. // !!! If one block length bigger than available width,
  1010. // next line will be overflow. but never endless loop. !!!
  1011. //--------------------------------------------------------------------
  1012. lastlen += curlen + wspc;
  1013. //--------------------------------------------------------------------
  1014. //
  1015. //--------------------------------------------------------------------
  1016. if( letter[i] == '\n' ) {
  1017. lines += Get_Height();
  1018. lastlen = 0;
  1019. }
  1020. letter += n;
  1021. } // end-of-while
  1022. //-----------------------------------------------------------------------
  1023. // Left over, add a line.
  1024. //-----------------------------------------------------------------------
  1025. if( lastlen ) {
  1026. lines += Get_Height();
  1027. }
  1028. }
  1029. //--------------------------------------------------------------------------
  1030. // Return the number of lines.
  1031. //--------------------------------------------------------------------------
  1032. if ( !lines ) {
  1033. lines = Get_Height();
  1034. }
  1035. return( lines );
  1036. }
  1037. /***********************************************************************************************
  1038. * FontManagerClass::FontManagerClass -- Constructor for FontManager class. *
  1039. * *
  1040. * INPUT: none. *
  1041. * *
  1042. * OUTPUT: none *
  1043. * *
  1044. * WARNINGS: none *
  1045. * *
  1046. * HISTORY: *
  1047. * 03/26/1998 MML : Created. *
  1048. *=============================================================================================*/
  1049. FontManagerClass::FontManagerClass ( HDC hdc )
  1050. {
  1051. //--------------------------------------------------------------------------
  1052. // Open a DC to the BackBuffer.
  1053. //--------------------------------------------------------------------------
  1054. if ( hdc ) {
  1055. char szPath[ MAX_PATH ];
  1056. char szFile[ MAX_PATH ];
  1057. char szFacename[ MAX_PATH ];
  1058. char drive[ _MAX_DRIVE ];
  1059. char dir[ _MAX_DIR ];
  1060. bool b640X480 = false;
  1061. RECT rect; // Desktop Window ( used once ).
  1062. strcpy( szFile, "Arial.ttf" );
  1063. strcpy( szFacename, "Arial" );
  1064. strcpy( szPath, Args->Get_argv(0));
  1065. _splitpath( szPath, drive, dir, NULL, NULL );
  1066. _makepath( szPath, drive, dir, "Setup\\Setup", ".ini" );
  1067. GetPrivateProfileString( "Fonts", "Font", "Arial.tff", szFile, MAX_PATH, szPath );
  1068. GetPrivateProfileString( "Fonts", "Fontname", "Arial", szFacename, MAX_PATH, szPath );
  1069. //---------------------------------------------------------------------
  1070. // Use codepage set by Locomoto class.
  1071. //---------------------------------------------------------------------
  1072. UINT codepage = CodePage; // GetACP();
  1073. GetClientRect( GetDesktopWindow(), &rect );
  1074. if( rect.right <= 640 ) {
  1075. b640X480 = TRUE;
  1076. }
  1077. Msg( __LINE__, __FILE__, "FontManagerClass -- szFile = %s, szFilename = %s.", szFile, szFacename );
  1078. //---------------------------------------------------------------------
  1079. // Create the True Type Fonts.
  1080. //
  1081. // Value Weight
  1082. // ____________________________
  1083. // FW_DONTCARE 0
  1084. // FW_THIN 100
  1085. // FW_EXTRALIGHT 200
  1086. // FW_ULTRALIGHT 200
  1087. // FW_LIGHT 300
  1088. // FW_NORMAL 400
  1089. // FW_REGULAR 400
  1090. // FW_MEDIUM 500
  1091. // FW_SEMIBOLD 600
  1092. // FW_DEMIBOLD 600
  1093. // FW_BOLD 700
  1094. // FW_EXTRABOLD 800
  1095. // FW_ULTRABOLD 800
  1096. // FW_HEAVY 900
  1097. // FW_BLACK 900
  1098. //---------------------------------------------------------------------
  1099. switch( LanguageID ) { // [OYO] Add this line if you wish to support another languages
  1100. //=================================================================
  1101. // JAPANESE
  1102. //=================================================================
  1103. case LANG_JAP: // [OYO] Use MS PGothic for Japanese Win9x
  1104. if( codepage == 932 ) {
  1105. strcpy( szFile, "MSGothic.ttc" );
  1106. strcpy( szFacename, "MS PGothic" );
  1107. TTButtonFontPtr = new TTFontClass( hdc, szFile, szFacename, 20, FW_NORMAL, SHIFTJIS_CHARSET );
  1108. TTButtonFontPtrSmall= new TTFontClass( hdc, szFile, szFacename, 12, FW_NORMAL, SHIFTJIS_CHARSET );
  1109. TTTextFontPtr = new TTFontClass( hdc, szFile, szFacename, 16, FW_MEDIUM, SHIFTJIS_CHARSET );
  1110. TTTextFontPtr640 = new TTFontClass( hdc, szFile, szFacename, 14, FW_MEDIUM, SHIFTJIS_CHARSET );
  1111. TTTextFontPtr800 = new TTFontClass( hdc, szFile, szFacename, 14, FW_MEDIUM, SHIFTJIS_CHARSET );
  1112. TTLicenseFontPtr = new TTFontClass( hdc, szFile, szFacename, 12, FW_NORMAL, SHIFTJIS_CHARSET );
  1113. }
  1114. break;
  1115. //=================================================================
  1116. // KOREAN
  1117. //=================================================================
  1118. case LANG_KOR: // [OYO] Use GulimChe for Korean Win9x
  1119. if ( codepage == 949 ) {
  1120. strcpy( szFile, "Gulim.tff" );
  1121. strcpy( szFacename, "Gulim" );
  1122. TTButtonFontPtr = new TTFontClass( hdc, szFile, szFacename, 20, FW_NORMAL, HANGEUL_CHARSET );
  1123. TTButtonFontPtrSmall= new TTFontClass( hdc, szFile, szFacename, 20, FW_NORMAL, HANGEUL_CHARSET );
  1124. TTTextFontPtr = new TTFontClass( hdc, szFile, szFacename, 16, FW_MEDIUM, HANGEUL_CHARSET );
  1125. TTTextFontPtr640 = new TTFontClass( hdc, szFile, szFacename, 14, FW_MEDIUM, HANGEUL_CHARSET );
  1126. TTTextFontPtr800 = new TTFontClass( hdc, szFile, szFacename, 14, FW_MEDIUM, HANGEUL_CHARSET );
  1127. TTLicenseFontPtr = new TTFontClass( hdc, szFile, szFacename, 12, FW_NORMAL, HANGEUL_CHARSET );
  1128. }
  1129. break;
  1130. //=================================================================
  1131. // CHINESE
  1132. //=================================================================
  1133. case LANG_CHI:
  1134. if ( codepage == 950 ) {
  1135. strcpy( szFile, "mingliu.ttc" );
  1136. strcpy( szFacename, "mingliu" );
  1137. TTButtonFontPtr = new TTFontClass( hdc, szFile, szFacename, 20, FW_NORMAL, CHINESEBIG5_CHARSET );
  1138. TTButtonFontPtrSmall= new TTFontClass( hdc, szFile, szFacename, 14, FW_NORMAL, CHINESEBIG5_CHARSET );
  1139. TTTextFontPtr = new TTFontClass( hdc, szFile, szFacename, 16, FW_MEDIUM, CHINESEBIG5_CHARSET );
  1140. TTTextFontPtr640 = new TTFontClass( hdc, szFile, szFacename, 14, FW_MEDIUM, CHINESEBIG5_CHARSET );
  1141. TTTextFontPtr800 = new TTFontClass( hdc, szFile, szFacename, 14, FW_MEDIUM, CHINESEBIG5_CHARSET );
  1142. TTLicenseFontPtr = new TTFontClass( hdc, szFile, szFacename, 12, FW_NORMAL, CHINESEBIG5_CHARSET );
  1143. }
  1144. break;
  1145. //=================================================================
  1146. // ENGLISH, FRENCH, GERMAN
  1147. //=================================================================
  1148. case LANG_GER:
  1149. case LANG_FRE:
  1150. case LANG_USA:
  1151. default:
  1152. TTButtonFontPtr = new TTFontClass( hdc, szFile, szFacename, 22, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1153. if( LANG_FRE == LanguageID ) {
  1154. TTButtonFontPtrSmall= new TTFontClass( hdc, szFile, szFacename, 20, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1155. } else {
  1156. TTButtonFontPtrSmall= new TTFontClass( hdc, szFile, szFacename, 22, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1157. }
  1158. TTTextFontPtr = new TTFontClass( hdc, szFile, szFacename, 16, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1159. TTTextFontPtr640 = new TTFontClass( hdc, szFile, szFacename, 14, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1160. TTTextFontPtr800 = new TTFontClass( hdc, szFile, szFacename, 14, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1161. TTLicenseFontPtr = new TTFontClass( hdc, szFile, szFacename, 12, FW_MEDIUM, ANSI_CHARSET, 0, 0, 0, FALSE );
  1162. break;
  1163. }
  1164. //----------------------------------------------------------------------
  1165. // If we fell through...
  1166. //----------------------------------------------------------------------
  1167. if( TTButtonFontPtr == NULL || TTTextFontPtr == NULL ) {
  1168. strcpy( szFile, "Arial.tff" );
  1169. strcpy( szFacename, "Arial" );
  1170. if( TTButtonFontPtr == NULL ) {
  1171. TTButtonFontPtr = new TTFontClass( hdc, szFile, szFacename, 22, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1172. }
  1173. if( TTButtonFontPtrSmall == NULL ) {
  1174. TTButtonFontPtrSmall= new TTFontClass( hdc, szFile, szFacename, 22, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1175. }
  1176. if( TTTextFontPtr == NULL ) {
  1177. TTTextFontPtr = new TTFontClass( hdc, szFile, szFacename, 16, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1178. }
  1179. if( TTTextFontPtr640 == NULL ) {
  1180. TTTextFontPtr640 = new TTFontClass( hdc, szFile, szFacename, 14, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1181. }
  1182. if( TTTextFontPtr800 == NULL ) {
  1183. TTTextFontPtr800 = new TTFontClass( hdc, szFile, szFacename, 14, FW_SEMIBOLD, ANSI_CHARSET, 0, 0, 0, FALSE );
  1184. }
  1185. if( TTLicenseFontPtr == NULL ) {
  1186. TTLicenseFontPtr = new TTFontClass( hdc, szFile, szFacename, 12, FW_MEDIUM, ANSI_CHARSET, 0, 0, 0, FALSE );
  1187. }
  1188. }
  1189. }
  1190. assert( TTTextFontPtr != NULL );
  1191. assert( TTTextFontPtr640 != NULL );
  1192. assert( TTTextFontPtr800 != NULL );
  1193. assert( TTButtonFontPtr != NULL );
  1194. assert( TTButtonFontPtrSmall != NULL );
  1195. assert( TTLicenseFontPtr != NULL );
  1196. }
  1197. /***********************************************************************************************
  1198. * FontManagerClass::~FontManagerClass -- Destructor for FontManager class. *
  1199. * *
  1200. * INPUT: none. *
  1201. * *
  1202. * OUTPUT: none *
  1203. * *
  1204. * WARNINGS: none *
  1205. * *
  1206. * HISTORY: *
  1207. * 03/26/1998 MML : Created. *
  1208. *=============================================================================================*/
  1209. FontManagerClass::~FontManagerClass ( void )
  1210. {
  1211. if ( TTButtonFontPtr != NULL ) {
  1212. delete TTButtonFontPtr;
  1213. TTButtonFontPtr = NULL;
  1214. }
  1215. if ( TTTextFontPtr != NULL ) {
  1216. delete TTTextFontPtr;
  1217. TTTextFontPtr = NULL;
  1218. }
  1219. }
  1220. /***********************************************************************************************
  1221. * Font_From_TPF -- Convert flags into a font pointer. *
  1222. * *
  1223. * This routine will examine the specified flags and return with a pointer to the font *
  1224. * that the flags represent. *
  1225. * *
  1226. * INPUT: flags -- The flags to convert into a font pointer. *
  1227. * *
  1228. * OUTPUT: Returns with a font pointer that matches the flags. *
  1229. * *
  1230. * WARNINGS: If no match could be found, a default font pointer is returned. *
  1231. * *
  1232. * HISTORY: *
  1233. * 05/26/1997 JLB : Created. *
  1234. *=============================================================================================*/
  1235. TTFontClass * Font_From_TPF ( TextPrintType flags )
  1236. {
  1237. TTFontClass *fontptr= NULL;
  1238. switch (flags & 0x000F) {
  1239. case TPF_BUTTON_FONT:
  1240. fontptr = TTButtonFontPtr;
  1241. break;
  1242. case TPF_TEXT_FONT:
  1243. fontptr = TTTextFontPtr;
  1244. break;
  1245. default:
  1246. fontptr = TTTextFontPtr;
  1247. break;
  1248. }
  1249. return( fontptr );
  1250. }
  1251. /************************************************************************************************
  1252. * Is_True_Type_Font -- Convert flags into a font pointer. *
  1253. * *
  1254. * This routine will examine the specified flags and return with a pointer to the font *
  1255. * that the flags represent. *
  1256. * *
  1257. * INPUT: flags -- The flags to convert into a font pointer. *
  1258. * *
  1259. * OUTPUT: Returns with a font pointer that matches the flags. *
  1260. * *
  1261. * WARNINGS: If no match could be found, a default font pointer is returned. *
  1262. * *
  1263. * HISTORY: *
  1264. * 05/26/1997 JLB : Created. *
  1265. *==============================================================================================*/
  1266. bool Is_True_Type_Font( TextPrintType flags )
  1267. {
  1268. if (( flags == TPF_BUTTON_FONT ) || ( flags == TPF_TEXT_FONT )) {
  1269. return TRUE;
  1270. } else {
  1271. return FALSE;
  1272. }
  1273. }