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.

257 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. gpc2gpd.c
  5. Abstract:
  6. GPC-to-GPD conversion program
  7. Environment:
  8. User-mode, stand-alone utility tool
  9. Revision History:
  10. 10/16/96 -zhanw-
  11. Created it.
  12. --*/
  13. #include "StdAfx.H"
  14. #include "ProjNode.H"
  15. #include "Resource.H"
  16. #include "GPDFile.H"
  17. #include "..\GPC2GPD\GPC2GPD.H"
  18. extern "C" void VOutputGlobalEntries(PCONVINFO pci, PCSTR pstrModelName,
  19. PCSTR pstrResourceDLLName,
  20. PCSTR pstrGPDFileName);
  21. /******************************************************************************
  22. VPrintErros
  23. VOut
  24. These replace functions used in the command line converter.
  25. ******************************************************************************/
  26. static void VPrintErrors(CStringArray& csaLog, DWORD dwError) {
  27. for (unsigned u = 0; u < NUM_ERRS; u++)
  28. if (dwError & gdwErrFlag[u])
  29. csaLog.Add(gpstrErrMsg[u]);
  30. for (u = 0; u < (unsigned) csaLog.GetSize(); u++)
  31. csaLog[u].TrimRight(); // Trim off the white space, we won't need it
  32. }
  33. extern "C" void _cdecl
  34. VOut(
  35. PCONVINFO pci,
  36. PSTR pstrFormat,
  37. ...)
  38. /*++
  39. Routine Description:
  40. This function formats a sequence of bytes and writes to the GPD file.
  41. Arguments:
  42. pci - conversionr related info
  43. pstrFormat - the formatting string
  44. ... - optional arguments needed by formatting
  45. Return Value:
  46. None
  47. --*/
  48. {
  49. va_list ap;
  50. BYTE aubBuf[MAX_GPD_ENTRY_BUFFER_SIZE];
  51. int iSize;
  52. va_start(ap, pstrFormat);
  53. StringCchPrintfA((PSTR)aubBuf, CCHOF(aubBuf), pstrFormat, ap);
  54. va_end(ap);
  55. iSize = strlen((CHAR*)aubBuf) + 1;
  56. if (pci->dwMode & FM_VOUT_LIST && iSize > 4)
  57. {
  58. //
  59. // check for the extra comma before the closing bracket
  60. //
  61. if (aubBuf[iSize-4] == ',' && aubBuf[iSize-3] == ')')
  62. {
  63. aubBuf[iSize-4] = aubBuf[iSize-3]; // ')'
  64. aubBuf[iSize-3] = aubBuf[iSize-2]; // '\r'
  65. aubBuf[iSize-2] = aubBuf[iSize-1]; // '\n'
  66. iSize--;
  67. }
  68. }
  69. // Memory exceptions should be all that's possible, but call any MFC
  70. // exception a "file write error" for compatibility.
  71. try {
  72. CString csLine(aubBuf);
  73. // If the previous line does not end in whitespace, add this one to it
  74. if (pci -> pcsaGPD -> GetSize()) {
  75. CString& csPrevious =
  76. pci -> pcsaGPD -> ElementAt( -1 + pci -> pcsaGPD -> GetSize());
  77. if (csPrevious.Right(1)[0] != _TEXT('\n')) {
  78. csPrevious += csLine;
  79. return;
  80. }
  81. csPrevious.TrimRight(); // Remove the CR/LF combo.
  82. }
  83. pci -> pcsaGPD -> Add(csLine);
  84. }
  85. catch (CException * pce) {
  86. pce -> ReportError();
  87. pce -> Delete();
  88. pci -> dwErrorCode |= ERR_WRITE_FILE;
  89. }
  90. // continue even if an error has occurred.
  91. }
  92. /******************************************************************************
  93. CModelData::Load(PCSTR pcstr, CString csResource, unsigned uModel,
  94. CMapWordToDWord& cmw2dFontMap, WORD wfGPDConvert)
  95. This member function fills this instance by converting a model from the GPC
  96. data pointed at by pcstr.
  97. ******************************************************************************/
  98. BOOL CModelData::Load(PCSTR pstr, CString csResource, unsigned uModel,
  99. CMapWordToDWord& cmw2dFontMap, WORD wfGPDConvert) {
  100. CONVINFO ci; // structure to keep track conversion information
  101. //
  102. // check if we have all the arguments needed
  103. //
  104. if (!pstr || csResource.IsEmpty() || !uModel)
  105. return FALSE;
  106. ZeroMemory((PVOID)&ci, sizeof(CONVINFO));
  107. //
  108. // Open the GPC file and map it into memory.
  109. //
  110. ci.pdh = (PDH) pstr;
  111. //
  112. // GPC file sanity check
  113. //
  114. if (ci.pdh->sMagic != 0x7F00 ||
  115. !(ci.pmd = (PMODELDATA)GetTableInfo(ci.pdh, HE_MODELDATA, uModel-1)) ||
  116. !(ci.ppc = (PPAGECONTROL)GetTableInfo(ci.pdh, HE_PAGECONTROL,
  117. ci.pmd->rgi[MD_I_PAGECONTROL]))) {
  118. ci.dwErrorCode |= ERR_BAD_GPCDATA;
  119. goto exit;
  120. }
  121. //
  122. // allocate dynamic buffers needed for conversion
  123. //
  124. if (!(ci.ppiSize=(PPAPERINFO)MemAllocZ(ci.pdh->rghe[HE_PAPERSIZE].sCount*sizeof(PAPERINFO))) ||
  125. !(ci.ppiSrc=(PPAPERINFO)MemAllocZ(ci.pdh->rghe[HE_PAPERSOURCE].sCount*sizeof(PAPERINFO))) ||
  126. !(ci.presinfo=(PRESINFO)MemAllocZ(ci.pdh->rghe[HE_RESOLUTION].sCount*sizeof(RESINFO))))
  127. {
  128. ci.dwErrorCode |= ERR_OUT_OF_MEMORY;
  129. goto exit;
  130. }
  131. //
  132. // generate GPD data
  133. //
  134. ci.pcsaGPD = &m_csaGPD;
  135. ci.pcmw2dFonts = &cmw2dFontMap;
  136. // eigos /1/16/98
  137. // ci.dwStrType = wfGPDConvert % (1 + STR_RCID_SYSTEM_PAPERNAMES); // Paranoid conversion...
  138. //rm - Use value macros (see stdnames.gpd) - fixes a want request
  139. ci.dwStrType = STR_MACRO;
  140. // Emit RCID_DMPAPER_SYSTEM_NAME
  141. // Done by v-erike on 3/30/98. Requested by patryan
  142. ci.bUseSystemPaperNames = TRUE ;
  143. VOutputGlobalEntries(&ci, m_csName, csResource + _T(".Dll"), FileTitleExt());
  144. VOutputUIEntries(&ci);
  145. VOutputPrintingEntries(&ci);
  146. m_csaGPD[-1 + m_csaGPD.GetSize()].TrimRight();
  147. exit:
  148. if (ci.ppiSize)
  149. MemFree(ci.ppiSize);
  150. if (ci.ppiSrc)
  151. MemFree(ci.ppiSrc);
  152. if (ci.presinfo)
  153. MemFree(ci.presinfo);
  154. if (ci.dwErrorCode) {
  155. //
  156. // Open the log file and print out errors/warnings.
  157. // Borrow the GPD file name buffer.
  158. //
  159. VPrintErrors(m_csaConvertLog, ci.dwErrorCode);
  160. }
  161. return TRUE;
  162. }
  163. /******************************************************************************
  164. vMapFontList
  165. This procedure uses the CMapWordToDWord mapping in the CONVINFO structure to
  166. map font indices in font lists. This is the final bit of skullduggery needed
  167. to make the mapping of a single PFM to multiple UFMs effective.
  168. ******************************************************************************/
  169. extern "C" void vMapFontList(IN OUT PWORD pwFonts, IN DWORD dwcFonts,
  170. IN PCONVINFO pci) {
  171. // If there are n fonts, or just one and the ID is 0 (happens if there are
  172. // no device fonts.
  173. if (!dwcFonts || (dwcFonts == 1 && !*pwFonts))
  174. return;
  175. CWordArray cwaFonts;
  176. CMapWordToDWord& cmw2dFonts = *pci -> pcmw2dFonts;
  177. WORD wGreatest = 0; // Highest font ID in the new array
  178. for (unsigned uFont = 0; uFont < dwcFonts; uFont++) {
  179. WORD widThis = pwFonts[uFont];
  180. if (cmw2dFonts[widThis]) // It will be 0 if unmapped
  181. widThis = (WORD) cmw2dFonts[widThis];
  182. if (widThis > wGreatest) { // Is this the new end of the list?
  183. cwaFonts.Add(widThis);
  184. wGreatest = widThis;
  185. continue;
  186. }
  187. for (int i = 0; i < cwaFonts.GetSize(); i++)
  188. if (cwaFonts[i] > widThis) {
  189. cwaFonts.InsertAt(i, widThis);
  190. break;
  191. }
  192. _ASSERT(i < cwaFonts.GetSize());
  193. }
  194. // OK, the font list is corrected and is once again sorted. Copy it back
  195. memcpy(pwFonts, cwaFonts.GetData(), dwcFonts * sizeof wGreatest);
  196. }