Chapter 14. Printing From the Desktop
Prev | Part II. Creating Desktop Icons | Next

## Chapter 14. Printing From the Desktop

The desktop provides printing services so that users can print from an application. This chapter covers these topics:

- “About routeprint” discusses the `routeprint` command, which converts files into printable form.

- “Converting a File for Printing” explains how the Desktop converts a file for printing.

- “The Print Conversion Rules” explains the print conversion rules.

- “The Current Printer” discusses the Desktop's concept of the current, or default, printer and the Desktop environment variable $CURRENTPRINTER.

## About `routeprint`

To print a file, the Desktop invokes the `routeprint`(1) command. `routeprint` knows how to convert most files into printable form, even if the conversion requires several steps.

You can show `routeprint` how to convert your application's data files into printable format by adding one or more CONVERT rules to your application's FTR file.

This chapter explains the process `routeprint` uses to convert data files into a printable format, what file types `routeprint` already recognizes, and how to write your own print CONVERT rule to allow your application to tap into `routeprint`'s powerful printing capabilities.

## Converting a File for Printing

The Desktop already has rules for printing many types of files, such as ASCII, PostScript, and RGB image files. The easiest method for printing a file of arbitrary format is to break down the printing process into small, modular steps.

For example, instead of writing dozens of specialized rules to print reference pages directly for each kind of printer, you can instead convert reference pages to `nroff` format and then convert the `nroff` format to the format required for the current printer.

The diagram shown in Figure 14-1 illustrates the steps by which some of the supported Desktop file types are converted for printing. Each box represents one or more file types; the arrows between them indicate the steps by which the file types are converted. The values associated with the arrows represent the cost of the conversion. This concept is talked about more in “Print Costs” later in this chapter.

Figure 14-1. File Conversions for Printing Standard Desktop Files

This modular approach to printing has two major advantages:

- The modular steps are reusable. Because you can reuse each modular printing step, you write fewer rules.

- routeprint can pick the most efficient route for printing. There is often more than one sequence of conversion steps to print a file. `routeprint` chooses the sequence of steps that provides the best possible image quality.

This modular, multi-step conversion to printable form is called the print conversion pipeline, a series of IRIX commands that process a copy of the file's data in modular increments. The print conversion rules are designed to take advantage of this method of processing printable files.

In addition, applications or software packages can add new arcs to the CONVERT rule database whenever they define new types or have a better way of converting existing types. For example, Impressario includes a filter to go directly from NroffFile to PostScriptFile—this new filter has a lower cost than the default conversion, which goes from NroffFile to Ascii to PostScriptFile.

The Desktop already has rules for printing a large number of file types. You can use `grep` to list all of these print conversions definitions by typing:

    % grep -i convert /usr/lib/filetype/*/*.ftr

| Note: The list of print conversion definitions generated by the above command is long and unsorted.

### Print Costs

Frequently, there is more than one set of steps that `routeprint` can use to print your file. To compare different ways of printing a file of a particular type, `routeprint` associates cost numbers with each conversion, then chooses the series of conversions with the lowest total cost. The cost of a conversion represents image degradation and processing cost, and is specified by a number between 0 and 1000 inclusive. The higher the cost of a conversion, the more `routeprint` attempts to avoid that conversion method if it has alternative methods.

The conventions for determining the cost assigned to a given conversion are described in Table 14-1.

Table 14-1. Conversion Costs for Print Conversion Rules

Cost | Reason
--- | ---
0 | Equivalent filetypes, or a SETVAR rule (described in “The Print Conversion Rules” )
50 | Default conversion cost
125 | Trivial data loss, or conversion is expensive
200 | Minor data loss, but conversion is not expensive
300 | Noticeable data loss and conversion is expensive
500 | Obvious data loss (for example, color to monochrome)

## The Print Conversion Rules

There are three parts to a complete print conversion rule:

- the CONVERT rule

- the COST rule

- the FILTER rule

### The CONVERT Rule

Syntax: |  | CONVERT source-type-name destination-type-name
Description: |  | source-type-name is the file type you are converting from. destination-type-name is the file type you are converting to.
Example: |  | `CONVERT NroffFile PostScriptFile`

Do not use the convert rule to convert directly to a new printer type; convert to a standard Desktop file type instead. Silicon Graphics reserves the right to alter printer types, so converting to a standard file type (for example, PostScriptFile) is a more portable solution. Appendix E, “Predefined File Types”, lists some of the file types defined by Silicon Graphics. You can generate a complete list of file types installed on your system using the `grep`(1) command:

    % grep TYPE /usr/lib/filetype/*/*.ftr

| Note: The list of file types generated by the above command is very long and unsorted.

### The COST Rule

Syntax: |  | COST non-negative-integer
Description: |  | The non-negative-integer represents the arc cost, or incremental cost of the conversion. This cost is used to reflect processing complexity or can also be used inversely to reflect the output quality. When `routeprint` selects a conversion sequence, it takes the arc costs into account, choosing the print conversion sequence with the least total cost. It is highly recommended that you specify a COST rule. If you omit it, `routeprint` assumes the cost of the conversion is zero, which may cause `routeprint` to return an inappropriate print conversion pipeline. The default cost is 50.
Example: |  | `COST 50`

### The FILTER Rule

Syntax: |  | FILTER filter-expression
Description: |  | The FILTER rule represents part of an IRIX pipeline that prepares a file for printing. filter-expression can be any single IRIX command line expression, and generally takes the form of one or more piped commands. In the general case, the first command within a single FILTER rule receives input from `stdin`; the last command in the rule sends its output to `stdout`. `routeprint` concatenates all the FILTER rules in the print conversion pipeline to form one continuous command that sends the selected file to its destination printer.

There are three special cases in creating FILTER rules:

- “first” case

- “last” case

- “setvar” case

In a “first” case rule, the FILTER rule is the very first rule in the print conversion pipeline. In this case, `routeprint` passes the list of selected files to the first command in the FILTER rule as arguments. If a first case FILTER rule begins with a command that does not accept the files in this fashion, prepend the `cat` command to your rule:

FILTER cat | tbl - | psroff -t

The files will then be piped to the next command's `stdin`.

In a “last” case rule, the FILTER rule is the very last rule in the print conversion pipeline. This rule contains a command that sends output directly to a printer (such as `lp`). Last-case rules are already provided for many file types. To ensure compatibility between your application and future printing software releases, you should refrain from writing your own last-case rules. Instead, write rules that convert from your file type to any of the existing file types, and let the built-in print conversion rules do the rest.

In a “setvar” case rule, the FILTER rule is used to set an environment variable used later in the print conversion pipeline. The first CONVERT rule in the example below sets a variable that defines an `nroff` macro used in the second rule. In all setvar cases, `stdin` is passed to `stdout` transparently. Thus, you can include setvar as part of the pipeline in a single FILTER rule.

CONVERT mmNroffFile NroffFIle
COST 1
FILTER setvar MACRO=mm

CONVERT NroffFile PostScriptFile
COST 50
FILTER eqn | tbl | psroff -$MACRO -t

## The Current Printer

The current printer is the system default printer that the user sets with the Print Manager or, alternatively, the printer specified by the -p option to `routeprint`. If no default is set and -p is not used, an error message is returned by `routeprint` to either `stdout` or a notifier window (if the -g option to `routeprint` was set). The Desktop environment variable $CURRENTPRINTER is set to the currently selected default printer.

Prev | Table of Contents | Next
Chapter 13. File Typing Rules |  | Appendix A. Example Programs for SGI Enhanced Widgets