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.

646 lines
16 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. BOOL GetINFFontDescription(
  326. LPSZ lpszInf,
  327. LPSZ lpszDescription,
  328. LPSZ lpszPSFontName
  329. )
  330. {
  331. INT hfile, iToken;
  332. CHAR szName[128];
  333. CHAR szAngle[10];
  334. CHAR szStyle[2];
  335. CHAR szMods[30];
  336. BOOL bAddItalic = FALSE;
  337. CHAR szBold[20];
  338. CHAR szItalic[20];
  339. static KEY infKeys[] = {
  340. "FontName", TK_PSNAME,
  341. "MSMenuName", TK_MSMENUNAME,
  342. "VPStyle", TK_VPSTYLE,
  343. "ItalicAngle",TK_ANGLE,
  344. NULL, 0
  345. };
  346. hfile = OpenParseFile( lpszInf );
  347. if( hfile == -1 ) return(FALSE);
  348. szName[0] = szStyle[0] = szMods[0] = lpszPSFontName[0] = 0;
  349. // bodind replaced AtmGetString by strcpy
  350. strcpy(szBold, "Bold");
  351. strcpy(szItalic, "Italic");
  352. //AtmGetString( RCN(STR_BOLD), szBold, sizeof(szBold) );
  353. //AtmGetString( RCN(STR_ITALIC), szItalic, sizeof(szItalic) );
  354. while( GetLine(hfile) ) {
  355. iToken = GetToken(hfile,infKeys);
  356. switch(iToken) {
  357. case TK_MSMENUNAME:
  358. GetString(szName, sizeof(szName));
  359. break;
  360. case TK_PSNAME:
  361. GetString(lpszPSFontName, MAX_PATH);
  362. break;
  363. case TK_ANGLE:
  364. GetWord(szAngle, sizeof(szAngle));
  365. if ( strcmp (szAngle, "0") )
  366. bAddItalic = TRUE;
  367. break;
  368. case TK_VPSTYLE:
  369. GetString(szStyle, sizeof(szStyle));
  370. switch( toupper(szStyle[0]) ) {
  371. case 'N': break;
  372. case 'B': strcpy(szMods, szBold); break;
  373. case 'T': strcpy(szMods, szBold);
  374. case 'I':
  375. strcat(szMods, szItalic);
  376. bAddItalic = FALSE;
  377. break;
  378. /* default: break; */
  379. }
  380. break;
  381. }
  382. }
  383. _lclose(hfile);
  384. if( !szName[0] ) return(FALSE);
  385. strcpy( lpszDescription, szName );
  386. if( szMods[0] ) {
  387. strcat( lpszDescription, "," );
  388. strcat( lpszDescription, szMods );
  389. if (bAddItalic)
  390. strcat(lpszDescription, szItalic);
  391. }
  392. else
  393. {
  394. if (bAddItalic)
  395. {
  396. strcat (lpszDescription, "," );
  397. strcat (lpszDescription, szItalic);
  398. }
  399. }
  400. return(TRUE);
  401. } // end of GetINFFontDescription
  402. /*--------------------------------------------------------------------------*/
  403. INT MakePfm(afmpath, infdir, pfmdir) /* MEF */
  404. LPSZ afmpath, infdir, pfmdir;
  405. {
  406. #define FATALERROR 2
  407. #define NOERROR 0
  408. CHAR bname[9];
  409. indexMemArray = 0; /* init global */
  410. strcpy(afm.szFile, afmpath);
  411. GetFilename(afmpath, bname);
  412. if( infdir[strlen(infdir)-1] == '\\' )
  413. sprintf(infofile, "%s%s%s", infdir, bname, str_DotINF);
  414. else
  415. sprintf(infofile, "%s\\%s%s", infdir, bname, str_DotINF);
  416. if( pfmdir[strlen(pfmdir)-1] == '\\' )
  417. sprintf(outfile, "%s%s%s", pfmdir, bname, str_DotPFM);
  418. else
  419. sprintf(outfile, "%s\\%s%s", pfmdir, bname, str_DotPFM);
  420. afm.iPtSize = 12;
  421. encfile[0] = EOS;
  422. devType = POSTSCRIPT;
  423. if( !strcmp(_strupr(bname), "SY______") ) charset = SYMBOL_CHARSET;
  424. else charset = -1;
  425. /*
  426. * yh 8/16/91 -- Keep forceVariablePitch to TRUE for now to be compatible
  427. * with bitmaps generated by Font Foundry. ATM and device driver will
  428. * report different value for PitchAndFamily for monospaced fonts.
  429. *
  430. * forceVariablePitch = FALSE;
  431. */
  432. if( !_MakePfm() ) {
  433. return FATALERROR;
  434. }
  435. return(NOERROR);
  436. }
  437. #endif // ADOBE_CODE_WE_DO_NOT_USE
  438. /*--------------------------------------------------------------------------*/
  439. VOID GetFilename(path, name)
  440. LPSZ path, name;
  441. {
  442. LPSZ p;
  443. INT i;
  444. if( (p = strrchr(path,'\\')) == NULL )
  445. if( (p = strrchr(path,':') ) == NULL ) p = path;
  446. if( p != NULL ) p++;
  447. for(i=0; i<8; i++) {
  448. if( p[i]=='.' || p[i]==EOS ) break;
  449. name[i] = p[i];
  450. }
  451. name[i] = EOS;
  452. }
  453. /*----------------------------------------------------------------------------*/
  454. INT OpenParseFile(lpszPath)
  455. LPSZ lpszPath;
  456. {
  457. OFSTRUCT of;
  458. StartParse();
  459. return( OpenFile(lpszPath, &of, OF_READ) );
  460. }
  461. /*----------------------------------------------------------------------------*/
  462. INT OpenTargetFile(lpszPath)
  463. LPSZ lpszPath;
  464. {
  465. OFSTRUCT of;
  466. return( OpenFile(lpszPath, &of, OF_CREATE | OF_WRITE) );
  467. }
  468. LPVOID AllocateMem(size)
  469. UINT size;
  470. {
  471. HANDLE hmem;
  472. if( !(hmem=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size)) ) return(NULL);
  473. hMemArray[indexMemArray++] = hmem;
  474. return( GlobalLock(hmem) );
  475. }
  476. /*--------------------------------------------------------------------------*/
  477. VOID FreeAllMem()
  478. {
  479. INT i;
  480. for(i=0; i<indexMemArray; i++) {
  481. GlobalUnlock( hMemArray[i] );
  482. GlobalFree( hMemArray[i] );
  483. }
  484. }
  485. /*--------------------------------------------------------------------------*/
  486. /*----------------------------------------------------------------------------*/
  487. GlyphName *SetupGlyphArray(encFilePath)
  488. LPSZ encFilePath;
  489. {
  490. return(winEnc);
  491. }
  492. /*----------------------------------------------------------------------------*/
  493. /******************************Public*Routine******************************\
  494. *
  495. * BOOL bGetDescFromInf(char * pszINF, DWORD cjDesc, char *pszDesc)
  496. *
  497. * Not same as adobe's routine, we use font name from which we weed out
  498. * hyphes '-'
  499. *
  500. * History:
  501. * 28-Apr-1994 -by- Bodin Dresevic [BodinD]
  502. * Wrote it.
  503. \**************************************************************************/
  504. BOOL bGetDescFromInf(char * pszINF, DWORD cjDesc, char *pszDesc)
  505. {
  506. INT hfile;
  507. static KEY akeyInf[] = {
  508. "FontName", TK_PSNAME,
  509. NULL, 0
  510. };
  511. hfile = OpenParseFile( pszINF );
  512. if( hfile == -1 ) return(FALSE);
  513. pszDesc[0] = 0;
  514. while( GetLine(hfile) )
  515. {
  516. if (GetToken(hfile,akeyInf) == TK_PSNAME)
  517. {
  518. GetString(pszDesc, cjDesc);
  519. break;
  520. }
  521. }
  522. _lclose(hfile);
  523. if( !pszDesc[0] ) return(FALSE);
  524. // weed out hyphens
  525. for ( ; *pszDesc; pszDesc++)
  526. {
  527. if (*pszDesc == '-')
  528. *pszDesc = ' ';
  529. }
  530. return(TRUE);
  531. }
  532. /******************************Public*Routine******************************\
  533. *
  534. * short CreatePFM(char *pszINF, char *pszAFM, char *pszPFM);
  535. *
  536. * slightly modified adobe's routine
  537. *
  538. * History:
  539. * 28-Apr-1994 -by- Bodin Dresevic [BodinD]
  540. * Wrote it.
  541. *
  542. * Returns: 16-bit encoded value indicating error and type of file where
  543. * error occurred. (see fvscodes.h) for definitions.
  544. * The following table lists the "status" portion of the codes
  545. * returned.
  546. *
  547. * FVS_SUCCESS
  548. * FVS_INVALID_FONTFILE
  549. * FVS_FILE_OPEN_ERR
  550. * FVS_FILE_BUILD_ERR
  551. *
  552. \**************************************************************************/
  553. short CreatePFM(char *pszINF, char *pszAFM, char *pszPFM)
  554. {
  555. CHAR bname[9];
  556. indexMemArray = 0; /* init global */
  557. strcpy(afm.szFile, pszAFM);
  558. GetFilename(pszAFM, bname);
  559. strcpy (infofile, pszINF);
  560. strcpy (outfile, pszPFM);
  561. afm.iPtSize = 12;
  562. encfile[0] = EOS;
  563. devType = POSTSCRIPT;
  564. // this is something that would have never come to my mind [bodind]
  565. if( !strcmp(_strupr(bname), "SY______") )
  566. charset = SYMBOL_CHARSET;
  567. else
  568. charset = -1;
  569. /*
  570. * yh 8/16/91 -- Keep forceVariablePitch to TRUE for now to be compatible
  571. * with bitmaps generated by Font Foundry. ATM and device driver will
  572. * report different value for PitchAndFamily for monospaced fonts.
  573. *
  574. * forceVariablePitch = FALSE;
  575. */
  576. return _MakePfm();
  577. }