summaryrefslogtreecommitdiff
path: root/dviware/ln03/rose/toppnft.pli
blob: 0ea9b4dd535a7b9233ea3343b8afc06fb31b72a5 (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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
%REPLACE true BY '1'B;
%REPLACE false BY '0'B;
%REPLACE maxnfonts BY 21;
%REPLACE maxtexfonts BY 100;
%REPLACE nblanks BY 0;
%REPLACE leftfirst BY 33;
%REPLACE leftlast BY 126;
%REPLACE rightfirst BY 161;
%REPLACE rightlast BY 254;

/* This file contains those portions of LN03Topp that deal directly with
the font file format (.NFT files). It is under development...

Development chronology: 

11/28/84: Initial version. Wrote COPY_CHAR. 

11/29/84: GOOD_OPENING. Second thoughts about whole interface.
    	  Merge the three functions into one.

Copyright (c) 1983, 1984 by Digital Equipment Corporation. */ 

/* The purpose of ADD_TXF_TO_LNF is to read an NFT file corresponding to
TeX font TXFNO and place its rasters into the output font buffer. It
returns the number of bytes by which the NFT file incremented the size of
the output file, or a negative value to indicate lossage. */ 

add_txf_to_lnf: PROCEDURE(lnfno,txfno,nftfname,outf) RETURNS(FIXED);

    DCL nftfname CHAR(*);
    DCL (txfno,lnfno) FIXED;
    DCL outf FILE;

    DCL (strip,frontstrip) EXTERNAL ENTRY (CHAR (*)) 
	RETURNS (CHAR (*)),
	cvis EXTERNAL ENTRY (FIXED) RETURNS (CHAR (*));

    DCL lastch(0:maxnfonts) FIXED GLOBALREF;
    DCL chw(0:maxnfonts,0:255) FIXED GLOBALREF;

    DCL 1 txf BASED,
    	2 nchs FIXED,
        2 chu(0:255) CHAR(1);
    DCL txfa(0:maxtexfonts) PTR GLOBALREF;

/* The buffer for the output fonts is currently of fixed size. Eventually
it should be possible to chain a lot of these together so output fonts of
unlimited size can be handled, subject only to virtual memory availability.
*/ 
    
    %REPLACE obuflen BY 131120;
    DCL lnf(0:obuflen) CHAR(1) STATIC;    
    DCL (ras_len,psize,lsize,msize) FIXED STATIC;     
    DCL using_r BIT STATIC;  

/* Out of laziness, we read the entire input NFT file into a big array and
then copy it. Obviously this is foolish; we should read it block by block
only, and even use "random reading" if the RMS file type is suitable. */ 

    DCL nfta(0:obuflen) CHAR(1); 
    DCL (i,j,k,nftlen) FIXED;
	
    IF txfno < 0 | txfno > maxtexfonts | txfa(txfno) = Null() THEN
	GOTO error_return;
    IF lnfno < 0 | lnfno > maxnfonts THEN GOTO error_return;
			
    PUT SKIP EDIT ('Loading font ' || nftfname) (A);

    nftlen = 0;
    CALL read_into_nfta;

/* The NFT file comes to us in bytes. We need ways to understand it as
words or longwords. When we need to parse some bytes as something, we copy
them into the following overlaid variables. Note that unsigned quantities
still require fixing. */ 

    DCL longword FIXED;
    DCL chars CHAR(4) BASED (Addr(longword));

/* We make exactly one gratuitous test of NFT validity: the second longword
must be 'FONT'. */ 

    IF nfta(4) ^= 'F' | nfta(5) ^= 'O' | nfta(6) ^= 'N' | nfta(7) ^= 'T'
    THEN GOTO bad_format;

/* We also have to check that there are a full 16 bytes of character
parameters. If there are fewer, we give up: it's too hard to figure out how
to give the missing ones reasonable values. Maybe in the next version... */

    %REPLACE fnt$l_parameters_size BY 200;
    CALL nft_copy(fnt$l_parameters_size);
    IF longword ^= 16 THEN GOTO bad_format;

/* Figure out where the character directory in the NFT file begins */

    %REPLACE fnt$a_char_directory BY 120;
    DCL chardir_offset FIXED;

/* CHARDIR_OFFSET should always equal 480. But we read it off the file
anyway. */ 

    CALL nft_copy(fnt$a_char_directory);
    chardir_offset = longword;
    IF chardir_offset <= 0 | chardir_offset > nftlen 
    THEN GOTO bad_format;

/* Figure out what the lowest character in the NFT file is */

    %REPLACE fnt$l_first_character BY 164;
    DCL nft_first_ch FIXED;

    nft_first_ch = rank(nfta(fnt$l_first_character));

/* Now, determine if this is the first or last TXF which is being copied
into this file. */ 

    DCL (first_txfc,last_txfc) FIXED;
    DCL (first_txf,last_txf) BIT;

    first_txfc = -1; last_txfc = -1;
    DO i = 0 TO 255;
	IF txfa(txfno) -> chu(i) ^= byte(0) THEN DO;
	    IF first_txfc = -1 THEN first_txfc = rank(txfa(txfno) -> chu(i));
	    last_txfc = rank(txfa(txfno) -> chu(i));
	END;	    
    END;

    IF first_txfc = -1 | last_txfc = -1 THEN DO;
    	PUT SKIP EDIT ('LN03Topp internal error - empty TXF passed to ' ||
	    'ADD_TXF_TO_LNF') (A);
	GOTO error_return;
    END;	

    first_txf = (first_txfc = leftfirst+nblanks);
    last_txf = (last_txfc = lastch(lnfno));

/* If this is the first TXF, then we have to initialize the font buffer */ 

    IF first_txf THEN DO;
    	using_r = false;
    	CALL initialize_lnf;
    END;

/* The initialization routine computes where the rasters begin in the
output buffer, puts in the blanks, etc. */ 

    DCL (lnf_chardir,ras_beg) FIXED STATIC;
    DCL ras_len_added FIXED; 

    ras_len_added = 0;

/* Now go through all the characters in the TeX font and copy them into the
right position */ 

    DO i = 0 TO 255;
    	IF txfa(txfno) -> chu(i) ^= byte(0)
    	THEN DO;
    	    j = rank(txfa(txfno) -> chu(i));
    	    IF ^using_r & j >= rightfirst THEN DO;
    		CALL write_lnf;
    		PUT SKIP EDIT (',') (A) FILE(outf);
    		using_r = true;
    		CALL initialize_lnf;
    	    END;
    	    CALL copy_char(i,j);
	END;
    END;

/* If this is the last TXF for this LNF, write out the LNF. */

    IF last_txf THEN CALL write_lnf;
    

/* What we have to return is the incremental amount of space that the TXF
takes up in the output font */ 

    PUT EDIT (' with ' || cvis(ras_len_added+4*(txfa(txfno) -> nchs+nblanks)) 
    	|| ' bytes of rasters ') (A);

    RETURN(ras_len_added+4*(txfa(txfno) -> nchs+nblanks));

error_return: 
    RETURN(-1);

rasters_too_big:
    RETURN(-2);

bad_format:
    RETURN(-3);

    read_into_nfta: PROCEDURE;

	DCL nftf FILE;
	DCL nftline CHAR(512) VARYING;

	ON ENDFILE (nftf) GOTO end_of_nftfile;
	ON UNDEFINEDFILE (nftf) BEGIN;
	    PUT SKIP LIST('No such file:' || nftfname);
	    GOTO error_return;
	END;

	nftlen = 0;
	OPEN FILE (nftf) TITLE (nftfname)
	    ENVIRONMENT(Default_file_name('TEX$LN03DIR:AMR10.NFT'))
	    RECORD;

	DO WHILE (true);
	    		    		
	    READ FILE(nftf) INTO (nftline);
	    IF nftlen+length(nftline) > obuflen THEN DO;
	    	PUT SKIP EDIT ('NFT file ' || nftfname || ' too large')
	    		(A);
	    	GOTO error_return;
	    END;
    	    DO i = 1 TO length(nftline);
	    	nfta(nftlen+i-1) = substr(nftline,i,1);
	    END;    	    
	    nftlen = nftlen+length(nftline);
	    
	END;

    end_of_nftfile:
	CLOSE FILE (nftf);

    END read_into_nfta;

/* Copy the character corresponding to FROM out of NFTA and into the LNFR;
update the CHW array. */ 

    copy_char: PROCEDURE (from,to);
    	DCL (from,to,i,j) FIXED;
    	DCL (def_start,rows,columns,quo,len) FIXED;

/* First we need to determine where the character definition for FROM
begins in the NFTA array */ 

    	CALL nft_copy(chardir_offset+(from-nft_first_ch)*4);
    	def_start = longword;

/* For the moment, if there is "no such character", we just stop.
Eventually we should substitute some blank character or something. */ 

    	IF def_start < chardir_offset | def_start > nftlen THEN
        GOTO bad_format;

/* Now we need to check that the rasters are uncompressed. */

    	IF nfta(def_start+17) ^= byte(129) THEN DO;
    	    PUT SKIP EDIT ('Can''t handle compressed rasters') (A);
	    GOTO bad_format;
    	END;

/* Fill in the CHW array. Gutenberg to pixel conversion is necessary (there
are 24 gutenbergs in a pixel), with rounding (hence the 12). */ 

    	CALL nft_copy(def_start+4);
    	chw(lnfno,to) = DIVIDE(longword+12,24,31);

/* Because of the LN03's rounding algorithm, it is necessary also to
change the value being copied to the rounded value */

    	longword = 24*chw(lnfno,to);
        nfta(def_start+4) = substr(chars,1,1);
        nfta(def_start+5) = substr(chars,2,1);
        nfta(def_start+6) = substr(chars,3,1);
        nfta(def_start+7) = substr(chars,4,1);

/* Now we need to compute the size of the rasters, and copy that number of
bytes into LNF as the case may be. */ 

    	rows = rank(nfta(def_start+20))+256*rank(nfta(def_start+21));
    	columns = rank(nfta(def_start+22))+256*rank(nfta(def_start+23));

/* We have to update PSIZE, LSIZE and MSIZE to fill slots in the format. */

    	quo = DIVIDE(rows,8,31);
        IF rows ^= quo*8 THEN quo = quo+1;
        i = quo*columns;
        lsize = lsize+quo*columns;
    	quo = DIVIDE(columns,8,31);
        IF columns ^= quo*8 THEN quo = quo+1;
    	psize = psize+quo*rows;
    	IF i > quo*rows THEN msize = msize+i; ELSE msize = msize+quo*rows;

/* Now do the actual copy */

    	IF MOD(rank(nfta(def_start+16)),2) = 0 THEN len = quo*rows;
    	ELSE len = i;
	len = len+24;
	DO i = 0 TO len-1;
	    lnf(ras_beg+ras_len+i) = nfta(def_start+i);
	END;
	longword = ras_len+ras_beg;
	IF to <= leftlast THEN i = to-leftfirst; ELSE i = to-rightfirst;
	lnf(lnf_chardir+4*i) = substr(chars,1,1);
	lnf(lnf_chardir+4*i+1) = substr(chars,2,1);
	lnf(lnf_chardir+4*i+2) = substr(chars,3,1);
	lnf(lnf_chardir+4*i+3) = substr(chars,4,1);
	ras_len = ras_len+len;
    	ras_len_added = ras_len_added+len;
	IF MOD(ras_len,2) ^= 0 THEN DO;
    	    ras_len = ras_len+1;
	    ras_len_added = ras_len_added+1;
    	END;

    END copy_char;

/* It would be much more efficient if the following were a macro. Later on
maybe we'll do the macro expansion "by hand" in the code. */ 

    nft_copy: PROCEDURE (index);
	DCL index FIXED;

	substr(chars,1,1) = nfta(index);
	substr(chars,2,1) = nfta(index+1);
	substr(chars,3,1) = nfta(index+2);
	substr(chars,4,1) = nfta(index+3);

    END nft_copy;

/* write_lnf performs the last fixups to the lnf buffer and dumps it,
sixelized, into the OUTF. */ 

    write_lnf: PROCEDURE;

	DCL preline CHAR(96);	    
	DCL (i,j,k,rem,quo,ma) FIXED;

/* We now have to fix a number of slots: size of file, length of rasters,
final 'FONT', psize, lsize, msize. */

    	longword = ras_beg+ras_len+8;
    	lnf(0) = substr(chars,1,1);
    	lnf(1) = substr(chars,2,1);
    	lnf(2) = substr(chars,3,1);
    	lnf(3) = substr(chars,4,1);
    	lnf(longword-8) = substr(chars,1,1);
    	lnf(longword-7) = substr(chars,2,1);
    	lnf(longword-6) = substr(chars,3,1);
    	lnf(longword-5) = substr(chars,4,1);
    	lnf(longword-4) = 'F';
    	lnf(longword-3) = 'O';
    	lnf(longword-2) = 'N';
    	lnf(longword-1) = 'T';

/* Length of rasters */

	%REPLACE fnt$l_char_definitions_length BY 156;
    	longword = ras_len;
    	lnf(fnt$l_char_definitions_length) = substr(chars,1,1);
    	lnf(fnt$l_char_definitions_length+1) = substr(chars,2,1);
    	lnf(fnt$l_char_definitions_length+2) = substr(chars,3,1);
    	lnf(fnt$l_char_definitions_length+3) = substr(chars,4,1);

	%REPLACE fnt$l_portrait_byte_count BY 228;
	%REPLACE fnt$l_landscape_byte_count BY 232;
	%REPLACE fnt$l_mixed_byte_count BY 236;

    	longword = psize;
    	lnf(fnt$l_portrait_byte_count) = substr(chars,1,1);
    	lnf(fnt$l_portrait_byte_count+1) = substr(chars,2,1);
    	lnf(fnt$l_portrait_byte_count+2) = substr(chars,3,1);
    	lnf(fnt$l_portrait_byte_count+3) = substr(chars,4,1);

    	longword = lsize;
    	lnf(fnt$l_landscape_byte_count) = substr(chars,1,1);
    	lnf(fnt$l_landscape_byte_count+1) = substr(chars,2,1);
    	lnf(fnt$l_landscape_byte_count+2) = substr(chars,3,1);
    	lnf(fnt$l_landscape_byte_count+3) = substr(chars,4,1);

    	longword = msize;
    	lnf(fnt$l_mixed_byte_count) = substr(chars,1,1);
    	lnf(fnt$l_mixed_byte_count+1) = substr(chars,2,1);
    	lnf(fnt$l_mixed_byte_count+2) = substr(chars,3,1);
    	lnf(fnt$l_mixed_byte_count+3) = substr(chars,4,1);

/* Now sixelize and write the contents of LNF. */ 

	CALL sixelize_and_write(ras_beg+ras_len+8);

	sixelize_and_write: PROCEDURE (howmuch);
	    DCL (howmuch,quo,i,j) FIXED;

	    quo = DIVIDE(howmuch,96,31);
	    IF howmuch > quo*96 THEN quo = quo+1;

	    DO i = 1 TO quo;
		DO j = 1 TO 96;
		    substr(preline,j,1) = lnf(96*(i-1)+j-1);
		END;
		CALL write_preline;
	    END;

	END sixelize_and_write;

	write_preline: PROCEDURE;
	    DCL sixel_line CHAR(128) VARYING;
	    DCL (ix,pllen) FIXED;

	    pllen = 96;

	    ix = 1;
	    sixel_line = copy('?',128);
	    DO i = 1 TO pllen BY 3;
		DCL cha CHAR(1);
		DCL chb BIT(8) BASED (addr(cha));
		DCL chc FIXED(7) BASED (addr(cha));
		DCL ocha CHAR(1);
		DCL ochb BIT(8) BASED(addr(ocha));

		chc = 0;
		ocha = substr(preline,i,1);
		substr(chb,1,6) = substr(ochb,3,6);
		chc = chc + 63;
		substr(sixel_line,ix,1) = cha;
		ix = ix+1;
		chc = 0;
		substr(chb,5,2) = substr(ochb,1,2);
		ocha = substr(preline,i+1,1);
		substr(chb,1,4) = substr(ochb,5,4);
		chc = chc + 63;
		substr(sixel_line,ix,1) = cha;
		ix = ix+1;
		chc = 0;
		substr(chb,3,4) = substr(ochb,1,4);
		ocha = substr(preline,i+2,1);
		substr(chb,1,2) = substr(ochb,7,2);
		chc = chc + 63;
		substr(sixel_line,ix,1) = cha;
		ix = ix+1;
		chc = 0;
		substr(chb,1,6) = substr(ochb,1,6);
		chc = chc + 63;
		substr(sixel_line,ix,1) = cha;
		ix = ix+1;
	    END;
	    PUT SKIP EDIT (sixel_line) (A) FILE(outf);

	END write_preline;

    END write_lnf;

/* Initializes the LNF buffer. */

    initialize_lnf: PROCEDURE;

	DCL (i,j) FIXED;

/* The following array holds good values for bytes 0-479 of an LN03 format
font. */ 

	DCL good_opening(0:511) FIXED STATIC INIT(
	    104,38,0,0,70,79,78,84,
	    1,0,0,0,31,0,0,0,
	    20,0,0,0,85,48,48,48,
	    48,48,48,48,48,50,83,75,
	    48,48,71,71,48,48,48,49,
	    85,90,90,90,90,48,50,70,
	    48,48,48,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    181,7,9,0,11,0,14,0,
	    0,0,0,0,104,0,0,0,
	    252,0,0,0,124,0,0,0,
	    100,1,0,0,120,1,0,0,
	    224,1,0,0,4,0,0,0,
	    88,3,0,0,0,0,0,0,
	    92,3,0,0,48,0,0,0,
	    92,3,0,0,0,0,0,0,
	    140,3,0,0,212,34,0,0,
	    140,3,0,0,33,0,0,0,
	    126,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    32,0,0,0,168,0,0,0,
	    16,0,0,0,94,0,0,0,
	    0,0,0,0,94,0,0,0,
	    0,0,0,0,94,0,0,0,
	    0,0,0,0,236,25,0,0,
	    54,25,0,0,14,27,0,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,2,0,0,0,
	    7,0,0,0,92,3,0,0,
	    7,0,0,0,99,3,0,0,
	    16,0,0,0,106,3,0,0,
	    16,0,0,0,122,3,0,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    10,0,0,0,244,1,0,0,
	    0,0,24,0,16,0,0,0,
	    16,0,0,0,1,0,1,0,
	    1,0,1,0,0,0,1,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,
	    30,0,0,0,20,0,0,0,
	    196,255,255,255,20,0,0,0,
	    106,255,255,255,20,0,0,0,
	    0,0,1,0,0,0,30,0,
	    166,255,255,255,0,0,0,0,
	    40,0,0,0,0,0,0,0,
	    60,0,0,0,240,0,0,0,
	    60,0,0,0,100,0,0,0,
	    240,0,0,0,120,0,0,0,
	    40,0,0,0,120,0,0,0,
	    96,255,255,255,136,255,255,255,
	    186,255,255,255,240,0,0,0,
	    76,255,255,255,60,0,0,0,
	    160,0,0,0,120,0,0,0,
	    20,0,0,0,20,0,0,0,
	    140,3,0,0,194,3,0,0,
	    244,3,0,0,160,4,0,0,
	    254,4,0,0,162,5,0,0,
	    46,6,0,0,84,6,0,0);

	lnf_chardir = 480; /* Fixed */

 /* Clear out LNF */

	lnf = byte(0); 
    	ras_len = 0;
    	psize = 0;
    	lsize = 0;
    	msize = 0;

 /* Copy the good values into LNF */

	DO i = 0 TO 479;
	    lnf(i) = byte(good_opening(i));
	END;

 /* Set the last character if necessary */ 

	IF lastch(lnfno) < leftlast & ^using_r
    	THEN lnf(fnt$l_first_character+4) = byte(lastch(lnfno));
	IF using_r
    	THEN lnf(fnt$l_first_character+4) = byte(lastch(lnfno)-rightfirst+
    	    leftfirst);

 /* Set the character counts */

	%REPLACE fnt$l_infile_locators BY 204;
	%REPLACE fnt$l_character_definitions BY 212;
	%REPLACE fnt$l_raster_count BY 220;

    	i = rank(lnf(fnt$l_first_character+4))-
    		rank(lnf(fnt$l_first_character))+1;
	ras_beg = lnf_chardir + 4*i + 4 + 48;
	lnf(fnt$l_infile_locators) = byte(i);
	lnf(fnt$l_character_definitions) = byte(i);
	lnf(fnt$l_raster_count) = byte(i);

/* Set the font file id. The font family is dependent on the value of
LNFNO, U0000nn where nn is LNFNO possibly with a leading zero. The
character set is 1O if USING_R, otherwise the default from GOOD_OPENING. */

    	%REPLACE fnt$t_font_file_id BY 20;

	lnf(fnt$t_font_file_id+5) = byte(DIVIDE(lnfno,10,31)+rank('0'));
	lnf(fnt$t_font_file_id+6) = byte(MOD(lnfno,10)+rank('0'));
	IF using_r 
	THEN lnf(fnt$t_font_file_id+20) = 'O';

/* Set various offsets which are dependent on the number of characters in
the font file. */ 

	%REPLACE fnt$a_subset_tables BY 128;
        longword = lnf_chardir+4*i;
	lnf(fnt$a_subset_tables) = substr(chars,1,1);
	lnf(fnt$a_subset_tables+1) = substr(chars,2,1);
	lnf(fnt$a_subset_tables+2) = substr(chars,3,1);
	lnf(fnt$a_subset_tables+3) = substr(chars,4,1);

	longword = longword+4;
	lnf(fnt$a_subset_tables+8) = substr(chars,1,1);
	lnf(fnt$a_subset_tables+9) = substr(chars,2,1);
	lnf(fnt$a_subset_tables+10) = substr(chars,3,1);
	lnf(fnt$a_subset_tables+11) = substr(chars,4,1);
	lnf(fnt$a_subset_tables+16) = substr(chars,1,1);
	lnf(fnt$a_subset_tables+17) = substr(chars,2,1);
	lnf(fnt$a_subset_tables+18) = substr(chars,3,1);
	lnf(fnt$a_subset_tables+19) = substr(chars,4,1);

	longword = longword+48;
	lnf(fnt$a_subset_tables+24) = substr(chars,1,1);
	lnf(fnt$a_subset_tables+25) = substr(chars,2,1);
	lnf(fnt$a_subset_tables+26) = substr(chars,3,1);
	lnf(fnt$a_subset_tables+27) = substr(chars,4,1);

	%REPLACE fnt$a_char_definitions BY 160;
	lnf(fnt$a_char_definitions) = substr(chars,1,1);
	lnf(fnt$a_char_definitions+1) = substr(chars,2,1);
	lnf(fnt$a_char_definitions+2) = substr(chars,3,1);
	lnf(fnt$a_char_definitions+3) = substr(chars,4,1);

/* Set up the string pool (48 bytes). */

	DCL pool_beg FIXED;

	pool_beg = ras_beg-48;
	
	lnf(pool_beg) = '0';
	IF using_r THEN lnf(pool_beg+1) = '<'; ELSE lnf(pool_beg+1) = 'B';
	lnf(pool_beg+2) = byte(9);	    
	lnf(pool_beg+3) = 'Z';	    
	lnf(pool_beg+4) = 'Z';	    
	lnf(pool_beg+5) = 'Z';	    
	lnf(pool_beg+6) = 'Z';

	DO i = 1 TO 7;
	    lnf(pool_beg+7+i-1) = lnf(fnt$t_font_file_id+i-1);
	END;
	DO i = 1 TO 16;
	    lnf(pool_beg+7+7+i-1) = ' ';
	END;
	DO i = 1 TO 16;
	    lnf(pool_beg+7+7+16+i-1) = lnf(fnt$t_font_file_id+i-1);
	END;

/* Now make string descriptors point into the string pool. */
	%REPLACE fnt$a_char_set BY 260;
	%REPLACE fnt$a_family_id BY 268;
	%REPLACE fnt$a_family_name BY 276;
	%REPLACE fnt$a_font_id BY 284;

        longword = pool_beg;
	lnf(fnt$a_char_set) = substr(chars,1,1);
	lnf(fnt$a_char_set+1) = substr(chars,2,1);
	lnf(fnt$a_char_set+2) = substr(chars,3,1);
	lnf(fnt$a_char_set+3) = substr(chars,4,1);
        longword = pool_beg+7;
	lnf(fnt$a_family_id) = substr(chars,1,1);
	lnf(fnt$a_family_id+1) = substr(chars,2,1);
	lnf(fnt$a_family_id+2) = substr(chars,3,1);
	lnf(fnt$a_family_id+3) = substr(chars,4,1);
        longword = pool_beg+7+7;
	lnf(fnt$a_family_name) = substr(chars,1,1);
	lnf(fnt$a_family_name+1) = substr(chars,2,1);
	lnf(fnt$a_family_name+2) = substr(chars,3,1);
	lnf(fnt$a_family_name+3) = substr(chars,4,1);
        longword = pool_beg+7+7+16;
	lnf(fnt$a_font_id) = substr(chars,1,1);
	lnf(fnt$a_font_id+1) = substr(chars,2,1);
	lnf(fnt$a_font_id+2) = substr(chars,3,1);
	lnf(fnt$a_font_id+3) = substr(chars,4,1);

/* Mercifully, all remaining font file slots that we can fill now are
already good as received from GOOD_OPENING. */ 

    END initialize_lnf;

END add_txf_to_lnf;