FYI: Clipping in aView.Restore

Bruno Essmann (bessmann@iiic.ethz.ch)
Fri, 26 Jul 1996 08:39:49 +0200

For my current project I had to create a view that displays data in form of
a table. The contents of the table are several columns proportional text.
Since the text of a column may not fit into the column completely the text
has to be clipped to the width of the column.

After snooping around a bit I found the following solution which should work
on any port (tested for screen as well as printer).

PROCEDURE (v: aView) Restore* (f: Views.Frame; l, t, r, b: LONGINT);
VAR aFont: Fonts.Font;

PROCEDURE DrawStringC (x, y, w: LONGINT; s: ARRAY OF CHAR; font: Fonts.Font);
VAR nl, o1, nr, or: LONGINT;
BEGIN
(* calculate clipping rectangle in pixels *)
nl := (x + f.gx) DIV f.unit;
nr := (x + w + f.gx) DIV f.unit;

(* save old clipping rectangle *)
o1 := f.rider.l;
or := f.rider.r;

(* set new clipping rectangle *)
f.rider.Set(nl, f.rider.t, nr, f.rider.b);

(* restore "to be clipped away" parts *)
f.DrawString(x, y, Ports.black, s, font);

(* restore old clipping rectangle *)
f.rider.Set(o1, f.rider.t, or, f.rider.b);
END DrawStringC;

BEGIN
aFont := Fonts.dir.Default(); (* get default font *)
DrawStringC(0, aFont.asc, 50 * f.dot, "This string is clipped away", aFont)
END Restore;

I hope this wasn't to obvious...

Cheers,
Bruno