GEM pages
Home -> GEM -> GEM file formats -> GEM metafile

Format of GEM metafile (.GEM)


The GEM metafile is a stored sequence of GEM drawing instructions. Its normal uses are:

Judging by the code in GEM Output, .GMP files created by Desktop Publisher use the same or a very similar format.

All word values are 16-bit, signed and little-endian (at least in Intel GEM). In this listing, "DW" (define word) is used to indicate such a word.

File header

All GEM metafiles start with a header:

      DW        magic       ;Magic number.
      DW        length      ;Header length
      DW        version     ;GEM version required to interpret this file.
      DW        coords      ;Coordinate type
      DW        Xmin,Ymin,Xmax,Ymax
      DW        Xpage,Ypage
      DW        Xminc,Yminc,Xmaxc,Ymaxc
      DW        flags

Most GEM metafiles have a 24-word header; the remaining header words being reserved.

is always -1 (0xFFFF)
is the number of words in the header; in most metafiles, this will be 24 (0x18). Some metafiles (those generated by Deskpress) have been seen with headers 71 words long; words nos. 23-70 being a text description with one character per word.
is the GEM version needed to play back this file, encoded as a decimal number. Common versions are:
0 (ie, any GEM)
Metafile EVENTS.GEM in the Programmers' Toolkit
101 (ie, GEM 1.01)
Metafiles produced by GEM Paint and GEM Draw
310 (ie, GEM 3.10)
Metafiles produced by Deskpress.
400 (ie, GEM 4.00)
Metafiles produced by Artline.
is the coordinate system in use. This is either 0 (Normalised Device Coordinates) or 2 (Raster Coordinates).
  • NDC files have their origin in the bottom left hand corner of the page, and coordinates are given as 32767 * fraction of the page size (so 16383 means halfway across the page).
  • RC files have their origin at the top left hand corner of the page, and coordinates are given in pixels.

Nearly always, files will be in raster coordinates.

The maximum and minimum coordinates used by the image.
The size of the page, in tenths of millimetres. Can be zero.
The bottom left and top right corners of the coordinate system. In the case of GEM Paint images, this is the maximum size that the bitmap could have been (in pixels). These values can be zero, in which case the coordinate system is assumed to go from (0,0) to (32767,32767).
Bit 0 is set if the metafile is a wrapper for a bitmap image (eg: those files written by GEM Paint).

Metafile records

The body of the file is composed of drawing commands. Each record is laid out as follows:

    DW  command
    DW  n_points
    DW  n_integers
    DW  subcommand
- then n_points pairs of coordinates:
    DW  x
    DW  y
- and finally n_integers integers:
    DW  z

The command and subcommand numbers are the same as those used in VDI calls - see the VDI list for details.

Metafile sub-opcodes

VDI function 5, subfunction 99 is used to implement functions unique to metafiles. These functions must take at least one integer parameter, which is the "sub-opcode":

   10        Start Group. 
   11        End Group.
   32        Set Bezier curve quality. Two further integer parameters; the
             first is always 1, and the second is the quality (%).
   49        Set No Line Style. 
   50        Set Attribute Shadow On. 
   51        Set Attribute Shadow Off. 
   80        Start Draw Area Type Primitive. 
   81        End Draw Area Type Primitive. 

End of metafile

    DW  -1  ;End

The file is terminated by the function number -1.


Files produced by PAINT.APP contain one drawing instruction:

    DW  5   ;Escape
    DW  2   ;2 points
    DW  lf  ;5 + length of filename
    DW  23  ;Bitmap image escape
    DW  xmin,ymin,xmax,ymax
    DW  aspect  ; 0 to ignore aspect ratio, 1 to preserve it
    DW  xscale  ; X axis scaling: 0 = fractional, 1 = integer
    DW  yscale  ; Y axis scaling: 0 = fractional, 1 = integer
    DW  halign  ; Horizontal alignment: 0=left 1=centre 2=right
    DW  valign  ; Vertical alignment:   0=top  1=centre 2=bottom
    DW  filename character 1
    DW  filename character 2
    DW  filename character n    

The filename is the name (no path) of the corresponding .IMG file.