DEFINITION Printer3; (* portable *) (* jm 18.1.95 *)

(* Module Printer3 implements clipped printing through display masks. It has
a twin module Display3 for displaying graphics. *)
 IMPORT Display3, Display, Fonts, Pictures;

 VAR 
  Pattern: ARRAY 9 OF Display.Pattern;  (* Display patterns that correspond
to the printer patterns. *)

 (* Block fill X, Y, W, H using color col. *)
 PROCEDURE ReplConst (M: Display3.Mask; col: Display.Color; X, Y, W, H, mode: INTEGER);

 (* Print dot in color col at X, Y. *)
 PROCEDURE Dot (M: Display3.Mask; col: Display.Color; X, Y, mode: INTEGER);

 (* Replicate fill pattern pat in area X, Y, W, H, using color col. pX, pY is
the pattern pin-point. *)
 PROCEDURE FillPattern (M: Display3.Mask; col: Display.Color; pat: Display.Pattern; pX, pY, X, Y, W, H, mode: INTEGER);

 (* Print rectangle outline X, Y, W, H of width and in pattern pat. *)
 PROCEDURE Rect (M: Display3.Mask; col: Display.Color; pat: Display.Pattern; X, Y, W, H, width, mode: INTEGER);

(* Print a rectangle outline X, Y, W, H of width width in 3D effect using top
shadow topcol and bottom shadow botcol. *)
 PROCEDURE Rect3D (M: Display3.Mask; topcol, botcol: Display.Color; X, Y, W, H, width, mode: INTEGER);

(* Print a filled rectangle X, Y, W, H of width width in 3D effect using top
shadow topcol and bottom shadow botcol. The "inside" color is incol. *)
 PROCEDURE FilledRect3D (M: Display3.Mask; topcol, botcol, incol: Display.Color; X, Y, W, H, width, mode: INTEGER);

(* Print a line of width width between X, Y and X1, Y1 in color col using pattern
pat. Hair-lines (of width = 1) cannot be patterned. *)
 PROCEDURE Line (M: Display3.Mask; col: Display.Color; pat: Display.Pattern; X, Y, X1, Y1, width, mode: INTEGER);

(* Print a polygon of n vertices in color col and pattern pat. The vertices
are passed in the arrays X and Y. Style can be {Display3.filled}. *)
 PROCEDURE Poly (M: Display3.Mask; col: Display.Color; pat: Display.Pattern; VAR X, Y: ARRAY OF INTEGER; n, width: INTEGER; style: SET; mode: INTEGER);

(* Print an ellipse of horizontal radius a and vertical radius b at position
X, Y. Implementation restriction: Ellipses cannot be filled or drawn with a
thick brush. *)
 PROCEDURE Ellipse (M: Display3.Mask; col: Display.Color; pat: Display.Pattern; X, Y, a, b, width: INTEGER; style: SET; mode: INTEGER);

(* Print a circle of radius r and width width using pattern pat and color col
at X, Y. Style can be {Display3.filled}. *)
 PROCEDURE Circle (M: Display3.Mask; col: Display.Color; pat: Display.Pattern; X, Y, r, width: INTEGER; style: SET; mode: INTEGER);

(* Returns the size of a string on the printer. Width is w, height is h, and
the descender offset is dsr. *)
 PROCEDURE StringSize (s: ARRAY OF CHAR; fnt: Fonts.Font; VAR w, h, dsr: INTEGER);

(* Print string s using font fnt in color col at X, Y. *)
 PROCEDURE String (M: Display3.Mask; col: Display.Color; X, Y: INTEGER; fnt: Fonts.Font; s: ARRAY OF CHAR; mode: INTEGER);

(* Print string s centered in area X, Y, W, H using color col and font fnt.
Line-breaks will be inserted if the string is too long. *)
 PROCEDURE CenterString (M: Display3.Mask; col: Display.Color; X, Y, W, H: INTEGER; fnt: Fonts.Font; s: ARRAY OF CHAR; mode: INTEGER);

(* Picture is stretched/reduce to fit at X, Y, W, H on the printer. *)
 PROCEDURE Pict (M: Display3.Mask; P: Pictures.Picture; X, Y, W, H, mode: INTEGER);

(* Replicate picture P. px, py is the picture origin, X, Y, W, H is printer
coordinates of the area to be filled. *)
 PROCEDURE ReplPict (M: Display3.Mask; P: Pictures.Picture; px, py, X, Y, W, H, mode: INTEGER);
END Printer3.

(* Remarks:

1. Printer3 uses the same mask descriptors as Display3 but expects all coordinates
to be specified in printer coordinates (often 300dpi). It has a similar interface
as Display3, although some minor differences can be found. Although the formal
arguments are approximately the same as those of Display3, some of them are
ignored, notably "mode". Due to the very limited interface of the underlying
Printer module, strings cannot be clipped correctly. This means that whole characters
are clipped at a time. As Oberon has no true color model, the col parameters
are indexes into the momentary displayed palette. This means that by changing
the display palette, your documents will print in different colors. No special
color mappings are attempted for monochrome printers. The latter has to be done
by the client.

2. Note that typical Oberon fonts differ non-linearly in size on the display
and printer. You cannot multiply a display string size by a constant factor
to obtain an approximation of the printer string size.

3. Patterns passed to the print procedures are display patterns (for example
Display.solid, Display.grey1, Pattern[x] etc). The Pattern array contains display
patterns corresponding to the pattern numbers expected by the Printer module.
That is, Pattern[2] is the display pattern that corresponds to pattern number
2 on the printer. *)