/*************************************************************** * convert.c portrait font to landscape HP LaserJet II format * Compiled under Lattice C Compiler vers 5.04 * * Call: convert(portrait[file],landscape[file]) * * by Tom Lynch, * version 4 April 90 ***************************************************************/ #include #include #include #include #include #include #define MAX 200 /* byte X byte array for individual character image */ extern long DOSBase; FILE *fp,*fl; int filepos = 0; /* position in file being read (32 bits in AMIGA */ int filend = 0; /* file end flag */ int debug; unsigned int n = 0; /* value counter */ unsigned char c; /* character read from portrait font file */ unsigned char rdchar(); /* define function to return char */ unsigned char skip(); /* define function to return char */ unsigned char change(); /* define function to return char */ unsigned int measureto(); unsigned int _measureto(); char bitmap(); /* read, rotate, and measure length of image in bytes */ unsigned char base2[10][1]; /* temporary storage for binary string */ unsigned char _read(); TEXT file_name[34]; TEXT dir_name[67]; TEXT portrait[67]; TEXT landscape[67]; TEXT slash[10] = "/"; int SLASH = '\057'; /* decimal 42, forward slash (UNIX, AMIGA) */ char *LAND = ".land"; char *temp; unsigned char far map[MAX][MAX][1]; /* 'far' is REQUIRED for large arrays */ void main(argc, argv) int argc; char *argv[]; { extern convert(); int error; if (argc > 1) { if (argc == 3) { if (error = convert(argv[1],argv[2]) != 0) { /* process the request */ printf("Failure to process font\n"); printf("\nError message: %d\n ",error); switch(error) { case '4': printf("Failure to open portrait font file\n"); break; case '5': printf("Landscape file exists; rename.\n"); break; case '6': printf("Not font file?? First char should be 'escape'\n"); break; default: break; } exit(0); } printf("\nFont converted: %s --> %s\n",argv[1],argv[2]); exit(0); } else { printf("\nArgument ERROR. Correct form is:"); printf("\n'path'PORTOLAN PORTRAIT LANDSCAPE\n\n"); exit(0); } } } convert(p,l) /* CLI format: PORTOLAN font.port(old) font.land(new) */ char *p; char *l; { extern unsigned char c; /* reference externals */ extern FILE *fp, *fl; extern unsigned int n; extern unsigned char rdchar(); extern unsigned char skip(); extern unsigned char change(); extern char bitmap(); extern unsigned int measureto(); extern unsigned int _measureto(); extern unsigned char _read(); extern unsigned char base2[][]; unsigned char descriptor[20][1]; unsigned int LeftOffset; unsigned int TopOffset; unsigned int width, h_dots_p; unsigned int height, w_bytes_p; int size; unsigned int w_dots; /* landscape width in dots equal to height */ unsigned int w_bytes; /* integral number of bytes */ unsigned int h_dots; /* landscape height equal to portrait */ unsigned int h_bytes; int a,h,i; char *res = "01234567890"; DOSBase = OpenLibrary("dos.library",0); if ((fp = fopen(p,"r")) == NULL) { return(4); } if ((fl = fopen(l,"w")) == NULL) { return(5); } /* files ready, convert portrait file to landscape */ rdchar(); /* look for initial escape character */ if (c != (char)'\033') return(6); skip(2); /* esc, ')', and 's' of font descriptor */ measureto ('W'); /* read index 'n' that points to next esc */ skip(12); /* skip to orientation byte */ change(0,1); /* change from port(0) to land(1) */ skip(n-13); /* skip to end of font descriptor */ rdchar(); /* read first byte (esc) of charater descriptor */ while (filend == 0) { /* test for end of charaters in font */ skip (2); /* '*' and 'c' of char descriptor */ measureto('E'); /* read charater number */ skip(3); /* bypass esc, '(', 's' */ /* store char descriptor; must measure length to correct old length then write new descriptor */ _measureto('W'); /* read char descriptor length */ size = n - 16; /* bitmap size */ descriptor[0][1] = 'W'; _read(); descriptor[1][1] = c; /* Format byte = 4 */ _read(); descriptor[2][1] = c; /* no continuation byte = 0 */ _read(); descriptor[3][1] = c; /* descriptor size = 14 */ _read(); descriptor[4][1] = c; /* class, format of data = 1 */ _read(); descriptor[5][1] = '\001'; /* Orientation 1 = land */ _read(); descriptor[6][1] = c; /* reserved by HP = 0 */ /* left offset (portrait) = */ _read(); descriptor[7][1] = c; /* left offset (P) hi byte */ _read(); descriptor[8][1] = c; /* left offset (P) lo byte */ /* top offset (port) = */ _read(); descriptor[9][1] = c; /* top offset (P) hi byte */ _read(); descriptor[10][1] = c; /* top offset (P) lo byte */ /* portrait width is read into landscape height descriptor bits */ _read(); descriptor[13][1] = c; /* char width land hi */ _read(); descriptor[14][1] = c; /* char width land hi */ /* land */ height = 256 * descriptor[13][1] + descriptor[14][1]; /* dots */ h_dots = height; /* landscape height pixels */ h_bytes = height/8; if(height % 8) h_bytes += 1; /* bytes */ w_bytes_p = h_bytes; /* portrait height is read into landscape width descriptor bits */ _read(); descriptor[11][1] = c; /* char height land */ _read(); descriptor[12][1] = c; /* char height land */ /* land */ width = 256 * descriptor[11][1] + descriptor[12][1]; /* dots */ w_dots = width; h_dots_p = width; w_bytes = width/8; if(width % 8) w_bytes += 1; /* bytes */ _read(); descriptor[15][1] = c; /* Delta X hi byte */ _read(); descriptor[16][1] = c; /* Delta X lo byte */ /* top offset (land) = left offset(P) + char width(P) - 1 + byte offset, 16 bit hex */ TopOffset = 256 * descriptor[7][1] + descriptor[8][1] + 256 * descriptor[13][1] + descriptor[14][1] - 1; /* left offset (landscape) = 0xFFFF - top offset(P) 16 bit hex */ LeftOffset = 65535 - (256 * descriptor[9][1] + descriptor[10][1]); descriptor[7][1] = (unsigned char) (LeftOffset / 256); /* hi byte */ descriptor[8][1] = (unsigned char) (LeftOffset % 256); /* lo byte */ descriptor[9][1] = (unsigned char) TopOffset / 256; /* hi byte */ descriptor[10][1] = (unsigned char) TopOffset % 256; /* lo byte */ /* estimate of bit image size after rotation 8/ /* landscape bit_image size = width[bytes] * height[dot-rows] */ n = w_bytes * h_dots + 16; /* bytes for descriptor and bit image */ h = stci_d(res,n); /* convert to decimal string */ a = 1; if(n>9) a = 2; if(n>99) a = 3; if(a>999) a = 4; /* write char size to landscape file, ascii format */ for(i=0; i=1; p--) { i = p / 8; /* points to byte, contingent to mod below */ q = p % 8; /* points to bit as computed in switch below */ switch(q) { case 0: /* points to next lower byte, bit = LSB */ k = 1; /* k = value of bit position of */ break; /* byte used to mask correct bit */ case 1: /* points to next higher byte, msb */ i += 1; k = 128; /* first bit is MSB in HP format */ break; case 2: i += 1; k = 64; break; case 3: i += 1; k = 32; break; case 4: i += 1; k = 16; break; case 5: i += 1; k = 8; break; case 6: i += 1; k = 4; break; case 7: i += 1; k = 2; break; } /* there is no possible default */ for(j=0; j0); /* calculate byte value */ /* extract bit from portrait and assign value 'a' for bit */ } /* bit of pixel data along old port height */ n = fputc(c,fl); /* put computed byte into landscape file */ } /* j = byte along width (old portrait height) */ /* k = bit pixel data value used in bitwise mask */ } /* i = byte along height (old portrait width) from max */ return NULL; } unsigned char rdchar () { /* read byte store in char 'c' */ extern unsigned char c; extern FILE *fp, *fl; int r; filepos++; c = fgetc(fp); if ((filend = feof(fp)) != 0) return 0; r = fputc(c,fl); return c; } unsigned char _read() { /* read byte store in char 'c' */ extern unsigned char c; extern FILE *fp; filepos++; c = fgetc(fp); if ((filend = feof(fp)) != 0) return 0; return c; } unsigned char skip(int n) { /* skip 'n' bytes in file */ extern unsigned char c; extern FILE *fp, *fl; int x, r; for (x = 0; x < n; ++x) { filepos++; c = fgetc(fp); if ((filend = feof(fp)) != 0) return 0; r = fputc(c,fl); } return c; } unsigned char change(int prev, int new) /* change byte */ { extern unsigned char c; extern FILE *fp, *fl; int r; filepos++; c = fgetc(fp); if (c == prev) r = fputc(new,fl); else r = fputc(new,fl); return c; } unsigned int measureto (char test) /* calculate ascii format number (base 10) */ { unsigned char rdchar(); extern unsigned char c; rdchar(); n = (c - '0'); /* convert from ASCII to integer */ rdchar(); /* good for 1 to 5 character number */ if (c == test) return n; n = n*10 + (c - '0'); rdchar(); if (c == test) return n; n = n*10 + (c - '0'); rdchar(); if (c == test) return n; n = n*10 + (c - '0'); rdchar(); if (c == test) return n; n = n*10 + (c - '0'); rdchar(); /* this will read 'test' character */ return n; /* with 5 character ascii number */ } unsigned int _measureto (char test) /* calculate ascii format number (base 10) */ { unsigned char _read(); extern unsigned char c; _read(); n = (c - '0'); /* convert from ASCII to integer */ _read(); /* good for 1 to 5 character number */ if (c == test) return n; n = n*10 + (c - '0'); _read(); if (c == test) return n; n = n*10 + (c - '0'); _read(); if (c == test) return n; n = n*10 + (c - '0'); _read(); if (c == test) return n; n = n*10 + (c - '0'); _read(); /* this will read 'test' character */ return n; /* with 4 character ascii number */ }