Tuesday, July 31, 2007

How does the CUPS filter work?

Printing in the Unix world is heavily dependent on filters. These are the work horses of the unix printing. Filters are nothing but a program which one data type as input and converts them into another format. Different applications can generate data in different formats. Like a plain text file, Postscript file or an image file. Printers can also support different data types. A postscript printer will not need any filter if the application is generating postscript data. This is how the  print flow looks
Application-> CUPS->Application->CUPS->Filter->CUPS->printer.

1. User clicks on the print button of the application.
2. Application calls CUPS to show the list of printers installed in the system.
3. User selects a printer.
4. Cups reads the PPD file associated with the printer and displays the print options available for that model. If no PPD is available then a default list of options are shown.
5. When user finishes making all the choices, CUPS parses PPD and gets the appropriate postscript commands for the options. Like for duplex command the PPD contains a specific postscript command.
6. If a filter is mentioned in the PPD, cups will try to convert the output data type of the application to the input data type of the filter.
7.How does cups determine the output data type of the application. For this it uses a mime.types file. This file has 2 columns. The 1st column describes the data type/sub type. Like image/jpeg. The 2nd column tells the extension of the file and the hexadecimal code found in the beginning of the file. Like application/x-dvi dvi string(0,<F702>) F7 and 02 shows it is a dvi file.
8. Now it looks into a mime.convs file. This file has 4 entries. Source data type,  output datatype, cost, name of filter.
application/x-dvi application/postscript 50 dvitops
9. The cost determines which path to take to reach the output type if multiple ways are available.
10. The filter takes its input from the argv parameter in the main function.
11. The filter mostly takes it input from the  stdin, but can also take from the a filepath stored in the argv[6] location.


Powered by ScribeFire.

No comments: