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.

224 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. sfupgrd.c
  5. Abstract:
  6. Routines to upgrade the NT 4.0 SoftFont File format to NT 5.0 file format.
  7. Environment:
  8. Windows NT Unidrv driver
  9. Revision History:
  10. 29/10/97 -ganeshp-
  11. Created
  12. --*/
  13. #include "precomp.h"
  14. #ifndef WINNT_40
  15. // NT 5.0 only
  16. //
  17. // Internal helper function prototype
  18. //
  19. HANDLE HCreateHeapForCI();
  20. BOOL
  21. BSoftFontsAreInstalled(
  22. HANDLE hPrinter
  23. )
  24. /*++
  25. Routine Description:
  26. Arguments:
  27. Determine whether font installer keys are present in the registry or not.
  28. Return Value:
  29. TRUE/FALSE, TRUE meaning New keys are Present
  30. Note:
  31. 10/29/1997 -ganeshp-
  32. Created it.
  33. --*/
  34. {
  35. BOOL bRet = FALSE;
  36. DWORD dwType = REG_SZ ;
  37. DWORD cbNeeded = 0;
  38. DWORD dwErrCode = 0;
  39. dwErrCode = GetPrinterData( hPrinter, REGVAL_FONTFILENAME, &dwType,
  40. NULL,0, &cbNeeded );
  41. if ( cbNeeded &&
  42. ((dwErrCode == ERROR_MORE_DATA) ||
  43. (dwErrCode == ERROR_INSUFFICIENT_BUFFER))
  44. )
  45. {
  46. bRet = TRUE;
  47. }
  48. return bRet;
  49. }
  50. BOOL
  51. BIsUNIDRV(
  52. PDRIVER_UPGRADE_INFO_2 pUpgradeInfo
  53. )
  54. /*++
  55. Routine Description:
  56. This routine checks if new driver is UNIDRV base GPD minidriver.
  57. Arguments:
  58. pUpgradeInfo Upgrade Info 2 structure.
  59. Return Value:
  60. TRUE if it's UNIDRV, Otherwise FALSE.
  61. Note:
  62. --*/
  63. {
  64. PWSTR pDriverName; // Old Printer Driver data file name
  65. //
  66. // Search "UNIDRV" string in the pDriverPath. If there is,
  67. // it is GPD base printer driver.
  68. // since the end of string must be "UNIDRV.DLL" in case of GPD minidriver.
  69. // Compare it with "unidrv.dll".
  70. //
  71. // Get the unqulaified driver name. Add +1 to point to first letter
  72. // of driver name.
  73. //
  74. pDriverName = wcsrchr( pUpgradeInfo->pDriverPath, L'\\' ) + 1;
  75. return (0 == _wcsicmp(pDriverName, L"unidrv.dll"));
  76. }
  77. BOOL
  78. BUpgradeSoftFonts(
  79. PCOMMONINFO pci,
  80. PDRIVER_UPGRADE_INFO_2 pUpgradeInfo
  81. )
  82. /*++
  83. Routine Description:
  84. This routine upgrade the NT 4.0 soft font file to NT 5.0 format.
  85. Arguments:
  86. pci Structure containing all necessary information.
  87. pUpgradeInfo Upgrade Info structure.
  88. Return Value:
  89. TRUE for success, FALSE for failure.
  90. Note:
  91. 10/29/97: Created it -ganeshp-
  92. --*/
  93. {
  94. INT iNum; // Number of fonts
  95. INT iI,iRet; // Loop parameter
  96. FI_MEM FIMem; // For accessing installed fonts
  97. BOOL bRet;
  98. LPTSTR pOldDataFile; // Old Printer Driver data file name
  99. bRet = FALSE;
  100. pOldDataFile = NULL ;
  101. ASSERT(pci);
  102. //
  103. // Create heap if it is not allocated yet.
  104. //
  105. if (!pci->hHeap)
  106. pci->hHeap = HCreateHeapForCI();
  107. //
  108. // Check if any soft fonts are installed. If yes then we don't need to do
  109. // anything. return TRUE.
  110. //
  111. pOldDataFile = pUpgradeInfo->pDataFile;
  112. if ( pUpgradeInfo->pOldDriverDirectory &&
  113. !BIsUNIDRV(pUpgradeInfo) &&
  114. !BSoftFontsAreInstalled(pci->hPrinter) )
  115. {
  116. //
  117. // Initialize Old driver's datafile
  118. //
  119. if (iNum = IFIOpenRead( &FIMem, pOldDataFile) )
  120. {
  121. VERBOSE(( "UniFont!iXtraFonts: ++++ Got %ld EXTRA FONTS", iNum ));
  122. for( iRet = 0, iI = 0; iI < iNum; ++iI )
  123. {
  124. if( BFINextRead( &FIMem ) )
  125. {
  126. PVOID pPCLData;
  127. //
  128. // Get the Pointer to PCL data
  129. //
  130. pPCLData = FIMem.pbBase + FIMem.ulVarOff;
  131. //
  132. // Now Call the fontinstaller to install the font.
  133. //
  134. if (BInstallSoftFont( pci->hPrinter, pci->hHeap, pPCLData, FIMem.ulVarSize) )
  135. ++iRet;
  136. else
  137. {
  138. ERR(("Unidrvui!BUpgradeSoftFonts:BInstallSoftFont Failed.\n"));
  139. goto ErrorExit;
  140. }
  141. }
  142. else
  143. break; /* Should not happen */
  144. }
  145. if( !BFICloseRead(&FIMem))
  146. {
  147. ERR(("\nUniFont!iXtraFonts: bFICloseRead() fails\n" ));
  148. }
  149. }
  150. }
  151. bRet = TRUE;
  152. //
  153. // Here means that there are no fonts OR that the HeapAlloc()
  154. // failed. In either case, return no fonts.
  155. //
  156. ErrorExit:
  157. return bRet;
  158. }
  159. #endif //ifndef WINNT_40