]>
git.ipfire.org Git - thirdparty/cups.git/blob - filter/texttops.c
2 * "$Id: texttops.c,v 1.1 1996/10/14 16:07:57 mike Exp $"
4 * PostScript text output filter for espPrint, a collection of printer
7 * Copyright 1993-1996 by Easy Software Products
9 * These coded instructions, statements, and computer programs contain
10 * unpublished proprietary information of Easy Software Products, and
11 * are protected by Federal copyright law. They may not be disclosed
12 * to third parties or copied or duplicated in any form, in whole or
13 * in part, without the prior written consent of Easy Software Products.
19 * $Log: texttops.c,v $
20 * Revision 1.1 1996/10/14 16:07:57 mike
26 * Include necessary headers...
35 #include <errorcodes.h>
45 # define TRUE (!FALSE)
48 #define MAX_COLUMNS 256
51 #define ATTR_BOLD 0x01
52 #define ATTR_UNDERLINE 0x02
56 * Character/attribute structure...
61 char ch
, /* ASCII character */
62 attr
; /* Any attributes */
75 float CharsPerInch
= 10.0;
80 * 'Setup()' - Output a PostScript prolog for this page.
85 PDSizeTableStruct
*size
,
91 float length
, width
, left
;
94 LinesPerInch
= 72.0 / fontsize
;
95 CharsPerInch
= 120.0 / fontsize
;
99 SizeColumns
= (size
->length
- 2.0 * size
->top_margin
- (PageColumns
- 1) * 0.25) * CharsPerInch
;
100 SizeLines
= (size
->width
- 2.0 * size
->left_margin
) * LinesPerInch
;
102 left
= 72.0 * size
->top_margin
;
103 width
= 72.0 * (size
->length
- 2.0 * size
->top_margin
) / PageColumns
;
104 length
= 72.0 * (size
->width
- size
->left_margin
) - fontsize
;
108 SizeColumns
= (size
->width
- 2.0 * size
->left_margin
- (PageColumns
- 1) * 0.25) * CharsPerInch
;
109 SizeLines
= (size
->length
- 2.0 * size
->top_margin
) * LinesPerInch
;
111 left
= 72.0 * size
->left_margin
;
112 width
= 72.0 * (size
->width
- 2.0 * size
->left_margin
) / PageColumns
;
113 length
= 72.0 * (size
->length
- size
->top_margin
) - fontsize
;
116 SizeColumns
/= PageColumns
;
118 fputs("%!PS-Adobe-3.0\n", out
);
119 fprintf(out
, "%%%%BoundingBox: %f %f %f %f\n",
120 72.0 * size
->left_margin
,
121 72.0 * size
->top_margin
,
122 72.0 * (size
->width
- size
->left_margin
),
123 72.0 * (size
->length
- size
->left_margin
));
124 fputs("%%LanguageLevel: 1\n", out
);
125 fputs("%%Creator: ntext2ps 3.1 Copyright 1993-1996 Easy Software Products\n", out
);
126 fprintf(out
, "%%%%Pages: (atend)\n");
127 fputs("%%EndComments\n\n", out
);
129 fputs("%%BeginProlog\n", out
);
130 fprintf(out
, "/R /%s findfont %f scalefont def\n", fontname
, fontsize
);
131 fprintf(out
, "/B /%s-Bold findfont %f scalefont def\n", fontname
, fontsize
);
132 fprintf(out
, "/S { setfont /y exch %f mul %f sub neg def %f mul %f add exch %f mul add /x exch def "
133 "x y moveto show } bind def\n",
134 fontsize
, length
, 72.0 / CharsPerInch
, left
, width
);
135 fprintf(out
, "/U { setfont /y exch %f mul %f sub neg def %f mul %f add exch %f mul add /x exch def "
136 "x y moveto dup show x y moveto stringwidth rlineto } bind def\n",
137 fontsize
, length
, 72.0 / CharsPerInch
, left
, width
);
138 fputs("%%EndProlog\n", out
);
146 fprintf(out
, "%%%%Pages: %d\n", pages
);
147 fputs("%%EOF\n", out
);
155 fprintf(out
, "%%%%Page: %d\n", page
);
162 fputs("showpage\n", out
);
163 fputs("%%EndPage\n", out
);
168 output_line(FILE *out
, int page_column
, int column
, int row
, int attr
, char *line
)
170 fprintf(out
, "(%s) %d %d %d %s %s\n", line
, page_column
, column
,
171 row
, (attr
& ATTR_BOLD
) ? "B" : "R", (attr
& ATTR_UNDERLINE
) ? "U" : "S");
176 OutputLine(FILE *out
,
184 char line
[MAX_COLUMNS
* 2 + 1],
188 for (column
= 0, attr
= 0, lineptr
= line
, linecol
= 0;
189 column
< SizeColumns
;
190 column
++, buffer
++)
192 if (buffer
->ch
== '\0')
195 if (attr
^ buffer
->attr
)
200 output_line(out
, page_column
, linecol
, row
, attr
, line
);
208 if (strchr("()\\", buffer
->ch
) != NULL
)
214 *lineptr
= buffer
->ch
;
221 output_line(out
, page_column
, linecol
, row
, attr
, line
);
227 * 'Usage()' - Print usage message and exit.
233 fputs("Usage: ntext2ps -P <printer-name> [-D]\n", stderr
);
234 fputs(" [-e] [-s] [-w] [-Z]\n", stderr
);
235 fputs(" [-L <log-file>] [-O <output-file>]\n", stderr
);
236 fputs(" [-M <printer-model]\n", stderr
);
243 * 'main()' - Main entry and processing of driver.
247 main(int argc
, /* I - Number of command-line arguments */
248 char *argv
[]) /* I - Command-line arguments */
250 int i
, /* Looping var */
251 ch
; /* Current char from file */
252 char *opt
; /* Current option character */
253 int empty_infile
, /* TRUE if the input file is empty */
254 need_status
; /* TRUE if all we need to do is update the printer status */
255 char *filename
, /* Input filename, if specified (NULL otherwise). */
256 *printer
; /* Name of printer */
257 FILE *fp
; /* Input file */
265 PDInfoStruct
*info
; /* POD info */
266 PDStatusStruct
*status
; /* POD status */
267 time_t mod_time
; /* Modification time */
268 PDSizeTableStruct
*size
; /* Page size */
271 lchar_t buffer
[MAX_COLUMNS
];
275 * Process any command-line args...
280 fontname
= "Courier";
287 for (i
= 1; i
< argc
; i
++)
288 if (argv
[i
][0] == '-')
289 for (opt
= argv
[i
] + 1; *opt
!= '\0'; opt
++)
292 case 'P' : /* Specify the printer name */
300 case 'L' : /* Log file */
305 freopen(argv
[i
], "w", stderr
);
308 case 'O' : /* Output file */
310 if (i
>= argc
|| outfile
!= NULL
)
316 case 'D' : /* Produce debugging messages */
320 case 'l' : /* Landscape output */
324 case 'F' : /* Font name */
332 case 'p' : /* Font pointsize */
337 fontsize
= atof(argv
[i
]);
340 case 'M' : /* Multiple column mode */
345 PageColumns
= atof(argv
[i
]);
352 else if (filename
!= NULL
)
359 fputs("ntext2ps: Command-line args are:", stderr
);
360 for (i
= 1; i
< argc
; i
++)
361 fprintf(stderr
, " %s", argv
[i
]);
366 * Check for necessary args...
373 * Open the POD database files and get the printer definition record.
376 if (PDLocalReadInfo(printer
, &info
, &mod_time
) < 0)
378 fprintf(stderr
, "ntext2ps: Could not open required POD database files for printer \'%s\'.\n",
380 fprintf(stderr
, " Are you sure all required POD files are properly installed?\n");
382 PDPerror("ntext2ps");
383 exit(ERR_POD_ACCESS
);
386 status
= info
->active_status
;
387 size
= PDFindPageSize(info
, PD_SIZE_CURRENT
);
390 * Setup the output file...
396 out
= fopen(outfile
, "w");
400 fprintf(stderr
, "ntext2ps: Unable to create PostScript output to %s - %s\n",
401 outfile
== NULL
? "(stdout)" : outfile
, strerror(errno
));
402 exit(ERR_TRANSMISSION
);
405 Setup(out
, size
, fontname
, fontsize
, landscape
);
408 * Read text from the specified source and print them...
411 if (filename
!= NULL
)
413 if ((fp
= fopen(filename
, "r")) == NULL
)
425 exit(ERR_DATA_SHORT_FILE
);
434 memset(buffer
, 0, sizeof(buffer
));
436 while ((ch
= getc(fp
)) >= 0)
438 empty_infile
= FALSE
;
443 StartPage(out
, page
);
450 case 0x08 : /* BS - backspace for boldface & underline */
454 case 0x09 : /* HT - tab to next 8th column */
457 if (column
>= SizeColumns
)
458 { /* Wrap text to margins */
459 OutputLine(out
, page_column
, line
, buffer
);
461 if (line
>= SizeLines
)
465 if (page_column
>= PageColumns
)
471 memset(buffer
, 0, sizeof(buffer
));
475 buffer
[column
].ch
= ' ';
480 case 0x0a : /* LF - output current line */
481 OutputLine(out
, page_column
, line
, buffer
);
483 if (line
>= SizeLines
)
487 if (page_column
>= PageColumns
)
493 memset(buffer
, 0, sizeof(buffer
));
496 case 0x0c : /* FF - eject current page... */
497 OutputLine(out
, page_column
, line
, buffer
);
500 if (page_column
>= PageColumns
)
505 memset(buffer
, 0, sizeof(buffer
));
508 case 0x0d : /* CR - ignored */
510 default : /* All others... */
512 break; /* Ignore other control chars */
514 if (column
>= SizeColumns
)
515 { /* Wrap text to margins */
516 OutputLine(out
, page_column
, line
, buffer
);
518 if (line
>= SizeLines
)
522 if (page_column
>= PageColumns
)
528 memset(buffer
, 0, sizeof(buffer
));
532 if (ch
== buffer
[column
].ch
)
533 buffer
[column
].attr
|= ATTR_BOLD
;
534 else if (buffer
[column
].ch
== '_')
535 buffer
[column
].attr
|= ATTR_UNDERLINE
;
537 buffer
[column
].ch
= ch
;
545 OutputLine(out
, page_column
, line
, buffer
);
553 exit(ERR_DATA_SHORT_FILE
);
556 * Exit with no errors...
564 * End of "$Id: texttops.c,v 1.1 1996/10/14 16:07:57 mike Exp $".