CircleCommand: Commander.CommandProc ~ {
textA, ipOutA, radiusA, yScaleA, fontA, sizeA, ccwA, rangeA: Args.Arg;
[textA, ipOutA, radiusA, yScaleA, fontA, sizeA, rangeA, ccwA] ¬
Args.ArgsGet[cmd, "%ss-radius%r-yScale%r-font%s-size%r-range%r-ccw%b"
! Args.Error => {msg ¬ reason; GOTO Bad}];
{
size: REAL ¬ IF sizeA.ok THEN sizeA.real ELSE 14.0;
color: Color ¬ ImagerColor.ColorFromGray[1.0];
fName: ROPE ¬ IF fontA.ok THEN fontA.rope ELSE "helvetica-mrr";
font: Font ¬ Imager.FindFontScaled[Rope.Concat["xerox/pressfonts/", fName], size];
radius: REAL ¬ IF radiusA.ok THEN radiusA.real ELSE 1.0;
yScale: REAL ¬ IF yScaleA.ok THEN yScaleA.real ELSE 1.0;
range: REAL ¬ IF rangeA.ok THEN rangeA.real ELSE 360.0;
Circularize[textA.rope, ipOutA.rope, font, color, radius, yScale, range, ccwA.ok
! Imager.Warning => {msg ¬ IO.PutFR1["no font: %g", IO.rope[fName]]; GOTO Bad}];
};
EXITS Bad => RETURN[$Failure, msg];
};
Circularize:
PROC [
text, out: ROPE, font: Font, color: Color, radius, yScale, range: REAL, ccw: BOOL]
~ {
IPAction:
PROC [context: Context] ~ {
Imager.ScaleT[context, metersPerPoint];
Imager.TranslateT[context, [0.0, 0.5*11.0*Imager.pointsPerInch]];
G2dOutline.TransformRope[text, CircleTransform, context, 0, 0, font, color, 0.05, d];
};
b: Imager.Box ¬ ImagerBox.BoxFromExtents[ImagerFont.RopeBoundingBox[font, text]];
ref: ImagerInterpress.Ref ¬ ImagerInterpress.Create[out];
d:
REF CircleData ¬
NEW[CircleData ¬
[radius, (2.0*3.1415926535)*(range/360.0)/(b.xmax-b.xmin), yScale, ccw]];
ImagerInterpress.DoPage[ref, IPAction];
ImagerInterpress.Close[ref];
};
CircleTransform: G2dOutline.TransformProc ~ {
data: REF CircleData ¬ NARROW[clientData];
a: REAL ¬ data.xScale*v.x;
r: REAL ¬ data.radius+data.yScale*(IF data.ccw THEN -v.y ELSE v.y);
IF data.ccw THEN a ¬ 3.1415926535-a;
xv ¬ [r*RealFns.Sin[a], r*RealFns.Cos[a]];
};