#include #include #include #include #include typedef struct { char CharSet; char CodeType; unsigned Code; char FontID[4]; int FontWidth; int FontHeight; int reserve; int VerOff; int HorOff; unsigned char far *Buffer; int WidthByte; int Attrib; int ShadowType; int HorDepth; int VerDepth; int OutlineWidth; int ItalicAmount; int RotateAngle; int MeshVerOff; int MeshHorOff; int MeshWidth; int MeshHeight; unsigned char far *Mesh; int ClipLeft; int ClipRight; int ClipTop; int ClipBottom; int BufferWidth; int BufferHeight; int SystemData[6]; } DynaPara; #define INT_AX 0xfdfd #define GETBMP 0 #define QUERYBMP 5 #define GET_ILL 0x02 #define GET_NOTYPE 0x04 #define GET_TOHI 0x05 #define GET_TOWIDE 0x06 #define GET_WRATTR 0x08 #define GET_EMPCHAR 0x0c #define GET_UNKNOW 0xff #define CS_ENG 0 #define CS_CHI 1 #define CS_JP 2 #define CS_KR 3 #define CT_BIG 0 #define CT_CNS 1 #define CT_TCA 2 #define CT_IBM 3 #define ATTR_RIT 0x0008 #define ATTR_LIT 0x0010 union REGS regs; struct SREGS sregs; DynaPara far *para; unsigned char far *buffer; FILE *fp,*tmpfp; unsigned int i,j,k,l; int font_size; char tmpstr[200]; char dyna_type[4]; int italic=0; char font_name[20]; short (far *DynaSub)(); void init(); void main(int argc,char *argv[]) { int result; int dynafunct; unsigned int font_num; unsigned int buf_ptr; if (argc < 6) { printf ("Usage: DYNABDF dyna_type [I|N] font_size font_name filename\n"); return; } strcpy (tmpstr,argv[1]); strcpy (dyna_type," "); printf ("dyna_type : %s strlen : %d\n",tmpstr,strlen(tmpstr)); switch (strlen (tmpstr)) { case 1 : dyna_type[3] = tmpstr[0]; break; case 2 : dyna_type[3] = tmpstr[1]; dyna_type[2] = tmpstr[0]; break; case 3 : dyna_type[3] = tmpstr[2]; dyna_type[2] = tmpstr[1]; dyna_type[1] = tmpstr[0]; break; default : dyna_type[3] = tmpstr[3]; dyna_type[2] = tmpstr[2]; dyna_type[1] = tmpstr[1]; dyna_type[0] = tmpstr[0]; } printf("font type : %c%c%c%c\n",dyna_type[0],dyna_type[1],dyna_type[2],dyna_type[3]); if ((argv[2][0] == 'I') || (argv[3][0] == 'i')) italic = 4; font_size = atoi(argv[3]); strcpy (font_name,argv[4]); if ((fp = fopen(argv[5],"wb"))==NULL) { printf ("Error Open output file\n"); exit(1); } if ((tmpfp = fopen("dynabdf.tmp","wr")) == NULL) { printf ("Error Open temp file \n"); exit(1); } font_num = 0; if ((para = farmalloc (sizeof (DynaPara)))==NULL) { printf ("Error allocate memory for Parameter block.\n"); exit(1); }; init(); fprintf (fp,"STARTFONT 2.1\n"); fprintf (fp,"COMMENT\n"); fprintf (fp,"COMMENT TWMOE Chinese font\n"); fprintf (fp,"COMMENT This font is original in Dynalab font format and converted to BDF\n"); fprintf (fp,"COMMENT The original font(in DynaFont format) is released by\n"); fprintf (fp,"COMMENT Taiwan Ministry Of Education for general public use.\n"); fprintf (fp,"COMMENT You can get the original DynaFont format font from\n"); fprintf (fp,"COMMENT ftp://moers2.edu.tw/chinese-pub/chinese-sys/kuh/\n"); fprintf (fp,"COMMENT The program I used to convert these is not yet completed\n"); fprintf (fp,"COMMENT for release. If you are intrested in it please e-mail\n"); fprintf (fp,"COMMENT Wukai.bbs@bbs.csie.nctu.edu.tw.\n"); fprintf (fp,"COMMENT FONT twome_%s\n",font_name); if (italic == 4) fprintf (fp,"FONT -twmoe-%s-medium-i-normal--%d-%d0-75-75-c-%d0-Big5-1\n",font_name,font_size,font_size,font_size); else fprintf (fp,"FONT -twmoe-%s-medium-r-normal--%d-%d0-75-75-c-%d0-Big5-1\n",font_name,font_size,font_size,font_size); fprintf (fp,"SIZE %d 75 75\n",font_size); fprintf (fp,"FONTBOUNDINGBOX %d %d 0 -%d\n",font_size,font_size,(font_size +5)/12); fprintf (fp,"COMMENT\n"); fprintf (fp,"COMMENT Begin Logical Font Description -- 20 special properties for this FONT\n"); fprintf (fp,"COMMENT\n"); fprintf (fp,"STARTPROPERTIES 20\n"); fprintf (fp,"FONTNAME_REGISTRY \"\"\n"); fprintf (fp,"FOUNDRY \"twmoe\"\n"); fprintf (fp,"FAMILY_NAME \"%s\"\n",font_name); fprintf (fp,"WEIGHT_NAME \"medium\"\n"); if (italic == 4) fprintf (fp,"SLANT \"i\"\n"); else fprintf (fp,"SLANT \"r\"\n"); fprintf (fp,"SETWIDTH_NAME \"normal\"\n"); fprintf (fp,"ADD_STYLE_NAME \"\"\n"); fprintf (fp,"PIXEL_SIZE %d\n",font_size); fprintf (fp,"POINT_SIZE %d0\n",font_size); fprintf (fp,"RESOLUTION_X 75\n"); fprintf (fp,"RESOLUTION_Y 75\n"); fprintf (fp,"SPACING \"c\"\n"); fprintf (fp,"AVERAGE_WIDTH %d0\n",font_size); fprintf (fp,"CHARSET_REGISTRY \"Big5\"\n"); fprintf (fp,"CHARSET_ENCODING \"1\"\n"); fprintf (fp,"FONT_ASCENT %d\n",(font_size - ((font_size+5))/12)); fprintf (fp,"FONT_DESCENT %d\n",(font_size +5)/12); fprintf (fp,"DEFAULT_CHAR 41280\n"); fprintf (fp,"COMMENT 0xA140 is the Space character.\n"); fprintf (fp,"COPYRIGHT \"Taiwan Ministry Of Education Standard Chinese Chars Ming & Kai style\"\n"); fprintf (fp,"NOTICE \"This font is orignal in Dynafont,and have been converted to BDF\"\n"); fprintf (fp,"ENDPROPERTIES\n"); dynafunct = GETBMP; for (i = 0xa1 ;i< 0xfe; i++) { for (j = 0x40 ;j < 0x7f; j++) { para->Code = i * 256 + j; asm { push ES push DI push AX mov AX,dynafunct; les DI,para } DynaSub(); asm { mov result,AX pop AX pop DI pop ES } switch (result) { case 0 : font_num++; fprintf (tmpfp,"STARTCHAR C%02x%02x\n",(unsigned char) i,(unsigned char) j); fprintf (tmpfp,"ENCODING %u\n",i*256+j); fprintf (tmpfp,"SWIDTH 666 0\n"); fprintf (tmpfp,"DWIDTH %d 0\n",font_size); fprintf (tmpfp,"BBX %d %d 0 -%d\n",font_size,font_size,(int)(font_size+5)/12); fprintf (tmpfp,"BITMAP\n"); buf_ptr = 0; for (k = 0; k < font_size; k++) { for (l = 0; l < para->WidthByte; l++) { fprintf (tmpfp,"%02X",buffer[buf_ptr]); buffer[buf_ptr++] = 0; } fprintf (tmpfp,"\n"); } fprintf (tmpfp,"ENDCHAR\n"); break; case GET_ILL : printf ("Illegal Parameter.\n"); exit(1); case GET_NOTYPE : printf ("Font Type Not exist.\n"); exit(1); case GET_TOHI : printf ("Font Height Too Large.\n"); exit(1); case GET_TOWIDE : printf ("Font Width Too Large.\n"); exit(1); case GET_WRATTR : printf ("Attribute Error.\n"); exit (1); case GET_EMPCHAR : printf ("Char %02X%02X dose not exist\n",i,j); break; case GET_UNKNOW : printf ("Unknown Error\n"); exit(1); } } for (j = 0xa1;j < 0xff; j++) { para->Code = i * 256 + j; asm { push ES push DI push AX mov AX,dynafunct; les DI,para } DynaSub(); asm { mov result,AX pop AX pop DI pop ES } switch (result) { case 0 : font_num++; fprintf (tmpfp,"STARTCHAR C%02x%02x\n",(unsigned char) i,(unsigned char) j); fprintf (tmpfp,"ENCODING %u\n",i*256+j); fprintf (tmpfp,"SWIDTH 666 0\n"); fprintf (tmpfp,"DWIDTH %d 0\n",font_size); fprintf (tmpfp,"BBX %d %d 0 -%d\n",font_size,font_size,(int)(font_size+5)/12); fprintf (tmpfp,"BITMAP\n"); buf_ptr = 0; for (k = 0; k < font_size; k++) { for (l = 0; l < para->WidthByte; l++) { fprintf (tmpfp,"%02X",buffer[buf_ptr]); buffer[buf_ptr++]=0; } fprintf (tmpfp,"\n"); } fprintf (tmpfp,"ENDCHAR\n"); break; case GET_ILL : printf ("Illegal Parameter.\n"); exit(1); case GET_NOTYPE : printf ("Font Type Not exist.\n"); exit(1); case GET_TOHI : printf ("Font Height Too Large.\n"); exit(1); case GET_TOWIDE : printf ("Font Width Too Large.\n"); exit(1); case GET_WRATTR : printf ("Attribute Error.\n"); exit (1); case GET_EMPCHAR : printf ("Char %02X%02X dose not exist\n",i,j); break; case GET_UNKNOW : printf ("Unknown Error\n"); exit(1); } } } fprintf (fp,"CHARS %u\n",font_num); fclose (tmpfp); if ((tmpfp = fopen("dynabdf.tmp","rb")) == NULL) { printf ("Error Open temp file \n"); exit(1); } while (fgets(tmpstr,199,tmpfp)!=NULL) { fprintf (fp,tmpstr); } fprintf (fp,"ENDFONT\n"); fprintf (fp,"COMMENT %d chars\n",font_num); printf ("Total font : %d",font_num); } void init() { if ((para = farmalloc (sizeof (DynaPara)))==NULL) { printf ("Error allocate memory for Parameter block\n"); exit(1); }; regs.x.ax = 0xfdfd; intdosx (®s,®s,&sregs); FP_SEG(DynaSub) = sregs.es; FP_OFF(DynaSub) = regs.x.bx; printf ("Dynalab Font driver found at %04X:%04X\n",sregs.es,regs.x.bx); para->CharSet = CS_CHI; para->CodeType = CT_BIG; para->FontID[0] = dyna_type[0]; para->FontID[1] = dyna_type[1]; para->FontID[2] = dyna_type[2]; para->FontID[3] = dyna_type[3]; if (italic ==4) para->FontWidth = (font_size * 3) /4; else para->FontWidth = font_size; para->FontHeight = font_size; para->VerOff = 0; para->HorOff = 0; para->WidthByte = (font_size + 7) / 8 ; if ((buffer = farmalloc (32768))==NULL) { printf ("Error allococate memory for font buffer\n"); exit(1); }; para->Buffer = buffer; para->Attrib = italic; para->ItalicAmount = 70; }