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.

885 lines
26 KiB

  1. /*++
  2. Copyright (c) 1996-1997 Microsoft Corporation
  3. Module Name:
  4. cttconv.c
  5. Abstract:
  6. Convert Win 3.1 CTT format tables to NT's GTT spec.
  7. Environment:
  8. Windows NT PostScript driver
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. //
  13. // Debug flags
  14. //
  15. #define SET_PRINT 0
  16. #define SET_RIP 0
  17. //
  18. // Some macro definitions.
  19. //
  20. #define BBITS 8 /* Bits in a byte */
  21. #define DWBITS (BBITS * sizeof( DWORD )) /* Bits in a DWORD */
  22. #define DW_MASK (DWBITS - 1)
  23. //
  24. // Local
  25. //
  26. BYTE ubGetAnsi(WCHAR, INT, PWCHAR, PBYTE);
  27. //
  28. // Conversion function
  29. //
  30. BOOL
  31. BConvertCTT2GTT(
  32. IN HANDLE hHeap,
  33. IN PTRANSTAB pCTTData,
  34. IN DWORD dwCodePage,
  35. IN WCHAR wchFirst,
  36. IN WCHAR wchLast,
  37. IN PBYTE pCPSel,
  38. IN PBYTE pCPUnSel,
  39. IN OUT PUNI_GLYPHSETDATA *ppGlyphSetData,
  40. IN DWORD dwGlySize)
  41. /*++
  42. Routine Description:
  43. Conversion from CTT to GLYPHSETDATA
  44. Arguments:
  45. hHeap - Heap handle
  46. pCTTData - Pointer to the 3.1 format translate table
  47. dwCodePage - additonal codepage
  48. pCPSel - symbol set selection command null terminate string.
  49. pCPUnsel - symbol set selection command null terminate string.
  50. ppGlyphSetData - Pointer to the GlyphSetData pointer
  51. Return Value:
  52. If TRUE, function succeeded. Othewise FALSE.
  53. Note:
  54. Allocates memory from the heap for this.
  55. --*/
  56. {
  57. UNI_CODEPAGEINFO CodePageInfo;
  58. UNI_GLYPHSETDATA GlyphSetData;
  59. PGLYPHRUN pOldGlyphRun, pOldGlyphFirst,
  60. pNewGlyphRun, pNewGlyphFirst;
  61. PMAPTABLE pOldMapTable, pNewMapTable;
  62. PUNI_CODEPAGEINFO pOldCodePageInfo;
  63. TRANSDATA *pTrans;
  64. WCHAR awchUnicode[ 256 ]; // Converted array of points
  65. WCHAR wchMin; /* Find the first unicode value */
  66. WCHAR wchMax; /* Find the last unicode value */
  67. WCHAR wchChar;
  68. DWORD *pdwBits; /* For figuring out runs */
  69. DWORD dwFlags;
  70. DWORD dwOldCodePageCount;
  71. DWORD dwOldCPCmdSize;
  72. DWORD dwI;
  73. DWORD dwcbBits; /* Size of this area */
  74. DWORD dwMapTableCommandOffset;
  75. WORD wType;
  76. WORD wcbData;
  77. WORD wI;
  78. INT iI, iJ; // Loop index
  79. INT iIndex;
  80. INT iNumOfHandle; // The number of handles we need
  81. INT iNumOfHandleInCTT; // The number of handles in CTT
  82. INT iTotalOffsetCmd;
  83. INT iTotalGlyphSetDataSize;
  84. INT iTotalCommandSize;
  85. INT iAdditionalGlyphRun;
  86. INT iAdditionalMapTable;
  87. INT iSizeOfSelUnsel;
  88. INT iNumOfRuns; /* Number of runs we create */
  89. BYTE aubAnsi[ 256 ];
  90. BYTE *pbBase;
  91. BYTE ubCodePageID;
  92. BYTE *pMapTableCommand;
  93. BYTE *pubData;
  94. BYTE ubAnsi;
  95. BOOL bInRun; /* For processing run accumulations */
  96. #define DWFLAGS_NEWCREATION 0x00000001
  97. //
  98. // Assertion
  99. //
  100. ASSERT(hHeap != NULL && pCTTData != NULL);
  101. //
  102. // Check if this is additional CTT.
  103. //
  104. #if 0
  105. if (*ppGlyphSetData == 0 || dwGlySize == 0)
  106. {
  107. dwFlags = DWFLAGS_NEWCREATION;
  108. }
  109. else
  110. {
  111. dwFlags = 0;
  112. }
  113. #else
  114. dwFlags = DWFLAGS_NEWCREATION;
  115. #endif
  116. //
  117. // 1. Create UNI_GLYPHSETDATA header
  118. // 2. Count total size of command in CTT.
  119. // 3. Create Unicode table
  120. // 4. Get min and max Unicode value
  121. // 5. Create Unicode bits table from CTT.
  122. // 6. Count the number of run.
  123. // 7. Create GLYPHRUN.
  124. // 8. Create UNI_CODEPAGEINFO.
  125. // 9. Calculate total size of this file.
  126. // 10. Allocate memory for header, GLYPYRUN, CODEPAGEINFO
  127. // 11. Create MAPTABLE
  128. //
  129. //
  130. //
  131. // 1. Initialize basic members of GLYPHSETDATA if necessary
  132. //
  133. //
  134. #if SET_RIP
  135. RIP(("1. Initialize basic members of GLYPHSETDATA if necessary.\n"));
  136. #elif SET_PRINT
  137. printf("1. Initialize basic members of GLYPHSETDATA if necessary.\n");
  138. #endif
  139. if (dwFlags & DWFLAGS_NEWCREATION)
  140. {
  141. GlyphSetData.dwVersion = UNI_GLYPHSETDATA_VERSION_1_0;
  142. GlyphSetData.dwFlags = 0;
  143. GlyphSetData.lPredefinedID = CC_NOPRECNV;
  144. GlyphSetData.dwGlyphCount = 0;
  145. GlyphSetData.dwRunCount = 0;
  146. GlyphSetData.dwCodePageCount = 1;
  147. GlyphSetData.loCodePageOffset = (DWORD)0;
  148. GlyphSetData.loMapTableOffset = (DWORD)0;
  149. }
  150. else
  151. {
  152. GlyphSetData.dwVersion = (*ppGlyphSetData)->dwVersion;
  153. GlyphSetData.dwFlags = (*ppGlyphSetData)->dwFlags;
  154. GlyphSetData.lPredefinedID = (*ppGlyphSetData)->lPredefinedID;
  155. GlyphSetData.dwGlyphCount = (*ppGlyphSetData)->dwGlyphCount;
  156. GlyphSetData.dwRunCount = (*ppGlyphSetData)->dwRunCount;
  157. GlyphSetData.dwCodePageCount = (*ppGlyphSetData)->dwCodePageCount +
  158. 1;
  159. GlyphSetData.loCodePageOffset = (DWORD)0;
  160. GlyphSetData.loMapTableOffset = (DWORD)0;
  161. dwOldCodePageCount = (*ppGlyphSetData)->dwCodePageCount;
  162. pOldGlyphFirst =
  163. pOldGlyphRun = (PGLYPHRUN)((PBYTE)*ppGlyphSetData+
  164. (*ppGlyphSetData)->loRunOffset);
  165. pOldCodePageInfo = (PUNI_CODEPAGEINFO)((PBYTE)*ppGlyphSetData+
  166. (*ppGlyphSetData)->loCodePageOffset);
  167. pOldMapTable = (PMAPTABLE)((PBYTE)*ppGlyphSetData +
  168. (*ppGlyphSetData)->loMapTableOffset);
  169. }
  170. //
  171. // 2. Total size of WTYPE_OFFSET format command in CTT.
  172. //
  173. #if SET_RIP
  174. RIP(("2. Count total number of run in CTT.\n"));
  175. #elif SET_PRINT
  176. printf("2. Count total number of run in CTT.\n");
  177. #endif
  178. wchFirst = min(pCTTData->chFirstChar, wchFirst);
  179. wchLast = max(pCTTData->chLastChar, wchLast);
  180. GlyphSetData.dwGlyphCount =
  181. iNumOfHandle = wchLast - wchFirst + 1;
  182. iNumOfHandleInCTT = pCTTData->chLastChar - pCTTData->chFirstChar + 1;
  183. switch (pCTTData->wType)
  184. {
  185. case CTT_WTYPE_COMPOSE:
  186. iTotalOffsetCmd = pCTTData->uCode.psCode[iNumOfHandleInCTT] -
  187. pCTTData->uCode.psCode[0] +
  188. iNumOfHandleInCTT * 2;
  189. break;
  190. case CTT_WTYPE_DIRECT:
  191. iTotalOffsetCmd = 0;
  192. break;
  193. case CTT_WTYPE_PAIRED:
  194. iTotalOffsetCmd = 0;
  195. break;
  196. }
  197. //
  198. // 3. Create Unicode table
  199. // We need to figure out how many runs are required to describe
  200. // this font. First obtain the correct Unicode encoding of these
  201. // values, then examine them to find the number of runs, and
  202. // hence much extra storage is required.
  203. //
  204. #if SET_RIP
  205. RIP(("3. Create Unicode table.\n"));
  206. #elif SET_PRINT
  207. printf("3. Create Unicode table.\n");
  208. #endif
  209. //
  210. // We know it is < 256
  211. //
  212. for( iI = 0; iI < iNumOfHandle; ++iI )
  213. aubAnsi[ iI ] = (BYTE)(iI + wchFirst);
  214. #ifdef NTGDIKM
  215. if( -1 == EngMultiByteToWideChar(dwCodePage,
  216. awchUnicode,
  217. (ULONG)(iNumOfHandle * sizeof(WCHAR)),
  218. (PCH) aubAnsi,
  219. (ULONG) iNumOfHandle))
  220. {
  221. return FALSE;
  222. }
  223. #else
  224. if( ! MultiByteToWideChar(dwCodePage,
  225. 0,
  226. aubAnsi,
  227. iNumOfHandle,
  228. awchUnicode,
  229. iNumOfHandle))
  230. {
  231. return FALSE;
  232. }
  233. #endif
  234. //
  235. // 4. Get min and max Unicode value
  236. // Find the largest Unicode value, then allocate storage to allow us
  237. // to create a bit array of valid unicode points. Then we can
  238. // examine this to determine the number of runs.
  239. //
  240. #if SET_RIP
  241. RIP(("4. Get min and max Unicode value.\n"));
  242. #elif SET_PRINT
  243. printf("4. Get min and max Unicode value.\n");
  244. #endif
  245. for( wchMax = 0, wchMin = 0xffff, iI = 0; iI < iNumOfHandle; ++iI )
  246. {
  247. if( awchUnicode[ iI ] > wchMax )
  248. wchMax = awchUnicode[ iI ];
  249. if( awchUnicode[ iI ] < wchMin )
  250. wchMin = awchUnicode[ iI ];
  251. }
  252. //
  253. // 5. Create Unicode bits table from CTT.
  254. // Note that the expression 1 + wchMax IS correct. This comes about
  255. // from using these values as indices into the bit array, and that
  256. // this is essentially 1 based.
  257. //
  258. #if SET_RIP
  259. RIP(("5. Create Unicode bits table from CTT.\n"));
  260. #elif SET_PRINT
  261. printf("5. Create Unicode bits table from CTT.\n");
  262. #endif
  263. dwcbBits = (1 + wchMax + DWBITS - 1) / DWBITS * sizeof( DWORD );
  264. if( !(pdwBits = (DWORD *)HeapAlloc( hHeap, 0, dwcbBits )) )
  265. {
  266. return FALSE; /* Nothing going */
  267. }
  268. ZeroMemory( pdwBits, dwcbBits );
  269. //
  270. // Set bits in this array corresponding to Unicode code points
  271. //
  272. for( iI = 0; iI < iNumOfHandle; ++iI )
  273. {
  274. pdwBits[ awchUnicode[ iI ] / DWBITS ]
  275. |= (1 << (awchUnicode[ iI ] & DW_MASK));
  276. }
  277. //
  278. //
  279. // 6. Count the number of run.
  280. //
  281. //
  282. #if SET_RIP
  283. RIP(("6. Count the number of run.\n"));
  284. #elif SET_PRINT
  285. printf("6. Count the number of run.\n");
  286. #endif
  287. if (dwFlags & DWFLAGS_NEWCREATION)
  288. {
  289. //
  290. // Now we can examine the number of runs required. For starters,
  291. // we stop a run whenever a hole is discovered in the array of 1
  292. // bits we just created. Later we MIGHT consider being a little
  293. // less pedantic.
  294. //
  295. bInRun = FALSE;
  296. iNumOfRuns = 0;
  297. for( iI = 0; iI <= (INT)wchMax; ++iI )
  298. {
  299. if( pdwBits[ iI / DWBITS ] & (1 << (iI & DW_MASK)) )
  300. {
  301. /* Not in a run: is this the end of one? */
  302. if( !bInRun )
  303. {
  304. /* It's time to start one */
  305. bInRun = TRUE;
  306. ++iNumOfRuns;
  307. }
  308. }
  309. else
  310. {
  311. if( bInRun )
  312. {
  313. /* Not any more! */
  314. bInRun = FALSE;
  315. }
  316. }
  317. }
  318. GlyphSetData.dwRunCount = iNumOfRuns;
  319. }
  320. else
  321. {
  322. //
  323. // CTT addition case
  324. //
  325. iNumOfRuns = (*ppGlyphSetData)->dwRunCount;
  326. //
  327. // Merge CTT and GlyphRun
  328. //
  329. for (iI = 0; iI < iNumOfRuns; iI ++)
  330. {
  331. for (iJ = 0; iJ < pOldGlyphRun->wGlyphCount; iJ ++)
  332. {
  333. INT iGlyph = iJ + pOldGlyphRun->wcLow;
  334. pdwBits[ iGlyph / DWBITS ] |= (1 << (iGlyph & DW_MASK));
  335. }
  336. pOldGlyphRun++;
  337. }
  338. bInRun = FALSE;
  339. iNumOfRuns = 0;
  340. iNumOfHandle = 0;
  341. for( iI = 0; iI <= (INT)wchMax; ++iI )
  342. {
  343. if( pdwBits[ iI / DWBITS ] & (1 << (iI & DW_MASK)) )
  344. {
  345. /* Not in a run: is this the end of one? */
  346. if( !bInRun )
  347. {
  348. /* It's time to start one */
  349. bInRun = TRUE;
  350. ++iNumOfRuns;
  351. }
  352. iNumOfHandle ++;
  353. }
  354. else
  355. {
  356. if( bInRun )
  357. {
  358. /* Not any more! */
  359. bInRun = FALSE;
  360. }
  361. }
  362. }
  363. }
  364. //
  365. // 7. Create GLYPHRUN
  366. //
  367. #if SET_RIP
  368. RIP(("7. Create GLYPHRUN.\n"));
  369. #elif SET_PRINT
  370. printf("7. Create GLYPHRUN.\n");
  371. #endif
  372. if( !(pNewGlyphFirst = pNewGlyphRun =
  373. (PGLYPHRUN)HeapAlloc( hHeap, 0, iNumOfRuns * sizeof(GLYPHRUN) )) )
  374. {
  375. return FALSE; /* Nothing going */
  376. }
  377. bInRun = FALSE;
  378. for (wI = 0; wI <= wchMax; wI ++)
  379. {
  380. if (pdwBits[ wI / DWBITS ] & (1 << (wI & DW_MASK)) )
  381. {
  382. if (!bInRun)
  383. {
  384. bInRun = TRUE;
  385. pNewGlyphRun->wcLow = wI ;
  386. pNewGlyphRun->wGlyphCount = 1;
  387. }
  388. else
  389. {
  390. pNewGlyphRun->wGlyphCount++;
  391. }
  392. }
  393. else
  394. {
  395. if (bInRun)
  396. {
  397. bInRun = FALSE;
  398. pNewGlyphRun++;
  399. }
  400. }
  401. }
  402. pNewGlyphRun = pNewGlyphFirst;
  403. //
  404. //
  405. // 8. Create UNI_CODEPAGEINFO.
  406. //
  407. //
  408. #if SET_RIP
  409. RIP(("8. Create UNI_CODEPAGEINFO.\n"));
  410. #elif SET_PRINT
  411. printf("8. Create UNI_CODEPAGEINFO.\n");
  412. #endif
  413. CodePageInfo.dwCodePage = dwCodePage;
  414. if (pCPSel)
  415. {
  416. CodePageInfo.SelectSymbolSet.dwCount = strlen(pCPSel) + 1;
  417. }
  418. else
  419. {
  420. CodePageInfo.SelectSymbolSet.dwCount = 0;
  421. }
  422. if (pCPUnSel)
  423. {
  424. CodePageInfo.UnSelectSymbolSet.dwCount = strlen(pCPUnSel) + 1;
  425. }
  426. else
  427. {
  428. CodePageInfo.UnSelectSymbolSet.dwCount = 0;
  429. }
  430. if (dwFlags & DWFLAGS_NEWCREATION)
  431. {
  432. if (pCPSel)
  433. {
  434. CodePageInfo.SelectSymbolSet.loOffset = sizeof(UNI_CODEPAGEINFO);
  435. }
  436. else
  437. {
  438. CodePageInfo.SelectSymbolSet.loOffset = 0;
  439. }
  440. if (pCPUnSel)
  441. {
  442. CodePageInfo.UnSelectSymbolSet.loOffset = sizeof(UNI_CODEPAGEINFO) +
  443. CodePageInfo.SelectSymbolSet.dwCount;
  444. }
  445. else
  446. {
  447. CodePageInfo.UnSelectSymbolSet.loOffset = 0;
  448. }
  449. }
  450. else
  451. {
  452. dwOldCPCmdSize = 0;
  453. for (dwI = 0; dwI < dwOldCodePageCount; dwI++)
  454. {
  455. dwOldCPCmdSize += (pOldCodePageInfo+dwI)->SelectSymbolSet.dwCount +
  456. (pOldCodePageInfo+dwI)->UnSelectSymbolSet.dwCount;
  457. (pOldCodePageInfo+dwI)->SelectSymbolSet.loOffset +=
  458. sizeof(UNI_CODEPAGEINFO);
  459. (pOldCodePageInfo+dwI)->UnSelectSymbolSet.loOffset +=
  460. sizeof(UNI_CODEPAGEINFO);
  461. }
  462. CodePageInfo.SelectSymbolSet.loOffset =
  463. sizeof(UNI_CODEPAGEINFO) +
  464. dwOldCPCmdSize;
  465. CodePageInfo.UnSelectSymbolSet.loOffset =
  466. sizeof(UNI_CODEPAGEINFO) +
  467. dwOldCPCmdSize +
  468. CodePageInfo.SelectSymbolSet.dwCount;
  469. }
  470. //
  471. //
  472. // 9. Calculate total size of this file.
  473. //
  474. //
  475. #if SET_RIP
  476. RIP(("9. Calculate total size of this file.\n"));
  477. #elif SET_PRINT
  478. printf("9. Calculate total size of this file.\n");
  479. #endif
  480. iSizeOfSelUnsel = CodePageInfo.SelectSymbolSet.dwCount +
  481. CodePageInfo.UnSelectSymbolSet.dwCount;
  482. if (dwFlags & DWFLAGS_NEWCREATION)
  483. {
  484. iTotalGlyphSetDataSize = sizeof(UNI_GLYPHSETDATA) +
  485. sizeof(UNI_CODEPAGEINFO) +
  486. iSizeOfSelUnsel +
  487. iNumOfRuns * sizeof( GLYPHRUN ) +
  488. sizeof(MAPTABLE) +
  489. (iNumOfHandle - 1) * sizeof(TRANSDATA) +
  490. iTotalOffsetCmd;
  491. }
  492. else
  493. {
  494. iTotalGlyphSetDataSize = sizeof(UNI_GLYPHSETDATA) +
  495. dwOldCodePageCount * sizeof(UNI_CODEPAGEINFO) +
  496. sizeof(UNI_CODEPAGEINFO) +
  497. dwOldCPCmdSize +
  498. iSizeOfSelUnsel +
  499. iNumOfRuns * sizeof( GLYPHRUN ) +
  500. sizeof(MAPTABLE) +
  501. (iNumOfHandle - 1) * sizeof(TRANSDATA);
  502. }
  503. //
  504. //
  505. // 10. Allocate memory and set header, copy GLYPHRUN, CODEPAGEINFO
  506. //
  507. //
  508. #if SET_RIP
  509. RIP(("10. Allocate memory and set header, copy GLYPHRUN, CODEPAGEINFO.\n"));
  510. #elif SET_PRINT
  511. printf("10. Allocate memory and set header, copy GLYPHRUN, CODEPAGEINFO.\n");
  512. #endif
  513. if( !(pbBase = HeapAlloc( hHeap, 0, iTotalGlyphSetDataSize )) )
  514. {
  515. HeapFree( hHeap, 0, (LPSTR)pbBase );
  516. return FALSE;
  517. }
  518. ZeroMemory( pbBase, iTotalGlyphSetDataSize ); //Safer if we miss something
  519. if (dwFlags & DWFLAGS_NEWCREATION)
  520. {
  521. GlyphSetData.dwSize = iTotalGlyphSetDataSize;
  522. GlyphSetData.loRunOffset = sizeof(UNI_GLYPHSETDATA);
  523. GlyphSetData.loCodePageOffset = sizeof(UNI_GLYPHSETDATA) +
  524. sizeof(GLYPHRUN) * iNumOfRuns;
  525. GlyphSetData.loMapTableOffset = sizeof(UNI_GLYPHSETDATA) +
  526. sizeof(GLYPHRUN) * iNumOfRuns +
  527. sizeof(UNI_CODEPAGEINFO) +
  528. CodePageInfo.SelectSymbolSet.dwCount +
  529. CodePageInfo.UnSelectSymbolSet.dwCount;
  530. CopyMemory(pbBase,
  531. &GlyphSetData,
  532. sizeof(UNI_GLYPHSETDATA));
  533. CopyMemory(pbBase+sizeof(UNI_GLYPHSETDATA),
  534. pNewGlyphRun,
  535. sizeof(GLYPHRUN) * iNumOfRuns);
  536. CopyMemory(pbBase +
  537. GlyphSetData.loCodePageOffset,
  538. &CodePageInfo,
  539. sizeof(UNI_CODEPAGEINFO));
  540. if (pCPSel)
  541. {
  542. CopyMemory(pbBase +
  543. GlyphSetData.loCodePageOffset +
  544. sizeof(UNI_CODEPAGEINFO),
  545. pCPSel,
  546. CodePageInfo.SelectSymbolSet.dwCount);
  547. }
  548. if (pCPUnSel)
  549. {
  550. CopyMemory(pbBase +
  551. GlyphSetData.loCodePageOffset +
  552. sizeof(UNI_CODEPAGEINFO) +
  553. CodePageInfo.SelectSymbolSet.dwCount,
  554. pCPUnSel,
  555. CodePageInfo.UnSelectSymbolSet.dwCount);
  556. }
  557. pNewMapTable = (PMAPTABLE)(pbBase + GlyphSetData.loMapTableOffset);
  558. }
  559. else
  560. {
  561. GlyphSetData.dwSize = iTotalGlyphSetDataSize;
  562. GlyphSetData.loRunOffset = sizeof(UNI_GLYPHSETDATA);
  563. GlyphSetData.loCodePageOffset = sizeof(UNI_GLYPHSETDATA) +
  564. sizeof(GLYPHRUN) * iNumOfRuns;
  565. GlyphSetData.loMapTableOffset = sizeof(UNI_GLYPHSETDATA) +
  566. sizeof(GLYPHRUN) * iNumOfRuns +
  567. sizeof(UNI_CODEPAGEINFO) *
  568. (dwOldCodePageCount + 1),
  569. dwOldCPCmdSize +
  570. CodePageInfo.SelectSymbolSet.dwCount +
  571. CodePageInfo.UnSelectSymbolSet.dwCount;
  572. CopyMemory(pbBase, &GlyphSetData, sizeof(UNI_GLYPHSETDATA));
  573. CopyMemory(pbBase + sizeof(UNI_GLYPHSETDATA),
  574. pNewGlyphRun,
  575. iNumOfRuns * sizeof (GLYPHRUN));
  576. CopyMemory(pbBase +
  577. sizeof(UNI_GLYPHSETDATA) +
  578. sizeof(GLYPHRUN) * iNumOfRuns,
  579. pOldCodePageInfo,
  580. sizeof(UNI_CODEPAGEINFO) * dwOldCodePageCount);
  581. CopyMemory(pbBase +
  582. sizeof(UNI_GLYPHSETDATA) +
  583. sizeof(GLYPHRUN) * iNumOfRuns +
  584. sizeof(UNI_CODEPAGEINFO) * dwOldCodePageCount,
  585. &CodePageInfo,
  586. sizeof(UNI_CODEPAGEINFO));
  587. CopyMemory(pbBase +
  588. sizeof(UNI_GLYPHSETDATA) +
  589. sizeof(GLYPHRUN) * iNumOfRuns +
  590. sizeof(UNI_CODEPAGEINFO) * (dwOldCodePageCount + 1),
  591. (PBYTE)pOldCodePageInfo +
  592. sizeof(UNI_CODEPAGEINFO) * dwOldCodePageCount,
  593. dwOldCPCmdSize);
  594. if (pCPSel)
  595. {
  596. CopyMemory(pbBase +
  597. sizeof(UNI_GLYPHSETDATA) +
  598. sizeof(GLYPHRUN) * iNumOfRuns +
  599. sizeof(UNI_CODEPAGEINFO) * (dwOldCodePageCount + 1) +
  600. dwOldCPCmdSize,
  601. pCPSel,
  602. CodePageInfo.SelectSymbolSet.dwCount);
  603. }
  604. if (pCPUnSel)
  605. {
  606. CopyMemory(pbBase +
  607. sizeof(UNI_GLYPHSETDATA) +
  608. sizeof(GLYPHRUN)*iNumOfRuns +
  609. sizeof(UNI_CODEPAGEINFO) * (dwOldCodePageCount + 1) +
  610. dwOldCPCmdSize + CodePageInfo.SelectSymbolSet.dwCount,
  611. pCPUnSel,
  612. CodePageInfo.UnSelectSymbolSet.dwCount);
  613. }
  614. pNewMapTable = (PMAPTABLE)(pbBase + GlyphSetData.loMapTableOffset);
  615. }
  616. //
  617. //
  618. // 11. Now we create MAPTABLE.
  619. // size = MAPTABLE + (number of glyph - 1) x TRANSDATA
  620. //
  621. //
  622. #if SET_RIP
  623. RIP(("11. Now We create MAPTABLE.\n"));
  624. #elif SET_PRINT
  625. printf("11. Now We create MAPTABLE.\n");
  626. #endif
  627. pNewMapTable->dwSize = sizeof(MAPTABLE) +
  628. (iNumOfHandle - 1) * sizeof(TRANSDATA) +
  629. iTotalOffsetCmd;
  630. pNewMapTable->dwGlyphNum = iNumOfHandle;
  631. pNewGlyphRun = pNewGlyphFirst;
  632. pTrans = pNewMapTable->Trans;
  633. if (dwFlags & DWFLAGS_NEWCREATION)
  634. ubCodePageID = 0;
  635. else
  636. ubCodePageID = (BYTE)((*ppGlyphSetData)->dwCodePageCount) - 1;
  637. pMapTableCommand = (PBYTE)&(pNewMapTable->Trans[iNumOfHandle]);
  638. dwMapTableCommandOffset = sizeof(MAPTABLE) +
  639. (iNumOfHandle - 1) * sizeof(TRANSDATA);
  640. iTotalCommandSize = 0;
  641. iIndex = 0;
  642. for( iI = 0; iI < iNumOfRuns; iI ++, pNewGlyphRun ++)
  643. {
  644. for( iJ = 0; iJ < pNewGlyphRun->wGlyphCount; iJ ++)
  645. {
  646. wchChar = pNewGlyphRun->wcLow + iJ;
  647. ubAnsi = ubGetAnsi(wchChar, iNumOfHandle, awchUnicode, aubAnsi);
  648. if( ubAnsi >= pCTTData->chFirstChar &&
  649. ubAnsi <= pCTTData->chLastChar )
  650. {
  651. BYTE chTemp;
  652. chTemp = ubAnsi - pCTTData->chFirstChar;
  653. switch( pCTTData->wType )
  654. {
  655. case CTT_WTYPE_DIRECT:
  656. pTrans[iIndex].ubCodePageID = ubCodePageID;
  657. pTrans[iIndex].ubType = MTYPE_DIRECT;
  658. pTrans[iIndex].uCode.ubCode =
  659. pCTTData->uCode.bCode[ chTemp ];
  660. break;
  661. case CTT_WTYPE_PAIRED:
  662. pTrans[iIndex].ubCodePageID = ubCodePageID;
  663. pTrans[iIndex].ubType = MTYPE_PAIRED;
  664. pTrans[iIndex].uCode.ubPairs[0] =
  665. pCTTData->uCode.bPairs[ chTemp ][ 0 ];
  666. pTrans[iIndex].uCode.ubPairs[1] =
  667. pCTTData->uCode.bPairs[ chTemp ][ 1 ];
  668. break;
  669. case CTT_WTYPE_COMPOSE:
  670. wcbData = pCTTData->uCode.psCode[ chTemp + 1 ] -
  671. pCTTData->uCode.psCode[ chTemp ];
  672. pubData = (BYTE *)pCTTData +
  673. pCTTData->uCode.psCode[chTemp];
  674. pTrans[iIndex].ubCodePageID = ubCodePageID;
  675. pTrans[iIndex].ubType = MTYPE_COMPOSE;
  676. pTrans[iIndex].uCode.sCode = (SHORT)dwMapTableCommandOffset;
  677. #if SET_PRINT
  678. {
  679. DWORD dwK;
  680. printf("ubAnsi = 0x%x\n", ubAnsi);
  681. printf("Offset = 0x%x\n", dwMapTableCommandOffset);
  682. printf("Size = %d\n", wcbData);
  683. printf("Command = ");
  684. for (dwK = 0; dwK < wcbData; dwK ++)
  685. {
  686. printf("%02x", pubData[dwK]);
  687. }
  688. }
  689. printf("\n");
  690. #endif
  691. *(WORD*)pMapTableCommand = (WORD)wcbData;
  692. pMapTableCommand += 2;
  693. CopyMemory(pMapTableCommand, pubData, wcbData);
  694. pMapTableCommand += wcbData;
  695. dwMapTableCommandOffset += 2 + wcbData;
  696. iTotalCommandSize += wcbData + 2;
  697. break;
  698. }
  699. }
  700. else
  701. {
  702. pTrans[iIndex].ubCodePageID = ubCodePageID;
  703. pTrans[iIndex].ubType = MTYPE_DIRECT;
  704. pTrans[iIndex].uCode.ubCode = ubAnsi;
  705. }
  706. iIndex++;
  707. }
  708. }
  709. //
  710. //
  711. // Set pointer.
  712. //
  713. //
  714. *ppGlyphSetData = (PUNI_GLYPHSETDATA)pbBase;
  715. return TRUE;
  716. }
  717. BYTE
  718. ubGetAnsi(
  719. WCHAR wchChar,
  720. INT iNumOfHandle,
  721. PWCHAR pwchUnicode,
  722. PBYTE pchAnsi)
  723. {
  724. BYTE ubRet;
  725. INT iI;
  726. for (iI = 0; iI < iNumOfHandle; iI ++)
  727. {
  728. if (wchChar == pwchUnicode[iI])
  729. {
  730. ubRet = pchAnsi[iI];
  731. break;
  732. }
  733. }
  734. return ubRet;
  735. }