<> <> <> <> <<>> 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; <> 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]]; }; }; <> 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.