|
|
1.1 root 1: /*
2: * Copyright (c) 1984, 1985, 1986 Xerox Corp.
3: *
4: * create TeX font files
5: *
6: * HISTORY
7: * 11-Feb-86 Lee Moore (lee) at Xerox Webster Research Center
8: * Added the creation of an extra text file which contains information
9: * on how to access characters in other character-sets than zero (0).
10: *
11: * 15-Dec-85 Lee Moore (lee) at Xerox Webster Research Center
12: * Created.
13: *
14: */
15:
16: #include <stdio.h>
17: #include <math.h>
18: #include "stack.h"
19: #include "token.h"
20: #include "config.h"
21: #include "ipmetrics.h"
22: #include "tex.h"
23:
24: #define TRUE 1
25: #define FALSE 0
26:
27: #define public
28: #define private static
29:
30: public char *malloc();
31:
32: public char *DeviceName,
33: *LibraryDirectory;
34:
35: public
36: CleanUpTeX(configChain)
37: struct FontConfig *configChain; {
38: struct FontConfig *p;
39:
40: WriteTeXInstallFile(configChain);
41: WriteTeXCleanUpFile(configChain);
42:
43: for( p = configChain; p != NULL; p = p->Next )
44: if( !p->SeenFlag )
45: printf("couldn't find: %s/%s/%s\n",
46: p->FontPt1, p->FontPt2, p->FontPt3);
47: }
48:
49:
50: private
51: WriteTeXInstallFile(configChain)
52: struct FontConfig *configChain; {
53: FILE *installFile;
54: struct FontConfig *p;
55:
56: if( (installFile = fopen(INSTALLNAME, "w")) == NULL ) {
57: fprintf(stderr, "can't open the file 'install' for writing\n");
58: return; }
59:
60: fprintf(installFile, "#! /bin/sh\n");
61: fprintf(installFile, "if test ! -d %s/fonts/%s\n", LibraryDirectory, DeviceName);
62: fprintf(installFile, " then\n");
63: fprintf(installFile, " mkdir %s/fonts/%s\n", LibraryDirectory, DeviceName);
64: fprintf(installFile, " fi\n");
65: fprintf(installFile, "if test ! -d %s/fonts/%s/tex\n", LibraryDirectory, DeviceName);
66: fprintf(installFile, " then\n");
67: fprintf(installFile, " mkdir %s/fonts/%s/tex\n", LibraryDirectory, DeviceName);
68: fprintf(installFile, " fi\n");
69:
70:
71: for( p = configChain; p != NULL; p = p->Next )
72: if( p->SeenFlag ) {
73: fprintf(installFile, "cp %s.pl %s/fonts/%s/tex\n",
74: p->TargetName, LibraryDirectory, DeviceName);
75: fprintf(installFile, "pltotf %s.pl %s.tfm\n",
76: p->TargetName, p->TargetName); }
77:
78: fprintf(installFile, "cd %s/fonts/%s/tex\n", LibraryDirectory,
79: DeviceName);
80: (void) fclose(installFile);
81: (void) chmod(INSTALLNAME, 0755); }
82:
83:
84: /*
85: * write a file that rm's all the files created by this program
86: */
87:
88: private
89: WriteTeXCleanUpFile(configChain)
90: struct FontConfig *configChain; {
91: FILE *cleanupFile;
92: struct FontConfig *p;
93:
94: if( (cleanupFile = fopen(CLEANUPNAME, "w")) == NULL ) {
95: fprintf(stderr, "can't open the file 'cleanup' for writing\n");
96: return; }
97:
98: fprintf(cleanupFile, "#! /bin/sh\n");
99:
100: for( p = configChain; p != NULL; p = p->Next )
101: if( p->SeenFlag ) {
102: fprintf(cleanupFile, "rm %s.pl\n", p->TargetName);
103: fprintf(cleanupFile, "rm %s.xc\n", p->TargetName); }
104:
105: fprintf(cleanupFile, "rm %s\n", CLEANUPNAME);
106: fprintf(cleanupFile, "rm %s\n", INSTALLNAME);
107: (void) fclose(cleanupFile);
108: (void) chmod(CLEANUPNAME, 0755); }
109:
110:
111: PerTeXFont(configChain, fontDescVec)
112: struct FontConfig *configChain;
113: unsigned char *fontDescVec; {
114: unsigned char *charMetricsProperty,
115: *width,
116: *charMetric;
117: char iType[MAXTOKENSIZE],
118: iCharName[MAXTOKENSIZE],
119: fileType[MAXTOKENSIZE],
120: *fontName[40],
121: metricFileName[40],
122: XCInfoFileName[40],
123: iCharSet[MAXTOKENSIZE],
124: iCharCode[MAXTOKENSIZE];
125: unsigned short TeXtoXCMap[256];
126: FILE *descFile,
127: *modelFile,
128: *XCInfoFile;
129: struct FontConfig *p;
130: struct TokenState *ts;
131: int charSet,
132: charNumber,
133: charIndex,
134: i;
135: double xWidth;
136:
137: if( !GetFontNameProperty(fontDescVec, fontName) ) {
138: fprintf(stderr, "ipmetrics: can't get font name\n");
139: return;
140: }
141:
142: if( (charMetricsProperty = GetStringProp("characterMetrics", fontDescVec))
143: == NULL ) {
144: printf("ipmetrics: can't find 'characterMetrics' property\n");
145: return; }
146:
147: for( p = configChain; p != NULL; p = p->Next ) {
148: if( !(strcmp(p->FontPt1, fontName[0]) == 0 &&
149: strcmp(p->FontPt2, fontName[1]) == 0 &&
150: strcmp(p->FontPt3, fontName[2]) == 0) )
151: continue;
152:
153: (void) sprintf(metricFileName, "%s.pl", p->TargetName);
154:
155: if( (descFile = fopen(metricFileName, "w")) == NULL ) {
156: printf("ipmetrics: can't open %s for writing\n", metricFileName);
157: return;}
158:
159: (void) sprintf(XCInfoFileName, "%s.xc", p->TargetName);
160:
161: if( (XCInfoFile = fopen(XCInfoFileName, "w")) == NULL ) {
162: printf("ipmetrics: can't open %s for writing\n", XCInfoFileName);
163: return;}
164:
165: for( i = 0; i < 256; i++ )
166: TeXtoXCMap[i] = 0;
167:
168: if( (modelFile = fopen(p->MapFile, "r")) == NULL ) {
169: printf("ipmetrics: can't open %s for reading\n", p->MapFile);
170: return;}
171:
172: p->SeenFlag = TRUE;
173: /* (void) strcpy(malloc((unsigned) 40), p->TargetName); */
174:
175: ts = InitTokenStream(modelFile);
176:
177: fprintf(descFile, "(COMMENT %s/%s/%s for Interpress device %s\n", p->FontPt1, p->FontPt2, p->FontPt3, DeviceName);
178:
179: fprintf(descFile, " for interpress device '%s')\n", DeviceName);
180: fprintf(descFile, "(CODINGSCHEME XC1-1-1)\n");
181: fprintf(descFile, "(FAMILY %s)\n", p->TargetName);
182: fprintf(descFile, "(DESIGNSIZE D 10)\n");
183: fprintf(descFile, "(DESIGNUNITS D 1)\n");
184:
185: GetToken(ts, fileType, MAXTOKENSIZE);
186: /* file type doesn't mean much in this case... */
187:
188: while( !EndOfFile(ts) ) {
189: GetToken(ts, iCharSet, MAXTOKENSIZE);
190: (void) sscanf(iCharSet, "%o", &charSet);
191: GetToken(ts, iCharCode, MAXTOKENSIZE);
192: (void) sscanf(iCharCode, "%o", &charNumber);
193: GetToken(ts, iType, MAXTOKENSIZE);
194: GetToken(ts, iCharName, MAXTOKENSIZE);
195: charIndex = Make16BitChar(charSet, charNumber);
196:
197: /* skip the rest of this loop if it's not in this font */
198: if( (charMetric =
199: GetIntegerProp(charIndex, charMetricsProperty)) == NULL )
200: continue;
201:
202: fprintf(descFile, "(CHARACTER %s %s", iType, iCharName);
203: TeXtoXCMap[PLtoBinary(iType, iCharName)] = charIndex;
204:
205: if( (width = GetStringProp("widthX", charMetric)) == NULL ){
206: printf("ipmetrics: can't find widthX property of %d\n",
207: charIndex);
208: continue;}
209:
210: if( gettype(width) != type_number ) {
211: printf("ipmetrics: width not of type number for %d\n",
212: charIndex);
213: continue;}
214:
215: if( getsubtype(width) != subtype_rational ) {
216: printf("ipmetrics: width not of subtype number for %d\n",
217: charIndex);
218: continue;}
219:
220: xWidth = ((float) getnumerator(width)) / ((float) getdenominator(width));
221:
222: fprintf(descFile, " (CHARWD R %6.4f)", xWidth);
223:
224: if( charSet == 0 )
225: fprintf(descFile, ")\n");
226: else
227: fprintf(descFile, ")\t(COMMENT in charset 0%o)\n", charSet);
228:
229: while( !EndOfLine(ts) ) {
230: /* we currently don't support aliases */
231: GetToken(ts, iCharName, MAXTOKENSIZE);} }
232:
233: fprintf(XCInfoFile, "# mapping into extended characters\n");
234:
235: for( i = 0; i < 256; i++ )
236: fprintf(XCInfoFile, "0%o\n", TeXtoXCMap[i]);
237:
238: CloseTokenStream(ts);
239: (void) fclose(descFile);
240: (void) fclose(XCInfoFile);
241: (void) fclose(modelFile); }
242: }
243:
244: static
245: PLtoBinary(typeStr, valueStr)
246: char *typeStr, *valueStr; {
247: int result;
248:
249: if( strcmp(typeStr, "O") == 0 ) {
250: (void) sscanf(valueStr, "%o", &result);
251: return result;}
252: else if( strcmp(typeStr, "C") == 0 )
253: return *valueStr;
254:
255: fprintf(stderr, "unknown type %s\n", typeStr);
256: return *valueStr;
257: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.