Gecko:Unix Plugin Printing

From MozillaWiki
Jump to: navigation, search

Plugin Printing On Unix

This page records the history of support for printing pages containing plugins. Note it's not a complete reference to the printing portion of the plugin API.

The unix Plugin API contains a function called Print(), which is called while printing a document. It gives the plugin a chance to include its own imagery in the print job. This function receives, one argument, a pointer to an NPPrint structure containing platform-specific data.

For mozilla 1.4, it appears that the platform-specific data consisted of a pointer to a wide string (a PRUnichar*) containing the name of the PostScript output file. The apparent intent was for the plugin to open the file and append PostScript to it.

This changed in bug 198515. For mozilla 1.5 and later, gecko creates a temporary file and passes a FILE* pointer to the plugin, which is expected to write the desired postscript to the file.

The plugin's postscript output is supposed to appear within a particular rectangle on the page. The plugin has to know what kind of postscript environment is being provided--how the coordinate system is set up, what is the current color, etc.--and what rules it should follow, such as whether it can start printing a new page. For mozilla 1.5, these things weren't well documented. Plugins were expected to target a PS environment unique to mozilla:

  1. The coordinate system is scaled to points (1/72th of an inch).
  2. The origin (coordinate [0,0]) is at the top left corner of the page's printable region (not the corner of the plugin's rectangle).
  3. The Y axis increases downward.
  4. Other issues, such as the current color, were unspecified.

This was originally supported in both the PostScript Module and the Xprint Module. But during the 1.6 development cycle, a bug was introduced into PS which caused it to provide the wrong coordinate system. Unfortunately, this wasn't caught until after 1.6 was released; see bug 234470.

The long gap between the time the bug was introduced and the time it was discovered illustrated the fact that there were as yet no plugins implementing this interface. This made it possible to consider moving to a better design instead of just fixing the bug, and after some deliberation, the decision was made to support the industry-standard Encapsulated PostScript (EPS) specification. For mozilla 1.8 and later, plugins are expected to generate an encapsulated postscript file. It's likely that gecko will stay with this scheme moving forward.

Support for the 1.5 scheme was removed from the firefox 1.0, thunderbird 1.0, and mozilla 1.7 branches, to avoid potential interactions from future plugins that simply output EPS. See bug 261589.