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.

306 lines
5.7 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, pb2, pb3;
  65. struct SMOOTHPRM prm;
  66. unsigned char *tmp1, *tmp2;
  67. int msiz;
  68. inputSiz = siz;
  69. reverseBMP( buf, ((siz+15)/16*2*siz));
  70. if ( init==0)
  71. if (OInit()) return -1;
  72. tmp1 = tmp2 = (unsigned char *)0;
  73. BMPInit();
  74. msiz = (siz+15)/16*2 * siz;
  75. if ( (tmp1 = (unsigned char *)malloc( msiz))==(unsigned char *)0)
  76. goto ERET;
  77. if ( (tmp2 = (unsigned char *)malloc( msiz))==(unsigned char *)0)
  78. goto ERET;
  79. if ( (pb1 = BMPDefine( buf, siz, siz))<0)
  80. goto ERET;
  81. if ( (pb2 = BMPDefine( tmp1, siz, siz))<0)
  82. goto ERET;
  83. if ( (pb3 = BMPDefine( tmp2, siz, siz))<0)
  84. goto ERET;
  85. VDNew( OUTLSTH);
  86. if (BMPMkCont( pb1, pb2, pb3, OUTLSTH)<0)
  87. goto ERET;
  88. prm.SmoothLevel = level;
  89. prm.UseConic = 1;
  90. /* ���͂̂S�{�ŏ����_�ȉ��S�r�b�g�Ōv�Z */
  91. if (SmoothVector( OUTLSTH, TMPLSTH, siz, siz,siz*4, &prm, 16))
  92. goto ERET;
  93. VDCopy( OUTLSTH, TMPLSTH);
  94. RemoveFp( TMPLSTH, siz*4, 16);
  95. free( tmp1);
  96. free( tmp2);
  97. BMPFreDef( pb1);
  98. BMPFreDef( pb2);
  99. BMPFreDef( pb3);
  100. reverseBMP( buf, ((siz+15)/16*2*siz));
  101. /* �Ԃ��̂́A���͂̂S�{�ɂ������� */
  102. return TMPLSTH;
  103. ERET:
  104. if ( tmp1) free( tmp1);
  105. if ( tmp2) free( tmp2);
  106. BMPFreDef( pb1);
  107. BMPFreDef( pb2);
  108. BMPFreDef( pb3);
  109. return -1;
  110. }
  111. /***********************************************************************
  112. * check File exist
  113. */
  114. /* */ int
  115. /* */ OExistTTF( TCHAR *path)
  116. /*
  117. * returns : 0, 1 (exist)
  118. ***********************************************************************/
  119. {
  120. HANDLE fh;
  121. fh = CreateFile(path,
  122. GENERIC_READ,
  123. FILE_SHARE_READ,
  124. NULL,
  125. OPEN_EXISTING,
  126. FILE_ATTRIBUTE_NORMAL,
  127. NULL);
  128. if ( fh == INVALID_HANDLE_VALUE) return 0;
  129. CloseHandle( fh);
  130. return 1;
  131. }
  132. #ifdef BUILD_ON_WINNT
  133. int OExistUserFont( TCHAR *path)
  134. {
  135. HANDLE fh;
  136. fh = CreateFile(path,
  137. GENERIC_READ,
  138. FILE_SHARE_READ | FILE_SHARE_WRITE,
  139. NULL,
  140. OPEN_EXISTING,
  141. FILE_ATTRIBUTE_NORMAL,
  142. NULL);
  143. if ( fh == INVALID_HANDLE_VALUE)
  144. return 0;
  145. CloseHandle( fh);
  146. return 1;
  147. }
  148. #endif // BUILD_ON_WINNT
  149. static void
  150. setWIFEBBX( struct BBX *bbx, short *uPEm)
  151. {
  152. bbx->xMin = 0;
  153. bbx->xMax = 255;
  154. bbx->yMin = 0;
  155. bbx->yMax = 255;
  156. *uPEm = 256;
  157. }
  158. /***********************************************************************
  159. * Create EUDC TTF
  160. */
  161. /* */ int
  162. /* */ OCreateTTF(
  163. /* */ HDC hDC,
  164. /* */ TCHAR *path,
  165. /* */ int fontType)
  166. /*
  167. * returns : 0, -1
  168. ***********************************************************************/
  169. {
  170. struct BBX bbx;
  171. short uPEm;
  172. if ( fontType)
  173. setWIFEBBX( &bbx, &uPEm);
  174. else {
  175. if (TTFGetBBX( hDC, &bbx, &uPEm))
  176. goto ERET;
  177. }
  178. makeNullGlyph( NGLYPHLSTH, &bbx, uPEm);
  179. if (TTFCreate( hDC, path, &bbx, NGLYPHLSTH, fontType))
  180. goto ERET;
  181. return 0;
  182. ERET:
  183. return -1;
  184. }
  185. /***********************************************************************
  186. * Output to EUDC TTF
  187. */
  188. /* */ int
  189. /* */ OOutTTF(
  190. /* */ HDC hDC,
  191. /* */ TCHAR *path, /* TrueType Path */
  192. /* */ unsigned short code,
  193. /* */ BOOL bUnicode)
  194. /*
  195. * returns : 0, -1
  196. ***********************************************************************/
  197. {
  198. int mesh;
  199. struct BBX bbx;
  200. short uPEm;
  201. int sts;
  202. if (TTFGetEUDCBBX( path, &bbx, &uPEm))
  203. goto ERET;
  204. mesh = uPEm;
  205. /* OUTLSTH mesh is inputBitmapSiz*4 , and made into ufp 4bit*/
  206. /* ufp : under Fixed Point */
  207. ConvMesh( OUTLSTH, inputSiz*4, mesh);
  208. RemoveFp( OUTLSTH, mesh, 16);
  209. if (toTTFFrame( OUTLSTH, &bbx))
  210. goto ERET;
  211. if (!bUnicode)
  212. {
  213. code = sjisToUniEUDC( code);
  214. }
  215. if ( sts = TTFAddEUDCChar( path,code, &bbx, OUTLSTH)) {
  216. if (sts == -3) // tte file is being used by another process.
  217. return -3;
  218. if ( TTFLastError()==-2)
  219. return -2;
  220. else return -1;
  221. }
  222. return 0;
  223. ERET:
  224. return -1;
  225. }
  226. static void
  227. smtoi( unsigned short *s)
  228. {
  229. unsigned short sval;
  230. unsigned char *c;
  231. c = (unsigned char *)s;
  232. sval = *c;
  233. sval<<=8;
  234. sval += (unsigned short)*c;
  235. }
  236. static void
  237. reverseBMP( unsigned char *mem, int siz)
  238. {
  239. while ( siz-->0)
  240. *mem++ ^= (unsigned char)0xff;
  241. }
  242. static int
  243. makeNullGlyph( int lstH, struct BBX *bbx, short uPEm)
  244. {
  245. int width;
  246. int height;
  247. int cx, cy;
  248. int dx, dy;
  249. struct vecdata vd;
  250. width = height = uPEm;
  251. cx = bbx->xMin + width/2;
  252. cy = bbx->yMin + height/2;
  253. dx = width/20;
  254. dy = height/20;
  255. VDNew( lstH);
  256. vd.atr = 0;
  257. vd.x = cx - dx;
  258. vd.y = cy - dy;
  259. if (VDSetData( lstH, &vd)) goto ERET;
  260. vd.y = cy + dy;
  261. if (VDSetData( lstH, &vd)) goto ERET;
  262. vd.x = cx + dx;
  263. if (VDSetData( lstH, &vd)) goto ERET;
  264. vd.y = cy - dy;
  265. if (VDSetData( lstH, &vd)) goto ERET;
  266. if ( VDClose( lstH)) goto ERET;
  267. return 0;
  268. ERET:
  269. return -1;
  270. }
  271. /* EOF */