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.

825 lines
27 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: stockfnt.cxx
  3. *
  4. * Initializes the stock font objects.
  5. *
  6. * Note:
  7. *
  8. * This module requires the presence of the following section in the
  9. * WIN.INI file:
  10. *
  11. * [GRE_Initialize]
  12. * fonts.fon=[System font filename]
  13. * oemfont.fon=[OEM (terminal) font filename]
  14. * fixedfon.fon=[System fixed-pitch font filename]
  15. *
  16. * Also, an undocumented feature of WIN 3.0/3.1 is supported: the ability
  17. * to override the fonts.fon definition of the system font. This is
  18. * done by defining SystemFont and SystemFontSize in the [windows]
  19. * section of WIN.INI.
  20. *
  21. *
  22. * Rewritten 13-Nov-1994 Andre Vachon [andreva]
  23. * Created: 06-May-1991 11:22:23
  24. * Author: Gilman Wong [gilmanw]
  25. *
  26. * Copyright (c) 1990-1999 Microsoft Corporation
  27. *
  28. \**************************************************************************/
  29. #include "precomp.hxx"
  30. // Function prototypes.
  31. extern "C" BOOL bInitStockFonts(VOID);
  32. extern "C" BOOL bInitStockFontsInternal(PWSZ pwszFontDir);
  33. extern "C" BOOL bInitOneStockFont(PWSZ pwszValue, LFTYPE type, int iFont, HANDLE RegistryKey,
  34. PKEY_VALUE_PARTIAL_INFORMATION ValueKeyInfo,
  35. ULONG ValueLength, PWCHAR ValueName, PWCHAR ValueKeyName);
  36. extern "C" BOOL bInitOneStockFontInternal(PWCHAR pwszFont, LFTYPE type, int iFont);
  37. extern "C" BOOL bInitSystemFont(PWCHAR pfontFile, ULONG fontSize);
  38. extern "C" VOID vInitEmergencyStockFont(PWCHAR pfontFile);
  39. #if(WINVER >= 0x0400)
  40. extern "C" HFONT hfontInitDefaultGuiFont();
  41. #endif
  42. extern BOOL G_fConsole;
  43. #pragma alloc_text(INIT, bInitStockFonts)
  44. #pragma alloc_text(INIT, bInitStockFontsInternal)
  45. #pragma alloc_text(INIT, bInitOneStockFont)
  46. #pragma alloc_text(INIT, bInitOneStockFontInternal)
  47. #pragma alloc_text(INIT, bInitSystemFont)
  48. #pragma alloc_text(INIT, vInitEmergencyStockFont)
  49. #if(WINVER >= 0x0400)
  50. #pragma alloc_text(INIT, hfontInitDefaultGuiFont)
  51. #endif
  52. // "Last resort" default HPFE for use by the mapper.
  53. extern PFE *gppfeMapperDefault;
  54. #if(WINVER >= 0x0400)
  55. BOOL gbFinishDefGUIFontInit;
  56. #endif
  57. //
  58. // This was the USER mode version of font initialization.
  59. // This code relied on the ability of transforming a file name found in the
  60. // registry to a full path name so the file could be loaded.
  61. //
  62. // In the kernel mode version, we will assume that all font files (except
  63. // winsrv.dll) will be in the system directory
  64. //
  65. // If we, for some reason, need to get system font files loaded later on
  66. // from another directory, the graphics engine should be "fixed" to allow
  67. // for dynamic changing of the system font - especially when the USER logs
  68. // on to a different desktop.
  69. //
  70. //
  71. // Kernel mode version of font initialization.
  72. //
  73. /******************************Public*Routine******************************\
  74. * BOOL bOpenKey(PWSZ pwszKey, HANDLE *pRegistryKey)
  75. *
  76. * History:
  77. * 06-Aug-1997 -by- Bodin Dresevic [BodinD]
  78. * Wrote it.
  79. \**************************************************************************/
  80. BOOL bOpenKey(PWSZ pwszKey, HANDLE *pRegistryKey)
  81. {
  82. UNICODE_STRING UnicodeRoot;
  83. OBJECT_ATTRIBUTES ObjectAttributes;
  84. RtlInitUnicodeString(&UnicodeRoot, pwszKey);
  85. InitializeObjectAttributes(&ObjectAttributes,
  86. &UnicodeRoot,
  87. OBJ_CASE_INSENSITIVE,
  88. NULL,
  89. NULL);
  90. return NT_SUCCESS(ZwOpenKey(pRegistryKey,
  91. (ACCESS_MASK) 0,
  92. &ObjectAttributes));
  93. }
  94. /******************************Public*Routine******************************\
  95. * BOOL bQueryValueKey
  96. *
  97. * History:
  98. * 06-Aug-1997 -by- Bodin Dresevic [BodinD]
  99. * Wrote it.
  100. \**************************************************************************/
  101. BOOL bQueryValueKey
  102. (
  103. PWSZ pwszValue,
  104. HANDLE RegistryKey,
  105. PKEY_VALUE_PARTIAL_INFORMATION ValueKeyInfo,
  106. ULONG ValueLength
  107. )
  108. {
  109. UNICODE_STRING UnicodeValue;
  110. ULONG ValueReturnedLength;
  111. RtlInitUnicodeString(&UnicodeValue,pwszValue);
  112. return NT_SUCCESS(ZwQueryValueKey(RegistryKey,
  113. &UnicodeValue,
  114. KeyValuePartialInformation,
  115. ValueKeyInfo,
  116. ValueLength,
  117. &ValueReturnedLength));
  118. }
  119. /******************************Public*Routine******************************\
  120. * BOOL bInitStockFonts ()
  121. *
  122. * Part of the GRE initialization.
  123. *
  124. * Creates LFONTs representing each of the different STOCK OBJECT fonts.
  125. *
  126. \**************************************************************************/
  127. #define KEY_SOFTWARE_FONTS L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current\\Software\\Fonts"
  128. #define KEY_GRE_INITIALIZE L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Gre_Initialize"
  129. #define FONTDIR_FONTS L"\\SystemRoot\\Fonts\\"
  130. extern "C" BOOL bInitStockFontsInternal(PWSZ pwszFontDir)
  131. {
  132. ENUMLOGFONTEXDVW elfw;
  133. HANDLE RegistryKey;
  134. BOOL bOk;
  135. PULONG ValueBuffer;
  136. PKEY_VALUE_PARTIAL_INFORMATION ValueKeyInfo;
  137. PWCHAR ValueName;
  138. PWCHAR ValueKeyName;
  139. ULONG ValueLength = MAX_PATH * 2 - sizeof(LARGE_INTEGER);
  140. ULONG FontSize;
  141. ULONG cjFontDir = (wcslen(pwszFontDir) + 1) * sizeof(WCHAR);
  142. ValueBuffer = (PULONG)PALLOCMEM((MAX_PATH + cjFontDir) * 2,'gdii');
  143. if (!ValueBuffer)
  144. return FALSE;
  145. RtlMoveMemory(ValueBuffer,
  146. pwszFontDir,
  147. cjFontDir);
  148. ValueName = (PWCHAR) ValueBuffer;
  149. ValueKeyName = (PWCHAR)
  150. (((PUCHAR)ValueBuffer) + cjFontDir -
  151. sizeof(UNICODE_NULL));
  152. // Offset the regsitry query buffer into the ValueBuffer, but make sure
  153. // it is quad-word aligned.
  154. ValueKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION) (
  155. (((ULONG_PTR)ValueBuffer) + cjFontDir +
  156. sizeof(LARGE_INTEGER)) & (~(ULONG_PTR)(sizeof(LARGE_INTEGER) - 1)) );
  157. // Lets try to use the USER defined system font
  158. if (bOpenKey(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
  159. &RegistryKey))
  160. {
  161. if (bQueryValueKey(L"SystemFontSize", RegistryKey,
  162. ValueKeyInfo,
  163. ValueLength))
  164. {
  165. FontSize = *((PULONG)(&ValueKeyInfo->Data[0]));
  166. if (bQueryValueKey(L"SystemFont", RegistryKey,
  167. ValueKeyInfo,
  168. ValueLength))
  169. {
  170. RtlMoveMemory(ValueKeyName,
  171. &ValueKeyInfo->Data[0],
  172. ValueKeyInfo->DataLength);
  173. bInitSystemFont(ValueName, FontSize);
  174. }
  175. }
  176. ZwCloseKey(RegistryKey);
  177. }
  178. bOk = bOpenKey(KEY_SOFTWARE_FONTS, &RegistryKey);
  179. if (!bOk)
  180. {
  181. bOk = bOpenKey(KEY_GRE_INITIALIZE, &RegistryKey);
  182. }
  183. if (bOk)
  184. {
  185. // If the user did not specify a font, or it failed to load, then use the
  186. // font in the fonts section. This functionality is here to allow
  187. // a sophisticated user to specify a system font other than the
  188. // default system font which is defined by font.fon
  189. // entry in gre_initialize. for instance, lucida unicode was
  190. // one attempted by LoryH for international setup's but it was
  191. // not deemed acceptable because of the shell hardcoded issues
  192. if (STOCKOBJ_SYSFONT == NULL)
  193. {
  194. bInitOneStockFont(
  195. L"FONTS.FON", LF_TYPE_SYSTEM, SYSTEM_FONT,
  196. RegistryKey, ValueKeyInfo,ValueLength,ValueName,ValueKeyName);
  197. }
  198. // init oem stock font
  199. bInitOneStockFont(
  200. L"OEMFONT.FON", LF_TYPE_OEM, OEM_FIXED_FONT,
  201. RegistryKey, ValueKeyInfo,ValueLength,ValueName,ValueKeyName);
  202. // Initialize the fixed system font - use the default system font
  203. // if the fixed font could not be loaded
  204. bInitOneStockFont(
  205. L"FIXEDFON.FON", LF_TYPE_SYSTEM_FIXED, SYSTEM_FIXED_FONT,
  206. RegistryKey, ValueKeyInfo,ValueLength,ValueName,ValueKeyName);
  207. ZwCloseKey(RegistryKey);
  208. }
  209. // Load the emergency fonts for the system and OEM font in case one
  210. // of the previous two failed. The vInitEmergencyStockFont routine itself
  211. // does appropriate checks to determine if one or the other of these fonts
  212. // has been loaded.
  213. vInitEmergencyStockFont(L"\\SystemRoot\\System32\\winsrv.dll");
  214. // if system fixed font was not initialized above, make it equal to "ordinary"
  215. // system font. (This is warrisome, because system in not fixed pitch).
  216. if (STOCKOBJ_SYSFIXEDFONT == NULL)
  217. {
  218. bSetStockObject(STOCKOBJ_SYSFONT,SYSTEM_FIXED_FONT);
  219. }
  220. DcAttrDefault.hlfntNew = STOCKOBJ_SYSFONT;
  221. // Create the DeviceDefault Font
  222. bOk = TRUE;
  223. RtlZeroMemory(&elfw,sizeof(ENUMLOGFONTEXDVW));
  224. elfw.elfEnumLogfontEx.elfLogFont.lfPitchAndFamily = FIXED_PITCH;
  225. if (!bSetStockObject(
  226. hfontCreate(&elfw,
  227. LF_TYPE_DEVICE_DEFAULT,
  228. LF_FLAG_STOCK | LF_FLAG_ALIASED,
  229. NULL),DEVICE_DEFAULT_FONT))
  230. {
  231. if (!G_fConsole)
  232. {
  233. bOk = FALSE;
  234. goto error;
  235. }
  236. else
  237. RIP("bInitStockFonts(): could not create STOCKOBJ_DEFAULTDEVFONT\n");
  238. }
  239. // Create the ANSI variable Font
  240. RtlZeroMemory(&elfw,sizeof(ENUMLOGFONTEXDVW));
  241. elfw.elfEnumLogfontEx.elfLogFont.lfPitchAndFamily = VARIABLE_PITCH;
  242. if (!bSetStockObject(
  243. hfontCreate(&elfw,
  244. LF_TYPE_ANSI_VARIABLE,
  245. LF_FLAG_STOCK | LF_FLAG_ALIASED,
  246. NULL),ANSI_VAR_FONT))
  247. {
  248. if (!G_fConsole)
  249. {
  250. bOk = FALSE;
  251. goto error;
  252. }
  253. else
  254. RIP("bInitStockFonts(): could not create STOCKOBJ_ANSIVARFONT\n");
  255. }
  256. // Create the ANSI Fixed Font
  257. RtlZeroMemory(&elfw,sizeof(ENUMLOGFONTEXDVW));
  258. elfw.elfEnumLogfontEx.elfLogFont.lfPitchAndFamily = FIXED_PITCH;
  259. if (!bSetStockObject( hfontCreate(&elfw,
  260. LF_TYPE_ANSI_FIXED,
  261. LF_FLAG_STOCK | LF_FLAG_ALIASED,
  262. NULL),ANSI_FIXED_FONT))
  263. {
  264. if (!G_fConsole)
  265. {
  266. bOk = FALSE;
  267. goto error;
  268. }
  269. else
  270. RIP("bInitStockFonts(): could not create STOCKOBJ_ANSIFIXEDFONT\n");
  271. }
  272. #if(WINVER >= 0x0400)
  273. // Create the default GUI font.
  274. if (!bSetStockObject(hfontInitDefaultGuiFont(), DEFAULT_GUI_FONT))
  275. {
  276. if (!G_fConsole)
  277. {
  278. bOk = FALSE;
  279. goto error;
  280. }
  281. else
  282. RIP("bInitStockFonts(): could not create STOCKOBJ_DEFAULTGUIFONT\n");
  283. }
  284. #endif
  285. // Set all stock fonts public.
  286. if ( (!GreSetLFONTOwner(STOCKOBJ_SYSFONT, OBJECT_OWNER_PUBLIC))
  287. || (!GreSetLFONTOwner(STOCKOBJ_SYSFIXEDFONT, OBJECT_OWNER_PUBLIC))
  288. || (!GreSetLFONTOwner(STOCKOBJ_OEMFIXEDFONT, OBJECT_OWNER_PUBLIC))
  289. || (!GreSetLFONTOwner(STOCKOBJ_DEFAULTDEVFONT, OBJECT_OWNER_PUBLIC))
  290. || (!GreSetLFONTOwner(STOCKOBJ_ANSIFIXEDFONT, OBJECT_OWNER_PUBLIC))
  291. || (!GreSetLFONTOwner(STOCKOBJ_ANSIVARFONT, OBJECT_OWNER_PUBLIC))
  292. #if(WINVER >= 0x0400)
  293. || (!GreSetLFONTOwner(STOCKOBJ_DEFAULTGUIFONT, OBJECT_OWNER_PUBLIC))
  294. #endif
  295. )
  296. {
  297. if (!G_fConsole)
  298. {
  299. bOk = FALSE;
  300. goto error;
  301. }
  302. else
  303. RIP("bInitStockFonts(): could not set owner\n");
  304. }
  305. error:
  306. VFREEMEM(ValueBuffer);
  307. return bOk;
  308. }
  309. /******************************Public*Routine******************************\
  310. *
  311. * BOOL bInitStockFonts(VOID)
  312. *
  313. * first check for stock fonts in the %windir%\fonts directory
  314. * and if they are not there, check in the %windir%\system directory
  315. * Later we should even remove the second attepmt when fonts directory
  316. * becomes established, but for now we want to check both places.
  317. *
  318. * History:
  319. * 05-Oct-1995 -by- Bodin Dresevic [BodinD]
  320. * Wrote it.
  321. \**************************************************************************/
  322. extern "C" BOOL bInitStockFonts(VOID)
  323. {
  324. return bInitStockFontsInternal(FONTDIR_FONTS);
  325. }
  326. /******************************Public*Routine******************************\
  327. * BOOL bInitSystemFont ()
  328. *
  329. * Initialize the system font from either the SystemFont and SystemFontSize
  330. * or the FONTS.FON definitions in the [windows] and [GRE_Initialize]
  331. * sections of the WIN.INI file, respectively.
  332. *
  333. \**************************************************************************/
  334. BOOL bInitSystemFont(
  335. PWCHAR pfontFile,
  336. ULONG fontSize)
  337. {
  338. ENUMLOGFONTEXDVW elfw;
  339. COUNT cFonts;
  340. BOOL bRet = FALSE;
  341. if ( (pfontFile) &&
  342. (*pfontFile != L'\0') &&
  343. (fontSize != 0) )
  344. {
  345. //
  346. // Load font file.
  347. //
  348. PPFF pPFF_Font;
  349. PUBLIC_PFTOBJ pfto;
  350. // The engine does not handle FOT files anymore, we shouldn't get here with a FOT file
  351. if ( (pfto.bLoadAFont(pfontFile,
  352. &cFonts,
  353. PFF_STATE_PERMANENT_FONT,
  354. &pPFF_Font)) &&
  355. (cFonts != 0) &&
  356. (pPFF_Font != NULL) )
  357. {
  358. //
  359. // Create and validate public PFF user object.
  360. //
  361. PFFOBJ pffo(pPFF_Font);
  362. if (pffo.bValid())
  363. {
  364. //
  365. // Find the best size match from the faces (PFEs) in the PFF.
  366. //
  367. LONG lDist; // diff. in size of candidate
  368. LONG lBestDist = 0x7FFFFFFF; // arbitrarily high number
  369. PFE *ppfeBest = (PFE *) NULL; // handle of best candidate
  370. for (COUNT c = 0; c < cFonts; c++)
  371. {
  372. PFEOBJ pfeoTmp(pffo.ppfe(c)); // candidate face
  373. if (pfeoTmp.bValid())
  374. {
  375. //
  376. // Compute the magnitude of the difference in size.
  377. // simulations are not relevant
  378. //
  379. IFIOBJ ifio(pfeoTmp.pifi());
  380. if (ifio.bContinuousScaling())
  381. {
  382. //don't care about best dist.
  383. //lBestDist = 0;
  384. ppfeBest = pfeoTmp.ppfeGet();
  385. break;
  386. }
  387. else
  388. {
  389. lDist = (LONG) fontSize - ifio.lfHeight();
  390. if ((lDist >= 0) && (lDist < lBestDist))
  391. {
  392. lBestDist = lDist;
  393. ppfeBest = pfeoTmp.ppfeGet();
  394. if (lDist == 0)
  395. break;
  396. }
  397. }
  398. }
  399. }
  400. //
  401. // Fill a LOGFONT based on the IFIMETRICS from the best PFE.
  402. //
  403. PFEOBJ pfeo(ppfeBest);
  404. if (pfeo.bValid())
  405. {
  406. vIFIMetricsToEnumLogFontExDvW(&elfw, pfeo.pifi());
  407. IFIOBJ ifio(pfeo.pifi());
  408. // If this is a scalable font, force the height to be the same
  409. // as that specified by [SystemFontSize].
  410. if (ifio.bContinuousScaling())
  411. {
  412. elfw.elfEnumLogfontEx.elfLogFont.lfHeight = fontSize;
  413. elfw.elfEnumLogfontEx.elfLogFont.lfWidth = 0;
  414. }
  415. //
  416. // Save the HPFE handle. This is the mapper's default HPFE
  417. // (its last resort).
  418. //
  419. gppfeMapperDefault = pfeo.ppfeGet();
  420. //
  421. // Win 3.1 compatibility stuff
  422. //
  423. elfw.elfEnumLogfontEx.elfLogFont.lfQuality = PROOF_QUALITY;
  424. bRet = bSetStockObject(hfontCreate(&elfw,
  425. LF_TYPE_SYSTEM,
  426. LF_FLAG_STOCK,
  427. NULL),SYSTEM_FONT);
  428. }
  429. }
  430. }
  431. }
  432. return bRet;
  433. }
  434. /******************************Public*Routine******************************\
  435. * VOID bInitOneStockFont()
  436. *
  437. * Routine to initialize a stock font object
  438. *
  439. \**************************************************************************/
  440. BOOL bInitOneStockFontInternal(
  441. PWCHAR pwszFont,
  442. LFTYPE type,
  443. int iFont)
  444. {
  445. COUNT cFonts;
  446. PPFF pPFF_Font;
  447. PUBLIC_PFTOBJ pfto;
  448. ENUMLOGFONTEXDVW elfw;
  449. BOOL bRet = FALSE;
  450. if ( (pfto.bLoadAFont(pwszFont,
  451. &cFonts,
  452. PFF_STATE_PERMANENT_FONT,
  453. &pPFF_Font)) &&
  454. (cFonts != 0) &&
  455. (pPFF_Font != NULL) )
  456. {
  457. PFFOBJ pffo(pPFF_Font);
  458. if (pffo.bValid())
  459. {
  460. PFEOBJ pfeo(pffo.ppfe(0));
  461. if (pfeo.bValid())
  462. {
  463. vIFIMetricsToEnumLogFontExDvW(&elfw, pfeo.pifi());
  464. if (iFont == SYSTEM_FONT)
  465. {
  466. //
  467. // Save the HPFE handle. This is the mapper's default
  468. // HPFE (its last resort).
  469. //
  470. gppfeMapperDefault = pfeo.ppfeGet();
  471. }
  472. //
  473. // Win 3.1 compatibility stuff
  474. //
  475. elfw.elfEnumLogfontEx.elfLogFont.lfQuality = PROOF_QUALITY;
  476. bRet = bSetStockObject(hfontCreate(&elfw,type,LF_FLAG_STOCK,NULL),iFont);
  477. }
  478. }
  479. }
  480. if (STOCKFONT(iFont) == NULL)
  481. {
  482. KdPrint(("bInitOneStockFontInternal: Failed to initialize the %ws stock fonts\n",
  483. pwszFont));
  484. }
  485. return bRet;
  486. }
  487. BOOL bInitOneStockFont
  488. (
  489. PWSZ pwszValue,
  490. LFTYPE type,
  491. int iFont,
  492. HANDLE RegistryKey,
  493. PKEY_VALUE_PARTIAL_INFORMATION ValueKeyInfo,
  494. ULONG ValueLength,
  495. PWCHAR ValueName,
  496. PWCHAR ValueKeyName
  497. )
  498. {
  499. BOOL bRet = FALSE;
  500. if (bQueryValueKey(pwszValue, RegistryKey,
  501. ValueKeyInfo,
  502. ValueLength))
  503. {
  504. RtlMoveMemory(ValueKeyName,
  505. &ValueKeyInfo->Data[0],
  506. ValueKeyInfo->DataLength);
  507. bRet = bInitOneStockFontInternal(ValueName, type, iFont);
  508. }
  509. return bRet;
  510. }
  511. /******************************Public*Routine******************************\
  512. * VOID vInitEmergencyStockFont()
  513. *
  514. * Initializes the system and oem fixed font stock objects in case the
  515. * something failed during initialization of the fonts in WIN.INI.
  516. *
  517. \**************************************************************************/
  518. VOID vInitEmergencyStockFont(
  519. PWSTR pfontFile)
  520. {
  521. PPFF pPFF_Font;
  522. PUBLIC_PFTOBJ pfto;
  523. COUNT cFonts;
  524. ENUMLOGFONTEXDVW elfw;
  525. if ( ((STOCKOBJ_OEMFIXEDFONT == NULL) || (STOCKOBJ_SYSFONT == NULL)) &&
  526. (pfontFile) &&
  527. (pfto.bLoadAFont(pfontFile,
  528. &cFonts,
  529. PFF_STATE_PERMANENT_FONT,
  530. &pPFF_Font)) &&
  531. (cFonts != 0) &&
  532. (pPFF_Font != NULL) )
  533. {
  534. // Create and validate PFF user object.
  535. PFFOBJ pffo(pPFF_Font); // most recent PFF
  536. if (pffo.bValid())
  537. {
  538. // Create and validate PFE user object.
  539. for (COUNT i = 0;
  540. (i < cFonts) && ((STOCKOBJ_OEMFIXEDFONT == NULL) ||
  541. (STOCKOBJ_SYSFONT == NULL));
  542. i++)
  543. {
  544. PFEOBJ pfeo(pffo.ppfe(i));
  545. if (pfeo.bValid())
  546. {
  547. // For the system font use the first face with the name
  548. // "system." For the OEM font use the first face with
  549. // then name "terminal."
  550. IFIOBJ ifiobj( pfeo.pifi() );
  551. if ( (STOCKOBJ_SYSFONT == NULL) &&
  552. (!_wcsicmp(ifiobj.pwszFaceName(), L"SYSTEM")) )
  553. {
  554. WARNING("vInitEmergencyStockFont(): trying to set STOCKOBJ_SYSFONT\n");
  555. vIFIMetricsToEnumLogFontExDvW(&elfw, pfeo.pifi());
  556. gppfeMapperDefault = pfeo.ppfeGet();
  557. // Win 3.1 compatibility stuff
  558. elfw.elfEnumLogfontEx.elfLogFont.lfQuality = PROOF_QUALITY;
  559. bSetStockObject(
  560. hfontCreate(&elfw,LF_TYPE_SYSTEM,LF_FLAG_STOCK,NULL),
  561. SYSTEM_FONT);
  562. }
  563. if ( (STOCKOBJ_OEMFIXEDFONT == NULL) &&
  564. (!_wcsicmp(ifiobj.pwszFaceName(), L"TERMINAL")) )
  565. {
  566. WARNING("vInitEmergencyStockFont(): trying to set STOCKOBJ_OEMFIXEDFONT\n");
  567. vIFIMetricsToEnumLogFontExDvW(&elfw, pfeo.pifi());
  568. // Win 3.1 compatibility stuff
  569. elfw.elfEnumLogfontEx.elfLogFont.lfQuality = PROOF_QUALITY;
  570. bSetStockObject(
  571. hfontCreate(&elfw,LF_TYPE_OEM,LF_FLAG_STOCK,NULL),
  572. OEM_FIXED_FONT);
  573. }
  574. }
  575. }
  576. }
  577. WARNING("vInitEmergencyStockFont(): Done\n");
  578. }
  579. }
  580. #if(WINVER >= 0x0400)
  581. /******************************Public*Routine******************************\
  582. * hfontInitDefaultGuiFont
  583. *
  584. * Initialize the DEFAULT_GUI_FONT stock font.
  585. *
  586. * The code Win95 uses to initialize this stock font can be found in
  587. * win\core\gdi\gdiinit.asm in the function InitGuiFonts. Basically,
  588. * a description of several key parameters (height, weight, italics,
  589. * charset, and facename) are specified as string resources of GDI.DLL.
  590. * After scaling, to compensate for the DPI of the display, these parameters
  591. * are used to create the logfont.
  592. *
  593. * We will emulate this behavior by loading these properties from the
  594. * registry. Also, so as to not have to recreate the hives initially, if
  595. * the appropriate registry entries do not exist, we will supply defaults
  596. * that match the values currently used by the initial Win95 US release.
  597. *
  598. * The registry entries are:
  599. *
  600. * [GRE_Initialize]
  601. * ...
  602. *
  603. * GUIFont.Height = (height in POINTS, default 8pt.)
  604. * GUIFont.Weight = (font weight, default FW_NORMAL (400))
  605. * GUIFont.Italic = (1 if italicized, default 0)
  606. * GUIFont.CharSet = (charset, default ANSI_CHARSET (0))
  607. * GUIFont.Facename = (facename, default "MS Sans Serif")
  608. *
  609. * Note: On Win95, the facename is NULL. This defaults to "MS Sans Serif"
  610. * on Win95. Unfortunately, the WinNT mapper is different and will
  611. * map to "Arial". To keep ensure that GetObject returns a LOGFONT
  612. * equivalent to Win95, we could create this font as LF_FLAG_ALIASED
  613. * so that externally the facename would be NULL but internally we
  614. * use one with the appropriate facename. On the other hand, an app
  615. * might query to find out the facename of the DEFAULT_GUI_FONT and
  616. * create a new font. On Win95, this would also map to "MS Sans Serif",
  617. * but we would map to "Arial". For now, I propose that we go with
  618. * the simpler method (do not set LF_FLAG_ALIASED). I just wanted
  619. * to note this in case a bug arises later.
  620. *
  621. * History:
  622. * 11-Jan-1996 -by- Gilman Wong [gilmanw]
  623. * Wrote it.
  624. \**************************************************************************/
  625. HFONT hfontInitDefaultGuiFont()
  626. {
  627. HANDLE hkey;
  628. PKEY_VALUE_PARTIAL_INFORMATION ValueKeyInfo;
  629. BYTE aj[sizeof(PKEY_VALUE_PARTIAL_INFORMATION) + (LF_FACESIZE * sizeof(WCHAR))];
  630. ENUMLOGFONTEXDVW elfw;
  631. RtlZeroMemory(&elfw,sizeof(ENUMLOGFONTEXDVW));
  632. // Initialize to defaults.
  633. wcscpy(elfw.elfEnumLogfontEx.elfLogFont.lfFaceName, L"MS Shell Dlg");
  634. elfw.elfEnumLogfontEx.elfLogFont.lfHeight = 8;
  635. elfw.elfEnumLogfontEx.elfLogFont.lfWeight = FW_NORMAL;
  636. elfw.elfEnumLogfontEx.elfLogFont.lfItalic = 0;
  637. elfw.elfEnumLogfontEx.elfLogFont.lfCharSet = gjCurCharset;
  638. // Now let's attempt to initialize from registry.
  639. ValueKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION) aj;
  640. if (bOpenKey(KEY_GRE_INITIALIZE, &hkey))
  641. {
  642. if (bQueryValueKey(L"GUIFont.Facename", hkey, ValueKeyInfo, sizeof(aj)))
  643. {
  644. wcsncpy(elfw.elfEnumLogfontEx.elfLogFont.lfFaceName, (WCHAR *) ValueKeyInfo->Data,
  645. LF_FACESIZE);
  646. }
  647. if (bQueryValueKey(L"GUIFont.Height", hkey, ValueKeyInfo, sizeof(aj)))
  648. {
  649. elfw.elfEnumLogfontEx.elfLogFont.lfHeight = *((PLONG)(&ValueKeyInfo->Data[0]));
  650. }
  651. if (bQueryValueKey(L"GUIFont.Weight", hkey, ValueKeyInfo, sizeof(aj)))
  652. {
  653. elfw.elfEnumLogfontEx.elfLogFont.lfWeight = *((PLONG)(&ValueKeyInfo->Data[0]));
  654. }
  655. if (bQueryValueKey(L"GUIFont.Italic", hkey, ValueKeyInfo, sizeof(aj)))
  656. {
  657. elfw.elfEnumLogfontEx.elfLogFont.lfItalic = (BYTE)*((PULONG)(&ValueKeyInfo->Data[0]));
  658. }
  659. if (bQueryValueKey(L"GUIFont.CharSet", hkey, ValueKeyInfo, sizeof(aj)))
  660. {
  661. elfw.elfEnumLogfontEx.elfLogFont.lfCharSet = (BYTE)*((PULONG)(&ValueKeyInfo->Data[0]));
  662. }
  663. ZwCloseKey(hkey);
  664. }
  665. // Compute height using vertical DPI of display.
  666. //
  667. // Unfortunately, we do not have a display driver loaded so we do not
  668. // know what the vertical DPI is. So, set a flag indicating that this
  669. // needs to be done and we will finish intitialization after the (first)
  670. // display driver is loaded.
  671. //elfw.elfEnumLogfontEx.elfLogFont.lfHeight = -((elfw.elfEnumLogfontEx.elfLogFont.lfHeight * ydpi + 36) / 72);
  672. gbFinishDefGUIFontInit = TRUE;
  673. // Create the LOGFONT and return.
  674. return hfontCreate(&elfw, LF_TYPE_DEFAULT_GUI, LF_FLAG_STOCK, NULL);
  675. }
  676. #endif