/* Font Compiler v1.0 Convert a GEM font to Ansi-C source Originally written by F. Arnaud, 3/91 It is Public Domain, so you can do what you want this source (copy, sell, eat, etc..) */ #include /* AES defs, includes WORD definition */ #include #include #include "gemfont.h" /* GEM font header, if you don't have it you're screwed */ char *malloc(long ); main(int argc,char **argv) { GEM_FONT font; char *font_data; WORD data_size; WORD *offsets_horiz; WORD *offsets_char; FILE *stream; char outfile[100]; if(argc!=2 && argc!=3) printf("\nUsage: fontcomp fontname.fnt [srcename.c]\n" " \\- Compiles a GEM font to a C source\n\n"); else { /* Welcome */ printf("Public Domain GEM Font Compiler v1.0\n"); /* parameters */ if(argc==3) strcpy(outfile,argv[2]); else strcpy(outfile,"FONT.C"); /* Open font file */ stream=fopen(argv[1],"rb"); if(stream) { /* Get data size */ fseek(stream,0,SEEK_END); data_size=ftell(stream)-sizeof(GEM_FONT); fseek(stream,0,SEEK_SET); font_data=malloc(data_size); if(font_data) /* Valid ? */ { if(fread(&font,sizeof(GEM_FONT),1,stream)==1) { if(fread(font_data,data_size,1,stream)==1) { if(!(font.flag & 4)) /* Intel or Motorola format */ { printf("Intel format is not supported, you're screwed!\n"); return 1; /* It's up to you to write the Intel format support :-) In fact you can remove this test and FONTCOMP will compile output a C source with an Intel format font, but your program will have some work to do ... */ } if(output_source(outfile,&font,font_data)) printf("Can't write C file.\n");; } else printf("Can't read font data.\n"); } else printf("Can't load font header.\n"); } else printf("Not enough memory (very big font or little ST).\n"); fclose(stream); } else printf("Can't open font file.\n"); /* Structured programming is fun */ printf("Done.\n"); } return 0; /* "Ok" */ } /* Output the source file */ int output_source(char *out, GEM_FONT *f, char *data) { FILE *str; char name_string[33]; char *temp; name_string[32]=0; strcpy(name_string,f->name); if((str=fopen(out,"w"))!=NULL) { /* It starts */ fprintf(str,"/* Gemdos font converted by FontComp */\n"); fprintf(str,"\n#include \"gemfont.h\"\n\n"); /* offset tables */ if(f->horiz_off!=NULL) /* if available */ output_wtable(str,"offsets_horiz", (WORD *)(data + (long)f->horiz_off - (long)sizeof(GEM_FONT)), f->hiasc - f->loasc +1); output_wtable(str,"offsets_char", (WORD *) (data + (long)f->char_off - (long)sizeof(GEM_FONT)), f->hiasc - f->loasc +1); /* char tables */ output_ctable(str,"font_data", data + (long)f->data - (long)sizeof(GEM_FONT), (long)f->width*f->height); /* The Header */ fprintf(str,"\nGEM_FONT the_font = {\n"); /* Id+Size */ fprintf(str," 0x%x, 0x%x,\n",f->id,f->size); /* name */ fprintf(str," \"%s\",\n",name_string); /* 17 words */ fprintf(str," 0x%x, 0x%x,\n",f->loasc,f->hiasc); fprintf(str," 0x%x, 0x%x, 0x%x, 0x%x, 0x%x,\n", f->topline, f->ascent,f->halfline, f->descent, f->bottomline); fprintf(str," 0x%x, 0x%x,\n", f->wchar, f->wcell); fprintf(str," 0x%x, 0x%x,\n",f->left_off,f->right_off); fprintf(str," 0x%x, 0x%x,\n",f->thickening,f->underline); fprintf(str," 0x%x, 0x%x,\n",f->lightening,f->skewing); fprintf(str," 0x%x,\n",f->flag); /* Offset tables */ if(f->horiz_off) fprintf(str," offsets_horiz,\n"); else fprintf(str," NULL,\n"); fprintf(str," offsets_char,\n"); /* Font data */ fprintf(str," font_data,\n"); /* Width+Height */ fprintf(str," 0x%x, 0x%x,\n",f->width,f->height); /* No link */ fprintf(str," (unsigned char *) 0 };\n\n"); fclose(str); } else return 1; return 0; } /* Output a table of WORDs */ output_wtable(FILE *s, char *name, WORD *data, WORD number) { WORD nb,line; fprintf(s,"WORD %s[] = {\n ",name); nb=number; line=8; do { fprintf(s,"0x%x,",*data); nb--; data++; if(--line==0) { fprintf(s,"\n "); line=8; } } while(nb); fprintf(s,"0 };\n\n"); } /* Output a table of chars */ output_ctable(FILE *s, char *name, char *data, long number) { WORD nb,line; fprintf(s,"char %s[] = {\n ",name); nb=number; line=16; do { fprintf(s,"%d,",(int)*data); nb--; data++; if(--line==0) { fprintf(s,"\n "); line=16; } } while(nb); fprintf(s,"0 };\n\n"); } /* eof */