Chapter 12. Enhancing Impressario with Plug-Ins

This chapter explains how you can add plug-ins to Impressario to satisfy needs that haven't yet been integrated into the base software. This allows you to dynamically update the feature set of Impressario.

This chapter explains:

How the Impressario File Conversion Pipeline Works

The key components of the Impressario file conversion pipeline are:

  • A database of File Type Rules (FTRs)

  • The wstype runtime filetype recognition utility

  • The fileconvert file conversion utility

File Type Rules

The file type rules of the FTR database are well-documented in the Indigo Magic Integration Guide, which is available as an online book and is installable from your IRIX CD.

The File Type Rules have two parts relevant to printing. The first part is a TYPE rule for recognizing that a file is of a particular type, given the first 512 bytes of the file. The second part is a CONVERT rule for converting that type to another type, with the eventual goal of being able to convert any file type to a set of printable file types. Each CONVERT rule contains a pair of known types (source and destination type), a Bourne shell command for going from the source to the destination type, and a cost for the conversion. Impressario builds on the standard IRIX database of filetypes, extending the FTR set to handle additional input file types, and adding new destination file types.

Runtime File Type Recognition Utility

The wstype utility is used to determine the file type of a file or set of files. It is similar to file(1) in basic operation, but has no hardcoded special cases and no /etc/magic file, relying on the compiled FTR database for typing information.

See the wstype(1) man page for additional information.

File Conversion Utility

The fileconvert utility builds a directed acyclic graph out of all known file types, determines the input file type, and attempts to find the lowest-cost path from source to destination.

If a conversion path exists, fileconvert prints a Bourne shell command string which, when executed, generates the destination file type on stdout. Most model files simply execute this shell command string, piping the results to the printer driver. This flexible, extensible mechanism enables Impressario to print virtually any recognizable file type on any printer that is compliant with Impressario.

See the fileconvert(1) man page for additional information.

Adding a New Filetype to Impressario

To extend Impressario to make a new type of file printable, you need only perform the following steps:

  1. Write a filter to convert your new type.

  2. Write an FTR rule that recognizes the new filetype.

  3. Add a CONVERT rule from that type to a known Impressario type.

  4. Install and test your changes.

Writing a New Filter

First, write a filter to convert your new type to either STIFF or PostScript, the two main formats for input to Impressario. Fileconvert requires that your filter be able to accept input either on stdin or from a specified filename. It should also be able to write output to stdout without using intermediate files, so that the conversion can succeed, even if the converting host has low disk space. See the Indigo Magic Integration Guide, Chapter 5, for more details. See the gif2stiff(1) man page for an example.

Writing an FTR

Next, write an FTR that can recognize the new filetype given only the first 512 bytes of the file. See the Indigo Magic Integration Guide and the ftr(1) man page for a description of the available primitives for matching a file's type and for a description of the additional parts of a good FTR.

Adding a CONVERT Rule

As part of your FTR, add a CONVERT rule from that type to a known Impressario type. We strongly recommend that you convert image types to the STIFF93aImage type and convert other non-image file formats to the PostScriptFile type. Refer to Appendix A and the libstiff(3) man page for information on writing STIFF output. Note that once you convert to either a PostScriptFile or a STIFF93aImage, Impressario knows how to convert that filetype to a printable format on any printer.

Model files that are compliant with Impressario also automatically set the proper environment variables for the options the user selected on the spooler command line, and the standard Impressario CONVERT rules automatically pick up the appropriate environment variables when converting these file types to printable types. This is how user-specified printing options are applied to the dynamically-constructed file conversion pipeline.

Installation and Testing

The easiest way to show how to test a new filetype is by example.

Setting Up an Example

Our example makes the following assumptions:

  • The new filetype is called "BlastFile."

  • The new FTR is in the directory /usr/tmp/blastfile.ftr.

  • A sample BlastFile is in the directory /usr/tmp/sample.blastfile.

  • All BlastFiles start with the word "blastfile."

A sample (although incomplete) TYPE rule for our example would look like this:

TYPE BlastFile
    MATCH string(0,9) == "blastfile";
    LEGEND Blast Image File

CONVERT BlastFile STIFF93aImage
    COST 50
    FILTER /usr/lib/print/blast2stiff $IMPR_IMG2STIFFOPTS

Testing the New Filetype

  1. To test the new filetype, become root by typing:

    su
    

    and supplying a password, if necessary.

  2. Copy your FTR into /usr/lib/filetype/install:

    cp /usr/tmp/blastfiletype.ftr /usr/lib/filetype/install
    

  3. Compile the FTR database:

    cd /usr/lib/filetype ; make
    

    See the ftr(1) man page if any errors occur.

  4. Run wstype to verify that Impressario now recognizes your file type:

    wstype /usr/tmp/sample.blastfile
    

    You should see the following output:

    /usr/tmp/sample.blastfile BlastFile
    

  5. Try to convert that file type to a printable file type. The most printable filetype in the Impressario database is ImpressarioPostScriptFile, so let's try that:

    fileconvert -d ImpressarioPostScriptFile \
    /usr/tmp/sample.blastfile
    

    You should get back something like:

         PRINTFILES="/usr/tmp/sample.blastfile" ; /usr/lib/print/blast2stiff
         $IMPR_IMG2STIFFOPTS $PRINTFILES | /usr/lib/print/stiff2ps $IMPR_SGI2PSOPTS
    


    Note: The above output would appear on one line.

    If fileconvert does not return a valid shell command string, check the exit code of the filter. If you are in the C shell, type:

    echo $status
    

    If you are in the Bourne shell, type:

    echo $?
    

    If the exit code is not zero, then fileconvert was unable to convert your filetype. Verify that your destination filetype is convertible to a printable type by checking the CONVERT rules in the FTR database and making sure there is a conversion path from your destination type to the Impressario type, and try the above steps again.

  6. Once the above steps work, verify that your filter produces valid output by typing:

    vstiff /usr/tmp/sample.blastfile
    

    This should bring up the vstiff(1) previewer, which uses the FTR database of TYPE and CONVERT rules to convert to a screen-viewable STIFF file. Use the "PostScript Options..." menu choice on the File menu to choose different color spaces and depths. See the vstiff(1) man page for more help.


    Note: If your filter converts directly to STIFF93aImage, the PostScript options in vstiff will not be applicable.


  7. Finally, try printing that file to an Impressario printer. Type:

    lp -dprintername /usr/tmp/sample.blastfile
    

    Watch the spooler log file for errors and the printstatus panel for printer messages until the file prints. If you were able to vstiff the file, then you should to be able to print it.

When you have completed this process, you should have the files shown in Table 12-1 . These files should be installed with the permissions and the ownerships shown and at the locations shown. The actual file basename may change but the pathname should not. Conversion filters should be installed in /usr/lib/print.

Table 12-1. New Filetype Pathnames

Mode

Owner

Group

Full Pathname

-r--r--r--

root

sys

/usr/lib/filetype/install/blastfiletype.ftr

-rwxr-xr-x

root

sys

/usr/lib/print/blast2stiff


Using an Alternate PostScript RIP

Using an alternate PostScript Raster Image Processor (RIP) is extremely easy in the Impressario open architecture. You can even switch RIPs on the fly, at the last possible moment, without losing any of the features of Impressario's file conversion pipeline.

The steps required to add an alternate RIP to your system are:

  1. Make the new RIP command line compatible with the Impressario RIP, psrip(1).

  2. Write a dummy TYPE.

  3. Test the alternative RIP.

  4. Package the files.

You should be able to use this alternate RIP instead of, or in addition to, the standard Impressario interpreter.


Note: In the example below, the new RIP is called "blastrip" and is installed in the directory /usr/lib/print, next to Impressario's psrip.


Making the Command line Compatible

Your new RIP must be command-line compatible with psrip. Look at the psrip(1) man page for more information on what that means. psrip accepts ASCII and binary PostScript either on stdin or in a disk file, and generates a variety of sizes, colorspaces, and depths of STIFF bitmaps on stdout.

Being command-line compatible with psrip is probably the most tedious part of adding a new interpreter, but is well worth the effort when you consider that you gain all the advantages of Impressario:

  • Plug-and-play printer drivers

  • Automatic filetype recognition

  • Automatic filetype conversion

Writing a Dummy TYPE

The next step is to write a dummy TYPE and a simple CONVERT rule. First create a new, empty TYPE definition for your output raster format. Here's an example:

TYPE BlastRasterBitmap
# dummy type for use in model file only
    MATCH false;

CONVERT ImpressarioPostScriptFile BlastRasterBitmap
# convert from formatted, filtered ImpressarioPostScriptFile
# to a RIPped bitmap
    COST   50
    FILTER /usr/lib/print/blastrip $IMPR_PSRIPOPTS

Install that file in /usr/lib/filetype/install/blastrip.ftr and compile your FTR database by typing:

su ; cd /usr/lib/filetype ; make

Now test the conversion and preview the bitmap by using vstiff:

fileconvert -d BlastRasterBitmap /etc/passwd | vstiff -stdin

If you run into problems viewing it, then save it to disk and use other tools to verify that you have a valid STIFF file. However, if vstiff cannot view it, then Impressario printer drivers will probably not be able to print it.

Testing the Alternate RIP

To use the alternative RIP in your printer model files instead of the default psrip, change all references to "ImpressarioRasterBitmap" to "BlastRasterBitmap." The lines below were taken from the laserjet_model template model file and the word "ImpressarioRasterBitmap" was changed to "BlastRasterBitmap":

# Use fileconvert to convert to the printer's native format.
# For raster printers, it is BlastRasterBitmap.
# For PostScript printers, it is ImpressarioPostScriptFile.
#
CMD=`$fileconvert $fileconvertopts -d BlastRasterBitmap $file 2> /dev/null`

Packaging the Files

You are done now, and need only package these optional RIP files for installation. The files you should be installing may have different names, but should be installed in the following directories, with the permissions and ownerships shown in Table 12-2 .

Table 12-2. Alternative RIP Pathnames

Mode

Owner

Group

Full Pathname

-r--r--r--

root

sys

/usr/lib/filetype/install/blastrip.ftr

-rwxr-xr-x

root

sys

/usr/lib/print/blastrip

You should modify your printer's model file to use the new RIP whenever you want. You can, of course, still ask for ImpressarioRasterBitmap.


Note: Test carefully to make sure that your new RIP is, in fact, compatible with the existing psrip before shipping your product.