IMFigsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, December 10, 1985 3:02:11 pm PST
DIRECTORY Imager, ImagerColorOperator, ImagerFont, ImagerInterpress, ImagerPath, ImagerPixelArray, ImagerTransformation, ImagerTypeface, Real, RealFns, Rope, Vector2;
IMFigsImpl: CEDAR PROGRAM
IMPORTS Imager, ImagerColorOperator, ImagerFont, ImagerPixelArray, ImagerTransformation, Real
Context: TYPE ~ Imager.Context;
VEC: TYPE ~ Vector2.VEC;
ROPE: TYPE ~ Rope.ROPE;
Transformation: TYPE ~ ImagerTransformation.Transformation;
PathProc: TYPE ~ ImagerPath.PathProc;
MoveToProc: TYPE ~ ImagerPath.MoveToProc;
LineToProc: TYPE ~ ImagerPath.LineToProc;
CurveToProc: TYPE ~ ImagerPath.CurveToProc;
XChar: TYPE ~ ImagerFont.XChar;
Font: TYPE ~ ImagerFont.Font;
trans: VEC ← [2540*1.0, 2540*1.0]; -- micas
scale: REAL ← 2540*2.5; -- micas
strokeWidth: REAL ← 25; -- micas
skew: Transformation ← ImagerTransformation.Create[
a: 1, b: 205.0/275.0, c: 0, d: 0, e: 159.0/275.0, f: 0];
LayerT:
PROC [layer:
NAT]
RETURNS [Transformation] ~ {
m: Transformation ~ ImagerTransformation.PostTranslate[skew, [0, (168.0/275.0)*layer]];
RETURN[ImagerTransformation.PostScale[m, scale]];
};
DoLayer:
PROC [context: Context, layer:
NAT, proc:
PROC [Context], border:
BOOL ←
FALSE] ~ {
m: Transformation ~ LayerT[layer];
IF border
THEN {
borderAction:
PROC ~ {
path: PathProc ~ {
p0: VEC ~ m.Transform[[0, 0]];
p1: VEC ~ m.Transform[[1, 0]];
p2: VEC ~ m.Transform[[1, 1]];
p3: VEC ~ m.Transform[[0, 1]];
rnd: PROC [p: VEC] RETURNS [VEC] ~ { RETURN[[Real.Round[p.x], Real.Round[p.y]]] };
moveTo[rnd[p0]]; lineTo[rnd[p1]]; lineTo[rnd[p2]]; lineTo[rnd[p3]];
};
Imager.SetStrokeWidth[context, strokeWidth];
Imager.SetStrokeJoint[context, $round];
Imager.MaskStroke[context, path, TRUE];
};
Imager.DoSave[context, borderAction];
};
IF proc#
NIL
THEN {
procAction:
PROC ~ {
Imager.ConcatT[context, m];
proc[context];
};
Imager.DoSave[context, procAction];
};
};
DoTranslated:
PROC [context: Context, x, y:
REAL, action:
PROC [Context]] ~ {
translatedAction:
PROC ~ {
Imager.TranslateT[context, [x, y]];
action[context];
};
Imager.DoSave[context, translatedAction];
};
font: Font ~ ImagerFont.Find["Xerox/PressFonts/TimesRoman-mrr"];
pa: ImagerPixelArray.PixelArray ~ ImagerPixelArray.Join3AIS[
name1: "/Cyan/AIS/ygn-red.ais",
name2: "/Cyan/AIS/ygn-grn.ais",
name3: "/Cyan/AIS/ygn-blu.ais"
];
pm: Transformation ~ ImagerTransformation.Scale[1.0/pa.fSize];
op: ImagerColorOperator.ColorOperator ~ ImagerColorOperator.RGBLinearColorModel[255];
m0: VEC ← [x: 0.25, y: 0.15];
m1: VEC ← [x: 0.5, y: 0.7];
mask: PathProc ~ { moveTo[m0]; arcTo[m1, m0] };
c0: VEC ← [0.1, 0.1];
c1: VEC ← [0.1, 0.9];
c2: VEC ← [0.8, 0.1];
clip: PathProc ~ { moveTo[c0]; lineTo[c1]; lineTo[c2] };
Fig1a:
PROC [context: Context] ~ {
a: ImagerFont.Extents ~ ImagerFont.RopeBoundingBox[font, "a"];
ax: REAL ~ (1-(a.leftExtent+a.rightExtent))/2+a.leftExtent;
ay: REAL ~ (1-(a.descent+a.ascent))/2+a.descent;
layer2:
PROC [context: Context] ~ {
Imager.SetGray[context, 0.5];
Imager.MaskRectangle[context, [0, 0, 1, 1]];
};
layer1:
PROC [context: Context] ~ {
Imager.MaskRectangle[context, [0, 0, 1, 1]];
Imager.SetGray[context, 0];
Imager.SetXY[context, [ax, ay]];
Imager.ShowRope[context, "a"];
};
layer0:
PROC [context: Context] ~ {
Imager.SetGray[context, 0.5];
Imager.SetXY[context, [ax, ay]];
Imager.ShowRope[context, "a"];
};
Imager.SetFont[context, font];
DoLayer[context, 2, layer2];
DoLayer[context, 1, layer1];
DoLayer[context, 0, layer0, TRUE];
};
Fig1b:
PROC [context: Context] ~ {
layer2:
PROC [context: Context] ~ {
Imager.SetSampledColor[context, pa, pm, op];
Imager.MaskRectangle[context, [0, 0, 1, 1]];
};
layer1:
PROC [context: Context] ~ {
Imager.MaskRectangle[context, [0, 0, 1, 1]];
Imager.SetGray[context, 0];
Imager.MaskFill[context, mask];
};
layer0:
PROC [context: Context] ~ {
Imager.SetSampledColor[context, pa, pm, op];
Imager.MaskFill[context, mask];
};
DoLayer[context, 2, layer2];
DoLayer[context, 1, layer1];
DoLayer[context, 0, layer0, TRUE];
};
Fig1:
PROC [context: Context] ~ {
DoTranslated[context, 0, 0, Fig1a];
DoTranslated[context, 2*scale, 0, Fig1b];
};
Fig2:
PROC [context: Context] ~ {
layer3:
PROC [context: Context] ~ {
Imager.SetSampledColor[context, pa, pm, op];
Imager.MaskRectangle[context, [0, 0, 1, 1]];
};
layer2:
PROC [context: Context] ~ {
Imager.MaskRectangle[context, [0, 0, 1, 1]];
Imager.SetGray[context, 0];
Imager.MaskFill[context, mask];
};
layer1:
PROC [context: Context] ~ {
Imager.MaskRectangle[context, [0, 0, 1, 1]];
Imager.SetGray[context, 0];
Imager.MaskFill[context, clip];
};
layer0:
PROC [context: Context] ~ {
Imager.Clip[context, clip];
Imager.SetSampledColor[context, pa, pm, op];
Imager.MaskFill[context, mask];
};
DoLayer[context, 3, layer3];
DoLayer[context, 2, layer2];
DoLayer[context, 1, layer1];
DoLayer[context, 0, layer0, TRUE];
};
Figure:
PROC [context: Context, fig:
PROC [Context], rotate:
BOOL ←
FALSE] ~ {
action:
PROC ~ {
Imager.ScaleT[context, 0.00001];
IF rotate
THEN {
Imager.TranslateT[context, [8.5*2540, 0]];
Imager.RotateT[context, 90];
};
Imager.TranslateT[context, trans];
fig[context];
};
Imager.DoSave[context, action];
};
Figure1: PROC [context: Context] ~ { Figure[context, Fig1, TRUE] };
Figure2: PROC [context: Context] ~ { Figure[context, Fig2] };
END.