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.

338 lines
6.5 KiB

  1. /*
  2. * Bitmap and TTF control
  3. *
  4. * Copyright (c) 1997-1999 Microsoft Corporation.
  5. */
  6. #include "stdafx.h"
  7. #include "eudcedit.h"
  8. #pragma pack(2)
  9. #include "vdata.h"
  10. #include "ttfstruc.h"
  11. #include "extfunc.h"
  12. static void reverseBMP( unsigned char *mem, int siz);
  13. static int makeNullGlyph( int lstH, struct BBX *bbx, short uPEm);
  14. #define OUTLSTH 0
  15. #define TMPLSTH 1
  16. #define NGLYPHLSTH 3
  17. static int init = 0;
  18. static int inputSiz = 0;
  19. /***********************************************************************
  20. * initialize
  21. */
  22. /* */ int
  23. /* */ OInit( )
  24. /*
  25. * returns 0 , -1 (Failed)
  26. ***********************************************************************/
  27. {
  28. if ( init)
  29. return 0;
  30. if (VDInit())
  31. return -1;
  32. else {
  33. init = 1;
  34. return 0;
  35. }
  36. }
  37. /***********************************************************************
  38. * initialize
  39. */
  40. /* */ int
  41. /* */ OTerm( )
  42. /*
  43. * returns 0
  44. ***********************************************************************/
  45. {
  46. if ( init) {
  47. init = 0;
  48. VDTerm();
  49. }
  50. return 0;
  51. }
  52. /***********************************************************************
  53. * Make Outline
  54. */
  55. /* */ int
  56. /* */ OMakeOutline(
  57. /* */ unsigned char *buf,
  58. /* */ int siz,
  59. /* */ int level)
  60. /*
  61. * returns : 0< : list handle, -1 ( error)
  62. ***********************************************************************/
  63. {
  64. int pb1=-1, pb2=-1, pb3=-1;
  65. struct SMOOTHPRM prm;
  66. unsigned char *tmp1, *tmp2;
  67. int msiz;
  68. if (!buf)
  69. {
  70. return -1;
  71. }
  72. inputSiz = siz;
  73. reverseBMP( buf, ((siz+15)/16*2*siz));
  74. if ( init==0)
  75. if (OInit()) return -1;
  76. tmp1 = tmp2 = (unsigned char *)0;
  77. BMPInit();
  78. msiz = (siz+15)/16*2 * siz;
  79. if ( (tmp1 = (unsigned char *)malloc( msiz))==(unsigned char *)0)
  80. goto ERET;
  81. if ( (tmp2 = (unsigned char *)malloc( msiz))==(unsigned char *)0)
  82. goto ERET;
  83. if ( (pb1 = BMPDefine( buf, siz, siz))<0)
  84. goto ERET;
  85. if ( (pb2 = BMPDefine( tmp1, siz, siz))<0)
  86. goto ERET;
  87. if ( (pb3 = BMPDefine( tmp2, siz, siz))<0)
  88. goto ERET;
  89. VDNew( OUTLSTH);
  90. if (BMPMkCont( pb1, pb2, pb3, OUTLSTH)<0)
  91. goto ERET;
  92. prm.SmoothLevel = level;
  93. prm.UseConic = 1;
  94. /* ���͂̂S�{�ŏ����_�ȉ��S�r�b�g�Ōv�Z */
  95. if (SmoothVector( OUTLSTH, TMPLSTH, siz, siz,siz*4, &prm, 16))
  96. goto ERET;
  97. VDCopy( OUTLSTH, TMPLSTH);
  98. RemoveFp( TMPLSTH, siz*4, 16);
  99. free( tmp1);
  100. free( tmp2);
  101. BMPFreDef( pb1);
  102. BMPFreDef( pb2);
  103. BMPFreDef( pb3);
  104. reverseBMP( buf, ((siz+15)/16*2*siz));
  105. /* �Ԃ��̂́A���͂̂S�{�ɂ������� */
  106. return TMPLSTH;
  107. ERET:
  108. if ( tmp1) free( tmp1);
  109. if ( tmp2) free( tmp2);
  110. if (pb1 > 0) BMPFreDef( pb1);
  111. if (pb2 > 0) BMPFreDef( pb2);
  112. if (pb3 > 0) BMPFreDef( pb3);
  113. return -1;
  114. }
  115. /***********************************************************************
  116. * check File exist
  117. */
  118. /* */ int
  119. /* */ OExistTTF( TCHAR *path)
  120. /*
  121. * returns : 0, 1 (exist)
  122. ***********************************************************************/
  123. {
  124. HANDLE fh;
  125. if (!path)
  126. {
  127. return 0;
  128. }
  129. fh = CreateFile(path,
  130. GENERIC_READ,
  131. FILE_SHARE_READ,
  132. NULL,
  133. OPEN_EXISTING,
  134. FILE_ATTRIBUTE_NORMAL,
  135. NULL);
  136. if ( fh == INVALID_HANDLE_VALUE) return 0;
  137. CloseHandle( fh);
  138. return 1;
  139. }
  140. #ifdef BUILD_ON_WINNT
  141. int OExistUserFont( TCHAR *path)
  142. {
  143. HANDLE fh;
  144. fh = CreateFile(path,
  145. GENERIC_READ,
  146. FILE_SHARE_READ | FILE_SHARE_WRITE,
  147. NULL,
  148. OPEN_EXISTING,
  149. FILE_ATTRIBUTE_NORMAL,
  150. NULL);
  151. if ( fh == INVALID_HANDLE_VALUE)
  152. return 0;
  153. CloseHandle( fh);
  154. return 1;
  155. }
  156. #endif // BUILD_ON_WINNT
  157. static void
  158. setWIFEBBX( struct BBX *bbx, short *uPEm)
  159. {
  160. if ( (!bbx) || (!uPEm))
  161. {
  162. return;
  163. }
  164. bbx->xMin = 0;
  165. bbx->xMax = 255;
  166. bbx->yMin = 0;
  167. bbx->yMax = 255;
  168. *uPEm = 256;
  169. }
  170. /***********************************************************************
  171. * Create EUDC TTF
  172. */
  173. /* */ int
  174. /* */ OCreateTTF(
  175. /* */ HDC hDC,
  176. /* */ TCHAR *path,
  177. /* */ int fontType)
  178. /*
  179. * returns : 0, -1
  180. ***********************************************************************/
  181. {
  182. struct BBX bbx;
  183. short uPEm;
  184. if (!path)
  185. {
  186. goto ERET;
  187. }
  188. if ( fontType)
  189. setWIFEBBX( &bbx, &uPEm);
  190. else {
  191. if (TTFGetBBX( hDC, &bbx, &uPEm))
  192. goto ERET;
  193. }
  194. makeNullGlyph( NGLYPHLSTH, &bbx, uPEm);
  195. if (TTFCreate( hDC, path, &bbx, NGLYPHLSTH, fontType))
  196. goto ERET;
  197. return 0;
  198. ERET:
  199. return -1;
  200. }
  201. /***********************************************************************
  202. * Output to EUDC TTF
  203. */
  204. /* */ int
  205. /* */ OOutTTF(
  206. /* */ HDC hDC,
  207. /* */ TCHAR *path, /* TrueType Path */
  208. /* */ unsigned short code,
  209. /* */ BOOL bUnicode)
  210. /*
  211. * returns : 0, -1
  212. ***********************************************************************/
  213. {
  214. int mesh;
  215. struct BBX bbx;
  216. short uPEm;
  217. int sts;
  218. if (!path)
  219. {
  220. goto ERET;
  221. }
  222. if (TTFGetEUDCBBX( path, &bbx, &uPEm))
  223. goto ERET;
  224. mesh = uPEm;
  225. /* OUTLSTH mesh is inputBitmapSiz*4 , and made into ufp 4bit*/
  226. /* ufp : under Fixed Point */
  227. ConvMesh( OUTLSTH, inputSiz*4, mesh);
  228. RemoveFp( OUTLSTH, mesh, 16);
  229. if (toTTFFrame( OUTLSTH, &bbx))
  230. goto ERET;
  231. if (!bUnicode)
  232. {
  233. code = sjisToUniEUDC( code);
  234. }
  235. if ( sts = TTFAddEUDCChar( path,code, &bbx, OUTLSTH)) {
  236. if (sts == -3) // tte file is being used by another process.
  237. return -3;
  238. if ( TTFLastError()==-2)
  239. return -2;
  240. else return -1;
  241. }
  242. return 0;
  243. ERET:
  244. return -1;
  245. }
  246. static void
  247. smtoi( unsigned short *s)
  248. {
  249. unsigned short sval;
  250. unsigned char *c;
  251. if (!s)
  252. {
  253. return;
  254. }
  255. c = (unsigned char *)s;
  256. sval = *c;
  257. sval<<=8;
  258. sval += (unsigned short)*c;
  259. }
  260. static void
  261. reverseBMP( unsigned char *mem, int siz)
  262. {
  263. if (!mem)
  264. {
  265. return;
  266. }
  267. while ( siz-->0)
  268. *mem++ ^= (unsigned char)0xff;
  269. }
  270. static int
  271. makeNullGlyph( int lstH, struct BBX *bbx, short uPEm)
  272. {
  273. int width;
  274. int height;
  275. int cx, cy;
  276. int dx, dy;
  277. struct vecdata vd;
  278. if (!bbx)
  279. {
  280. goto ERET;
  281. }
  282. width = height = uPEm;
  283. cx = bbx->xMin + width/2;
  284. cy = bbx->yMin + height/2;
  285. dx = width/20;
  286. dy = height/20;
  287. VDNew( lstH);
  288. vd.atr = 0;
  289. vd.x = cx - dx;
  290. vd.y = cy - dy;
  291. if (VDSetData( lstH, &vd)) goto ERET;
  292. vd.y = cy + dy;
  293. if (VDSetData( lstH, &vd)) goto ERET;
  294. vd.x = cx + dx;
  295. if (VDSetData( lstH, &vd)) goto ERET;
  296. vd.y = cy - dy;
  297. if (VDSetData( lstH, &vd)) goto ERET;
  298. if ( VDClose( lstH)) goto ERET;
  299. return 0;
  300. ERET:
  301. return -1;
  302. }
  303. /* EOF */