summaryrefslogtreecommitdiff
path: root/systems/os2/binaries/maketexpk.cmd
blob: f15b738baee6f0a5703b6fd30f79b1ab924db18c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*    

Translated from Piet Tutelaar's Unix shell script 
into Rexx by Sebastian Rahtz, 15.8.92 (spqr@minster.york.ac.uk)

last change: 28.12.92

   This script file makes a new TeX PK font, because one wasn't
   found.  Parameters are:

   name dpi bdpi magnification [[mode] subdir]

   `name' is the name of the font, such as `cmr10'.  `dpi' is
   the resolution the font is needed at.  `bdpi' is the base
   resolution, useful for figuring out the mode to make the font
   in.  `magnification' is a string to pass to MF as the
   magnification.  `mode', if supplied, is the mode to use.

   Note that this file must execute MetaFont (and then gftopk) or
   ps2pk, and place the result in the correct location for the
   PostScript driver to find it subsequently.  If this doesn't work,
   it will be evident because the program will be invoked over and over again.

   If no MetaFont source is available for `name' and the fontname
   starts with a `r' or is available in $TEXCONFIG/adobe then the 
   program tries to find a type1 font. If such a font is located 
   ps2pk will be used to render the font.

   Of course, it needs to be set up for your site with regard to paths etc
*/

PARSE Arg all_args
argc=words(all_args)
if ( argc < 4  | argc > 6 ) then 
do
   say "Usage: maketexpk fontname dpi bdpi magnification [[mode] subdir]"
   exit 1
end

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
os2env='OS2ENVIRONMENT'

/* destination of pk files */
DESTDIR='d:\texfonts\pixel.lj'

/* Where we look for METAFONT sources */
OLDMFINPUT=value('MFINPUT',,os2env)
if OLDMFINPUT='' then
do
	OLDMFINPUT='d:\emtex\mfinput'
end
MFINPUT=OLDMFINPUT
/* 
look for subdirs to add to path;
should find, eg, cm concrete dc euler pandora punk wasy 
*/
call SysFileTree OLDMFINPUT"\*.*",'fam','D'
do i=1 to fam.0
 MFINPUT=MFINPUT';'word(fam.i,5)
end
MFINPUT=value('MFINPUT',MFINPUT,os2env)
MFINPUT=value('MFINPUT',,os2env)
/* say 'search path: ' MFINPUT */

/* Where we look for Type1 fonts and AFM files */
T1INPUTS=value('T1INPUTS',,os2env)
if T1INPUTS='' then
do
	T1INPUTS='d:\emtex\ps'
	T1INPUTS=value('T1INPUTS',T1INPUTS,os2env)
	T1INPUTS=value('T1INPUTS',,os2env)
end

/* Where we look for dvips stuff */
TEXCONFIG='d:\emtex\ps'

listoftype1files=TEXCONFIG'\fontname'

/* 
 TEMPDIR needs to be unique for each process because of the possibility
 of simultaneous processes running this script.
*/
TEMPDIR=SysTempFileName("d:/tmp/mtpk.???")

NAME=word(all_args,1)
DPI=word(all_args,2)
BDPI=word(all_args,3)
MAG=word(all_args,4)
if argc > 4 then 
	MODE=word(all_args,5)
else
   if BDPI = 300   then
      MODE='hplaser'
   else if BDPI = 1270   then
      MODE='linohi'
   else if BDPI = 2540   then
      MODE='linosuper'
   else
    do
      say 'I do not know the mode for ' BDPI
      say 'update this MakeTeXPK script'
      exit 1
    end

if argc > 5 then 
	SUBDIR=word(all_args,6) 
else
	SUBDIR=BDPI'dpi'


PKNAME=NAME'.pk'
DESTDIR=DESTDIR'\'DPI'DPI'

say 'making for ' MODE ' in ' DESTDIR SUBDIR 
/*
say 'temporary output file is 'TEMPDIR'\'PKNAME
*/
call sysfiletree DESTDIR ,'test', 'OD'
if test.0=0 then
      call SysMkDir DESTDIR
/*
else
      say 'directory' DESTDIR 'exists'
*/
destpk=DESTDIR'\'PKNAME
fname = stream(destpk , 'C', 'QUERY EXISTS')
if \ (fname ='') then
  do
     say DESTDIR'\'PKNAME 'already exists!'
    exit 0
  end

/* OK, try to make the font by some means */

/* first try Adobe Type1 fonts 

 What encoding scheme do we use for Type1 text fonts? 

 Strip off the first letter and last letters
 and see if that gives us a hint 
*/

DEF_TEXT_ENCODING=' '
PREFIX=left(NAME,1)
SUFFIX=right(NAME,1)

select
when PREFIX='r' then
	do
	VNAME=substr(NAME,2)
	DEF_TEXT_ENCODING=' '
	end
when SUFFIX='0' then
	do
	VNAME=left(NAME,length(NAME)-1)
	DEF_TEXT_ENCODING="-eEC.enc"  /* (Extended Computer Modern) */
	end
otherwise
	VNAME=NAME
end

call sysfilesearch VNAME' ',listoftype1files, 'FILE.','C'

/* if that succeeded, the variable FILE contains the
matching lines in the file describing the fonts */

if rc=3 then
do
   say 'You should install file ' listoftype1files
   exit 0
end
FULLNAME='!'
slant=""
VVNAME=VNAME
if FILE.0>0 then 
   do i=1 to file.0
	if word(file.i,1)=VNAME then 
		do
		FULLNAME=word(file.i,2)
		if words(file.i) > 2 then
			do
			slant="-S "||word(file.i,3)
			VVNAME=left(VNAME,length(VNAME)-1)
			end
		leave
		end
   end
if FULLNAME='!' then  /* failed to locate a name in the list 

  Do we have a METAFONT source for this typeface? 
*/
  do
	if substr(NAME,1,3)='fmv' then 
			mfname=malvern(NAME)  /* Malvern font */ 
	else
	   mfname=syssearchpath('MFINPUT',NAME'.mf')
   say 'Result of MF search: 'mfname
   if mfname='' then
    do
	      say 'Sorry, no PostScript font or Metafont font found' 
	      exit 1
    end
   job='@mfp \mode:='MODE'; mag:='MAG'; scrollmode; input 'name
/* 
really no need to use a temporary directory, I think, in this environment

   curdir=directory()
   call SysMkDir TEMPDIR
   newdir= directory(TEMPDIR)
*/
   job
   if substr(NAME,1,3)='fmv' then  /* Malvern font */ 
	   x=sysfiledelete(NAME||'.mf')
   GFNAME=NAME'.'DPI
/*   if  (stream( GFNAME, 'C', 'QUERY EXISTS') = '') then
    do
      say 'Metafont failed for some reason on 'GFNAME' ('NAME')'
      exit 1
    end
    */
   '@gftopk' GFNAME PKNAME
   '@copy' PKNAME destpk 
   x=sysfiledelete(GFNAME)
   x=sysfiledelete(PKNAME)  
   x=sysfiledelete(NAME'.log')
   /* x=sysfiledelete(NAME'.tfm')   */
   exit 0
   MFINPUT=value('MFINPUT',OLDMFINPUT,os2env)
 end
else
/*  we have a Type1 font (at any rate, its in the list!) */
   afmname=syssearchpath('T1INPUTS',VVNAME'.afm')
   if afmname='' then
      do
        say 'Failed to find afm file for' VVNAME ' in 'T1INPUTS
        exit 1
      end
/*  If we don't use default AFM encoding then we have to check
   if we can apply this encoding (text fonts only) 
*/
ENCODING=DEF_TEXT_ENCODING
   if \ (DEF_TEXT_ENCODING = '')   then
    do
    /* What is encoding scheme that the AFM file uses? */
    call sysfilesearch 'EncodingScheme',afmname, 'FILE.','C'      
	if file.0=0  then
        do
         say afmname': Invalid AFM file! No Encoding line.'
         exit 0
        end
        if length(file.1) > 100 then
        do
         say afmname': Invalid AFM file! Encoding line too long.'
         exit 0
        end
      EXT_END=word(file.1,2)
      select
      when substr(ext_end,1,6)='AdobeS' then ENCODING=DEF_TEXT_ENCODING
      when substr(ext_end,1,3)='ISO' then ENCODING=DEF_TEXT_ENCODING
      otherwise
	     ENCODING=''
      end
   end
/*
   if substr(NAME,1,3)='hlc' then 
	do
	ENCODING="-eEC.enc"
	say 'applying EC encoding'
	end
*/
   pfbname=syssearchpath('T1INPUTS',VVNAME'.pfa')
   if pfbname='' then
    do
      pfbname=syssearchpath('T1INPUTS',VVNAME'.pfb')
      if pfbname='' then
        do
         say 'Source for font' VVNAME 'not found on path 'T1INPUTS
         exit 1
        end
   end
   job='@ps2pk -X'DPI ENCODING SLANT filespec('name',pfbname) destpk 
   say job
   job
exit 0

malvern: procedure
arg fontname
/* Malvern generation
#
#  The font name is of the form
#
#    	fmvWVV##		Karl Berry's standard font names
#
#  where W   denotes a weight (one of t, i, l, k, r, d, b, x, c)
#        VV  denotes a "variation" (one of <empty>, rn, re, i, in, ie)
#	 ##  is the design size, in points
#
#  or
#	maXXx##			my nonstandard font names
#	
#  where XX is 2 digits giving a style in the tradition of Univers
#        x  is a suffix describing the character set of the font
#	 ## is the design size, in points (with p as decimal point)
#
#  Examples:
#
#    fmvr10	ma55a10		Malvern 55 10-pt
#    fmvd10	ma65a10		Malvern 65 demibold 10-pt
#    fmvbix18	ma74a18		Malvern 74 bold extended italic 18-pt
#    fmvric7	ma58a7		Malvern 58 condensed italic 7-pt
#
#  The fmv- fonts all use the Cork encoding.
#
*/
weights.=''
weights.1= 'weight = 1/4;'	/* ultra-light */
weights.2= 'weight = 1/2;'	/* extra-light */
weights.3= 'weight = 3/4;'	/* light */
weights.4= 'weight = 7/8;'	/* book */
weights.5= 'weight = 1;'	/* medium */
weights.6= 'weight = 1.5;'	/* demi  */
weights.7= 'weight = 2;'	/* bold  */
weights.8= 'weight = 3;'	/* extra */
weights.9= 'weight = 4;'	/* ultra */

weights.t= 'weight = 1/4;'	/* thin [ultra-light] */
weights.i= 'weight = 1/2;'	/* extra-lIght */
weights.l= 'weight = 3/4;'	/* Light */
weights.k= 'weight = 7/8;'	/* booK */
weights.r= 'weight = 1;'	/* Regular */
weights.d= 'weight = 1.5;' 	/* Demi */
weights.b= 'weight = 2;'	/* Bold */
weights.x= 'weight = 3;'	/* eXtra */
weights.u= 'weight = 4;'	/* Ultra */

styles.=''

styles.9='hratio = 0.3;'
styles.0='hratio = 0.3; slant := 1/8; italicness = 1;'
styles.7='hratio = 0.6;'
styles.8='hratio = 0.6; slant := 1/8; italicness = 1;'
styles.5='hratio = 1;'
styles.6='hratio = 1; slant := 1/8; italicness = 1;'
styles.3='hratio = 1.15;'
styles.4='hratio = 1.15; slant := 1/8; italicness = 1;'
styles.1='hratio = 1.30;'
styles.2='hratio = 1.30; slant := 1/8; italicness = 1;'

styles.i='italicness = 1; slant := 1/8;'	/* italic */
styles.u='italicness = 1;'	 	/* vertical italic */
styles.o='slant := 1/8;'			/* oblique */

/* Berry's system has expansion after variant rather than before: */
styles.o='hratio = 0.3;'	/* narrow (extra condensed) */
styles.c='hratio = 0.6;'	/* compressed */
styles.x='hratio = 1.15;'	/* expanded */
styles.w='hratio = 1.30;' 	/* wide (extra expanded) */

/* not used here
-J 's=encoding=0'	# Standard TeX text (like cmr)
-J 'x=encoding=-200'	# Cork (TUGboat 11#4)
-J 'mi=encoding=-1'	# maths (like cmmi)
-J 'sy=encoding=-2'	# symbol (like cmsy)
-J 'ps=encoding=-1000'	# the AdobeStandardEncoding encoding
-J 'so=encoding=-1010'	# the ISOLatin1Encoding encoding

#  Malvern encodings:
-J 'a=encoding=1'	# Malvern A (simple letters)
-J 'b=encoding=2'	# Malvern B (strange symbols)
-J 'c=encoding=3'	# Malvern C (composites)
*/
rf=reverse(fontname)
parse var rf n1 +1 n2 +1 .
if datatype(n2,'N')=1 then
  size=n2||n1
else
  size=n1
parse var fontname basename (size) .
parse var basename base +3 weight +1 style +1 expansion 
if style\=' ' then
  y=value(style)
else
  y=''
if expansion\=' ' then
  z=value(expansion)
else 
  z=''
x=value(weight)
fontfile=value(fontname)||'.mf'
call lineout fontfile,'font_size 'size'pt#; 'weights.x styles.y styles.z 'input maltex;bye.'
call lineout fontfile 
say 'generated Malvern file ' fontfile
return fontfile