PipalWBImpl.mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Louis Monier January 15, 1988 9:10:02 pm PST
Bertrand Serlet May 19, 1988 6:33:49 pm PDT
DIRECTORY Imager, ImagerFont, IO, Pipal, PipalInt, PipalPaint, PipalReal, PipalWB, Real, Rope;
PipalWBImpl: CEDAR PROGRAM
IMPORTS Imager, ImagerFont, IO, Pipal, PipalInt, PipalPaint, PipalReal, Real
EXPORTS PipalWB =
BEGIN OPEN PipalWB;
Boxed Text
boxedTextClass: PUBLIC Pipal.Class ← Pipal.RegisterClass[name: "BoxedText", type: CODE [BoxedTextRec]];
SizeBoxedText: PipalInt.SizeProc ~ {
size ← NARROW [object, BoxedText].size};
fixedFont: Imager.Font ← Imager.FindFontScaled["Xerox/XC1-2-2/Modern", 20.0];
PaintBoxedText: PipalPaint.PaintProc ~ {
data: BoxedText ← NARROW [object];
Imager.SetXY[context, [0.0, 0.0]];
PipalPaint.SetColor[context, Imager.black];
Imager.SetFont[context, fixedFont];
Imager.ShowRope[context, data.rope];
};
DescribeBoxedText: Pipal.DescribeProc = {
boxedText: BoxedText ← NARROW [object];
Pipal.PutIndent[out, indent, cr];
IO.PutF[out, "BoxedText [%g]", IO.rope[boxedText.rope]];
};
-- problem: the size of a rope is naturally expressed in real numbers!
CreateBoxedText: PUBLIC PROC [rope: Rope.ROPE, size: PipalInt.Size] RETURNS [boxedText: BoxedText] ~ {
boxedText ← NEW[BoxedTextRec ← [rope: rope, size: size]];
IF size=PipalInt.emptySize THEN {
extents: ImagerFont.Extents ← ImagerFont.RopeBoundingBox[font: fixedFont, rope: rope];
boxedText.size ← [Real.Round[extents.leftExtent+extents.rightExtent], Real.Round[extents.descent+extents.ascent]];
};
};
Initialization
Pipal.PutClassMethod[boxedTextClass, PipalInt.sizeMethod, NEW [PipalInt.SizeProc ← SizeBoxedText]];
Pipal.PutClassMethod[boxedTextClass, PipalReal.sizeMethod, NEW [PipalReal.SizeProc ← PipalReal.UseIntSize]];
Pipal.PutClassMethod[boxedTextClass, PipalInt.abutBoxMethod, NEW [PipalInt.AbutBoxProc ← PipalInt.AbutBoxFromSize]];
Pipal.PutClassMethod[boxedTextClass, PipalPaint.paintMethod, NEW [PipalPaint.PaintProc ← PaintBoxedText]];
Pipal.PutClassMethod[boxedTextClass, Pipal.describeMethod, NEW [Pipal.DescribeProc ← DescribeBoxedText]];
END.