GET "FED.DEFS"

LET READFONT() BE	//READ INTO CURRENT FONT
[
	LET V = VEC 50
	WS("*NINPUT FONT FILE: ")
	IF NOT GETKEYST(V) THEN RETURN
	LET STR = OPENAFILE(V,0)
	IF STR EQ 0 THEN [ WS("*NNO SUCH FILE !"); RETURN ] 
	LET WORDX = FONT-2

	UNTIL ENDOFS(STR) DO
	[
		RV WORDX = GETS(STR);WORDX = WORDX + 1
	]
	WS (FORMATN("*N <D> WORDS",WORDX-FONT+2))
	CLOSEAFILE(STR)
]

AND WRITEFONT() BE
[
	LET V = VEC 50
	WS("*NOUTPUT FONT FILE: ")
	IF NOT GETKEYST(V) THEN RETURN
	LET STR = GETAFILE(V,1)
	GETHW()
	LET MAXWORD = GETLAST()
	FOR I= FONT-2 TO MAXWORD DO PUTS(STR,RV I)
	CLOSEAFILE(STR)
]



AND GETHW() BE
[
	RV(FONT-1)=0	//WIDTH
	RV(FONT-2)=0	//HEIGHT
	FOR I=0 TO 377B DO
	[
		LET W = GETHWX(I)
		IF W GR RV(FONT-1) THEN RV(FONT-1)=W
 	]
]


AND GETHWX(CHAR) = VALOF
[
	LET P = FONT+CHAR+FONT!CHAR
	LET HGT = (RV (P+1) RSHIFT 8) + (RV(P+1) & 177B)
	IF HGT GR RV(FONT-2) THEN RV(FONT-2) = HGT
	IF ((RV P) & 1) NE 0 THEN RESULTIS (RV P) RSHIFT 1
	RESULTIS 16+ GETHWX(RV P RSHIFT 1)
]


AND CUOUT() BE	//OUTPUT IN CU FORMAT,MAGNIFIED 7 TIMES
[
	LET V = VEC 50
	WS("*N.CU FORMAT OUTPUT FILE: ")
	IF NOT GETKEYST(V) THEN RETURN
	LET STR = GETAFILE(V,1)

	GETHW()	//SET HEIGHT AND WIDTH
	PUTS(STR, BOXSIZE*RV(FONT-2))	//OUTPUT HEIGHT IN BITS
	LET WORDW = (BOXSIZE*RV(FONT-1))/16 +1
	PUTS(STR, WORDW)  //WIDTH IN WORDS

	GAP = 0
	FOR I = 0 TO 377B DO
	[
		LET P = FONT+I+FONT!I
		//DUMMY CHARACTER (0 WIDTH) DO NOT PUT OUT
		IF RV (P) EQ 1 THEN LOOP
		IF ((RV(P) & 1) EQ 1) & ((RV(P+1) & #477) EQ 0) THEN LOOP

//PUT THE CHARACTER ONTO THE SCREEN, FROM WHICH IT WILL BE OUTPUT
		BSTORE(FARRAY,0,FHMAX*FWMAX)
		FCHEIGHT = 0
		FCWIDTH = COPYCH(I,FARRAY)
		BUILDCHAR()
//NOW WE HAVE THE CHARACTER IN FARRAY AND IN THE DISPLAY AREA

		PUTS(STR,I)	//OUTPUT THE CHARACTER CODE
		PUTS(STR,FCWIDTH*BOXSIZE)  //WIDTH OF THIS CHARACTER IN BITS
		FOR J = 0 TO BOXSIZE*RV(FONT-2)-1 DO  //FOR ALL SCAN LINES
		[
			LET OFFS = DISPLAYAREA+(CTOPMARGIN+J)*NWRDS + LWMARGIN
			FOR K = 0 TO WORDW-1 DO 
			PUTS(STR,RV(OFFS+K))
		]
	]
	GAP = 1
	CLOSEAFILE(STR)
]



AND GETKEYST(V) = VALOF
[
	V>>STR.LENGTH = 0
	[
		LET CHAR = GETCHAR()
		SWITCHON CHAR INTO
		[
			CASE $*N:	BREAK
			CASE 33B:	RESULTIS 0
			CASE 10B:	//BACKSPACE
				IF V>>STR.LENGTH GR 0 DO
				[
					PUTS(DSP, $/)
					PUTS(DSP, V>>STR.CHAR↑(V>>STR.LENGTH))
					(V>>STR.LENGTH)= (V>>STR.LENGTH)-1
				]
				ENDCASE
			DEFAULT:	PUTS(DSP,CHAR)
				V>>STR.LENGTH = V>>STR.LENGTH+1
				V>>STR.CHAR↑(V>>STR.LENGTH) = CHAR
		]
	] REPEAT
	RESULTIS V>>STR.LENGTH
]