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.

435 lines
13 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. ctt2gtt.c
  5. Abstract:
  6. Environment:
  7. Windows NT PostScript driver
  8. Revision History:
  9. --*/
  10. #include "precomp.h"
  11. //
  12. // Macros
  13. //
  14. #define FILENAME_SIZE 256
  15. #define CMD_SIZE 256
  16. DWORD gdwOutputFlags;
  17. //
  18. // flag definitions for gdwOutputFlags
  19. //
  20. #define OUTPUT_VERBOSE 0x00000001
  21. //
  22. // Local function prototypes
  23. //
  24. BOOL BiArgcheck(IN int, IN char**, IN OUT PWSTR, IN OUT PWSTR, IN OUT PWSTR);
  25. //
  26. // Globals
  27. //
  28. BYTE gcstrError1[] = "Usage: ctt2gtt [-v] CP_file CTT_file GLY_file\n";
  29. BYTE gcstrError2[] = "ctt2gtt: HeapCreate() failed\n.";
  30. BYTE gcstrError3[] = "Cannot open file \"%ws\".\n";
  31. BYTE gcstrError4[] = "Cannot create output file '%ws'.\n";
  32. BYTE gcstrError5[] = "Failed to convert CTT to GlyphSetData.\n";
  33. BYTE gcstrError6[] = "WriteFile fails: writes %ld bytes\n";
  34. BYTE gcstrError7[] = "Failure of BGetInfo\n";
  35. PSTR gcstrCTTType[] = {
  36. "CTT_WTYPE_COMPOSE",
  37. "CTT_WTYPE_DIRECT",
  38. "CTT_WTYPE_PAIRED"};
  39. INT __cdecl
  40. main(
  41. IN INT iArgc,
  42. IN CHAR **ppArgv)
  43. /*++
  44. Routine Description:
  45. main
  46. Arguments:
  47. iArgc - Number of parameters in the following
  48. ppArgv - The parameters, starting with our name
  49. Return Value:
  50. Return error code
  51. Note:
  52. --*/
  53. {
  54. HANDLE hHeap; // Acces to heap, to simulate driver environment
  55. HANDLE hOutput;
  56. PWSTR pwstrCTTName; // The file name being processed
  57. PWSTR pwstrGlyName; // The output file
  58. PWSTR pwstrCPTName; // The Codepage info text
  59. WCHAR awchCTTName[FILENAME_SIZE]; // The file name being processed
  60. WCHAR awchGlyName[FILENAME_SIZE]; // The output file
  61. WCHAR awchCPTName[FILENAME_SIZE]; // The Codepage info text
  62. BYTE aubSelectCmd[CMD_SIZE];
  63. BYTE aubUnSelectCmd[CMD_SIZE];
  64. PBYTE pubSelectCmd, pubUnSelectCmd;
  65. BYTE aubFormatCmd[256];
  66. PBYTE pCommand;
  67. WORD wSize, wJ;
  68. PTRANSTAB pCTTData;
  69. DWORD dwCTTSize;
  70. PUNI_GLYPHSETDATA pGlyphSetData;
  71. DWORD dwGlySize;
  72. DWORD dwCodePage;
  73. PBYTE pCPText;
  74. DWORD dwCPTextSize;
  75. DWORD dwWrittenSize; // Returned size from WriteFile
  76. HFILEMAP hCTTFile, hCPText, hGlyphFile;
  77. pwstrCTTName = awchCTTName;
  78. pwstrGlyName = awchGlyName;
  79. pwstrCPTName = awchCPTName;
  80. if (!BiArgcheck(iArgc, ppArgv, pwstrCPTName, pwstrCTTName, pwstrGlyName))
  81. {
  82. fprintf( stderr, gcstrError1);
  83. return -1;
  84. }
  85. if (gdwOutputFlags & OUTPUT_VERBOSE)
  86. {
  87. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  88. printf(" GlyphSetData\n");
  89. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  90. printf("\n");
  91. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  92. printf("CODEPAGEINFO file\n");
  93. printf("Codepage info text file: %ws\n", pwstrCPTName);
  94. printf("CTT file : %ws\n", pwstrCTTName);
  95. printf("Glyphset data : %ws\n", pwstrGlyName);
  96. }
  97. hCPText = MapFileIntoMemory( (PWSTR)pwstrCPTName,
  98. (PVOID)&pCPText,
  99. &dwCPTextSize );
  100. if (!hCPText)
  101. {
  102. fprintf( stderr, gcstrError3, pwstrCPTName);
  103. return -2;
  104. }
  105. pubSelectCmd = aubSelectCmd;
  106. pubUnSelectCmd = aubUnSelectCmd;
  107. if (!BGetInfo(pCPText,
  108. dwCPTextSize,
  109. &dwCodePage,
  110. pubSelectCmd,
  111. pubUnSelectCmd))
  112. {
  113. return -2;
  114. }
  115. if (gdwOutputFlags & OUTPUT_VERBOSE)
  116. {
  117. printf("\n");
  118. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  119. printf("CODEPAGE\n");
  120. printf ("Codepage: %d\n : %s\n : %s\n",
  121. dwCodePage,
  122. pubSelectCmd,
  123. pubUnSelectCmd);
  124. }
  125. if (*pubSelectCmd == (BYTE)NULL)
  126. pubSelectCmd = NULL;
  127. if (*pubUnSelectCmd == (BYTE)NULL)
  128. pubUnSelectCmd = NULL;
  129. UnmapFileFromMemory(hCPText);
  130. hHeap = HeapCreate( HEAP_NO_SERIALIZE, 0x10000, 0x100000 );
  131. if (!hHeap)
  132. {
  133. fprintf( stderr, gcstrError2);
  134. return -2;
  135. }
  136. hCTTFile = MapFileIntoMemory( (PTSTR)pwstrCTTName,
  137. (PVOID)&pCTTData,
  138. &dwCTTSize );
  139. if (!pCTTData || dwCTTSize == 0)
  140. {
  141. fprintf( stderr, gcstrError3, pwstrCTTName);
  142. return -2;
  143. }
  144. if (gdwOutputFlags & OUTPUT_VERBOSE)
  145. {
  146. printf("\n");
  147. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  148. printf("CTT FILE INFORMATION\n");
  149. printf( "Type: %s\nFirst Char = 0x%x\nLast Char = 0x%x\n",
  150. gcstrCTTType[ pCTTData->wType ],
  151. pCTTData->chFirstChar,
  152. pCTTData->chLastChar );
  153. }
  154. hGlyphFile = MapFileIntoMemory( (PTSTR)pwstrGlyName,
  155. (PVOID)&pGlyphSetData,
  156. &dwGlySize );
  157. if (!hGlyphFile)
  158. {
  159. pGlyphSetData = NULL;
  160. dwGlySize = 0;
  161. }
  162. if (!BConvertCTT2GTT( hHeap,
  163. pCTTData,
  164. dwCodePage,
  165. 0x20,
  166. 0xFF,
  167. pubSelectCmd,
  168. pubUnSelectCmd,
  169. &pGlyphSetData,
  170. dwGlySize))
  171. {
  172. fprintf( stderr, gcstrError5);
  173. return -3;
  174. }
  175. if (gdwOutputFlags & OUTPUT_VERBOSE)
  176. {
  177. PUNI_CODEPAGEINFO pCodePageInfo;
  178. PGLYPHRUN pGlyphRun;
  179. PMAPTABLE pMapTable;
  180. TRANSDATA *pTrans;
  181. DWORD dwI;
  182. printf("\n");
  183. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  184. printf("GLYPHSETDATA\n");
  185. printf ("GLYPHSETDATA.dwSize : %d\n", pGlyphSetData->dwSize);
  186. printf (" dwVersion : %d\n", pGlyphSetData->dwVersion);
  187. printf (" dwFlags : %d\n", pGlyphSetData->dwFlags);
  188. printf (" lPredefinedID : %d\n", pGlyphSetData->lPredefinedID);
  189. printf (" dwGlyphCount : %d\n", pGlyphSetData->dwGlyphCount);
  190. printf (" loRunOffset : 0x%x\n", pGlyphSetData->loRunOffset);
  191. printf (" dwRunCount : %d\n", pGlyphSetData->dwRunCount);
  192. printf (" dwCodePageCount : 0x%d\n", pGlyphSetData->dwCodePageCount);
  193. printf (" loCodePageOffset : 0x%x\n", pGlyphSetData->loCodePageOffset);
  194. printf (" loMapTableOffset : 0x%x\n", pGlyphSetData->loMapTableOffset);
  195. printf("\n");
  196. pCodePageInfo =
  197. (PUNI_CODEPAGEINFO)((PBYTE) pGlyphSetData + pGlyphSetData->loCodePageOffset);
  198. printf("\n");
  199. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  200. printf("CODEPAGEINFO\n");
  201. for (dwI = 0; dwI < pGlyphSetData->dwCodePageCount; dwI ++)
  202. {
  203. printf ("UNI_CODEPAGEINFO[%d].dwCodePage = %d\n",
  204. dwI, pCodePageInfo->dwCodePage);
  205. printf ("UNI_CODEPAGEINFO[%d].SelectSymbolSet.dwCount = %d\n",
  206. dwI, pCodePageInfo->SelectSymbolSet.dwCount);
  207. printf ("UNI_CODEPAGEINFO[%d].SelectSymbolSet:Command = %s\n",
  208. dwI, (PBYTE)pCodePageInfo+pCodePageInfo->SelectSymbolSet.loOffset);
  209. printf ("UNI_CODEPAGEINFO[%d].UnSelectSymbolSet.dwCount = %d\n",
  210. dwI, pCodePageInfo->UnSelectSymbolSet.dwCount);
  211. printf ("UNI_CODEPAGEINFO[%d].UnSelectSymbolSet:Command = %s\n",
  212. dwI, (PBYTE)pCodePageInfo+pCodePageInfo->UnSelectSymbolSet.loOffset);
  213. pCodePageInfo++;
  214. }
  215. pGlyphRun =
  216. (PGLYPHRUN) ((PBYTE)pGlyphSetData + pGlyphSetData->loRunOffset);
  217. printf("\n");
  218. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  219. printf("GLYPHRUN\n");
  220. for (dwI = 0; dwI < pGlyphSetData->dwRunCount; dwI ++)
  221. {
  222. printf("GLYPHRUN[%2d].wcLow = 0x%-4x\n", dwI, pGlyphRun->wcLow);
  223. printf("GLYPHRUN[%2d].wGlyphCount = %d\n", dwI, pGlyphRun->wGlyphCount);
  224. pGlyphRun++;
  225. }
  226. pMapTable = (PMAPTABLE) ((PBYTE)pGlyphSetData +
  227. pGlyphSetData->loMapTableOffset);
  228. pTrans = pMapTable->Trans;
  229. printf("\n");
  230. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  231. printf("MAPTABLE\n");
  232. printf("MAPTABLE.dwSize = %d\n", pMapTable->dwSize);
  233. printf("MAPTABLE.dwGlyphNum = %d\n", pMapTable->dwGlyphNum);
  234. for (dwI = 0; dwI < pMapTable->dwGlyphNum; dwI ++)
  235. {
  236. printf("MAPTABLE.pTrans[%5d].ubCodePageID = %d\n",
  237. dwI, pTrans[dwI].ubCodePageID);
  238. printf("MAPTABLE.pTrans[%5d].ubType = %d\n",
  239. dwI, pTrans[dwI].ubType);
  240. switch(pTrans[dwI].ubType)
  241. {
  242. case MTYPE_DIRECT:
  243. printf("MAPTABLE.pTrans[%5d].ubCode = %d\n",
  244. dwI+1, pTrans[dwI].uCode.ubCode);
  245. break;
  246. case MTYPE_PAIRED:
  247. printf("MAPTABLE.pTrans[%5d].ubPairs[0] = %d\n",
  248. dwI+1, pTrans[dwI].uCode.ubPairs[0]);
  249. printf("MAPTABLE.pTrans[%5d].ubPairs[1] = %d\n",
  250. dwI+1, pTrans[dwI].uCode.ubPairs[1]);
  251. break;
  252. case MTYPE_COMPOSE:
  253. printf("MAPTABLE.pTrans[%5d].sCode = %x\n",
  254. dwI+1, pTrans[dwI].uCode.sCode);
  255. pCommand = (PBYTE)pMapTable + pTrans[dwI].uCode.sCode;
  256. wSize = *(WORD*)pCommand;
  257. pCommand += 2;
  258. printf("Size = 0x%d\n", wSize);
  259. printf("Command = 0x");
  260. for (wJ = 0; wJ < wSize; wJ ++)
  261. {
  262. printf("%02x",pCommand[wJ]);
  263. }
  264. printf("\n");
  265. break;
  266. }
  267. }
  268. }
  269. UnmapFileFromMemory(hCTTFile);
  270. hOutput = CreateFile(pwstrGlyName,
  271. GENERIC_WRITE,
  272. 0,
  273. NULL,
  274. CREATE_ALWAYS,
  275. FILE_ATTRIBUTE_NORMAL,
  276. NULL );
  277. if( hOutput == INVALID_HANDLE_VALUE )
  278. {
  279. fprintf( stderr, gcstrError4, pwstrGlyName);
  280. return -2;
  281. }
  282. WriteFile( hOutput,
  283. pGlyphSetData,
  284. pGlyphSetData->dwSize,
  285. &dwWrittenSize,
  286. NULL );
  287. if( dwWrittenSize != pGlyphSetData->dwSize)
  288. {
  289. fprintf( stderr, gcstrError6, dwWrittenSize);
  290. return -4;
  291. }
  292. HeapDestroy(hHeap);
  293. return 0;
  294. }
  295. BOOL
  296. BiArgcheck(
  297. IN INT iArgc,
  298. IN CHAR **ppArgv,
  299. IN OUT PWSTR pwstrCPTName,
  300. IN OUT PWSTR pwstrCTTName,
  301. IN OUT PWSTR pwstrGlyName)
  302. /*++
  303. Routine Description:
  304. iArgcheck
  305. Arguments:
  306. iArgc - Number of parameters in the following
  307. ppArgv - The parameters, starting with our name
  308. pwstrCPTName -
  309. pwstrCTTName -
  310. pwstrGlyName -
  311. Return Value:
  312. If TRUE, function succeeded. Othewise FALSE.
  313. Note:
  314. --*/
  315. {
  316. INT iI;
  317. INT iRet;
  318. if (iArgc > 5 || iArgc < 4)
  319. {
  320. return FALSE;
  321. }
  322. if (iArgc == 5)
  323. {
  324. gdwOutputFlags |= OUTPUT_VERBOSE;
  325. ppArgv++;
  326. }
  327. ppArgv++;
  328. iRet = MultiByteToWideChar(CP_ACP, 0, *ppArgv, strlen(*ppArgv), pwstrCPTName, FILENAME_SIZE);
  329. *(pwstrCPTName + iRet) = (WCHAR)NULL;
  330. ppArgv++;
  331. iRet = MultiByteToWideChar(CP_ACP, 0, *ppArgv, strlen(*ppArgv), pwstrCTTName, FILENAME_SIZE);
  332. *(pwstrCTTName + iRet) = (WCHAR)NULL;
  333. ppArgv++;
  334. iRet = MultiByteToWideChar(CP_ACP, 0, *ppArgv, strlen(*ppArgv), pwstrGlyName, FILENAME_SIZE);
  335. *(pwstrGlyName + iRet) = (WCHAR)NULL;
  336. return TRUE;
  337. }