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.

276 lines
6.1 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. if ((!mem) || (!msiz))
  110. {
  111. return -1;
  112. }
  113. *msiz = W31Hdr.cCnt*2;
  114. if ( (*mem = (char *)malloc(*msiz)) == (char *)0)
  115. return -1;
  116. cbuf = (unsigned short *)*mem;
  117. startC = cSrchEntry.sCode;
  118. endC = cSrchEntry.eCode = getMaxUniCode();
  119. for ( code = startC; code <= endC; code++, cbuf++)
  120. *cbuf = code;
  121. return 0;
  122. }
  123. static int
  124. makeHCMap( char **mem, unsigned int *msiz)
  125. {
  126. unsigned short *hcp;
  127. unsigned short hc;
  128. unsigned short sofs;
  129. unsigned short start, end;
  130. if ((!mem) || (!msiz))
  131. {
  132. return -1;
  133. }
  134. *msiz = W31Hdr.sizHCmap;
  135. if ( (*mem = (char *)malloc( *msiz))==(char *)0)
  136. return -1;
  137. memset( *mem, 0xff, *msiz);
  138. hcp = (unsigned short *)*mem;
  139. sofs = (unsigned short)0;
  140. start = (unsigned short)W31Hdr.sCode[0];
  141. end = (unsigned short)W31Hdr.eCode[0];
  142. for ( hc = start; hc <= end; hc++) {
  143. *(hcp+hc) = (unsigned short)0;
  144. }
  145. return 0;
  146. }
  147. static int
  148. makeSrchTbl( char **mem, unsigned int *msiz)
  149. {
  150. if ((!mem) || (!msiz))
  151. {
  152. return -1;
  153. }
  154. *msiz = sizeof(struct SrchEntry);
  155. if ( (*mem = (char *)malloc( *msiz))==(char *)0)
  156. return -1;
  157. memcpy( *mem, &cSrchEntry, *msiz);
  158. return 0;
  159. }
  160. static int
  161. makeBdatSub( char **mem, unsigned int *msiz)
  162. {
  163. struct BDatSubTbl *bdtbl;
  164. if ((!mem) || (!msiz))
  165. {
  166. return -1;
  167. }
  168. *msiz = (W31Hdr.cCnt)*4 + sizeof(struct BDatSubTbl);
  169. if ( (*mem = (char *)malloc(*msiz))==(char *)0)
  170. return -1;
  171. memset( *mem, 0, *msiz);
  172. bdtbl = (struct BDatSubTbl *)*mem;
  173. bdtbl->head = bdtbl->tail = *msiz;
  174. bdtbl->locStartOfs=sizeof(struct BDatSubTbl);
  175. return 0;
  176. }
  177. /***************************************************************
  178. * Create EUDC Bitmap File (.EUF)
  179. */
  180. /* */ int
  181. /* */ creatW31JEUDC(
  182. /* */ TCHAR *path) /* .EUF file path */
  183. /*
  184. * returns : 0, -1
  185. ***************************************************************/
  186. {
  187. HANDLE fh=INVALID_HANDLE_VALUE;
  188. char *mem=NULL;
  189. unsigned int msiz;
  190. DWORD nByte;
  191. BOOL res;
  192. if (!path)
  193. {
  194. goto ERET;
  195. }
  196. mem = (char *)0;
  197. makeUniCodeTbl();
  198. fh = CreateFile(path,
  199. GENERIC_WRITE,
  200. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  201. NULL,
  202. CREATE_ALWAYS,
  203. FILE_ATTRIBUTE_NORMAL,
  204. NULL);
  205. if ( fh == INVALID_HANDLE_VALUE)
  206. goto ERET;
  207. /* File Header */
  208. setFileHeader( );
  209. res =WriteFile( fh, (char *)&W31Hdr, sizeof(W31Hdr), &nByte, NULL);
  210. if (!res || nByte !=sizeof(W31Hdr))
  211. goto ERET;
  212. /* Code Map */
  213. if (makeCodeMap( &mem, &msiz))
  214. goto ERET;
  215. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  216. if (!res || nByte !=msiz)
  217. goto ERET;
  218. free(mem);
  219. /* High Byte Mapping for Search table */
  220. if ( makeHCMap( &mem, &msiz))
  221. goto ERET;
  222. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  223. if (!res || nByte !=msiz)
  224. goto ERET;
  225. free(mem);
  226. /* Srch Table */
  227. if (makeSrchTbl( &mem, &msiz))
  228. goto ERET;
  229. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  230. if (!res || nByte !=msiz)
  231. goto ERET;
  232. free(mem);
  233. /* Segment Def Header */
  234. makeBdatSub( &mem, &msiz);
  235. res =WriteFile( fh, mem, msiz, &nByte, NULL);
  236. if (!res || nByte !=msiz)
  237. goto ERET;
  238. free(mem);
  239. CloseHandle( fh);
  240. return 0;
  241. ERET:
  242. if ( mem!=(char *)0)
  243. free( mem);
  244. if ( fh != INVALID_HANDLE_VALUE)
  245. CloseHandle( fh);
  246. return -1;
  247. }
  248. /* EOF */