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.

1014 lines
29 KiB

  1. /*++
  2. Copyright (c) 1990-1996 Microsoft Corporation
  3. Module Name:
  4. mkgtt.c
  5. Abstract:
  6. Construct UNI_GLYPHSETDATA structure in memory and dump it as binary
  7. data so that a printer driver can include it in its resource.
  8. The input data format is as following:
  9. <codepage>
  10. <multibyte code>\t<run length>
  11. <multibyte code>\t<run length>
  12. ...
  13. "codepage" is the codepage id to be used in multibyte to Unicode
  14. conversion. "Multibyte code" and "run length" pairs describes
  15. which codepoints of multibyte codes are available on the device.
  16. mkgtt will warn if there are multiple multibyte codepoints which
  17. are mapped to single Unicode codepoint. The user is expected
  18. to fix this in the source, then re-run mkgtt.
  19. Follogins are command line options recogized by mkgtt:
  20. -e Allow EUDC codepoints. Default is not allow.
  21. -t Output mapping table in text format also.
  22. -v Verbose.
  23. Author:
  24. 08-Apr-1995 Sat 00:00:00 created -by- Takashi Matsuzawa (takashim)
  25. 03-Mar-1996 Sat 00:00:00 updated -by- Takashi Matsuzawa (takashim)
  26. 02-Feb-1997 Sat 00:00:00 ported -by- Eigo Shimizu (eigos)
  27. Environment:
  28. GDI device drivers (printer)
  29. Notes:
  30. Revision History:
  31. --*/
  32. #include <lib.h>
  33. #include <win30def.h>
  34. #include <uni16gpc.h>
  35. #include <uni16res.h>
  36. #include <fmnewfm.h>
  37. #include <fmnewgly.h>
  38. #include <unilib.h>
  39. #include <fd_glyph.h>
  40. #include <unirc.h>
  41. #include <mkgtt.h>
  42. //
  43. // Macros
  44. //
  45. #define MIN_WCHAR_VALUE 0x0001
  46. #define MAX_WCHAR_VALUE 0xfffd
  47. #define INVALID_WCHAR_VALUE 0xffff
  48. #define IS_COMMENT(c) \
  49. ((c) == ';' || (c) == '#' || (c) == '%' || (c) == '\n')
  50. #define IS_EUDC_W(wc) \
  51. ((wc) >= 0xe000 && (wc) <= 0xf8ff)
  52. #define SWAPW(x) (((WORD)(x)<<8) | ((WORD)(x)>>8))
  53. //
  54. // Globals
  55. //
  56. WORD awMultiByteArray[0x10000];
  57. BOOL bEudc, bTable;
  58. INT iVerbose;
  59. //
  60. // Forward declaration
  61. //
  62. VOID
  63. VPrintGTT(
  64. IN PUNI_GLYPHSETDATA pGly);
  65. BOOL
  66. BCreateSubFileName(
  67. IN CHAR *pDestFileName,
  68. IN CHAR *pSrcFileName,
  69. IN CHAR cAdd);
  70. //
  71. // Functions.
  72. //
  73. PUNI_GLYPHSETDATA
  74. PBuildGTT(
  75. SHORT sMode,
  76. WORD wCodepage,
  77. WORD *pwArray,
  78. DWORD dwcbSize)
  79. /*++
  80. Routine Description:
  81. Build UNI_GLYPHSETDATA on memory.
  82. Arguments:
  83. Return Value:
  84. None.
  85. Author:
  86. Revision History:
  87. --*/
  88. {
  89. DWORD cGlyphs; // count of glyph handles.
  90. DWORD cRuns; // count of runs within FD_GLYPHSET.
  91. DWORD cbTotalMem; // count of bytes needed for FD_GLYPHSET.
  92. DWORD cEudc;
  93. DWORD cRunsGlyphs = 0;
  94. WCHAR wcChar, wcPrev, wcIndex, wcCommand;
  95. PBYTE pBase; // pointer to HGLYPH's.
  96. BYTE aubChar[2];
  97. BOOL bFirst, bInRun;
  98. PUNI_GLYPHSETDATA pGlyphSet;
  99. PUNI_CODEPAGEINFO pCodePageInfo;
  100. PGLYPHRUN pGlyphRun, pGlyphRunTmp;
  101. PMAPTABLE pMapTable;
  102. PTRANSDATA pTrans;
  103. TRANSTAB *lpctt;
  104. HMODULE hModule;
  105. HRSRC hRes;
  106. if (NULL == pwArray ||
  107. 0 == dwcbSize )
  108. {
  109. fprintf( stderr, "Invalid parameters\n" );
  110. return NULL;
  111. }
  112. if (dwcbSize < MAX_WCHAR_VALUE * 2)
  113. {
  114. fprintf( stderr, "Invalid parameters\n" );
  115. return NULL;
  116. }
  117. DBGMESSAGE(("sMode = %d, wCodepage = %d\n", sMode, wCodepage));
  118. cRuns = 0;
  119. cGlyphs = 0;
  120. cEudc = 0;
  121. bFirst = TRUE;
  122. for ( wcChar = MIN_WCHAR_VALUE; wcChar <= MAX_WCHAR_VALUE; wcChar++)
  123. {
  124. if (pwArray[wcChar] == INVALID_WCHAR_VALUE)
  125. continue;
  126. // GDI can't handle the value which cRunsGlyphs over 256. sueyas
  127. if (bFirst || (wcChar - wcPrev) > 1 || cRunsGlyphs++ > 255)
  128. {
  129. if (bFirst)
  130. bFirst = FALSE;
  131. cRuns++;
  132. cRunsGlyphs = 1;
  133. }
  134. if (IS_EUDC_W(wcChar))
  135. cEudc++;
  136. cGlyphs++;
  137. wcPrev = wcChar;
  138. }
  139. DBGMESSAGE(("cGlyphs = %d, cRuns = %d\n", cGlyphs, cRuns));
  140. // Allocate memory to build the UNI_GLYPHSET structure in. this
  141. // include space for the FD_GLYPHSET structure itself, as well
  142. // as space for all the glyph handles.
  143. // DWORD bound it.
  144. cbTotalMem = sizeof(UNI_GLYPHSETDATA) +
  145. sizeof(UNI_CODEPAGEINFO) +
  146. cRuns * sizeof(GLYPHRUN) +
  147. sizeof(MAPTABLE) +
  148. (cGlyphs - 1) * sizeof(TRANSDATA);
  149. cbTotalMem = (cbTotalMem + 3) & ~3;
  150. if ((pBase = (PVOID)GlobalAlloc( 0, cbTotalMem )) == NULL) {
  151. fprintf( stderr, "Error alloating memory\n" );
  152. return NULL;
  153. }
  154. //
  155. // fill in the UNI_GLYPHSETDATA structure.
  156. //
  157. DBGMESSAGE(("fill in the UNI_GLYPHSETDATA structure.\n"));
  158. pGlyphSet = (PUNI_GLYPHSETDATA) pBase;
  159. pGlyphSet->dwSize = cbTotalMem;
  160. pGlyphSet->dwVersion = UNI_GLYPHSETDATA_VERSION_1_0;
  161. pGlyphSet->dwFlags = 0;
  162. pGlyphSet->lPredefinedID = CC_NOPRECNV;
  163. pGlyphSet->dwGlyphCount = cGlyphs;
  164. pGlyphSet->dwRunCount = cRuns;
  165. pGlyphSet->loRunOffset = sizeof(UNI_GLYPHSETDATA);
  166. pGlyphSet->dwCodePageCount = 1;
  167. pGlyphSet->loCodePageOffset = sizeof(UNI_GLYPHSETDATA) +
  168. sizeof(GLYPHRUN) * cRuns;
  169. pGlyphSet->loMapTableOffset = sizeof(UNI_GLYPHSETDATA) +
  170. sizeof(GLYPHRUN) * cRuns +
  171. sizeof(UNI_CODEPAGEINFO) ;
  172. pGlyphRun = (PGLYPHRUN)((PBYTE)pBase +
  173. pGlyphSet->loRunOffset);
  174. pCodePageInfo = (PUNI_CODEPAGEINFO)((PBYTE)pBase +
  175. pGlyphSet->loCodePageOffset);
  176. pMapTable = (PMAPTABLE)((PBYTE)pBase +
  177. pGlyphSet->loMapTableOffset);
  178. pTrans = pMapTable->Trans;
  179. pCodePageInfo->dwCodePage = wCodepage;
  180. pCodePageInfo->SelectSymbolSet.dwCount = 0;
  181. pCodePageInfo->SelectSymbolSet.loOffset = (ULONG)NULL;
  182. pCodePageInfo->UnSelectSymbolSet.dwCount = 0;
  183. pCodePageInfo->UnSelectSymbolSet.loOffset = (ULONG)NULL;
  184. DBGMESSAGE(("Load resource\n"));
  185. hModule = GetModuleHandle(TEXT("mkgtt.exe"));
  186. DBGMESSAGE(("hModule=0x%xl\n", (LONG)hModule));
  187. switch (sMode)
  188. {
  189. case CC_JIS:
  190. case CC_JIS_ANK:
  191. hRes = FindResource(hModule, TEXT("CC_JIS"), TEXT("RC_TRANSTAB"));
  192. DBGMESSAGE(("hRes=0x%lx\n", (LONG)hRes));
  193. lpctt = (TRANSTAB*)LoadResource(hModule, hRes);
  194. if (lpctt == NULL)
  195. {
  196. return FALSE;
  197. }
  198. break;
  199. case CC_ISC:
  200. hRes = FindResource(hModule, TEXT("CC_ISC"), TEXT("RC_TRANSTAB"));
  201. DBGMESSAGE(("hRes=0x%lx\n", (LONG)hRes));
  202. lpctt = (TRANSTAB*)LoadResource(hModule, hRes);
  203. if (lpctt == NULL)
  204. {
  205. return FALSE;
  206. }
  207. break;
  208. case CC_NS86:
  209. hRes = FindResource(hModule, TEXT("CC_NS86"), TEXT("RC_TRANSTAB"));
  210. DBGMESSAGE(("hRes=0x%lx\n", (LONG)hRes));
  211. lpctt = (TRANSTAB*)LoadResource(hModule, hRes);
  212. if (lpctt == NULL)
  213. {
  214. return FALSE;
  215. }
  216. break;
  217. case CC_TCA:
  218. hRes = FindResource(hModule, TEXT("CC_ISC"), TEXT("RC_TRANSTAB"));
  219. DBGMESSAGE(("hRes=0x%lx\n", (LONG)hRes));
  220. lpctt = (TRANSTAB*)LoadResource(hModule, hRes);
  221. if (lpctt == NULL)
  222. {
  223. return FALSE;
  224. }
  225. break;
  226. default:
  227. lpctt = NULL;
  228. }
  229. DBGMESSAGE(("Start to create GLYPHRUN.\n"));
  230. bInRun = FALSE;
  231. cRuns = 1;
  232. for ( wcIndex = 1, wcChar = MIN_WCHAR_VALUE;
  233. wcChar <= MAX_WCHAR_VALUE;
  234. wcChar++)
  235. {
  236. if (pwArray[wcChar] == INVALID_WCHAR_VALUE)
  237. {
  238. if (bInRun)
  239. {
  240. bInRun = FALSE;
  241. pGlyphRun ++;
  242. cRuns ++;
  243. }
  244. }
  245. else
  246. {
  247. //
  248. // GDI can't handle the value which cRunsGlyphs over 256. sueyas
  249. //
  250. if (!bInRun)
  251. {
  252. bInRun = TRUE;
  253. pGlyphRun->wcLow = wcChar;
  254. pGlyphRun->wGlyphCount = 1;
  255. }
  256. else
  257. {
  258. pGlyphRun->wGlyphCount++;
  259. if (pGlyphRun->wGlyphCount > 255)
  260. {
  261. bInRun = FALSE;
  262. pGlyphRun ++;
  263. cRuns ++;
  264. }
  265. }
  266. pMapTable->Trans[wcIndex - 1].ubCodePageID = 0;
  267. switch (sMode)
  268. {
  269. case CC_JIS:
  270. if (HIBYTE(pwArray[wcChar]))
  271. {
  272. aubChar[0] = HIBYTE(pwArray[wcChar]);
  273. aubChar[1] = LOBYTE(pwArray[wcChar]);
  274. SJisToJis(lpctt, (LPSTR)aubChar, (LPSTR)&wcCommand);
  275. pMapTable->Trans[wcIndex - 1].ubType = MTYPE_DOUBLE |
  276. MTYPE_PAIRED;
  277. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[0] =
  278. LOBYTE(wcCommand);
  279. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[1] =
  280. HIBYTE(wcCommand);
  281. }
  282. else
  283. {
  284. AnkToJis(lpctt, (LPSTR)&pwArray[wcChar], (LPSTR)&wcCommand);
  285. pMapTable->Trans[wcIndex - 1].ubType = MTYPE_SINGLE |
  286. MTYPE_PAIRED;
  287. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[0] =
  288. LOBYTE(wcCommand);
  289. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[1] =
  290. HIBYTE(wcCommand);
  291. }
  292. DBGMESSAGE(("wcSJis=0x%4x, wcJis=0x%x\n", pwArray[wcChar], wcCommand));
  293. break;
  294. case CC_JIS_ANK:
  295. if (HIBYTE(pwArray[wcChar]))
  296. {
  297. aubChar[0] = HIBYTE(pwArray[wcChar]);
  298. aubChar[1] = LOBYTE(pwArray[wcChar]);
  299. SJisToJis(lpctt, (LPSTR)aubChar, (LPSTR)&wcCommand);
  300. pMapTable->Trans[wcIndex - 1].ubType = MTYPE_DOUBLE |
  301. MTYPE_PAIRED;
  302. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[0] =
  303. LOBYTE(wcCommand);
  304. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[1] =
  305. HIBYTE(wcCommand);
  306. }
  307. else
  308. {
  309. wcCommand = pwArray[wcChar];
  310. pMapTable->Trans[wcIndex - 1].ubType = MTYPE_SINGLE |
  311. MTYPE_PAIRED;
  312. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[0] = 0;
  313. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[1] =
  314. LOBYTE(wcCommand);
  315. }
  316. DBGMESSAGE(("wcSJis=0x%4x, wcJis=0x%x\n", pwArray[wcChar], wcCommand));
  317. break;
  318. case CC_ISC:
  319. if (HIBYTE(pwArray[wcChar]))
  320. {
  321. aubChar[0] = HIBYTE(pwArray[wcChar]);
  322. aubChar[1] = LOBYTE(pwArray[wcChar]);
  323. KSCToISC(lpctt, (LPSTR)aubChar, (LPSTR)&wcCommand);
  324. }
  325. else
  326. {
  327. wcCommand = pwArray[wcChar];
  328. }
  329. goto SetTransData;
  330. case CC_NS86:
  331. if (HIBYTE(pwArray[wcChar]))
  332. {
  333. aubChar[0] = HIBYTE(pwArray[wcChar]);
  334. aubChar[1] = LOBYTE(pwArray[wcChar]);
  335. Big5ToNS86(lpctt, (LPSTR)aubChar, (LPSTR)&wcCommand);
  336. }
  337. else
  338. {
  339. wcCommand = pwArray[wcChar];
  340. }
  341. goto SetTransData;
  342. case CC_TCA:
  343. if (HIBYTE(pwArray[wcChar]))
  344. {
  345. aubChar[0] = HIBYTE(pwArray[wcChar]);
  346. aubChar[1] = LOBYTE(pwArray[wcChar]);
  347. Big5ToTCA(lpctt, (LPSTR)aubChar, (LPSTR)&wcCommand);
  348. }
  349. else
  350. {
  351. wcCommand = pwArray[wcChar];
  352. }
  353. goto SetTransData;
  354. default:
  355. wcCommand = pwArray[wcChar];
  356. SetTransData:
  357. if (!HIBYTE(wcCommand))
  358. {
  359. pMapTable->Trans[wcIndex - 1].ubType = MTYPE_SINGLE |
  360. MTYPE_DIRECT;
  361. pMapTable->Trans[wcIndex - 1].uCode.ubCode =
  362. LOBYTE(wcCommand);
  363. }
  364. else
  365. {
  366. pMapTable->Trans[wcIndex - 1].ubType = MTYPE_DOUBLE |
  367. MTYPE_PAIRED;
  368. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[0] =
  369. HIBYTE(wcCommand);
  370. pMapTable->Trans[wcIndex - 1].uCode.ubPairs[1] =
  371. LOBYTE(wcCommand);
  372. }
  373. break;
  374. }
  375. DBGMESSAGE(("Valid char:0x%x, sMode=%d, Run=%d, GlyphHandle=%d, ubType=0x%x, Command=0x%x\n", wcChar, sMode, cRuns, wcIndex, pMapTable->Trans[wcIndex - 1].ubType, wcCommand));
  376. wcIndex ++;
  377. }
  378. }
  379. wcIndex --;
  380. pMapTable->dwSize = sizeof(MAPTABLE) + sizeof(TRANSDATA) * (wcIndex - 1);
  381. pMapTable->dwGlyphNum = wcIndex;
  382. if (hRes)
  383. {
  384. FreeResource(hRes);
  385. }
  386. DBG_VPRINTGTT(pGlyphSet);
  387. return pGlyphSet;
  388. }
  389. BOOL
  390. bWriteGlyphSet(
  391. IN PUNI_GLYPHSETDATA pGlyphSet,
  392. IN CHAR *pFileName )
  393. /*++
  394. Routine Description:
  395. Dump FD_GLYPHSET data into specified file.
  396. Arguments:
  397. Return Value:
  398. None.
  399. 08-Apr-1995 Sat 00:00:00 created -by- Takashi Matsuzawa (takashim)
  400. Revision History:
  401. --*/
  402. {
  403. HANDLE hFile;
  404. ULONG iIndex;
  405. WCRUN *pWcRun;
  406. HGLYPH *phg;
  407. DWORD dwTmp;
  408. if (NULL == pFileName)
  409. {
  410. fprintf( stderr, "Invalid parameters\n" );
  411. return FALSE;
  412. }
  413. if ((hFile = CreateFileA(
  414. pFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0))
  415. == INVALID_HANDLE_VALUE) {
  416. return FALSE;
  417. }
  418. // FD_GLYPHSET structure itself + WCRUN array
  419. if (!WriteFile( hFile, pGlyphSet, pGlyphSet->dwSize, &dwTmp, NULL ))
  420. {
  421. return FALSE;
  422. }
  423. return TRUE;
  424. }
  425. VOID
  426. Usage()
  427. {
  428. fprintf ( stderr, "\nUsage : mkgtt [-etvv] outfile\n" );
  429. exit (EXIT_FAILURE);
  430. }
  431. BOOL
  432. GetLine(
  433. BYTE *pjBuffer,
  434. INT cjSize)
  435. {
  436. if (NULL == pjBuffer)
  437. {
  438. fprintf( stderr, "Invalid parameters\n" );
  439. return NULL;
  440. }
  441. do
  442. {
  443. if(fgets(pjBuffer, cjSize, stdin) == NULL)
  444. return FALSE;
  445. } while (IS_COMMENT(*pjBuffer));
  446. return TRUE;
  447. }
  448. VOID __cdecl
  449. main(
  450. int argc,
  451. char *argv[] )
  452. /*++
  453. Routine Description:
  454. Main routine for mkgtt.exe
  455. Arguments:
  456. Output filename. Input data is read from standard input.
  457. Return Value:
  458. None.
  459. Author:
  460. 08-Apr-1995 Sat 00:00:00 created -by- Takashi Matsuzawa (takashim)
  461. Revision History:
  462. --*/
  463. {
  464. PUNI_GLYPHSETDATA pGlyphSet;
  465. CHAR *pFileName;
  466. INT iArg, iMbLen;
  467. CHAR *pStr;
  468. WORD wCodePage;
  469. WORD wMbChar, wMbRun, wMbChar2;
  470. WCHAR wcSysChar;
  471. BYTE ajMbChar[2];
  472. BYTE ajBuffer[256];
  473. BYTE FileName[256];
  474. bEudc = FALSE;
  475. bTable = FALSE;
  476. iVerbose = 1;
  477. pFileName = NULL;
  478. if (NULL == argv)
  479. {
  480. fprintf( stderr, "Invalid parameters.\n");
  481. return;
  482. }
  483. while (--argc)
  484. {
  485. pStr = *(++argv);
  486. if (*pStr == '-')
  487. {
  488. for ( pStr++; *pStr; pStr++)
  489. {
  490. if (*pStr == 'e')
  491. bEudc = TRUE;
  492. else if (*pStr == 't')
  493. bTable = TRUE;
  494. else if (*pStr == 'v')
  495. iVerbose++;
  496. else
  497. Usage();
  498. }
  499. }
  500. else
  501. {
  502. pFileName = pStr;
  503. break;
  504. }
  505. }
  506. if (pFileName == NULL)
  507. {
  508. Usage();
  509. }
  510. // get the codepage id used for conversion
  511. if (!GetLine(ajBuffer, sizeof(ajBuffer)))
  512. {
  513. fprintf(stderr, "mkgtt: unexpected end of file\n");
  514. exit(EXIT_FAILURE);
  515. }
  516. if (EOF == sscanf(ajBuffer, "%hd", &wCodePage ))
  517. {
  518. fprintf(stderr, "mkgtt: unexpected end of file\n");
  519. exit(EXIT_FAILURE);
  520. }
  521. DBGMESSAGE(("mkgtt: wCodePage = %d\n", wCodePage));
  522. memset(awMultiByteArray, 0xff, sizeof(awMultiByteArray));
  523. while (1)
  524. {
  525. if (!GetLine(ajBuffer, sizeof(ajBuffer)))
  526. break;
  527. if ( sscanf (ajBuffer, "%hx%hd", &wMbChar, &wMbRun ) != 2 )
  528. {
  529. fprintf(stderr, "mkgtt: unrecognized line - \"%s\"\n", ajBuffer);
  530. exit(EXIT_FAILURE);
  531. }
  532. DBGMESSAGE(("mkgtt: wMbChar = %x, wMbrun = %d\n", wMbChar, wMbRun));
  533. for (; wMbRun--; wMbChar++)
  534. {
  535. iMbLen = 0;
  536. if (wMbChar & 0xff00)
  537. {
  538. ajMbChar[iMbLen++] = (BYTE)((wMbChar >> 8) & 0xff);
  539. }
  540. ajMbChar[iMbLen++] = (BYTE)(wMbChar & 0xff);
  541. if (MultiByteToWideChar(wCodePage, MB_ERR_INVALID_CHARS,
  542. ajMbChar, iMbLen, &wcSysChar, 1) != 1)
  543. {
  544. fprintf(stderr, "mkgtt: MultiByteToWideChar failed - %d\n",
  545. GetLastError());
  546. exit(EXIT_FAILURE);
  547. }
  548. if ((iMbLen = WideCharToMultiByte(wCodePage, 0,
  549. &wcSysChar, 1, ajMbChar, sizeof(ajMbChar), NULL, NULL)) == FALSE)
  550. {
  551. fprintf(stderr, "mkgtt: WideCharToMultiByte failed - %d\n",
  552. GetLastError());
  553. exit(EXIT_FAILURE);
  554. }
  555. if (iMbLen == 2)
  556. wMbChar2 = (ajMbChar[0] << 8) + ajMbChar[1];
  557. else
  558. wMbChar2 = ajMbChar[0];
  559. if (wMbChar != wMbChar2)
  560. {
  561. fprintf(stderr, "mkgtt: round-trip not achieved %x => %x => %x\n",
  562. wMbChar, wcSysChar, wMbChar2 );
  563. }
  564. if (IS_EUDC_W(wcSysChar))
  565. {
  566. DBGMESSAGE(("mkgtt: eudc character %x => %x%s\n", wcSysChar, wMbChar, (bEudc ? "" : " ignored.")));
  567. if (!bEudc)
  568. continue;
  569. }
  570. if (awMultiByteArray[wcSysChar] != INVALID_WCHAR_VALUE)
  571. {
  572. fprintf(stderr, "mkgtt: duplicate mapping %x => %x overwritten by => %x\n",
  573. wcSysChar, awMultiByteArray[wcSysChar], wMbChar);
  574. }
  575. awMultiByteArray[wcSysChar] = wMbChar;
  576. }
  577. }
  578. DBGMESSAGE(("Call PBuildGTT\n"));
  579. switch (wCodePage)
  580. {
  581. case CP_SHIFTJIS_932:
  582. DBGMESSAGE(("Shiftjis\n"));
  583. if ((pGlyphSet = PBuildGTT(CC_SJIS, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  584. NULL)
  585. {
  586. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  587. return;
  588. }
  589. bWriteGlyphSet( pGlyphSet, pFileName );
  590. GlobalFree( pGlyphSet );
  591. DBGMESSAGE(("Jis\n"));
  592. if ((pGlyphSet = PBuildGTT(CC_JIS, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  593. NULL)
  594. {
  595. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  596. return;
  597. }
  598. BCreateSubFileName(FileName, pFileName, 'J');
  599. bWriteGlyphSet( pGlyphSet, FileName );
  600. GlobalFree( pGlyphSet );
  601. DBGMESSAGE(("Ank\n"));
  602. if ((pGlyphSet = PBuildGTT(CC_JIS_ANK, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  603. NULL)
  604. {
  605. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  606. return;
  607. }
  608. BCreateSubFileName(FileName, pFileName, 'A');
  609. bWriteGlyphSet( pGlyphSet, FileName );
  610. GlobalFree( pGlyphSet );
  611. break;
  612. case CP_GB2312_936:
  613. if ((pGlyphSet = PBuildGTT(0, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  614. NULL)
  615. {
  616. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  617. return;
  618. }
  619. bWriteGlyphSet( pGlyphSet, pFileName );
  620. GlobalFree( pGlyphSet );
  621. break;
  622. case CP_WANSUNG_949:
  623. if ((pGlyphSet = PBuildGTT(0, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  624. NULL)
  625. {
  626. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  627. return;
  628. }
  629. bWriteGlyphSet( pGlyphSet, pFileName );
  630. GlobalFree( pGlyphSet );
  631. if ((pGlyphSet = PBuildGTT(CC_ISC, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  632. NULL)
  633. {
  634. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  635. return;
  636. }
  637. BCreateSubFileName(FileName, pFileName, 'I');
  638. bWriteGlyphSet( pGlyphSet, FileName );
  639. GlobalFree( pGlyphSet );
  640. break;
  641. case CP_CHINESEBIG5_950:
  642. if ((pGlyphSet = PBuildGTT(CC_BIG5, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  643. NULL)
  644. {
  645. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  646. return;
  647. }
  648. bWriteGlyphSet( pGlyphSet, pFileName );
  649. GlobalFree( pGlyphSet );
  650. if ((pGlyphSet = PBuildGTT(CC_TCA, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  651. NULL)
  652. {
  653. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  654. return;
  655. }
  656. BCreateSubFileName(FileName, pFileName, 'T');
  657. bWriteGlyphSet( pGlyphSet, FileName );
  658. GlobalFree( pGlyphSet );
  659. if ((pGlyphSet = PBuildGTT(CC_NS86, wCodePage, awMultiByteArray, sizeof(awMultiByteArray) )) ==
  660. NULL)
  661. {
  662. fprintf( stderr, "Error creating FD_GLYPHSET structure.\n" );
  663. return;
  664. }
  665. BCreateSubFileName(FileName, pFileName, 'N');
  666. bWriteGlyphSet( pGlyphSet, FileName );
  667. GlobalFree( pGlyphSet );
  668. break;
  669. }
  670. }
  671. VOID
  672. VPrintGTT(
  673. IN PUNI_GLYPHSETDATA pGly)
  674. {
  675. PUNI_CODEPAGEINFO pCP;
  676. PGLYPHRUN pGlyphRun;
  677. PMAPTABLE pMapTable;
  678. TRANSDATA *pTrans;
  679. DWORD dwI;
  680. WORD wSize, wJ;
  681. PBYTE pCommand;
  682. if (NULL == pGly)
  683. {
  684. fprintf( stderr, "Invalid parameters.\n");
  685. return;
  686. }
  687. pCP = (PUNI_CODEPAGEINFO)((PBYTE) pGly + pGly->loCodePageOffset);
  688. pGlyphRun = (PGLYPHRUN) ((PBYTE)pGly + pGly->loRunOffset);
  689. pMapTable = (PMAPTABLE) ((PBYTE)pGly + pGly->loMapTableOffset);
  690. pTrans = pMapTable->Trans;
  691. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  692. printf("G L Y P H S E T D A T A F I L E\n");
  693. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  694. printf("GLYPHSETDATA\n");
  695. printf("GLYPHSETDATA.dwSize : %d\n", pGly->dwSize);
  696. printf(" dwVersion : %d.%d\n", (pGly->dwVersion) >>16,
  697. 0x0000ffff&pGly->dwVersion);
  698. printf(" dwFlags : %d\n", pGly->dwFlags);
  699. printf(" lPredefinedID : %d\n", pGly->lPredefinedID);
  700. printf(" dwGlyphCount : %d\n", pGly->dwGlyphCount);
  701. printf(" dwRunCount : %d\n", pGly->dwRunCount);
  702. printf(" loRunOffset : 0x%x\n", pGly->loRunOffset);
  703. printf(" dwCodePageCount : %d\n", pGly->dwCodePageCount);
  704. printf(" loCodePageOffset : 0x%x\n", pGly->loCodePageOffset);
  705. printf(" loMapTableOffset : 0x%x\n", pGly->loMapTableOffset);
  706. printf("\n");
  707. pCP = (PUNI_CODEPAGEINFO)((PBYTE) pGly + pGly->loCodePageOffset);
  708. printf("\n");
  709. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  710. printf("CODEPAGEINFO\n");
  711. for (dwI = 0; dwI < pGly->dwCodePageCount; dwI ++)
  712. {
  713. printf ("UNI_CODEPAGEINFO[%d].dwCodePage = %d\n",
  714. dwI, pCP->dwCodePage);
  715. printf ("UNI_CODEPAGEINFO[%d].SelectSymbolSet.dwCount = %d\n",
  716. dwI, pCP->SelectSymbolSet.dwCount);
  717. printf ("UNI_CODEPAGEINFO[%d].SelectSymbolSet:Command = %s\n",
  718. dwI, (PBYTE)pCP+pCP->SelectSymbolSet.loOffset);
  719. printf ("UNI_CODEPAGEINFO[%d].UnSelectSymbolSet.dwCount = %d\n",
  720. dwI, pCP->UnSelectSymbolSet.dwCount);
  721. printf ("UNI_CODEPAGEINFO[%d].UnSelectSymbolSet:Command = %s\n",
  722. dwI, (PBYTE)pCP+pCP->UnSelectSymbolSet.loOffset);
  723. pCP++;
  724. }
  725. pGlyphRun =
  726. (PGLYPHRUN) ((PBYTE)pGly + pGly->loRunOffset);
  727. printf("\n");
  728. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  729. printf("GLYPHRUN\n");
  730. for (dwI = 0; dwI < pGly->dwRunCount; dwI ++)
  731. {
  732. printf("GLYPHRUN[%2d].wcLow = 0x%-4x\n",
  733. dwI, pGlyphRun->wcLow);
  734. printf("GLYPHRUN[%2d].wGlyphCount = %d\n",
  735. dwI, pGlyphRun->wGlyphCount);
  736. pGlyphRun++;
  737. }
  738. pMapTable = (PMAPTABLE) ((PBYTE)pGly + pGly->loMapTableOffset);
  739. pTrans = pMapTable->Trans;
  740. printf("\n");
  741. printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  742. printf("MAPTABLE\n");
  743. printf("MAPTABLE.dwSize = %d\n", pMapTable->dwSize);
  744. printf("MAPTABLE.dwGlyphNum = %d\n", pMapTable->dwGlyphNum);
  745. for (dwI = 0; dwI < pMapTable->dwGlyphNum; dwI ++)
  746. {
  747. printf("MAPTABLE.pTrans[%5d].ubCodePageID = %d\n",
  748. dwI, pTrans[dwI].ubCodePageID);
  749. printf("MAPTABLE.pTrans[%5d].ubType = 0x%x\n",
  750. dwI, pTrans[dwI].ubType);
  751. switch(pTrans[dwI].ubType & MTYPE_FORMAT_MASK)
  752. {
  753. case MTYPE_DIRECT:
  754. printf("MAPTABLE.pTrans[%5d].ubCode = 0x%02x\n",
  755. dwI, pTrans[dwI].uCode.ubCode);
  756. break;
  757. case MTYPE_PAIRED:
  758. printf("MAPTABLE.pTrans[%5d].ubPairs[0] = 0x%02x\n",
  759. dwI, pTrans[dwI].uCode.ubPairs[0]);
  760. printf("MAPTABLE.pTrans[%5d].ubPairs[1] = 0x%02x\n",
  761. dwI, pTrans[dwI].uCode.ubPairs[1]);
  762. break;
  763. case MTYPE_COMPOSE:
  764. printf("MAPTABLE.pTrans[%5d].sCode = 0x%02x\n",
  765. dwI, pTrans[dwI].uCode.sCode);
  766. pCommand = (PBYTE)pMapTable + pTrans[dwI].uCode.sCode;
  767. wSize = *(WORD*)pCommand;
  768. pCommand += 2;
  769. printf("Size = 0x%d\n", wSize);
  770. printf("Command = 0x");
  771. for (wJ = 0; wJ < wSize; wJ ++)
  772. {
  773. printf("%02x",pCommand[wJ]);
  774. }
  775. printf("\n");
  776. break;
  777. }
  778. }
  779. }
  780. BOOL
  781. BCreateSubFileName(
  782. IN CHAR *pDestFileName,
  783. IN CHAR *pSrcFileName,
  784. IN CHAR cAdd)
  785. {
  786. INT iFileNameLen, iI;
  787. if (NULL == pDestFileName ||
  788. NULL == pSrcFileName )
  789. {
  790. fprintf( stderr, "Invalid parameters\n" );
  791. return FALSE;
  792. }
  793. iFileNameLen = strlen(pSrcFileName);
  794. strcpy(pDestFileName, pSrcFileName);
  795. for (iI = 0; iI < iFileNameLen; iI ++)
  796. {
  797. if (pSrcFileName[iI] == '.')
  798. {
  799. break;
  800. }
  801. }
  802. pDestFileName[iI] = cAdd;
  803. pDestFileName[iI + 1] = pSrcFileName[iI];
  804. pDestFileName[iI + 2] = pSrcFileName[iI + 1];
  805. pDestFileName[iI + 3] = pSrcFileName[iI + 2];
  806. pDestFileName[iI + 4] = pSrcFileName[iI + 3];
  807. pDestFileName[iI + 5] = (CHAR)NULL;
  808. return TRUE;
  809. }