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.

672 lines
18 KiB

  1. /*--------------------------------------------------------------------------*/
  2. /* WINATM version only */
  3. /*--------------------------------------------------------------------------*/
  4. //
  5. // Copyright 1990, 1991 -- Adobe Systems, Inc.
  6. // PostScript is a trademark of Adobe Systems, Inc.
  7. //
  8. // NOTICE: All information contained herein or attendant hereto is, and
  9. // remains, the property of Adobe Systems, Inc. Many of the intellectual
  10. // and technical concepts contained herein are proprietary to Adobe Systems,
  11. // Inc. and may be covered by U.S. and Foreign Patents or Patents Pending or
  12. // are protected as trade secrets. Any dissemination of this information or
  13. // reproduction of this material are strictly forbidden unless prior written
  14. // permission is obtained from Adobe Systems, Inc.
  15. //
  16. /*--------------------------------------------------------------------------*/
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <stdarg.h>
  21. #include <fcntl.h>
  22. #include <ctype.h>
  23. #include <io.h>
  24. #include "windows.h"
  25. #pragma pack(1)
  26. #include "makepfm.h"
  27. #pragma pack(4)
  28. #include "fvscodes.h" // FVS_xxxxxx (font validation status) codes and macros.
  29. #ifdef WIN30
  30. #define LPCSTR LPSTR
  31. #endif
  32. typedef LPSZ GlyphName;
  33. extern AFM afm;
  34. // bodind added these
  35. #define str_DotINF ".INF"
  36. #define str_DotPFM ".PFM"
  37. /*--------------------------------------------------------------------------*/
  38. static CHAR msgbuff[128];
  39. static HANDLE hMemArray[258]; // #_of_glyphnames + 1_glypharray + 1_kernpairs
  40. static INT indexMemArray = 0;
  41. static GlyphName winEnc[] =
  42. /* 8-27-91 yh Added some characters for Windows 3.1 */
  43. { /* 0 */ "",
  44. /* 1 */ "",
  45. /* 2 */ "",
  46. /* 3 */ "",
  47. /* 4 */ "",
  48. /* 5 */ "",
  49. /* 6 */ "",
  50. /* 7 */ "",
  51. /* 8 */ "",
  52. /* 9 */ "",
  53. /* 10 */ "",
  54. /* 11 */ "",
  55. /* 12 */ "",
  56. /* 13 */ "",
  57. /* 14 */ "",
  58. /* 15 */ "",
  59. /* 16 */ "",
  60. /* 17 */ "",
  61. /* 18 */ "",
  62. /* 19 */ "",
  63. /* 20 */ "",
  64. /* 21 */ "",
  65. /* 22 */ "",
  66. /* 23 */ "",
  67. /* 24 */ "",
  68. /* 25 */ "",
  69. /* 26 */ "",
  70. /* 27 */ "",
  71. /* 28 */ "",
  72. /* 29 */ "",
  73. /* 30 */ "",
  74. /* 31 */ "",
  75. /* 32 */ "space",
  76. /* 33 */ "exclam",
  77. /* 34 */ "quotedbl",
  78. /* 35 */ "numbersign",
  79. /* 36 */ "dollar",
  80. /* 37 */ "percent",
  81. /* 38 */ "ampersand",
  82. /* 39 */ "quotesingle",
  83. /* 40 */ "parenleft",
  84. /* 41 */ "parenright",
  85. /* 42 */ "asterisk",
  86. /* 43 */ "plus",
  87. /* 44 */ "comma",
  88. /* 45 */ "hyphen",
  89. /* 46 */ "period",
  90. /* 47 */ "slash",
  91. /* 48 */ "zero",
  92. /* 49 */ "one",
  93. /* 50 */ "two",
  94. /* 51 */ "three",
  95. /* 52 */ "four",
  96. /* 53 */ "five",
  97. /* 54 */ "six",
  98. /* 55 */ "seven",
  99. /* 56 */ "eight",
  100. /* 57 */ "nine",
  101. /* 58 */ "colon",
  102. /* 59 */ "semicolon",
  103. /* 60 */ "less",
  104. /* 61 */ "equal",
  105. /* 62 */ "greater",
  106. /* 63 */ "question",
  107. /* 64 */ "at",
  108. /* 65 */ "A",
  109. /* 66 */ "B",
  110. /* 67 */ "C",
  111. /* 68 */ "D",
  112. /* 69 */ "E",
  113. /* 70 */ "F",
  114. /* 71 */ "G",
  115. /* 72 */ "H",
  116. /* 73 */ "I",
  117. /* 74 */ "J",
  118. /* 75 */ "K",
  119. /* 76 */ "L",
  120. /* 77 */ "M",
  121. /* 78 */ "N",
  122. /* 79 */ "O",
  123. /* 80 */ "P",
  124. /* 81 */ "Q",
  125. /* 82 */ "R",
  126. /* 83 */ "S",
  127. /* 84 */ "T",
  128. /* 85 */ "U",
  129. /* 86 */ "V",
  130. /* 87 */ "W",
  131. /* 88 */ "X",
  132. /* 89 */ "Y",
  133. /* 90 */ "Z",
  134. /* 91 */ "bracketleft",
  135. /* 92 */ "backslash",
  136. /* 93 */ "bracketright",
  137. /* 94 */ "asciicircum",
  138. /* 95 */ "underscore",
  139. /* 96 */ "grave",
  140. /* 97 */ "a",
  141. /* 98 */ "b",
  142. /* 99 */ "c",
  143. /* 100 */ "d",
  144. /* 101 */ "e",
  145. /* 102 */ "f",
  146. /* 103 */ "g",
  147. /* 104 */ "h",
  148. /* 105 */ "i",
  149. /* 106 */ "j",
  150. /* 107 */ "k",
  151. /* 108 */ "l",
  152. /* 109 */ "m",
  153. /* 110 */ "n",
  154. /* 111 */ "o",
  155. /* 112 */ "p",
  156. /* 113 */ "q",
  157. /* 114 */ "r",
  158. /* 115 */ "s",
  159. /* 116 */ "t",
  160. /* 117 */ "u",
  161. /* 118 */ "v",
  162. /* 119 */ "w",
  163. /* 120 */ "x",
  164. /* 121 */ "y",
  165. /* 122 */ "z",
  166. /* 123 */ "braceleft",
  167. /* 124 */ "bar",
  168. /* 125 */ "braceright",
  169. /* 126 */ "asciitilde",
  170. /* 127 */ "",
  171. /* 128 */ "",
  172. /* 129 */ "",
  173. /* 130 */ "quotesinglbase",
  174. /* 131 */ "florin",
  175. /* 132 */ "quotedblbase",
  176. /* 133 */ "ellipsis",
  177. /* 134 */ "dagger",
  178. /* 135 */ "daggerdbl",
  179. /* 136 */ "circumflex",
  180. /* 137 */ "perthousand",
  181. /* 138 */ "Scaron",
  182. /* 139 */ "guilsinglleft",
  183. /* 140 */ "OE",
  184. /* 141 */ "",
  185. /* 142 */ "",
  186. /* 143 */ "",
  187. /* 144 */ "",
  188. /* 145 */ "quoteleft",
  189. /* 146 */ "quoteright",
  190. /* 147 */ "quotedblleft",
  191. /* 148 */ "quotedblright",
  192. /* 149 */ "bullet",
  193. /* 150 */ "endash",
  194. /* 151 */ "emdash",
  195. /* 152 */ "tilde",
  196. /* 153 */ "trademark",
  197. /* 154 */ "scaron",
  198. /* 155 */ "guilsinglright",
  199. /* 156 */ "oe",
  200. /* 157 */ "",
  201. /* 158 */ "",
  202. /* 159 */ "Ydieresis",
  203. /* 160 */ "space",
  204. /* 161 */ "exclamdown",
  205. /* 162 */ "cent",
  206. /* 163 */ "sterling",
  207. /* 164 */ "currency",
  208. /* 165 */ "yen",
  209. /* 166 */ "brokenbar",
  210. /* 167 */ "section",
  211. /* 168 */ "dieresis",
  212. /* 169 */ "copyright",
  213. /* 170 */ "ordfeminine",
  214. /* 171 */ "guillemotleft",
  215. /* 172 */ "logicalnot",
  216. /* 173 */ "minus",
  217. /* 174 */ "registered",
  218. /* 175 */ "macron",
  219. /* 176 */ "degree",
  220. /* 177 */ "plusminus",
  221. /* 178 */ "twosuperior",
  222. /* 179 */ "threesuperior",
  223. /* 180 */ "acute",
  224. /* 181 */ "mu",
  225. /* 182 */ "paragraph",
  226. /* 183 */ "periodcentered",
  227. /* 184 */ "cedilla",
  228. /* 185 */ "onesuperior",
  229. /* 186 */ "ordmasculine",
  230. /* 187 */ "guillemotright",
  231. /* 188 */ "onequarter",
  232. /* 189 */ "onehalf",
  233. /* 190 */ "threequarters",
  234. /* 191 */ "questiondown",
  235. /* 192 */ "Agrave",
  236. /* 193 */ "Aacute",
  237. /* 194 */ "Acircumflex",
  238. /* 195 */ "Atilde",
  239. /* 196 */ "Adieresis",
  240. /* 197 */ "Aring",
  241. /* 198 */ "AE",
  242. /* 199 */ "Ccedilla",
  243. /* 200 */ "Egrave",
  244. /* 201 */ "Eacute",
  245. /* 202 */ "Ecircumflex",
  246. /* 203 */ "Edieresis",
  247. /* 204 */ "Igrave",
  248. /* 205 */ "Iacute",
  249. /* 206 */ "Icircumflex",
  250. /* 207 */ "Idieresis",
  251. /* 208 */ "Eth",
  252. /* 209 */ "Ntilde",
  253. /* 210 */ "Ograve",
  254. /* 211 */ "Oacute",
  255. /* 212 */ "Ocircumflex",
  256. /* 213 */ "Otilde",
  257. /* 214 */ "Odieresis",
  258. /* 215 */ "multiply",
  259. /* 216 */ "Oslash",
  260. /* 217 */ "Ugrave",
  261. /* 218 */ "Uacute",
  262. /* 219 */ "Ucircumflex",
  263. /* 220 */ "Udieresis",
  264. /* 221 */ "Yacute",
  265. /* 222 */ "Thorn",
  266. /* 223 */ "germandbls",
  267. /* 224 */ "agrave",
  268. /* 225 */ "aacute",
  269. /* 226 */ "acircumflex",
  270. /* 227 */ "atilde",
  271. /* 228 */ "adieresis",
  272. /* 229 */ "aring",
  273. /* 230 */ "ae",
  274. /* 231 */ "ccedilla",
  275. /* 232 */ "egrave",
  276. /* 233 */ "eacute",
  277. /* 234 */ "ecircumflex",
  278. /* 235 */ "edieresis",
  279. /* 236 */ "igrave",
  280. /* 237 */ "iacute",
  281. /* 238 */ "icircumflex",
  282. /* 239 */ "idieresis",
  283. /* 240 */ "eth",
  284. /* 241 */ "ntilde",
  285. /* 242 */ "ograve",
  286. /* 243 */ "oacute",
  287. /* 244 */ "ocircumflex",
  288. /* 245 */ "otilde",
  289. /* 246 */ "odieresis",
  290. /* 247 */ "divide",
  291. /* 248 */ "oslash",
  292. /* 249 */ "ugrave",
  293. /* 250 */ "uacute",
  294. /* 251 */ "ucircumflex",
  295. /* 252 */ "udieresis",
  296. /* 253 */ "yacute",
  297. /* 254 */ "thorn",
  298. /* 255 */ "ydieresis",
  299. NULL,
  300. };
  301. extern CHAR encfile[MAX_PATH];
  302. extern CHAR outfile[MAX_PATH];
  303. extern CHAR infofile[MAX_PATH];
  304. extern INT charset;
  305. extern INT devType;
  306. extern BOOL forceVariablePitch;
  307. /*--------------------------------------------------------------------------*/
  308. BOOL GetINFFontDescription(LPSZ, LPSZ, LPSZ);
  309. BOOL MakePfm(LPSZ, LPSZ, LPSZ);
  310. VOID GetFilename(LPSZ, LPSZ);
  311. INT OpenParseFile(LPSZ);
  312. INT OpenTargetFile(LPSZ);
  313. VOID WriteDots(VOID);
  314. LPVOID AllocateMem(UINT);
  315. VOID FreeAllMem(VOID);
  316. GlyphName *SetupGlyphArray(LPSZ);
  317. extern short _MakePfm(VOID); /* afm.c */
  318. extern VOID StartParse(VOID); /* token.c */
  319. extern BOOL GetLine(INT);
  320. extern VOID GetWord(CHAR *, INT);
  321. extern BOOL GetString(CHAR *, INT);
  322. extern INT GetToken(INT, KEY *);
  323. /*--------------------------------------------------------------------------*/
  324. #ifdef ADOBE_CODE_WE_DO_NOT_USE
  325. // REVIEW: mjan - There should be a size argument for the out arguments
  326. // lpszDescription and lpszPSFontName. However, the api is
  327. // may not be used or we may not be able to change the API.
  328. BOOL GetINFFontDescription(
  329. LPSZ lpszInf, // in
  330. LPSZ lpszDescription, // out - Needs to be sizeof(szName)+sizeof(szBold)+sizeof(szItalic)+3 long = 171.
  331. LPSZ lpszPSFontName // out - Needs to be MAX_PATH long = 260
  332. )
  333. {
  334. INT hfile, iToken;
  335. CHAR szName[128];
  336. CHAR szAngle[10];
  337. CHAR szStyle[2];
  338. CHAR szMods[30];
  339. BOOL bAddItalic = FALSE;
  340. CHAR szBold[20];
  341. CHAR szItalic[20];
  342. static KEY infKeys[] = {
  343. "FontName", TK_PSNAME,
  344. "MSMenuName", TK_MSMENUNAME,
  345. "VPStyle", TK_VPSTYLE,
  346. "ItalicAngle",TK_ANGLE,
  347. NULL, 0
  348. };
  349. hfile = OpenParseFile( lpszInf );
  350. if( hfile == -1 ) return(FALSE);
  351. szName[0] = szStyle[0] = szMods[0] = lpszPSFontName[0] = 0;
  352. // bodind replaced AtmGetString by strcpy
  353. strcpy(szBold, "Bold");
  354. strcpy(szItalic, "Italic");
  355. //AtmGetString( RCN(STR_BOLD), szBold, sizeof(szBold) );
  356. //AtmGetString( RCN(STR_ITALIC), szItalic, sizeof(szItalic) );
  357. while( GetLine(hfile) ) {
  358. iToken = GetToken(hfile,infKeys);
  359. switch(iToken) {
  360. case TK_MSMENUNAME:
  361. GetString(szName, sizeof(szName));
  362. break;
  363. case TK_PSNAME:
  364. GetString(lpszPSFontName, MAX_PATH);
  365. break;
  366. case TK_ANGLE:
  367. GetWord(szAngle, sizeof(szAngle));
  368. if ( strcmp (szAngle, "0") )
  369. bAddItalic = TRUE;
  370. break;
  371. case TK_VPSTYLE:
  372. GetString(szStyle, sizeof(szStyle));
  373. switch( toupper(szStyle[0]) ) {
  374. case 'N': break;
  375. case 'B': strcpy(szMods, szBold); break;
  376. case 'T': strcpy(szMods, szBold);
  377. case 'I':
  378. strcat(szMods, szItalic);
  379. bAddItalic = FALSE;
  380. break;
  381. /* default: break; */
  382. }
  383. break;
  384. }
  385. }
  386. _lclose(hfile);
  387. if( !szName[0] ) return(FALSE);
  388. strcpy( lpszDescription, szName );
  389. if( szMods[0] ) {
  390. strcat( lpszDescription, "," );
  391. strcat( lpszDescription, szMods );
  392. if (bAddItalic)
  393. strcat(lpszDescription, szItalic);
  394. }
  395. else
  396. {
  397. if (bAddItalic)
  398. {
  399. strcat (lpszDescription, "," );
  400. strcat (lpszDescription, szItalic);
  401. }
  402. }
  403. return(TRUE);
  404. } // end of GetINFFontDescription
  405. /*--------------------------------------------------------------------------*/
  406. INT MakePfm(afmpath, infdir, pfmdir) /* MEF */
  407. LPSZ afmpath, infdir, pfmdir;
  408. {
  409. #define FATALERROR 2
  410. #define NOERROR 0
  411. CHAR bname[9];
  412. indexMemArray = 0; /* init global */
  413. afm.szFile[0] = '\0';
  414. if (afmpath)
  415. strncpy(afm.szFile, afmpath, sizeof(afm.szFile)-1);
  416. afm.szFile[sizeof(afm.szFile)-1] = '\0';
  417. GetFilename(afmpath, bname);
  418. if( infdir[strlen(infdir)-1] == '\\' )
  419. sprintf(infofile, "%s%s%s", infdir, bname, str_DotINF);
  420. else
  421. sprintf(infofile, "%s\\%s%s", infdir, bname, str_DotINF);
  422. if( pfmdir[strlen(pfmdir)-1] == '\\' )
  423. sprintf(outfile, "%s%s%s", pfmdir, bname, str_DotPFM);
  424. else
  425. sprintf(outfile, "%s\\%s%s", pfmdir, bname, str_DotPFM);
  426. afm.iPtSize = 12;
  427. encfile[0] = EOS;
  428. devType = POSTSCRIPT;
  429. if( !strcmp(_strupr(bname), "SY______") ) charset = SYMBOL_CHARSET;
  430. else charset = -1;
  431. /*
  432. * yh 8/16/91 -- Keep forceVariablePitch to TRUE for now to be compatible
  433. * with bitmaps generated by Font Foundry. ATM and device driver will
  434. * report different value for PitchAndFamily for monospaced fonts.
  435. *
  436. * forceVariablePitch = FALSE;
  437. */
  438. if( !_MakePfm() ) {
  439. return FATALERROR;
  440. }
  441. return(NOERROR);
  442. }
  443. #endif // ADOBE_CODE_WE_DO_NOT_USE
  444. /*--------------------------------------------------------------------------*/
  445. VOID GetFilename(path, name)
  446. LPSZ path, name;
  447. {
  448. LPSZ p;
  449. INT i = 0;
  450. if (path && name)
  451. {
  452. if( (p = strrchr(path,'\\')) == NULL )
  453. p = strrchr(path,':');
  454. if (p)
  455. p++;
  456. else
  457. p = path;
  458. for(i=0; i<8; i++)
  459. {
  460. if( p[i]=='.' || p[i]==EOS )
  461. break;
  462. name[i] = p[i];
  463. }
  464. }
  465. if (name)
  466. name[i] = EOS;
  467. }
  468. /*----------------------------------------------------------------------------*/
  469. INT OpenParseFile(lpszPath)
  470. LPSZ lpszPath;
  471. {
  472. OFSTRUCT of;
  473. StartParse();
  474. return( OpenFile(lpszPath, &of, OF_READ) );
  475. }
  476. /*----------------------------------------------------------------------------*/
  477. INT OpenTargetFile(lpszPath)
  478. LPSZ lpszPath;
  479. {
  480. OFSTRUCT of;
  481. return( OpenFile(lpszPath, &of, OF_CREATE | OF_WRITE) );
  482. }
  483. LPVOID AllocateMem(size)
  484. UINT size;
  485. {
  486. HANDLE hmem;
  487. if( !(hmem=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size)) ) return(NULL);
  488. // May cause a leak, which is better than a crash at least.
  489. if (indexMemArray < sizeof(hMemArray)/sizeof(hMemArray[0]))
  490. hMemArray[indexMemArray++] = hmem;
  491. return( GlobalLock(hmem) );
  492. }
  493. /*--------------------------------------------------------------------------*/
  494. VOID FreeAllMem()
  495. {
  496. INT i;
  497. for(i=0; i<indexMemArray; i++) {
  498. GlobalUnlock( hMemArray[i] );
  499. GlobalFree( hMemArray[i] );
  500. }
  501. }
  502. /*--------------------------------------------------------------------------*/
  503. /*----------------------------------------------------------------------------*/
  504. GlyphName *SetupGlyphArray(encFilePath)
  505. LPSZ encFilePath;
  506. {
  507. return(winEnc);
  508. }
  509. /*----------------------------------------------------------------------------*/
  510. /******************************Public*Routine******************************\
  511. *
  512. * BOOL bGetDescFromInf(char * pszINF, DWORD cjDesc, char *pszDesc)
  513. *
  514. * Not same as adobe's routine, we use font name from which we weed out
  515. * hyphens '-'
  516. *
  517. * History:
  518. * 28-Apr-1994 -by- Bodin Dresevic [BodinD]
  519. * Wrote it.
  520. \**************************************************************************/
  521. BOOL bGetDescFromInf(char * pszINF, DWORD cjDesc, char *pszDesc)
  522. {
  523. INT hfile;
  524. static KEY akeyInf[] = {
  525. "FontName", TK_PSNAME,
  526. NULL, 0
  527. };
  528. hfile = OpenParseFile( pszINF );
  529. if( hfile == -1 ) return(FALSE);
  530. pszDesc[0] = 0;
  531. while( GetLine(hfile) )
  532. {
  533. if (GetToken(hfile,akeyInf) == TK_PSNAME)
  534. {
  535. GetString(pszDesc, cjDesc);
  536. break;
  537. }
  538. }
  539. _lclose(hfile);
  540. if( !pszDesc[0] ) return(FALSE);
  541. // weed out hyphens
  542. for ( ; *pszDesc; pszDesc++)
  543. {
  544. if (*pszDesc == '-')
  545. *pszDesc = ' ';
  546. }
  547. return(TRUE);
  548. }
  549. /******************************Public*Routine******************************\
  550. *
  551. * short CreatePFM(char *pszINF, char *pszAFM, char *pszPFM);
  552. *
  553. * slightly modified adobe's routine
  554. *
  555. * History:
  556. * 28-Apr-1994 -by- Bodin Dresevic [BodinD]
  557. * Wrote it.
  558. *
  559. * Returns: 16-bit encoded value indicating error and type of file where
  560. * error occurred. (see fvscodes.h) for definitions.
  561. * The following table lists the "status" portion of the codes
  562. * returned.
  563. *
  564. * FVS_SUCCESS
  565. * FVS_INVALID_FONTFILE
  566. * FVS_FILE_OPEN_ERR
  567. * FVS_FILE_BUILD_ERR
  568. *
  569. \**************************************************************************/
  570. short CreatePFM(char *pszINF, char *pszAFM, char *pszPFM)
  571. {
  572. CHAR bname[9];
  573. // We need both the AFM and the INF file in order to create the PFM.
  574. if (pszAFM==NULL || pszINF==NULL)
  575. return FVS_MAKE_CODE(FVS_INVALID_ARG, FVS_FILE_UNK);
  576. indexMemArray = 0; /* init global */
  577. afm.szFile[0] = '\0';
  578. strncpy(afm.szFile, pszAFM, sizeof(afm.szFile)-1);
  579. afm.szFile[sizeof(afm.szFile)-1] = '\0';
  580. GetFilename(pszAFM, bname);
  581. strncpy (infofile, pszINF, sizeof(infofile)-1);
  582. infofile[sizeof(infofile)-1] = '\0';
  583. strncpy (outfile, pszPFM, sizeof(outfile)-1);
  584. outfile[sizeof(outfile)-1] = '\0';
  585. afm.iPtSize = 12;
  586. encfile[0] = EOS;
  587. devType = POSTSCRIPT;
  588. // this is something that would have never come to my mind [bodind]
  589. if( !strcmp(_strupr(bname), "SY______") )
  590. charset = SYMBOL_CHARSET;
  591. else
  592. charset = -1;
  593. /*
  594. * yh 8/16/91 -- Keep forceVariablePitch to TRUE for now to be compatible
  595. * with bitmaps generated by Font Foundry. ATM and device driver will
  596. * report different value for PitchAndFamily for monospaced fonts.
  597. *
  598. * forceVariablePitch = FALSE;
  599. */
  600. return _MakePfm();
  601. }