Next: , Previous: Page and Viewport Sizes, Up: Appendices

Appendix D The Graphics Metafile Format

A GNU graphics metafile is produced by any application that uses the Metafile Plotter support contained in GNU libplot. That includes the raw variants of graph, plot, pic2plot, tek2plot, and plotfont. A metafile is a sort of audit trail, which specifies a sequence of Plotter operations. Each operation is represented by an `op code': a single ASCII character. The arguments of the operation, if any, immediately follow the op code.

A metafile may use either of two encodings: binary (the default) or portable (human-readable). Metafiles in the binary encoding begin with the magic string "#PLOT 1\n", and metafiles in the portable encoding with the magic string "#PLOT 2\n". If you intend to transfer metafiles between machines of different types, you should use the portable rather than the binary encoding. Portable metafiles are produced by Metafile Plotters if the META_PORTABLE parameter is set to "yes", and by the raw variants of GNU graph and the other command-line graphics programs if the ‘-O’ option is specified. Both binary and portable metafiles can be translated to other formats by GNU plot. See plot.

In the portable encoding, the arguments of each operation (integers, floating point numbers, or strings) are printed in a human-readable form, separated by spaces, and each argument list ends with a newline. In the binary encoding, the arguments are represented as integers, single precision floating point numbers, or newline-terminated ASCII strings. Using the newline character as a terminator is acceptable because each Plotter operation includes a maximum of one string among its arguments, and such a string may not include a newline. Also, the string must come last among the arguments.

There are 97 Plotter operations in all. The most important are openpl and closepl, which open and close a Plotter, i.e., begin and end a page of graphics. They are represented by the op codeso’ and ‘x, respectively. The erase operation, if present, separates frames within a page. On real-time display devices, it is interpreted as a screen erasure. It is represented by the op code ‘e.

Each of the 94 other Plotter operations has a corresponding op code, with 12 exceptions. These 12 exceptions are (1) the control operation flushpl, (2) the operations havecap, labelwidth, and flabelwidth, which merely return information, (3) the color, colorname, pencolorname, fillcolorname, and bgcolorname operations, which are internally mapped to pencolor, fillcolor, and bgcolor, (4) the frotate, fscale, and ftranslate operations, which are internally mapped to fconcat, and (5) the ffontname operation, which in a metafile would be indistinguishable from fontname. So besideso’ and ‘x, there are 83 possible op codes, for a total of 85. The following table lists 10 of the op codes other than ‘o’ and ‘x, followed by the Plotter operation they stand for.

Op Code

The full set of 85 op codes is listed in the libplot header file plot.h and the libplotter header file plotter.h, which are distributed along with the plotting utilities. On most systems they are installed in /usr/include or /usr/local/include.

The 10 op codes in the table above are actually the op codes of the traditional `plot(5)' format produced by pre-GNU versions of graph and libplot. The use of these op codes make GNU metafile format compatible with plot(5) format. The absence of a magic string, and the absence of the ‘o’ and ‘x op codes, makes it possible to distinguish files in plot(5) format from GNU metafiles in the binary encoding. GNU plot can convert files in plot(5) format to GNU metafiles in either the binary or the portable encoding. See plot.