| 1 |
/* |
| 2 |
* $ApsCVS: src/apsfilter/contrib/ruslpdrv/lpfont.c,v 1.2 2000/04/16 11:42:16 andreas Exp $ |
| 3 |
*/ |
| 4 |
#include <stdio.h> |
| 5 |
#include <unistd.h> |
| 6 |
#include <fcntl.h> |
| 7 |
|
| 8 |
/* printing chars by pixels |
| 9 |
printer moves to graphics mode after issuing 1b,4b and number of chars |
| 10 |
to print (in packet) */ |
| 11 |
|
| 12 |
#define STDIN 0 |
| 13 |
#define STDOUT 1 |
| 14 |
#define STDERR 2 |
| 15 |
#define FALSE 0 |
| 16 |
#define TRUE 1 |
| 17 |
|
| 18 |
void main(int argc, char *argv[]){ |
| 19 |
unsigned char chartable[256*6],c; |
| 20 |
int readed,i,j,handle; |
| 21 |
int PacketSize; |
| 22 |
unsigned char Packet[90]; /* max string length */ |
| 23 |
int isMoreChars; |
| 24 |
int EachChar; |
| 25 |
int EachVertical; |
| 26 |
|
| 27 |
fprintf(stderr,"Matrix printer font filter by Penn ([email protected])\n"); |
| 28 |
fprintf(stderr,"GPL, april 1998\n"); |
| 29 |
if (argc==1){ /* no parameters */ |
| 30 |
fprintf(stderr,"Usage:\n"); |
| 31 |
fprintf(stderr,"\t<stdin> | lpfont [font file name] | <stdout>\n"); |
| 32 |
exit(1); |
| 33 |
} |
| 34 |
/*** in future to use memset here */ |
| 35 |
for(i=0;i<32*6;i++) chartable[i]=0; |
| 36 |
handle=open(argv[1],O_RDONLY); |
| 37 |
if (handle==-1){ |
| 38 |
perror(argv[1]); |
| 39 |
exit(1); |
| 40 |
} |
| 41 |
read(handle,&chartable[32*6],224*6); |
| 42 |
close(handle); |
| 43 |
|
| 44 |
PacketSize=0; |
| 45 |
isMoreChars=TRUE; |
| 46 |
while(isMoreChars) |
| 47 |
{ |
| 48 |
readed=read(0,&c,1); |
| 49 |
if (readed==0 || readed==-1) { isMoreChars=FALSE; continue; } |
| 50 |
if (c<128) |
| 51 |
{ |
| 52 |
if (PacketSize!=0) |
| 53 |
{ |
| 54 |
/* parsing packet */ |
| 55 |
putchar(0x1b);putchar(0x4b); |
| 56 |
/* number of vertical rows to print */ |
| 57 |
putchar((PacketSize*6)%256);putchar((PacketSize*6)/256); |
| 58 |
for(EachChar=0;EachChar<PacketSize;EachChar++) |
| 59 |
for(EachVertical=0;EachVertical<6;EachVertical++) |
| 60 |
putchar(chartable[Packet[EachChar]*6+EachVertical]); |
| 61 |
PacketSize=0; |
| 62 |
} |
| 63 |
if (c==0x0a) |
| 64 |
{ |
| 65 |
putchar(0x0d);putchar(0x0a); |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
putchar(c); |
| 70 |
} |
| 71 |
} |
| 72 |
else |
| 73 |
Packet[PacketSize++]=c; |
| 74 |
}while(readed!=0); |
| 75 |
} |
| 76 |
|