Source code of Windows XP (NT5)
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.

255 lines
5.5 KiB

  1. //
  2. // Copyright (c) 1997-1999 Microsoft Corporation.
  3. //
  4. #include "stdafx.h"
  5. #include "eudcedit.h"
  6. #pragma pack(2)
  7. #include "ttfstruc.h"
  8. #include "vdata.h"
  9. #include "extfunc.h"
  10. #define EUDCCODEBASE ((unsigned short)0xe000)
  11. /*
  12. File Structure */
  13. struct W31_Header {
  14. char identify[72];
  15. unsigned char segCnt[2]; /* ??? */
  16. unsigned char sCode[2],
  17. eCode[2];
  18. unsigned short cCnt; // Max character count
  19. unsigned long ofsCmap; // CMAP table offset
  20. unsigned short sizCmap; // Size of CMAP table
  21. unsigned long ofsHCmap;
  22. unsigned short sizHCmap;
  23. unsigned long ofsStbl; // Search table
  24. unsigned short sizStbl; // Size of search table
  25. unsigned long ofsBdatSub; // Sub table of bitmap data
  26. };
  27. struct BDatSubTbl {
  28. unsigned long tail;
  29. long locStartOfs;
  30. unsigned long head;
  31. short filler2;
  32. /* Following Pointer tbl. */
  33. };
  34. struct BMPHeader {
  35. unsigned long bitmapSiz;
  36. unsigned short xsiz, ysiz;
  37. };
  38. struct SrchEntry {
  39. unsigned short sCode;
  40. unsigned short eCode;
  41. unsigned short sloc;
  42. };
  43. /************************
  44. * Tables
  45. */
  46. /*
  47. * For Japan
  48. */
  49. #if (WINVER >= 0x0500)
  50. static struct W31_Header W31Hdr= {
  51. "Windows EUDC Editor Bitmap File (Uni-Code) ",
  52. {(unsigned char)0x0, (unsigned char)0x1},
  53. {(unsigned char)0xe0, (unsigned char)0x00},
  54. {(unsigned char)0xf8, (unsigned char)0xff},
  55. (unsigned short)6400,
  56. (unsigned long) 0,
  57. (unsigned short)0,
  58. (unsigned long)0,
  59. (unsigned short) 512,
  60. (unsigned long)0,
  61. (unsigned short)0,
  62. (unsigned long)0
  63. };
  64. #else
  65. static struct W31_Header W31Hdr= {
  66. "Windows95 EUDC Editor Bitmap File (Uni-Code) ",
  67. {(unsigned char)0x0, (unsigned char)0x1},
  68. {(unsigned char)0xe0, (unsigned char)0x00},
  69. {(unsigned char)0xe7, (unsigned char)0x57},
  70. (unsigned short)1880,
  71. (unsigned long) 0,
  72. (unsigned short)0,
  73. (unsigned long)0,
  74. (unsigned short) 512,
  75. (unsigned long)0,
  76. (unsigned short)0,
  77. (unsigned long)0
  78. };
  79. #endif
  80. static struct SrchEntry cSrchEntry = {
  81. (unsigned short)0xE000,(unsigned short)0xE757,(unsigned short)0
  82. };
  83. static void
  84. setFileHeader( )
  85. {
  86. struct W31_Header *hdr;
  87. unsigned short maxCode;
  88. maxCode = getMaxUniCode();
  89. hdr = &W31Hdr;
  90. hdr->eCode[0] = (unsigned char)(maxCode>>8);
  91. hdr->eCode[1] = (unsigned char)(maxCode & 0xff);
  92. hdr->cCnt = maxCode - EUDCCODEBASE +1;
  93. hdr->ofsCmap = sizeof(struct W31_Header);
  94. hdr->sizCmap = hdr->cCnt*2;
  95. hdr->ofsHCmap = hdr->ofsCmap + hdr->sizCmap;
  96. hdr->ofsStbl = hdr->ofsHCmap+hdr->sizHCmap;
  97. hdr->sizStbl = sizeof(struct SrchEntry);
  98. hdr->ofsBdatSub = hdr->ofsStbl + hdr->sizStbl;
  99. cSrchEntry.sCode = EUDCCODEBASE;
  100. cSrchEntry.eCode = maxCode;
  101. return;
  102. }
  103. static int
  104. makeCodeMap( char **mem, unsigned int *msiz)
  105. {
  106. unsigned short code;
  107. unsigned short *cbuf;
  108. unsigned short startC, endC;
  109. *msiz = W31Hdr.cCnt*2;
  110. if ( (*mem = (char *)malloc(*msiz)) == (char *)0)
  111. return -1;
  112. cbuf = (unsigned short *)*mem;
  113. startC = cSrchEntry.sCode;
  114. endC = cSrchEntry.eCode = getMaxUniCode();
  115. for ( code = startC; code <= endC; code++, cbuf++)
  116. *cbuf = code;
  117. return 0;
  118. }
  119. static int
  120. makeHCMap( char **mem, unsigned int *msiz)
  121. {
  122. unsigned short *hcp;
  123. unsigned short hc;
  124. unsigned short sofs;
  125. unsigned short start, end;
  126. *msiz = W31Hdr.sizHCmap;
  127. if ( (*mem = (char *)malloc( *msiz))==(char *)0)
  128. return -1;
  129. memset( *mem, 0xff, *msiz);
  130. hcp = (unsigned short *)*mem;
  131. sofs = (unsigned short)0;
  132. start = (unsigned short)W31Hdr.sCode[0];
  133. end = (unsigned short)W31Hdr.eCode[0];
  134. for ( hc = start; hc <= end; hc++) {
  135. *(hcp+hc) = (unsigned short)0;
  136. }
  137. return 0;
  138. }
  139. static int
  140. makeSrchTbl( char **mem, unsigned int *msiz)
  141. {
  142. *msiz = sizeof(struct SrchEntry);
  143. if ( (*mem = (char *)malloc( *msiz))==(char *)0)
  144. return -1;
  145. memcpy( *mem, &cSrchEntry, *msiz);
  146. return 0;
  147. }
  148. static int
  149. makeBdatSub( char **mem, unsigned int *msiz)
  150. {
  151. struct BDatSubTbl *bdtbl;
  152. *msiz = (W31Hdr.cCnt)*4 + sizeof(struct BDatSubTbl);
  153. if ( (*mem = (char *)malloc(*msiz))==(char *)0)
  154. return -1;
  155. memset( *mem, 0, *msiz);
  156. bdtbl = (struct BDatSubTbl *)*mem;
  157. bdtbl->head = bdtbl->tail = *msiz;
  158. bdtbl->locStartOfs=sizeof(struct BDatSubTbl);
  159. return 0;
  160. }
  161. /***************************************************************
  162. * Create EUDC Bitmap File (.EUF)
  163. */
  164. /* */ int
  165. /* */ creatW31JEUDC(
  166. /* */ TCHAR *path) /* .EUF file path */
  167. /*
  168. * returns : 0, -1
  169. ***************************************************************/
  170. {
  171. HANDLE fh;
  172. char *mem;
  173. unsigned int msiz;
  174. DWORD nByte;
  175. BOOL res;
  176. mem = (char *)0;
  177. makeUniCodeTbl();
  178. fh = CreateFile(path,
  179. GENERIC_WRITE,
  180. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  181. NULL,
  182. CREATE_ALWAYS,
  183. FILE_ATTRIBUTE_NORMAL,
  184. NULL);
  185. if ( fh == INVALID_HANDLE_VALUE)
  186. goto ERET;
  187. /* File Header */
  188. setFileHeader( );
  189. res =WriteFile( fh, (char *)&W31Hdr, sizeof(W31Hdr), &nByte, NULL);
  190. if (!res || nByte !=sizeof(W31Hdr))
  191. goto ERET;
  192. /* Code Map */
  193. if (makeCodeMap( &mem, &msiz))
  194. goto ERET;
  195. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  196. if (!res || nByte !=msiz)
  197. goto ERET;
  198. free(mem);
  199. /* High Byte Mapping for Search table */
  200. if ( makeHCMap( &mem, &msiz))
  201. goto ERET;
  202. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  203. if (!res || nByte !=msiz)
  204. goto ERET;
  205. free(mem);
  206. /* Srch Table */
  207. if (makeSrchTbl( &mem, &msiz))
  208. goto ERET;
  209. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  210. if (!res || nByte !=msiz)
  211. goto ERET;
  212. free(mem);
  213. /* Segment Def Header */
  214. makeBdatSub( &mem, &msiz);
  215. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  216. if (!res || nByte !=msiz)
  217. goto ERET;
  218. free(mem);
  219. CloseHandle( fh);
  220. return 0;
  221. ERET:
  222. if ( mem!=(char *)0)
  223. free( mem);
  224. if ( fh != INVALID_HANDLE_VALUE)
  225. CloseHandle( fh);
  226. return -1;
  227. }
  228. /* EOF */