DEFINITION MODULE GKSM;

(*
    Title: 	GKS Meta File Reading and Writing Procedures
    LastEdit:	"Mon Feb 25 18:30:32 1985"
    Author: 	jd
		Cambridge University Computer Laboratory
*)

FROM GKSTypes IMPORT TRANSFORM, PATH;
FROM Streams IMPORT Stream;
FROM Vector IMPORT RVEC, RBOX;

EXPORT QUALIFIED
    RECORDTYPE, RecordHigh, SelectMetaOutput, SelectMetaInput, 
    EndMetaOutput, EndMetaInput, WrRecord, WrUserRecord,
    RdRecord, RdUserRecord,
    WrInt, RdInt, WrReal, RdReal, WrVector, RdVector, WrPath, RdPath,
    WrBox, RdBox, WrPoints, RdPoints, 
    WrString, RdString, WrPixels, RdPixels, WrTransform, RdTransform;

(* This module contains basic procedures for reading and writing GKS
   metafiles. It allows one output metafile and one input metafile to be
   open simultaneously, though these should not be the same file. 

   RECORDTYPE is constructed so that the ordinal number of each
   command is the record number in the metafile. In their wisdom, the 
   metafile designers have left holes in the number allocation - this is
   the reason for the Rn entries, which have no assigned use.
*)


TYPE RECORDTYPE =
    (EndRec, ClearRec, RedrawRec, UpdateRec, MessageRec, 
        R5, R6, R7, R8, R9,
    BoxRec, LineIndexRec, MarkIndexRec, TextIndexRec, CharHeightRec,
    CharUpRec, CharExpandRec, CharPathRec, CharSpaceRec, FillIndexRec, 
    PatternSizeRec, PatternRefRec,
        R22, R23, R24, R25, R26, R27, R28, R29, R30,
    LineDefRec, MarkerDefRec, TextDefRec, FillDefRec, PatternDefRec, 
    ColourDefRec, DeferralRec, WindowRec, ViewportRec, 
        R40,
    LineRec, MarkerRec, TextRec, FillRec, PixelRec, GdpRec, 
        R47, R48, R49, R50, R51, R52, R53, R54, R55, R56, R57, R58, R59, R60,
    CreateSegRec, CloseSegRec, RenameSegRec, DeleteSetRec, SegTransRec,
    SegVisibleRec, SegLitRec, SegPriority);


CONST RecordHigh = 499; (* max 500 bytes per record *)

        (*    Procedures for Writing Metafiles    *)


PROCEDURE SelectMetaOutput (to: Stream): BOOLEAN;
    (* prepares to write an output metafile to the stream *)

PROCEDURE EndMetaOutput;
    (* terminates the output metafile stream in a nice way and
       deletes the Stream argument to SelectMetaOutput
    *)

PROCEDURE WrRecord (type: RECORDTYPE);
    (* terminates any current output metafile record, then begins a new
       metafile record of the given type.
    *)

PROCEDURE WrUserRecord (type: INTEGER);
    (* same as WrRecord, but used for writing user-defined records.
       type should be >100, according to the manual
    *)

PROCEDURE WrInt (i: INTEGER);
PROCEDURE WrReal (r: REAL);
PROCEDURE WrPath (p: PATH);
PROCEDURE WrVector (v: RVEC);
PROCEDURE WrBox (r: RBOX);
PROCEDURE WrPoints (high: INTEGER; VAR p: ARRAY OF RVEC);
PROCEDURE WrString (VAR s: ARRAY OF CHAR);
PROCEDURE WrPixels (rowhigh, colhigh: INTEGER;
        VAR pixels: ARRAY OF CARDINAL);
PROCEDURE WrTransform (t: TRANSFORM);

        (*    Procedures for Reading Metafiles    *)


PROCEDURE SelectMetaInput (from: Stream): BOOLEAN;
    (* prepares to read an input metafile from the stream *)

PROCEDURE EndMetaInput;
    (* finishes reading and EndStreams the argument to SelectMetaInput *)

PROCEDURE RdRecord (VAR type: CARDINAL; VAR length: INTEGER);
    (* returns the next input record type and byte length *)

PROCEDURE RdUserRecord (): Stream;
    (* returns a stream onto the data of the current input record.
       Should be called immediately after RdRecord. Reading beyond the end
       of the record stream returns EndStreamCh.
    *)

(* the following procedures operate on the current metafile record *)

PROCEDURE RdInt (VAR i: INTEGER);
PROCEDURE RdReal (VAR r: REAL);
PROCEDURE RdPath (VAR p: PATH);
PROCEDURE RdVector (VAR v: RVEC);
PROCEDURE RdBox (VAR r: RBOX);
PROCEDURE RdPoints (VAR count: INTEGER; VAR p: ARRAY OF RVEC);
PROCEDURE RdString (VAR s: ARRAY OF CHAR);
PROCEDURE RdPixels (VAR rows, cols: INTEGER;VAR pixels: ARRAY OF CARDINAL);
PROCEDURE RdTransform (VAR t: TRANSFORM);



END GKSM.
