summaryrefslogtreecommitdiff
path: root/systems/msdos/vga2mf/vga2mf.c
blob: f728f388514921f5b9d36b47497e6194e610947e (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
/* VGA2MF.C is Copyright 1990 Humanities and Arts Computing Center */
/* usage: vga2mf [vgafontname] [metafont_sourcecode_output_file] */
/* suggestions to ridgeway@blake.acs.washington.edu */

/* history: */
/* v. 1.0 released 4/25/1990 */
/* this is a minimally modified version of Ega2mf */
/* modifications to handle larger VGA character cell */
/* one might also modify egamf to accept a -v switch */
/* to permit one program to do both */
/* but _we_ didn't do it that way because . . . */
/* "So many programs, so little time . . . */

#include <stdio.h>
#include <string.h>



/* the charblock structure is used for processing each character */
typedef struct {
               unsigned char column[8];
               } videorow;
typedef struct {
                videorow row[16];
               } charblock;

/* the vga font is a naked 8x16 bitmap 256 chars deep */
typedef struct {
                unsigned char bitmap[16];
                } vgachar;

typedef struct {
	       vgachar charset[256];
               } vgafont;

/* globally accessible area */
charblock editchar;
/* global vars  and strings */
char infilename[128];
char outfilename[128];

jumpout() { exit(1); }

void copyright()
{
  puts("VGA2Mf  Screen font --> METAFONT code generator\n");
  puts("HUMANITIES AND ARTS COMPUTING CENTER, DR-10");
  puts("UNIVERSITY OF WASHINGTON, SEATTLE WA 98195 USA\n");
  puts("Copyright 1990 Humanities and Arts Computing Center\n");
  puts("This software may be used, modified, and redistributed free of any");
  puts("fee or royalty, provided that this copyright and 'free software' notice");
  puts("remains intact in any copies redistributed, and that you may charge no fee");
  puts("of any sort whatsoever without the written permission of the Humanities");
  puts("and Arts Computing Center.");
  return;
}


void exists (char *filename) 
  { 
    unsigned char response;
    FILE *handle;
    handle = fopen ( filename , "rb" ) ; 
    if (handle != (FILE *) NULL) 
       {  fclose(handle);
          printf("File %s already exists: O.K. to replace? (Y/N): ", filename);
          response = getchar();
          if ( ! ( (response=='y') || (response=='Y') ) ) 
            {
            printf("\nPlease rename files as necessary and try again.\n");
            jumpout();
            }
       }
    return;
    } 

FILE *getopen(char *filename, char *access)
{
	int	temp;
	FILE	*handle;
	gets(filename);
	if (access[0]=='w' || access[0]=='W') exists(filename);  
	handle=fopen(filename,access);
	if (handle == NULL) {
	  puts("\nCan't open file ");
	  puts(filename);
	  puts("\n");
	  }
	return handle;
}

FILE *get_file(char *access,char *prompt,char *filename)
{
	printf("\n %s",prompt);
	return getopen(filename,access);
}

void makedisplay(unsigned char thischar, vgafont *thisfont)
{
  int temp,mask,i,k,hold;
  for (i=0; i<16; i++) {
    temp=thisfont->charset[thischar].bitmap[i];
    mask=0x80;
    for (k=0; k<8; k++) {
      hold=temp & mask;
      if (hold==0) editchar.row[i].column[k]=0;
      else editchar.row[i].column[k]=1;
      mask=mask / 2;
    } /* endfor k */
  } /* endfor i */
  return;
}


main(int argc, char *argv[])
{
  FILE *f1=(FILE *) NULL;
  FILE *f2=(FILE *) NULL;
  int done,ch,i,k,codeout;
  char quote,percent;
  vgafont *thisvga;
  quote=34;
  percent=37;
  /* yes, yes! we are assuming the ASCII character set */
  copyright();
  thisvga = (vgafont *) malloc(sizeof(vgafont));
  if (argc > 1) {
    f1 = fopen(argv[1],"rb");
    (void) strcpy(infilename,argv[1]);
    }
  if (f1 == (FILE *) NULL) {
	/* prompt for and open input file */
	for ( ; f1 == (FILE *) NULL; f1=get_file("rb","Enter name of input vga font file: ",infilename)) ;
	}
  fread(thisvga,sizeof(vgafont),1,f1);
  fclose(f1);
  if (argc > 2) {
    (void) strcpy(outfilename,argv[2]);
    exists(outfilename);
    f2 = fopen(argv[2],"w");
    }
  if (f2 == (FILE *) NULL) {
	/* prompt for and open output file */
	for ( ; f2 == (FILE *) NULL; f2=get_file("w","Enter name of output Metafont source file: ",outfilename)) ;
	}
   fprintf(f2,"%c This is %s generated by VGA2MF from %s.\n",percent,outfilename,infilename);
   fprintf(f2,"if unknown cmbase: input cmbase fi\n");
   fprintf(f2,"mode_setup;\n");
   fprintf(f2,"def generate suffix t= enddef;\n");
   fprintf(f2,"input cmtt10; font_setup;\n");
   fprintf(f2,"if ligs>1: font_coding_scheme:=%cTeX text%c;\n",quote,quote);
   fprintf(f2,"else: font_coding_scheme:=if ligs=0: %cTeX typewriter text%c\n",quote,quote);
   fprintf(f2,"  else: %cTeX text without f-ligatures%c fi; fi \n",quote,quote);
   fprintf(f2,"numeric cheight; cheight=body_height+desc_depth;\n");
   fprintf(f2,"numeric hhalf; numeric vhalf; hhalf=.4u; vhalf=(cheight)/36;\n");
   fprintf(f2,"numeric vcent; vcent=cheight/32; numeric hcent; hcent=9/16u;\n");
   fprintf(f2,"def crt(expr row,col) =\n");
   fprintf(f2,"y.c:=body_height-(row * cheight / 16)-vcent; x.c:=hcent+(col * 9/8u);\n");
   fprintf(f2,"y.a:=y.c+vhalf; y.b:=y.c-vhalf;\n");
   fprintf(f2,"x.a:=x.c-hhalf; x.b:=x.c+hhalf;\n");
   fprintf(f2,"filldraw (x.a,y.b)..(x.a,y.a)..(x.b,y.a)..(x.b,y.b)..cycle;\n");
   fprintf(f2,"enddef;\n");
   printf("Now processing character ");
   for (ch=0; ch<256; ch++) {
     /* generate code for character ch */
     if ( (ch < 32) || (ch > 126) ) printf("[%d] ",ch);
     else printf("[%c] ",ch);
     fprintf(f2,"\nbeginchar(%d,9u#,body_height#,desc_depth#);",ch);
     fprintf(f2,"adjust_fit(0,0);\npickup pencircle scaled 0.2pt;\n");
     makedisplay(ch,thisvga);
     for(i=0; i < 16; i++) {
        codeout=0;
        for(k=0; k<8; k++) {
	    if (editchar.row[i].column[k] != 0) {
                fprintf(f2,"crt(%d,%d); ",i,k);
                codeout=1;
                } /* endif set dot on */
        } /* end k */
        if (codeout > 0) fprintf(f2,"\n");
     } /* endfor i */
     fprintf(f2,"endchar;\n");
     if ( ( ch % 16 ) == 0 ) printf("\n");
   } /* endfor ch */
   fprintf(f2,"\n");
   fprintf(f2,"font_slant slant; font_x_height x_height#;\n");
   fprintf(f2," font_normal_space 9u#;\n");
   fprintf(f2," font_quad 18u#;\n");
   fprintf(f2," font_extra_space 9u#;\n");
   fprintf(f2,"bye.\n");
   printf("\nVGA2MF is done.  Good luck with your new font.\n");
   fclose(f2);
}