1
2 Foomatic 3.0.2
3 ==============
4
5
6 foomatic-filters
7 ----------------
8
9 Filter scripts used by the printer spoolers to convert the incoming
10 PostScript data into the printer's native format using a
11 printer/driver specific, but spooler-independent PPD file.
12
13
14 Grant Taylor <gtaylor (a] picante.com>
15 Till Kamppeter <till.kamppeter (a] gmx.net>
16
17 http://www.linuxprinting.org/
18
19 This README contains mainly info for developers. See the file USAGE if
20 you want to know how to use Foomatic.
21
22
23 Copying
24 -------
25
26 This package and also the other Foomatic packages are under the
27 GPL. See http://www.gnu.org/.
28
29 If you spot a data error or any other bug, send mail describing the bug to
30 foomatic-devel (a] linuxprinting.org
31
32 General discussion happens in the foomatic-devel forum/list thing at
33 www.linuxprinting.org.
34
35
36 Intro
37 -----
38
39 This is the stable version of Foomatic. See
40
41 http://www.linuxprinting.org/contribute.html#programming
42 http://www.linuxprinting.org/pipermail/foomatic-devel/2002q3/thread.html
43 http://www.linuxprinting.org/pipermail/foomatic-devel/2002q4/thread.html
44 http://www.linuxprinting.org/kpfeifle/LinuxKongress2002/Tutorial/IV.Foomatic-Developer/IV.tutorial-handout-foomatic-development.html
45
46 to know more about its development.
47
48 Your suggestions, bug reports, patches, ... are welcome on
49
50 http://www.linuxprinting.org/newsportal/thread.php3?name=linuxprinting.foomatic.devel
51
52 For getting Foomatic PPD files for this version, go to
53
54 http://www.linuxprinting.org/
55
56 See the README file of "foomatic-db-engine" for a (more or less)
57 complete overview of Foomatic.
58
59
60 Supported spoolers
61 ------------------
62
63 CUPS - Common Unix Printing System (http://www.cups.org/)
64 SOLARIS - Solaris LP (lpsched)
65 LPD - Line Printer Daemon (Does this have a home page anywhere?)
66 LPRng - LPR - New Generation (http://www.lprng.org/)
67 GNUlpr - An enhanced LPD (http://sf.net/projects/lpr, development stopped)
68 PPR - Page PRinter spooler (http://ppr.sourceforge.net/)
69 PDQ - Print, Don't Queue (http://pdq.sf.net/, development stopped)
70 CPS - Coherent Printing System (http://www.tww.cx/cps.php)
71 --- - Direct, spooler-less printing (http://www.linuxprinting.org/)
72
73
74 Programs and important files from this package
75 ----------------------------------------------
76
77 This package contains only two scripts and its man pages: foomatic-rip
78 and foomatic-gswrapper. foomatic-rip is the main
79 PostScript-to-printer's-native-language filter and foomatic-gswrapper
80 is an m auxiliary filter ironing out some GhostScript quirks.
81
82 foomatic-rip works with all spoolers and always uses PPD files for
83 printer/driver capabilities info. Manufacturer-supplied PPDs of
84 PostScript printers can be used, too.
85
86 Note: The scripts appear as ".in" files in the source tree and CVS,
87 because the path for the Perl interpreter is inserted by the
88 "configure" script. The "configure" script makes the final files from
89 them with the inserted path of the Perl interpreter.
90
91 configure.in
92
93 The source from which GNU autoconf generates the "configure" script
94
95 acinclude.m4
96
97 Additional macros for the "configure" script
98
99 make_configure
100
101 Calls aclocal and autoconf to generate "configure" from "configure.ac"
102 and "acinclude.m4"
103
104 Makefile.in
105
106 The template from which "configure" generates the Makefile
107
108 install-sh
109
110 Helper script for "configure"
111
112 foomatic-rip
113
114 Universal print filter (PostScript -> printer's native language) to be
115 used with all known printer spoolers (CUPS, Solaris LP, LPRng, LPD, GNUlpr,
116 PPR, PDQ, CPS, spooler-less printing). It Gets printer/driver capability
117 information from PPD files. The PPD files can either be generated from
118 the Foomatic database or they can be manufacturer-supplied PPD files
119 for PostScript printers.
120
121 foomatic-gswrapper
122
123 This is not really a file conversion or print filter, but it is used
124 by foomatic-rip when it is present. This is a wrapper around
125 Ghostscript. It regularizes options if they differ between gs
126 flavors. It also assures that the GhostScript output is not mixed up
127 with messages produced by some PostScript files (esp. files from
128 Windows). foomatic-rip auto-detects the presence of
129 foomatic-gswrapper.
130
131 beh
132
133 Usually, if a CUPS backend exits with an error status other than zero
134 (for example if a printer is not turned on or not reachable on the
135 network), CUPS disables the print queue and one can only print again
136 if a system administrator re-enables the queue manually. Even restarting
137 CUPS (or rebooting) does not re-enable disabled queues.
138
139 This script makes the handling of such backend errors configurable, so
140 that the problem can easily be worked around. The execution of the backend
141 can be periodically repeated and/or the error state of the backend can
142 be kept away from CUPS, so that the queue stays active.
143
144 See instructions in the beginning of the beh script and in the USAGE file.
145
146 foomatic-rip.1
147 foomatic-gswrapper,1
148
149 man pages for the filter scripts.
150
151
152 Dependencies
153 ------------
154
155 To build and run this package only a Perl interpreter (5.6.0 and
156 newer) is needed.
157
158 To connect to remote printers, you need additional connectivity
159 software (as "rlpr", "nc", "smbspool', ...).
160
161
162 How does it work?
163 -----------------
164
165 foomatic-rip is a filter which takes PostScript (and also certain
166 non-PostScript formats) from standard input and translates it to the
167 printer's native language. The resulting data is usually directed to
168 standard output, but depending on the spooler abnd its configuration
169 it can also be directed to elsewhere. The information how to do this
170 translation it gets from a PPD file, from command line options,
171 environment variables, and spooler configuration files.
172
173 foomatic-rip is designed in a way that it does neither use any
174 temporary files nor reads the whole print job into memory. So even
175 huge jobs can be printed without needing big resources. Data is only
176 buffered in memory as long as it is not clear how to treat the
177 data. This happens for example when we don't know yet whether the
178 input file is PostScript, or when we are searching for embedded option
179 settings. This is done by forking into up to 6 subprocesses which do
180 all the tasks of the filter chain in parallel, see the overview of
181 these subprocesses below.
182
183 See also the numerous comments in the foomatic-rip Perl script.
184
185
186 foomatic-rip does the following steps to do its work:
187
188
189 Spooler auto-detection
190
191 At first, foomatic-rip reads its command line and a certain assortment
192 of environment variables. With this information it determines from
193 which spooler it was called, since every spooler calls its filter(s)
194 with different command lines and different information supplied via
195 environment variables.
196
197
198 Gathering all information to execute the print job
199
200 Next step after figuring out what the spooler is, is collecting the
201 information about the print job which was not found in the first
202 step. Now the knowledge of which spooler is used is taken into account
203 for interpreting the information.
204
205
206 Reading the PPD file
207
208 In one of the previous steps we have found the name of the PPD file
209 assigned to the print queue currently in use. Now the PPD file is read
210 to get all information needed to build the renderer's (Usually, the
211 renderer is GhostScript, when no renderer is needed, as for a
212 PostScript printer, "cat" is used) command line, the available
213 options, their default values, and how to apply them. After having
214 parsed the PPD file we have a renderer command line and a list of
215 options with the range of possible settings and a default setting. For
216 LPRng, LPD, GNUlpr, and spooler-less printing we get also the
217 so-called postpipe here, defining a shell command line into which
218 foomatic-rip should firect its output. If no postpipe is found, the
219 output data goes to standard output. The postpipe allows to print to
220 destinations which are not directly supported by the spooler.
221
222
223 Applying user-supplied settings
224
225 All option settings which the user has supplied on the command line
226 are checked whether they are valid (option exists, choice in range)
227 and then applied to the list of default settigs, replacing the
228 defaults by the values given by the user. The options not mentioned on
229 the command line keep their default values from the PPD file.
230
231
232 Check for the "docs" option
233
234 foomatic-rip accepts a special option which is not defined in the PPD
235 file, the "docs" option. When the user supplies it, he wants to print
236 a listing of all options available for the printer/driver combo in
237 use. So the incoming data on standard input is discarded and a
238 sub-process for generating the option listing in plain text form is
239 launched. Standard input of the main process is connected to the
240 output of the sub-process. Now the main process behaves as the option
241 listing would be the job which the user has sent.
242
243
244 Print files
245
246 With some spoolers the job(s) to be printed is supplied in (a)
247 file(s), in this case we close standard input and open the file on the
248 stabdard input handler. This way the following steps read from the
249 file instead of from standard input. The rest of the foomatic-rip
250 process is repeated for every input file, to print them one after the
251 other.
252
253
254 Raw queue
255
256 When we have a raw queue, all the rest of the incoming data is
257 directly passed to standard output or to the postpipe now. The
258 following steps will be omitted then.
259
260
261 Print the job
262
263 After all the preparation, the PostScript job is examined for traces
264 of option settings supposed to be applied to the renderer's command
265 line or to the JCL (Job Coomand Language, for example PJL) header
266 which is sent to the printer before the renderer's output is sent.
267 PPD-aware applications and spoolers stuff option settings directly
268 into the file, they do not necessarily send PPD options by the command
269 line. There is also stuffed in PostScript code to apply option
270 settings given by the command line of the printing command ("lpr",
271 "lp", ...) and to set the defaults given in the PPD file.
272
273 Examination strategy: We read lines from standard input until the
274 first %%Page: comment appears and save them as @psheader. This is the
275 page-independent header part of the PostScript file. The PostScript
276 interpreter (renderer) must execute this part once before rendering
277 any assortment of pages. Then pages can be printed in any arbitrary
278 selection or order. All option settings we find here will be collected
279 in the default option set for the RIP (Raster Image Processor,
280 renderer) command line.
281
282 Now the pages will be read and sent to the renderer, one after the
283 other. Every page is read into memory until the %%EndPageSetup comment
284 appears (or a certain amount of lines was read in the case that there
285 is no %%EndPageSetup). So we can get option settings only valid for
286 this page. If we have such settings we set them in the modified
287 command set for this page.
288
289 If the renderer is not running yet (first page) we start it with the
290 command line built from the current modified command set and send the
291 first page to it, in the end we leave the renderer running and keep
292 input and output pipes open, so that it can accept further pages. If
293 the renderer is still running from the previous page and the current
294 modified command set is the same as the one for the previous page, we
295 send the page. If the command set is different, we close the renderer,
296 re-start it with the command line built from the new modified command
297 set, send the header again, and then the page.
298
299 After the last page the trailer (%%Trailer) is sent.
300
301 The output pipe of this program stays open all the time so that the
302 spooler does not assume that the job has finished when the renderer is
303 re-started.
304
305 Non DSC-conforming documents will be read until a certain line number
306 is reached. Options for the renderer's command line or the JCL header
307 appearing later will be ignored. This means that option settings in
308 the page headers will not be taken into account.
309
310 If options are implemented by PostScript code supposed to be stuffed
311 into the job's PostScript data we stuff the code for all these options
312 into our job data, So all default settings made in the PPD file (the
313 user can have edited the PPD file to change them) are taken care of
314 and command line options get also applied. To give priority to
315 settings made by applications we insert the options's code in the
316 beginnings of their respective sections, so that sommething, which is
317 already inserted, gets executed after our code. Missing sections are
318 automatically created. In non-DSC-conforming files we insert the
319 option code in the beginning of the file. This is the same policy as
320 used by the "pstops" filter of CUPS.
321
322 If CUPS is the spooler, the option settings were already inserted by
323 the "pstops" filter (both PPD defaults and user-supplied options), so
324 we don't insert them again. The only thing we do is correcting
325 settings of numerical options when they were set to a value not
326 available as choice in the PPD file, As "pstops" does not support
327 "real" numerical options, it sees these settings as an invalid choice
328 and stays with the default setting. In this case we correct the
329 setting in the first occurence of the option's code, as this one is
330 the one added by CUPS, later occurences come from applications and
331 should not be touched.
332
333 If the input is not PostScript (if there is no "%!" after
334 $maxlinestopsstart lines) a file conversion filter will automatically
335 be applied to the incoming data, so that we will process the resulting
336 PostScript here. This way we have always PostScript data here and so
337 we can apply the printer/driver features described in the PPD
338 file. For the file conversion filter two subprocesses are started, the
339 task of the first one is to pass the already buffered lines into the
340 filter and then to continue reading standard input (without parsing
341 the data) to pass the rest of the job to the filter. The second
342 subprocess is the filter itself, getting its standard input from the
343 first subprocess and the giving its standard output to the main
344 process. This way the main process has again PostScript as its
345 standard input.
346
347 Supported file conversion filters are "a2ps", "enscript", "mpage", and
348 spooler-specific filters. All filters convert plain text to
349 PostScript, "a2ps" also other formats. The conversion filter is always
350 used when one prints the documentation pages, as they are created as
351 plain text, when CUPS is the spooler "pstops" is executed after the
352 filter so that the default option settings from the PPD file and
353 CUPS-specific options as N-up get applied. On regular printouts one
354 gets always PostScript when CUPS or PPR is the spooler, so the filter
355 is only used for regular printouts under LPD, LPRng, GNUlpr, PDQ, or
356 without spooler.
357
358 The main process keeps always parsing the PostScript onput, it
359 launches the renderer in one subprocess and launches and additional
360 subprocess for bracketing the renderer's output with the JCL commands
361 and putting the resulting data to standard output or to the postpipe.
362
363
364 Overview of the subprocesses
365 ----------------------------
366
367 To do the filtering without loading the whole file into memory we work
368 on a data stream, we read the data line by line analyse it to decide what
369 filters to use and start the filters if we have found out which we need.
370 We buffer the data only as long as we didn't determine which filters to
371 use for this piece of data and with which options. There are no temporary
372 files used.
373
374 foomatic-rip splits into up to 6 parallel processes to do the whole
375 filtering (listed in the order of the data flow):
376
377 KID0: Generate documentation pages (only jobs with "docs" option)
378 KID2: Put together already read data and current input stream for
379 feeding into the file conversion filter (only non-PostScript
380 and "docs" jobs)
381 KID1: Run the file conversion filter to convert non-PostScript
382 input into PostScript (only non-PostScript and "docs" jobs)
383 MAIN: Prepare the job auto-detecting the spooler, reading the PPD,
384 extracting the options from the command line, and parsing
385 the job data itself. It analyses the job data to check
386 whether it is PostScript and starts KID1/KID2 if not, it
387 also stuffs PostScript code from option settings into the
388 PostScript data stream. It starts the renderer (KID3/KID4)
389 as soon as it knows its command line and restarts it when
390 page-specific option settings need another command line
391 or different JCL commands.
392 KID3: The rendering process. In most cases GhostScript, "cat"
393 for native PostScript printers with their manufacturer's
394 PPD files.
395 KID4: Put together the JCL commands and the renderer's output
396 and send all that either to STDOUT or pipe it into the
397 command line defined with $postpipe.
398
399