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.

1427 lines
41 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. pfm2ufm.c
  5. Abstract:
  6. Program to read Windows 16 PFM format data and convert to NT's
  7. IFIMETRICS data. Note that since IFIMETRICS is somewhat more
  8. elaborate than PFM data, some of the values are best guesses.
  9. These are made on the basis of educated guesses.
  10. Environment:
  11. Windows NT Unidrv driver
  12. Revision History:
  13. 10/16/96 -eigos-
  14. Created from rasdd.
  15. --*/
  16. #include "precomp.h"
  17. #if !defined(DEVSTUDIO) // MDS doesn't need this stuff...
  18. //
  19. // Global variables
  20. //
  21. #define NUM_OF_ERROR1 15
  22. static BYTE *gcstrError1[NUM_OF_ERROR1] = {
  23. "Usage: pfm2ufm [-vcpf] [-s#] [-aCodePage] uniqname pfmfile [gttfile/codepage/predefined gtt id] ufmfile\n",
  24. " -v print out PFM and IFIMETRICS\n",
  25. " -c specify codepage instead of gtt file\n",
  26. " -p specify predefined gtt id instead of gtt file\n",
  27. " -f enable font simulation\n",
  28. " -a facename conversion to unicode using codepage\n",
  29. " -s# specify scaling option, can be -s0, -s1, -s2\n\n",
  30. " uniqname is used to create IFIMETRIC.dpwszUniqueName\n",
  31. " pfm_file is input, read only usage\n",
  32. " gtt_file is input, read only usage\n",
  33. " predefind gtt id can be -1,-2,-3,-10,-11,-13,-14,-15,-16,-17,-18\n",
  34. " ufm_file is output\n Files must be different\n\n",
  35. " E.g.\n",
  36. " (Specify code page) pfm2ufm -c UniqName XXX.PFM 1452 XXX.UFM\n",
  37. " (Specify predefined gtt id) pfm2ufm -p UniqName XXX.PFM -13 XXX.UFM\n"
  38. " (FaceName codepage conversion) pfm2ufm -p -a437 UniqName XXX.PFM -1 XXX.UFM\n"
  39. };
  40. static BYTE gcstrError2[] = "HeapCreate() fails in pfm2ufm.\n";
  41. static BYTE gcstrError3[] = "Cannot open input file: %ws.\n";
  42. static BYTE gcstrError4[] = "%ws is not a valid PFM file - ignored.\n";
  43. static BYTE gcstrError5[] = "Could not align PFM file.\n";
  44. static BYTE gcstrError6[] = "Failed to convert from FONTINFO to IFIMETRICS.\n";
  45. static BYTE gcstrError7[] = "Could not get font selection command\n";
  46. static BYTE gcstrError8[] = "Could not get font unselection command\n";
  47. static BYTE gcstrError9[] = "Could not open gtt file '%ws'\n";
  48. static BYTE gcstrError10[] = "Cannot convert PFM to UFM\n";
  49. static BYTE gcstrError11[] = "Cannot create output file: '%ws'\n";
  50. static BYTE gcstrError12[] = "Cannot write %ws data to output file.\n";
  51. static BYTE gcstrError13[] = "Invalid ctt id: %d\n";
  52. static WCHAR *gwstrGTT[3] = { TEXT("CP437_GTT"),
  53. TEXT("CP850_GTT"),
  54. TEXT("CP863_GTT") };
  55. #define WRITEDATAINTOFILE(pData, dwSize, pwstrErrorStr) \
  56. if (!WriteFile(hUFMFile, \
  57. (pData), \
  58. (dwSize), \
  59. &dwWrittenSize, \
  60. NULL)) \
  61. { \
  62. fprintf(stderr, gcstrError12, (pwstrErrorStr)); \
  63. return -12; \
  64. }
  65. #else
  66. #define WRITEDATAINTOFILE(pData, dwSize) \
  67. if (!WriteFile(hUFMFile, \
  68. (pData), \
  69. (dwSize), \
  70. &dwWrittenSize, \
  71. NULL)) \
  72. return FALSE;
  73. #endif
  74. DWORD gdwOutputFlags;
  75. //
  76. // Internal macros
  77. //
  78. #define FILENAME_SIZE 512
  79. //
  80. // Internal structure define
  81. //
  82. typedef VOID (*VPRINT) (char*,...);
  83. //
  84. // Internal function definition
  85. //
  86. VOID VPrintIFIMETRICS (IFIMETRICS*, VPRINT);
  87. VOID VPrintPFM (PFMHEADER*, VPRINT);
  88. VOID VPrintPFMExt (PFMEXTENSION*, VPRINT);
  89. VOID VPrintETM (EXTTEXTMETRIC*, VPRINT);
  90. VOID VPrintFontCmd (CD*, BOOL, VPRINT);
  91. VOID VPrintKerningPair(w3KERNPAIR*, DWORD, VPRINT);
  92. VOID VPrintWidthTable (PSHORT, DWORD, VPRINT);
  93. BOOL BArgCheck(IN INT, IN CHAR**, OUT PWSTR, OUT PWSTR, OUT PWSTR, OUT PWSTR, OUT PDWORD);
  94. BOOL BValidatePFM(BYTE *, DWORD);
  95. DWORD DwGetCodePageFromCTTID(LONG);
  96. DWORD DwGetCodePageFromGTTID(LONG);
  97. INT ICodePage2GTTID( DWORD dwCodePage);
  98. INT ICttID2GttID( LONG lPredefinedCTTID);
  99. #if defined(DEVSTUDIO)
  100. BOOL BConvertPFM(LPBYTE lpbPFM, DWORD dwCodePage, LPBYTE lpbGTT,
  101. PWSTR pwstrUnique, LPSTR lpstrUFM, int iGTTID) {
  102. HANDLE hHeap;
  103. HANDLE hUFMFile;
  104. PUNI_GLYPHSETDATA pGlyph = (PUNI_GLYPHSETDATA) lpbGTT;
  105. EXTTEXTMETRIC Etm;
  106. FONTOUT FOutData;
  107. FONTIN FInData;
  108. FONTMISC FMiscData;
  109. DWORD dwWrittenSize;
  110. //
  111. // Create a heap.
  112. //
  113. if ( !(hHeap = HeapCreate( HEAP_NO_SERIALIZE, 10 * 1024, 256 * 1024 )) )
  114. return FALSE;
  115. //
  116. // Init MiscData
  117. //
  118. FMiscData.pwstrUniqName = pwstrUnique;
  119. //
  120. // Init FInData
  121. //
  122. ZeroMemory( &FInData, sizeof(FONTIN));
  123. FInData.pETM = &Etm;
  124. //
  125. // Convert PFM to UFM
  126. //
  127. if (!BConvertPFM2UFM(hHeap,
  128. lpbPFM,
  129. pGlyph,
  130. dwCodePage,
  131. &FMiscData,
  132. &FInData,
  133. iGTTID,
  134. &FOutData,
  135. 0L))
  136. return FALSE;
  137. //
  138. // Create the output file.
  139. //
  140. hUFMFile = CreateFileA( lpstrUFM,
  141. GENERIC_WRITE,
  142. 0,
  143. NULL,
  144. CREATE_ALWAYS,
  145. FILE_ATTRIBUTE_NORMAL,
  146. 0 );
  147. if( hUFMFile == (HANDLE)-1 )
  148. return FALSE;
  149. //
  150. // Write the output file.
  151. //
  152. // First, tweak the GTT ID- the library code pulls it from the PFM,
  153. // which may not be correct.
  154. WRITEDATAINTOFILE(&FOutData.UniHdr, sizeof(UNIFM_HDR));
  155. WRITEDATAINTOFILE(&FOutData.UnidrvInfo, sizeof(UNIDRVINFO));
  156. if (FOutData.SelectFont.dwSize)
  157. {
  158. WRITEDATAINTOFILE(FOutData.SelectFont.pCmdString,
  159. FOutData.SelectFont.dwSize);
  160. }
  161. if (FOutData.UnSelectFont.dwSize)
  162. {
  163. WRITEDATAINTOFILE(FOutData.UnSelectFont.pCmdString,
  164. FOutData.UnSelectFont.dwSize);
  165. }
  166. // Pad to get DWORD alignment
  167. SetFilePointer(hUFMFile,
  168. FOutData.UnidrvInfo.dwSize - (sizeof FOutData.UnidrvInfo +
  169. FOutData.SelectFont.dwSize + FOutData.UnSelectFont.dwSize), NULL,
  170. FILE_CURRENT);
  171. WRITEDATAINTOFILE(FOutData.pIFI, FOutData.dwIFISize);
  172. if (FOutData.pETM)
  173. {
  174. WRITEDATAINTOFILE(FOutData.pETM, sizeof(EXTTEXTMETRIC));
  175. }
  176. if (FOutData.dwWidthTableSize != 0)
  177. {
  178. WRITEDATAINTOFILE(FOutData.pWidthTable, FOutData.dwWidthTableSize);
  179. }
  180. if (FOutData.dwKernDataSize != 0)
  181. {
  182. WRITEDATAINTOFILE(FOutData.pKernData, FOutData.dwKernDataSize);
  183. }
  184. // Clean it all up...
  185. CloseHandle(hUFMFile);
  186. HeapDestroy(hHeap);
  187. return TRUE;
  188. }
  189. #else
  190. //
  191. // Input data
  192. // Unique face name
  193. // ID string
  194. // pfm file name
  195. // gtt file name
  196. // ufm file name
  197. //
  198. // main function
  199. //
  200. // 1. Check argument. Unique facename, pfm filename, gtt file name, ufm filename
  201. // 2. Open pfm file
  202. // 3. PFM file validation
  203. // 4. Align non-aligned PFM file
  204. // 5. Convert Fontinfo to Ifimetrics
  205. // 6. Get font selection/unselection command
  206. // 7. Get kerning pair table and convert it to GTT base table
  207. // 8. Get width table and convert it to GTT base table
  208. // 9. Open UFM file
  209. // 10. Write to UFM file
  210. //
  211. INT __cdecl
  212. main(
  213. INT iArgc,
  214. CHAR **ppArgv)
  215. /*++
  216. Routine Description:
  217. main function of pfm to unifm converter
  218. Arguments:
  219. iArgc - the number of an argument
  220. ppArgv - the pointer to the argument string list
  221. Return Value:
  222. 0 if successful, otherwise failed to complete conversion
  223. --*/
  224. {
  225. HFILEMAP hPFMFileMap;
  226. HFILEMAP hGTTFileMap;
  227. HANDLE hHeap;
  228. HANDLE hUFMFile;
  229. PUNI_GLYPHSETDATA pGlyph;
  230. FONTOUT FOutData;
  231. FONTIN FInData;
  232. FONTMISC FMiscData;
  233. EXTTEXTMETRIC Etm;
  234. HMODULE hModule;
  235. HRSRC hRes;
  236. DWORD dwOffset;
  237. DWORD dwPFMSize;
  238. DWORD dwGTTSize;
  239. DWORD dwWrittenSize;
  240. DWORD dwCodePage;
  241. DWORD dwCodePageOfFacenameConv;
  242. DWORD dwGTTID;
  243. LONG lPredefinedCTTID;
  244. WCHAR awchUniqName[FILENAME_SIZE];
  245. WCHAR awchPFMFile[FILENAME_SIZE];
  246. WCHAR awchGTTFile[FILENAME_SIZE];
  247. WCHAR awchUFMFile[FILENAME_SIZE];
  248. DWORD dwFlags = 0L;
  249. INT iI, iGTTID;
  250. PBYTE pPFMData;
  251. //RIP(("Start pfm2ufm\n"));
  252. //
  253. // Argument check
  254. //
  255. if (!BArgCheck(iArgc,
  256. ppArgv,
  257. awchUniqName,
  258. awchPFMFile,
  259. awchGTTFile,
  260. awchUFMFile,
  261. &dwCodePageOfFacenameConv))
  262. {
  263. for (iI = 0; iI < NUM_OF_ERROR1; iI ++)
  264. {
  265. fprintf( stderr, gcstrError1[iI]);
  266. }
  267. return -1;
  268. }
  269. //
  270. // Create a heap.
  271. //
  272. if ( !(hHeap = HeapCreate( HEAP_NO_SERIALIZE, 10 * 1024, 256 * 1024 )) )
  273. {
  274. fprintf( stderr, gcstrError2);
  275. return -2;
  276. }
  277. //
  278. // Open PFM file
  279. //
  280. if( !(hPFMFileMap = MapFileIntoMemory(awchPFMFile,
  281. &pPFMData,
  282. &dwPFMSize)))
  283. {
  284. fprintf( stderr, gcstrError3, awchPFMFile );
  285. return -3;
  286. }
  287. //
  288. // PFM validation.
  289. // PFM Header, DRIVERINFO, PFMEXTENSION, DRIVERINFO_VERSION
  290. //
  291. if( !BValidatePFM( pPFMData, dwPFMSize ) )
  292. {
  293. fprintf( stderr, gcstrError4, awchPFMFile );
  294. return -4;
  295. }
  296. //
  297. // Open GTT file/Get codepage/predefined GTT
  298. //
  299. iGTTID = 0;
  300. pGlyph = NULL;
  301. if (gdwOutputFlags & OUTPUT_CODEPAGEMODE)
  302. {
  303. dwCodePage = _wtol(awchGTTFile);
  304. iGTTID = ICodePage2GTTID(dwCodePage);
  305. }
  306. else
  307. if (gdwOutputFlags & OUTPUT_PREDEFINED)
  308. {
  309. hModule = GetModuleHandle(TEXT("pfm2ufm.exe"));
  310. lPredefinedCTTID = _wtol(awchGTTFile);
  311. //
  312. // Bug support
  313. // Previous implementation only support plug value like
  314. // 1, 2, 3, 13, 263 etc.
  315. // We need to support this type still
  316. //
  317. if (lPredefinedCTTID > 0)
  318. lPredefinedCTTID = -lPredefinedCTTID;
  319. iGTTID = lPredefinedCTTID;
  320. //
  321. // UNI16 FE CTT ID handlig
  322. //
  323. if (-256 >= lPredefinedCTTID && lPredefinedCTTID >= -263)
  324. {
  325. //
  326. // CTT_BIG5 -261 // Chinese (PRC, Singapore)
  327. // CTT_ISC -258 // Korean
  328. // CTT_JIS78 -256 // Japan
  329. // CTT_JIS83 -259 // Japan
  330. // CTT_JIS78_ANK -262 // Japan
  331. // CTT_JIS83_ANK -263 // Japan
  332. // CTT_NS86 -257 // Chinese (PRC, Singapore)
  333. // CTT_TCA -260 // Chinese (PRC, Singapore)
  334. //
  335. gdwOutputFlags &= ~OUTPUT_PREDEFINED;
  336. gdwOutputFlags |= OUTPUT_CODEPAGEMODE;
  337. dwCodePage = DwGetCodePageFromCTTID(lPredefinedCTTID);
  338. iGTTID = ICttID2GttID(lPredefinedCTTID);
  339. }
  340. else
  341. //
  342. // UNI32 GTTID handling
  343. //
  344. if (-18 <= iGTTID && iGTTID <= -10 ||
  345. -3 <= iGTTID && iGTTID <= -1 )
  346. {
  347. dwCodePage = DwGetCodePageFromGTTID(iGTTID);
  348. if (-3 <= iGTTID && iGTTID <= -1)
  349. {
  350. if (lPredefinedCTTID)
  351. {
  352. hRes = FindResource(hModule,
  353. gwstrGTT[lPredefinedCTTID - 1],
  354. TEXT("RC_GLYPH"));
  355. pGlyph = (PUNI_GLYPHSETDATA)LoadResource(hModule, hRes);
  356. }
  357. }
  358. }
  359. else
  360. //
  361. // UNI16 US ID handling
  362. //
  363. if (1 <= lPredefinedCTTID || lPredefinedCTTID <= 3)
  364. {
  365. //
  366. // CC_CP437 -1
  367. // CC_CP850 -2
  368. // CC_CP863 -3
  369. //
  370. dwCodePage = DwGetCodePageFromCTTID(lPredefinedCTTID);
  371. if (lPredefinedCTTID)
  372. {
  373. hRes = FindResource(hModule,
  374. gwstrGTT[lPredefinedCTTID - 1],
  375. TEXT("RC_GLYPH"));
  376. pGlyph = (PUNI_GLYPHSETDATA)LoadResource(hModule, hRes);
  377. }
  378. }
  379. }
  380. else
  381. {
  382. if( !(hGTTFileMap = MapFileIntoMemory(awchGTTFile,
  383. &pGlyph,
  384. &dwGTTSize)))
  385. {
  386. fprintf( stderr, gcstrError9, awchGTTFile );
  387. return -9;
  388. }
  389. dwCodePage = 0;
  390. }
  391. //
  392. // Init MiscData
  393. //
  394. FMiscData.pwstrUniqName = awchUniqName;
  395. //
  396. // Init FInData
  397. //
  398. ZeroMemory( &FInData, sizeof(FONTIN));
  399. FInData.pETM = &Etm;
  400. if ( gdwOutputFlags & OUTPUT_FONTSIM)
  401. FInData.dwFlags = FLAG_FONTSIM;
  402. else
  403. FInData.dwFlags = 0;
  404. if ( gdwOutputFlags & OUTPUT_FACENAME_CONV)
  405. FInData.dwCodePageOfFacenameConv = dwCodePageOfFacenameConv;
  406. else
  407. FInData.dwCodePageOfFacenameConv = 0;
  408. if ( gdwOutputFlags & OUTPUT_SCALING_ANISOTROPIC )
  409. dwFlags |= PFM2UFM_SCALING_ANISOTROPIC;
  410. else if ( gdwOutputFlags & OUTPUT_SCALING_ARB_XFORMS )
  411. dwFlags |= PFM2UFM_SCALING_ARB_XFORMS;
  412. //
  413. // Convert PFM to UFM
  414. //
  415. if (!BConvertPFM2UFM(hHeap,
  416. pPFMData,
  417. pGlyph,
  418. dwCodePage,
  419. &FMiscData,
  420. &FInData,
  421. iGTTID,
  422. &FOutData,
  423. dwFlags))
  424. {
  425. fprintf( stderr, gcstrError10 );
  426. return -10;
  427. }
  428. if (gdwOutputFlags & OUTPUT_PREDEFINED)
  429. {
  430. FreeResource(hRes);
  431. }
  432. if (gdwOutputFlags & OUTPUT_VERBOSE)
  433. {
  434. VPrintPFM (&FInData.PFMH, printf);
  435. VPrintPFMExt (&FInData.PFMExt, printf);
  436. if (FInData.pETM)
  437. {
  438. VPrintETM (FInData.pETM, printf);
  439. }
  440. VPrintFontCmd (FInData.pCDSelectFont, TRUE, printf);
  441. VPrintFontCmd (FInData.pCDUnSelectFont, FALSE, printf);
  442. VPrintKerningPair (FInData.pKernPair,
  443. FInData.dwKernPairSize,
  444. printf);
  445. VPrintWidthTable (FInData.psWidthTable,
  446. FInData.dwWidthTableSize,
  447. printf);
  448. VPrintIFIMETRICS(FOutData.pIFI, printf);
  449. }
  450. //
  451. // Create the output file.
  452. //
  453. hUFMFile = CreateFile( awchUFMFile,
  454. GENERIC_WRITE,
  455. 0,
  456. NULL,
  457. CREATE_ALWAYS,
  458. FILE_ATTRIBUTE_NORMAL,
  459. 0 );
  460. if( hUFMFile == (HANDLE)-1 )
  461. {
  462. fprintf( stderr, gcstrError11, awchUFMFile );
  463. return -11;
  464. }
  465. //
  466. // Write the output file.
  467. //
  468. WRITEDATAINTOFILE(&FOutData.UniHdr, sizeof(UNIFM_HDR), L"UNIFM_HDR");
  469. WRITEDATAINTOFILE(&FOutData.UnidrvInfo, sizeof(UNIDRVINFO), L"UNIDRVINFO");
  470. if (FOutData.SelectFont.dwSize)
  471. {
  472. WRITEDATAINTOFILE(FOutData.SelectFont.pCmdString,
  473. FOutData.SelectFont.dwSize,
  474. L"SelectFont");
  475. }
  476. if (FOutData.UnSelectFont.dwSize)
  477. {
  478. WRITEDATAINTOFILE(FOutData.UnSelectFont.pCmdString,
  479. FOutData.UnSelectFont.dwSize,
  480. L"UnSelectFont");
  481. }
  482. // Pad to get DWORD alignment
  483. SetFilePointer(hUFMFile,
  484. FOutData.UnidrvInfo.dwSize - (sizeof FOutData.UnidrvInfo +
  485. FOutData.SelectFont.dwSize + FOutData.UnSelectFont.dwSize), NULL,
  486. FILE_CURRENT);
  487. WRITEDATAINTOFILE(FOutData.pIFI, FOutData.dwIFISize, L"IFIMETRICS");
  488. if (FOutData.pETM != NULL)
  489. {
  490. WRITEDATAINTOFILE(FOutData.pETM, sizeof(EXTTEXTMETRIC), L"EXTEXTMETRIC");
  491. }
  492. if (FOutData.dwWidthTableSize != 0)
  493. {
  494. WRITEDATAINTOFILE(FOutData.pWidthTable, FOutData.dwWidthTableSize, L"WIDTHTABLE");
  495. }
  496. if (FOutData.dwKernDataSize != 0)
  497. {
  498. WRITEDATAINTOFILE(FOutData.pKernData, FOutData.dwKernDataSize, L"KERNDATA");
  499. }
  500. //
  501. // All done, so clean up and away
  502. //
  503. UnmapViewOfFile( hGTTFileMap ); /* Input no longer needed */
  504. UnmapViewOfFile( hPFMFileMap ); /* Input no longer needed */
  505. CloseHandle(hUFMFile);
  506. HeapDestroy( hHeap ); /* Probably not needed */
  507. return 0;
  508. }
  509. //
  510. // Internal functions
  511. //
  512. BOOL
  513. BValidatePFM(
  514. IN BYTE *pBase,
  515. IN DWORD dwSize)
  516. /*++
  517. Routine Description:
  518. Look at a memory mapped PFM file, and see if it seems reasonable.
  519. Arguments:
  520. pBase - base address of file
  521. dwSize - size of bytes available
  522. Return Value:
  523. TRUE if successful, otherwise PFM file is invalid.
  524. --*/
  525. {
  526. res_PFMHEADER *rpfm; // In Win 3.1 format, UNALIGNED!!
  527. res_PFMEXTENSION *rpfme; // Final access to offset to DRIVERINFO
  528. DRIVERINFO di; // The actual DRIVERINFO data!
  529. DWORD dwOffset; // Calculate offset of interest as we go
  530. //
  531. // First piece of sanity checking is the size! It must be at least
  532. // as large as a PFMHEADER structure plus a DRIVERINFO structure.
  533. //
  534. if( dwSize < (sizeof( res_PFMHEADER ) +
  535. sizeof( DRIVERINFO ) +
  536. sizeof( res_PFMEXTENSION )) )
  537. {
  538. return FALSE;
  539. }
  540. //
  541. // Step along to find the DRIVERINFO structure, as this contains
  542. // some identifying information that we match to look for legitimacy.
  543. //
  544. rpfm = (res_PFMHEADER *)pBase; /* Looking for fixed pitch */
  545. dwOffset = sizeof( res_PFMHEADER );
  546. if( rpfm->dfPixWidth == 0 )
  547. {
  548. /* Proportionally spaced, so allow for the width table too! */
  549. dwOffset += (rpfm->dfLastChar - rpfm->dfFirstChar + 2) *
  550. sizeof( short );
  551. }
  552. rpfme = (res_PFMEXTENSION *)(pBase + dwOffset);
  553. //
  554. // Next is the PFMEXTENSION data
  555. //
  556. dwOffset += sizeof( res_PFMEXTENSION );
  557. if( dwOffset >= dwSize )
  558. {
  559. return FALSE;
  560. }
  561. dwOffset = DwAlign4( rpfme->b_dfDriverInfo );
  562. if( (dwOffset + sizeof( DRIVERINFO )) > dwSize )
  563. {
  564. return FALSE;
  565. }
  566. //
  567. // A memcpy is used because this data is typically not aigned. Ugh!
  568. //
  569. CopyMemory( &di, pBase + dwOffset, sizeof( di ) );
  570. if( di.sVersion > DRIVERINFO_VERSION )
  571. {
  572. return FALSE;
  573. }
  574. return TRUE;
  575. }
  576. BOOL
  577. BCheckIFIMETRICS(
  578. IFIMETRICS *pIFI,
  579. VPRINT vPrint
  580. )
  581. /*++
  582. Routine Description:
  583. This is where you put sanity checks on an incomming IFIMETRICS structure.
  584. Arguments:
  585. Return Value:
  586. TRUE if successful, otherwise PFM file is invalid.
  587. --*/
  588. {
  589. BOOL bGoodPitch;
  590. BYTE jPitch = pIFI->jWinPitchAndFamily &
  591. (DEFAULT_PITCH | FIXED_PITCH | VARIABLE_PITCH);
  592. if (pIFI->flInfo & FM_INFO_CONSTANT_WIDTH)
  593. {
  594. bGoodPitch = (jPitch == FIXED_PITCH);
  595. }
  596. else
  597. {
  598. bGoodPitch = (jPitch == VARIABLE_PITCH);
  599. }
  600. if (!bGoodPitch)
  601. {
  602. vPrint("\n\n<INCONSISTENCY DETECTED>\n");
  603. vPrint( " jWinPitchAndFamily = %-#2x, flInfo = %-#8lx\n\n",
  604. pIFI->jWinPitchAndFamily, pIFI->flInfo);
  605. return FALSE;
  606. }
  607. return TRUE;
  608. }
  609. BOOL
  610. BArgCheck(
  611. IN INT iArgc,
  612. IN CHAR **ppArgv,
  613. OUT PWSTR pwstrUniqName,
  614. OUT PWSTR pwstrPFMFile,
  615. OUT PWSTR pwstrGTTFile,
  616. OUT PWSTR pwstrUFMFile,
  617. OUT PDWORD pdwCodePageOfFacenameConv)
  618. {
  619. DWORD dwI;
  620. PTSTR pstrCodePageOfFacenameConv;
  621. INT iCount, iRet;
  622. ASSERT(pwstrUniqName != NULL ||
  623. pwstrPFMFile != NULL ||
  624. pwstrGTTFile != NULL ||
  625. pwstrUFMFile != NULL );
  626. if (iArgc < 5)
  627. {
  628. return FALSE;
  629. }
  630. ppArgv++;
  631. iArgc --;
  632. iCount = 0;
  633. while (iArgc > 0)
  634. {
  635. if ( (**ppArgv == '-' || **ppArgv == '/') &&
  636. // minus value GTT or CTT ID handling
  637. !(**ppArgv == '-' && 0x30 <= *(*ppArgv+1) && *(*ppArgv+1) <= 0x39)
  638. )
  639. {
  640. dwI = 1;
  641. while(*(*ppArgv+dwI))
  642. {
  643. switch(*(*ppArgv+dwI))
  644. {
  645. case 'v':
  646. gdwOutputFlags |= OUTPUT_VERBOSE;
  647. break;
  648. case 'c':
  649. gdwOutputFlags |= OUTPUT_CODEPAGEMODE;
  650. break;
  651. case 'p':
  652. gdwOutputFlags |= OUTPUT_PREDEFINED;
  653. break;
  654. case 'f':
  655. gdwOutputFlags |= OUTPUT_FONTSIM;
  656. break;
  657. case 'n':
  658. gdwOutputFlags |= OUTPUT_FONTSIM_NONADD;
  659. break;
  660. case 'a':
  661. gdwOutputFlags |= OUTPUT_FACENAME_CONV;
  662. pstrCodePageOfFacenameConv = (PTSTR)(*ppArgv + dwI + 1);
  663. *pdwCodePageOfFacenameConv = (DWORD)atoi((const char*)pstrCodePageOfFacenameConv);
  664. break;
  665. case 's':
  666. if ('1' == *((PSTR)(*ppArgv + dwI + 1)))
  667. gdwOutputFlags |= OUTPUT_SCALING_ANISOTROPIC;
  668. else if ('2' == *((PSTR)(*ppArgv + dwI + 1)))
  669. gdwOutputFlags |= OUTPUT_SCALING_ARB_XFORMS;
  670. break;
  671. }
  672. dwI ++;
  673. }
  674. if ((gdwOutputFlags & (OUTPUT_PREDEFINED|OUTPUT_CODEPAGEMODE)) ==
  675. (OUTPUT_PREDEFINED|OUTPUT_CODEPAGEMODE) )
  676. {
  677. return FALSE;
  678. }
  679. }
  680. else
  681. {
  682. if (iCount == 0)
  683. {
  684. iRet = MultiByteToWideChar(CP_ACP,
  685. 0,
  686. *ppArgv,
  687. strlen(*ppArgv),
  688. pwstrUniqName,
  689. FILENAME_SIZE);
  690. *(pwstrUniqName + iRet) = (WCHAR)NULL;
  691. }
  692. else if (iCount == 1)
  693. {
  694. iRet = MultiByteToWideChar(CP_ACP,
  695. 0,
  696. *ppArgv,
  697. strlen(*ppArgv),
  698. pwstrPFMFile,
  699. FILENAME_SIZE);
  700. *(pwstrPFMFile + iRet) = (WCHAR)NULL;
  701. }
  702. else if (iCount == 2)
  703. {
  704. iRet = MultiByteToWideChar(CP_ACP,
  705. 0,
  706. *ppArgv,
  707. strlen(*ppArgv),
  708. pwstrGTTFile,
  709. FILENAME_SIZE);
  710. *(pwstrGTTFile + iRet) = (WCHAR)NULL;
  711. }
  712. else if (iCount == 3)
  713. {
  714. iRet = MultiByteToWideChar(CP_ACP,
  715. 0,
  716. *ppArgv,
  717. strlen(*ppArgv),
  718. pwstrUFMFile,
  719. FILENAME_SIZE);
  720. *(pwstrUFMFile + iRet) = (WCHAR)NULL;
  721. }
  722. if (iRet == 0)
  723. {
  724. return FALSE;
  725. }
  726. iCount ++;
  727. }
  728. iArgc --;
  729. ppArgv++;
  730. }
  731. return TRUE;
  732. }
  733. //
  734. // Verbose output functions
  735. //
  736. VOID
  737. VPrintIFIMETRICS(
  738. IFIMETRICS *pIFI,
  739. VPRINT vPrint
  740. )
  741. /*++
  742. Routine Description:
  743. Dumps the IFMETERICS to the screen
  744. Arguments:
  745. pIFI - pointer to IFIMETRICS
  746. vPrint - output function pointer
  747. Return Value:
  748. None
  749. --*/
  750. {
  751. //
  752. // Convenient pointer to Panose number
  753. //
  754. PANOSE *ppan = &pIFI->panose;
  755. PWSTR pwszFamilyName = (PWSTR)(((BYTE*) pIFI) + pIFI->dpwszFamilyName);
  756. PWSTR pwszStyleName = (PWSTR)(((BYTE*) pIFI) + pIFI->dpwszStyleName) ;
  757. PWSTR pwszFaceName = (PWSTR)(((BYTE*) pIFI) + pIFI->dpwszFaceName) ;
  758. PWSTR pwszUniqueName = (PWSTR)(((BYTE*) pIFI) + pIFI->dpwszUniqueName);
  759. vPrint("********* IFIMETRICS ***************\n");
  760. vPrint("cjThis %-#8lx\n" , pIFI->cjThis );
  761. vPrint("cjIfiExtra %-#8lx\n" , pIFI->cjIfiExtra);
  762. vPrint("pwszFamilyName \"%ws\"\n", pwszFamilyName );
  763. if( pIFI->flInfo & FM_INFO_FAMILY_EQUIV )
  764. {
  765. /* Aliasing is in effect! */
  766. while( *(pwszFamilyName += wcslen( pwszFamilyName ) + 1) )
  767. vPrint(" \"%ws\"\n", pwszFamilyName );
  768. }
  769. vPrint("pwszStyleName \"%ws\"\n", pwszStyleName );
  770. vPrint("pwszFaceName \"%ws\"\n", pwszFaceName );
  771. vPrint("pwszUniqueName \"%ws\"\n", pwszUniqueName );
  772. vPrint("dpFontSim %-#8lx\n" , pIFI->dpFontSim );
  773. vPrint("lEmbedId %d\n", pIFI->lEmbedId );
  774. vPrint("lItalicAngle %d\n", pIFI->lItalicAngle);
  775. vPrint("lCharBias %d\n", pIFI->lCharBias );
  776. vPrint("dpCharSets %d\n", pIFI->dpCharSets );
  777. vPrint("jWinCharSet %04x\n" , pIFI->jWinCharSet );
  778. vPrint("jWinPitchAndFamily %04x\n" , pIFI->jWinPitchAndFamily );
  779. vPrint("usWinWeight %d\n" , pIFI->usWinWeight );
  780. vPrint("flInfo %-#8lx\n" , pIFI->flInfo );
  781. vPrint("fsSelection %-#6lx\n" , pIFI->fsSelection );
  782. vPrint("fsType %-#6lx\n" , pIFI->fsType );
  783. vPrint("fwdUnitsPerEm %d\n" , pIFI->fwdUnitsPerEm );
  784. vPrint("fwdLowestPPEm %d\n" , pIFI->fwdLowestPPEm );
  785. vPrint("fwdWinAscender %d\n" , pIFI->fwdWinAscender );
  786. vPrint("fwdWinDescender %d\n" , pIFI->fwdWinDescender );
  787. vPrint("fwdMacAscender %d\n" , pIFI->fwdMacAscender );
  788. vPrint("fwdMacDescender %d\n" , pIFI->fwdMacDescender );
  789. vPrint("fwdMacLineGap %d\n" , pIFI->fwdMacLineGap );
  790. vPrint("fwdTypoAscender %d\n" , pIFI->fwdTypoAscender );
  791. vPrint("fwdTypoDescender %d\n" , pIFI->fwdTypoDescender );
  792. vPrint("fwdTypoLineGap %d\n" , pIFI->fwdTypoLineGap );
  793. vPrint("fwdAveCharWidth %d\n" , pIFI->fwdAveCharWidth );
  794. vPrint("fwdMaxCharInc %d\n" , pIFI->fwdMaxCharInc );
  795. vPrint("fwdCapHeight %d\n" , pIFI->fwdCapHeight );
  796. vPrint("fwdXHeight %d\n" , pIFI->fwdXHeight );
  797. vPrint("fwdSubscriptXSize %d\n" , pIFI->fwdSubscriptXSize );
  798. vPrint("fwdSubscriptYSize %d\n" , pIFI->fwdSubscriptYSize );
  799. vPrint("fwdSubscriptXOffset %d\n" , pIFI->fwdSubscriptXOffset );
  800. vPrint("fwdSubscriptYOffset %d\n" , pIFI->fwdSubscriptYOffset );
  801. vPrint("fwdSuperscriptXSize %d\n" , pIFI->fwdSuperscriptXSize );
  802. vPrint("fwdSuperscriptYSize %d\n" , pIFI->fwdSuperscriptYSize );
  803. vPrint("fwdSuperscriptXOffset %d\n" , pIFI->fwdSuperscriptXOffset);
  804. vPrint("fwdSuperscriptYOffset %d\n" , pIFI->fwdSuperscriptYOffset);
  805. vPrint("fwdUnderscoreSize %d\n" , pIFI->fwdUnderscoreSize );
  806. vPrint("fwdUnderscorePosition %d\n" , pIFI->fwdUnderscorePosition);
  807. vPrint("fwdStrikeoutSize %d\n" , pIFI->fwdStrikeoutSize );
  808. vPrint("fwdStrikeoutPosition %d\n" , pIFI->fwdStrikeoutPosition );
  809. vPrint("chFirstChar %-#4x\n" , (int) (BYTE) pIFI->chFirstChar );
  810. vPrint("chLastChar %-#4x\n" , (int) (BYTE) pIFI->chLastChar );
  811. vPrint("chDefaultChar %-#4x\n" , (int) (BYTE) pIFI->chDefaultChar );
  812. vPrint("chBreakChar %-#4x\n" , (int) (BYTE) pIFI->chBreakChar );
  813. vPrint("wcFirsChar %-#6x\n" , pIFI->wcFirstChar );
  814. vPrint("wcLastChar %-#6x\n" , pIFI->wcLastChar );
  815. vPrint("wcDefaultChar %-#6x\n" , pIFI->wcDefaultChar );
  816. vPrint("wcBreakChar %-#6x\n" , pIFI->wcBreakChar );
  817. vPrint("ptlBaseline {%d,%d}\n" , pIFI->ptlBaseline.x,
  818. pIFI->ptlBaseline.y );
  819. vPrint("ptlAspect {%d,%d}\n" , pIFI->ptlAspect.x,
  820. pIFI->ptlAspect.y );
  821. vPrint("ptlCaret {%d,%d}\n" , pIFI->ptlCaret.x,
  822. pIFI->ptlCaret.y );
  823. vPrint("rclFontBox {%d,%d,%d,%d}\n",pIFI->rclFontBox.left,
  824. pIFI->rclFontBox.top,
  825. pIFI->rclFontBox.right,
  826. pIFI->rclFontBox.bottom );
  827. vPrint("achVendId \"%c%c%c%c\"\n",pIFI->achVendId[0],
  828. pIFI->achVendId[1],
  829. pIFI->achVendId[2],
  830. pIFI->achVendId[3] );
  831. vPrint("cKerningPairs %d\n" , pIFI->cKerningPairs );
  832. vPrint("ulPanoseCulture %-#8lx\n" , pIFI->ulPanoseCulture);
  833. vPrint(
  834. "panose {%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x}\n"
  835. , ppan->bFamilyType
  836. , ppan->bSerifStyle
  837. , ppan->bWeight
  838. , ppan->bProportion
  839. , ppan->bContrast
  840. , ppan->bStrokeVariation
  841. , ppan->bArmStyle
  842. , ppan->bLetterform
  843. , ppan->bMidline
  844. , ppan->bXHeight );
  845. BCheckIFIMETRICS(pIFI, vPrint);
  846. }
  847. VOID
  848. VPrintPFM(
  849. PFMHEADER *pPFMHdr,
  850. VPRINT vPrint)
  851. /*++
  852. Routine Description:
  853. Dumps the PFM to the screen
  854. Arguments:
  855. pFInData - pointer to FONTIN
  856. vPrint - output function pointer
  857. Return Value:
  858. None
  859. --*/
  860. {
  861. vPrint("*************************************************************\n");
  862. vPrint(" PFM HEADER\n");
  863. vPrint("*************************************************************\n");
  864. vPrint("PFM.dfType = %d\n", pPFMHdr->dfType);
  865. vPrint("PFM.dfPoints = %d\n", pPFMHdr->dfPoints);
  866. vPrint("PFM.dfVertRes = %d\n", pPFMHdr->dfVertRes);
  867. vPrint("PFM.dfHorizRes = %d\n", pPFMHdr->dfHorizRes);
  868. vPrint("PFM.dfAscent = %d\n", pPFMHdr->dfAscent);
  869. vPrint("PFM.dfInternalLeading = %d\n", pPFMHdr->dfInternalLeading);
  870. vPrint("PFM.dfExternalLeading = %d\n", pPFMHdr->dfExternalLeading);
  871. vPrint("PFM.dfItalic = %d\n", pPFMHdr->dfItalic);
  872. vPrint("PFM.dfUnderline = %d\n", pPFMHdr->dfUnderline);
  873. vPrint("PFM.dfStrikeOut = %d\n", pPFMHdr->dfStrikeOut);
  874. vPrint("PFM.dfWeight = %d\n", pPFMHdr->dfWeight);
  875. vPrint("PFM.dfCharSet = %d\n", pPFMHdr->dfCharSet);
  876. vPrint("PFM.dfPixWidth = %d\n", pPFMHdr->dfPixWidth);
  877. vPrint("PFM.dfPixHeight = %d\n", pPFMHdr->dfPixHeight);
  878. vPrint("PFM.dfPitchAndFamily = %d\n", pPFMHdr->dfPitchAndFamily);
  879. vPrint("PFM.dfAvgWidth = %d\n", pPFMHdr->dfAvgWidth);
  880. vPrint("PFM.dfMaxWidth = %d\n", pPFMHdr->dfMaxWidth);
  881. vPrint("PFM.dfFirstChar = %d\n", pPFMHdr->dfFirstChar);
  882. vPrint("PFM.dfLastChar = %d\n", pPFMHdr->dfLastChar);
  883. vPrint("PFM.dfDefaultChar = %d\n", pPFMHdr->dfDefaultChar);
  884. vPrint("PFM.dfBreakChar = %d\n", pPFMHdr->dfBreakChar);
  885. vPrint("PFM.dfWidthBytes = %d\n", pPFMHdr->dfWidthBytes);
  886. vPrint("PFM.dfDevice = %d\n", pPFMHdr->dfDevice);
  887. vPrint("PFM.dfFace = %d\n", pPFMHdr->dfFace);
  888. vPrint("PFM.dfBitsPointer = %d\n", pPFMHdr->dfBitsPointer);
  889. }
  890. VOID
  891. VPrintPFMExt(
  892. PFMEXTENSION *pPFMExt,
  893. VPRINT vPrint)
  894. {
  895. vPrint("*************************************************************\n");
  896. vPrint(" PFM EXTENSION\n");
  897. vPrint("*************************************************************\n");
  898. vPrint("PFMExt.dfSizeFields = %d\n", pPFMExt->dfSizeFields);
  899. vPrint("PFMExt.dfExtMetricsOffset = %d\n", pPFMExt->dfExtMetricsOffset);
  900. vPrint("PFMExt.dfExtentTable = %d\n", pPFMExt->dfExtentTable);
  901. vPrint("PFMExt.dfOriginTable = %d\n", pPFMExt->dfOriginTable);
  902. vPrint("PFMExt.dfPairKernTable = %d\n", pPFMExt->dfPairKernTable);
  903. vPrint("PFMExt.dfTrackKernTable = %d\n", pPFMExt->dfTrackKernTable);
  904. vPrint("PFMExt.dfDriverInfo = %d\n", pPFMExt->dfDriverInfo);
  905. vPrint("PFMExt.dfReserved = %d\n", pPFMExt->dfReserved);
  906. }
  907. VOID
  908. VPrintETM(
  909. EXTTEXTMETRIC *pETM,
  910. VPRINT vPrint)
  911. {
  912. vPrint("*************************************************************\n");
  913. vPrint(" EXTTEXTMETRIC\n");
  914. vPrint("*************************************************************\n");
  915. vPrint("pETM->emSize = %d\n", pETM->emSize);
  916. vPrint("pETM->emPointSize = %d\n", pETM->emPointSize);
  917. vPrint("pETM->emOrientation = %d\n", pETM->emOrientation);
  918. vPrint("pETM->emMasterHeight = %d\n", pETM->emMasterHeight);
  919. vPrint("pETM->emMinScale = %d\n", pETM->emMinScale);
  920. vPrint("pETM->emMaxScale = %d\n", pETM->emMaxScale);
  921. vPrint("pETM->emMasterUnits = %d\n", pETM->emMasterUnits);
  922. vPrint("pETM->emCapHeight = %d\n", pETM->emCapHeight);
  923. vPrint("pETM->emXHeight = %d\n", pETM->emXHeight);
  924. vPrint("pETM->emLowerCaseAscent = %d\n", pETM->emLowerCaseAscent);
  925. vPrint("pETM->emLowerCaseDescent = %d\n", pETM->emLowerCaseDescent);
  926. vPrint("pETM->emSlant = %d\n", pETM->emSlant);
  927. vPrint("pETM->emSuperScript = %d\n", pETM->emSuperScript);
  928. vPrint("pETM->emSubScript = %d\n", pETM->emSubScript);
  929. vPrint("pETM->emSuperScriptSize = %d\n", pETM->emSuperScriptSize);
  930. vPrint("pETM->emSubScriptSize = %d\n", pETM->emSubScriptSize);
  931. vPrint("pETM->emUnderlineOffset = %d\n", pETM->emUnderlineOffset);
  932. vPrint("pETM->emUnderlineWidth = %d\n", pETM->emUnderlineWidth);
  933. vPrint("pETM->emDoubleUpperUnderlineOffset = %d\n", pETM->emDoubleUpperUnderlineOffset);
  934. vPrint("pETM->emDoubleLowerUnderlineOffset = %d\n", pETM->emDoubleLowerUnderlineOffset);
  935. vPrint("pETM->emDoubleUpperUnderlineWidth = %d\n", pETM->emDoubleUpperUnderlineWidth);
  936. vPrint("pETM->emDoubleLowerUnderlineWidth = %d\n", pETM->emDoubleLowerUnderlineWidth);
  937. vPrint("pETM->emStrikeOutOffset = %d\n", pETM->emStrikeOutOffset);
  938. vPrint("pETM->emStrikeOutWidth = %d\n", pETM->emStrikeOutWidth);
  939. vPrint("pETM->emKernPairs = %d\n", pETM->emKernPairs);
  940. vPrint("pETM->emKernTracks = %d\n", pETM->emKernTracks);
  941. }
  942. VOID
  943. VPrintFontCmd(
  944. CD *pCD,
  945. BOOL bSelect,
  946. VPRINT vPrint)
  947. {
  948. INT iI;
  949. PBYTE pCommand;
  950. if (!pCD)
  951. return;
  952. pCommand = (PBYTE)(pCD + 1);
  953. if (!pCD->wLength)
  954. {
  955. return;
  956. }
  957. if (bSelect)
  958. {
  959. vPrint("*************************************************************\n");
  960. vPrint(" COMMAND\n");
  961. vPrint("*************************************************************\n");
  962. vPrint("Font Select Command = ");
  963. }
  964. else
  965. {
  966. vPrint("Font UnSelect Command = ");
  967. }
  968. for (iI = 0; iI < pCD->wLength; iI ++, pCommand++)
  969. {
  970. if (*pCommand < 0x20 || 0x7e < *pCommand )
  971. {
  972. vPrint("\\x%X",*pCommand);
  973. }
  974. else
  975. {
  976. vPrint("%c",*pCommand);
  977. }
  978. }
  979. vPrint("\n");
  980. }
  981. VOID
  982. VPrintKerningPair(
  983. w3KERNPAIR *pKernPair,
  984. DWORD dwKernPairSize,
  985. VPRINT vPrint)
  986. {
  987. }
  988. VOID
  989. VPrintWidthTable(
  990. PSHORT psWidthTable,
  991. DWORD dwWidthTableSize,
  992. VPRINT vPrint)
  993. {
  994. }
  995. #endif // defined(DEVSTUDIO)
  996. DWORD
  997. DwGetCodePageFromGTTID(
  998. LONG lPredefinedGTTID)
  999. {
  1000. DWORD dwRet;
  1001. switch(lPredefinedGTTID)
  1002. {
  1003. case CC_CP437:
  1004. dwRet = 437;
  1005. break;
  1006. case CC_CP850:
  1007. dwRet = 850;
  1008. break;
  1009. case CC_CP863:
  1010. dwRet = 863;
  1011. break;
  1012. case CC_BIG5:
  1013. dwRet = 950;
  1014. break;
  1015. case CC_ISC:
  1016. dwRet = 949;
  1017. break;
  1018. case CC_JIS:
  1019. dwRet = 932;
  1020. break;
  1021. case CC_JIS_ANK:
  1022. dwRet = 932;
  1023. break;
  1024. case CC_NS86:
  1025. dwRet = 949;
  1026. break;
  1027. case CC_TCA:
  1028. dwRet = 950;
  1029. break;
  1030. case CC_GB2312:
  1031. dwRet = 936;
  1032. break;
  1033. case CC_SJIS:
  1034. dwRet = 932;
  1035. break;
  1036. case CC_WANSUNG:
  1037. dwRet = 949;
  1038. break;
  1039. default:
  1040. dwRet =1252;
  1041. break;
  1042. }
  1043. return dwRet;
  1044. }
  1045. DWORD
  1046. DwGetCodePageFromCTTID(
  1047. LONG lPredefinedCTTID)
  1048. {
  1049. DWORD dwRet;
  1050. switch (lPredefinedCTTID)
  1051. {
  1052. case CTT_CP437:
  1053. dwRet = 437;
  1054. break;
  1055. case CTT_CP850:
  1056. dwRet = 850;
  1057. break;
  1058. case CTT_CP863:
  1059. dwRet = 863;
  1060. break;
  1061. case CTT_BIG5:
  1062. dwRet = 950;
  1063. break;
  1064. case CTT_ISC:
  1065. dwRet = 949;
  1066. break;
  1067. case CTT_JIS78:
  1068. dwRet = 932;
  1069. break;
  1070. case CTT_JIS83:
  1071. dwRet = 932;
  1072. break;
  1073. case CTT_JIS78_ANK:
  1074. dwRet = 932;
  1075. break;
  1076. case CTT_JIS83_ANK:
  1077. dwRet = 932;
  1078. break;
  1079. case CTT_NS86:
  1080. dwRet = 950;
  1081. break;
  1082. case CTT_TCA:
  1083. dwRet = 950;
  1084. break;
  1085. default:
  1086. dwRet = 1252;
  1087. break;
  1088. }
  1089. return dwRet;
  1090. }
  1091. INT ICodePage2GTTID(
  1092. DWORD dwCodePage)
  1093. {
  1094. INT iRet;
  1095. switch (dwCodePage)
  1096. {
  1097. case 1252:
  1098. iRet = 0;
  1099. break;
  1100. case 950:
  1101. iRet = CC_BIG5;
  1102. break;
  1103. case 949:
  1104. iRet = CC_WANSUNG;
  1105. break;
  1106. case 932:
  1107. iRet = CC_JIS_ANK;
  1108. break;
  1109. default:
  1110. iRet = 0;
  1111. break;
  1112. }
  1113. return iRet;
  1114. }
  1115. INT ICttID2GttID(
  1116. LONG lPredefinedCTTID)
  1117. {
  1118. INT iRet = lPredefinedCTTID;
  1119. switch (lPredefinedCTTID)
  1120. {
  1121. case CTT_CP437:
  1122. iRet = CC_CP437;
  1123. break;
  1124. case CTT_CP850:
  1125. iRet = CC_CP850;
  1126. break;
  1127. case CTT_CP863:
  1128. iRet = CC_CP863;
  1129. break;
  1130. case CTT_BIG5:
  1131. iRet = CC_BIG5;
  1132. break;
  1133. case CTT_ISC:
  1134. iRet = CC_ISC;
  1135. break;
  1136. case CTT_JIS78:
  1137. iRet = CC_JIS;
  1138. break;
  1139. case CTT_JIS83:
  1140. iRet = CC_JIS;
  1141. break;
  1142. case CTT_JIS78_ANK:
  1143. iRet = CC_JIS_ANK;
  1144. break;
  1145. case CTT_JIS83_ANK:
  1146. iRet = CC_JIS_ANK;
  1147. break;
  1148. case CTT_NS86:
  1149. iRet = CC_NS86;
  1150. break;
  1151. case CTT_TCA:
  1152. iRet = CC_TCA;
  1153. break;
  1154. }
  1155. return iRet;
  1156. }