[Previous] [Contents] [Next]

Making Your Own Filer

In this chapter...

A quick way to put together your own print filter is to replace the file pcl3.c with your own version (say acme.c). This file must contain the following two functions:

DumpLine()
This routine is called with actual data to be sent to the printer. All data is in the form of a raster scan from left to right across the page. Each call to DumpLine() is the data for a single color of a single scan. A 1 bit indicates a dot to be printed, a 0 bit indicates a dot not printed. The high-order bits of a byte are intended to be printed first. The order of colors sent to DumpLine() is Black, Cyan, Magenta, Yellow.
PrinterAction()
This routine has several subfunctions. You need to support only those that apply to your printer. There are two types of subfunctions:

DumpLine()

This routine is called as follows:

void DumpLine (FILE *fp,        
               int color,       
               int outbytes,    
               int left_border, 
               int max_out,     
               int print_line,  
               int more_data)   
fp
The output file.
color
The color for this data (0=black, 1=cyan, 2=magenta, 3=yellow).
outbytes
Number of data bytes in the buffer.
left_border
Number of zero-bytes to send for border.
max_out
Maximum data bytes advisable to be sent (excluding borders).
print_line
Vertical page position in scans.
more_data
(Boolean) this is not the last color.

Global variables

The following global variables are meaningful:

oubuffy
Data buffer address (changes by color).
compress (Boolean)
Compressed output requested.
compress_buff
Address of a buffer to hold compressed output.

PrinterAction()

This routine is called as follows:

int PrinterAction (FILE *prn_fp,
                   int action,
                   int *args)
prn_fp
The output file.
action
The subfunction requested.
args
The argument array.

Returns

0
This function is not applicable.
1
The argument array was not changed.
2
The argument array was changed.

The zero element of the argument array always contains a value that uniquely identifies the printer model. This value is computed as follows:

ID string
The concatenation of the Manufacturer and Model fields of the PNPID.
The value's low-order 16 bits
The Microsoft hash code of the ID string.
The value's high-order 16 bits
The sum of the first 20 bytes of the ID string and the two individual bytes of the hash code.

The remaining elements of the argument array depend on the function and may contain arguments or be places to store return values.

Actions

The following actions could be requested:

ACTION_PAGE_POSITION
Set the position of the first scan on the page.
args[1]
Top margin in thousandths of an inch
args[2]
Vertical resolution in DPI.
ACTION_RESET
Reset the printer after the print job.
ACTION_INIT
Initialize the printer at the start of a job.
ACTION_SHEET_FEED
Print the current page and loads a new one.
ACTION_SET_RESOLUTION
Set the resolution of the printer.
args[1]
Vertical resolution in DPI.
args[2]
Horizontal resolution in DPI.
ACTION_SET_QUALITY
Adjust printer quality settings.
args[1]
Number of colors (1 = Black, 3 = CMY, 4 = CMY+Black).
args[2]
Quality (set by the -oQ command-line option).
args[3]
Media type (not currently implemented).
args[4]
Dot size (set by the -oD command-line option).
args[5]
Shingling (set by the -os command-line option).
ACTION_SET_MARGINS
Set the printer margins. Sizes are in thousandths of an inch.
args[1]
Paper width.
args[2]
Paper height.
args[3]
Left margin.
args[4]
Top margin.
args[5]
Right margin.
args[6]
Bottom margin.
args[7]
Vertical resolution in DPI.
args[8]
Horizontal resolution in DPI.
ACTION_SET_PAPER_SOURCE
Select the media tray for this job.
args[1]
Paper source (set by the -oz command-line option).
args[2]
Media type (not currently implemented).
ACTION_SET_PAGE_LENGTH
Set the printer page format.
args[1]
Paper height in thousandths of an inch.
args[2]
Vertical resolution in DPI.
args[3]
Top margin in thousandths of an inch.
ACTION_SET_DEPLETION
Set the depletion level.
args[1]
Depletion (set by the -od command-line option).
ACTION_SET_TOP_OF_FORM
This action is requested at the start of the job and after every sheet feed.
ACTION_VERIFY_RESOLUTION
This action should return 1 if the resolution is acceptable. If not, then change the resolution and return 2.
args[1]
Vertical resolution in DPI.
args[2]
Horizontal resolution in DPI.
args[3]
Number of colors (1 = Black, 3 = CMY, 4 = CMY+Black).
ACTION_VERIFY_DEPLETION
This action should return 1 if the depletion is acceptable. If not, then change the depletion and return 2.
args[1]
Vertical resolution in DPI.
args[2]
Horizontal resolution in DPI.
args[3]
Depletion level.
ACTION_VERIFY_DOTSIZE
This action should return 1 if the dot size is acceptable. If not then change the dot size and return 2.
args[1]
Vertical resolution in DPI.
args[2]
Horizontal resolution in DPI.
args[3]
Dot size.
ACTION_ADJUST_INTENSITY
This action allows the intensity to be adjusted based on the selected resolution and printer model. Return 1 if the intensity is acceptable. If not, then change the intensity and return 2. Intensity values range from 0 to 99 (50 is normal).
args[1]
Current intensity.
args[2]
Vertical resolution in DPI.
args[3]
Horizontal resolution in DPI.

To make a correction, use the following equation:

NewIntensity = (OldIntensity * cf)/(100 - cf)

where cf is a correction factor ranging from 0 to 99. A value of 50 gives no correction.

ACTION_DEFAULT_BORDERS
This action doesn't affect the printer. It merely selects and returns suitable sizes for the borders in thousandths of an inch and returns a value of 2. Borders are defined as the minimum size to which the user may set the corresponding margins.
args[1]
Top border.
args[2]
Bottom border.
args[3]
Left border.
args[4]
Right border.
ACTION_COMPRESS_LENGTH
Calculate and return a size for the compression buffer.
args[1]
Page width in thousandths of an inch.
args[2]
Return value.
ACTION_VERIFY_PAPER_SIZE
This action should return 1 if the paper size is acceptable. If not, then change the paper size and return 2.
args[1]
Paper height in thousandths of an inch.
args[2]
Paper width in thousandths of an inch.
ACTION_VERIFY_MODEL
This action is the first to be requested and allows the model number to be examined. If this action changes the model number, the adjusted model number will be supplied to all the other actions.
args[0]
Model number.

[Previous] [Contents] [Next]