ImagerTester.mesa
Michael Plass, October 31, 1983 3:14 pm
DIRECTORY
GraphicsOps,
ViewerClasses,
ViewerOps,
Imager,
ImagerBasic,
RealFns,
Real,
LFUtil,
Rope,
Font;
ImagerTester: CEDAR PROGRAM
IMPORTS Imager, Font, RealFns, Real, GraphicsOps, ViewerOps
= BEGIN
Pair: TYPE ~ Imager.Pair;
Context: TYPE ~ Imager.Context;
FONT: TYPE ~ Imager.FONT;
ROPE: TYPE ~ Rope.ROPE;
mercuryPath: REF ← MercuryPath[];
MercuryPath: PROC RETURNS [t: Imager.Trajectory] = {
Curve: PROC [a,b,c,d,e,f: REAL] ~ INLINE {t ← t.CurveTo[[a, b], [c, d], [e, f]]};
t ← Imager.MoveTo[[192.0, 413.353]];
Curve[237.5415, 425.809, 255.3458, 401.7666, 288.0, 399.5085];
Curve[297.9937, 398.8174, 308.0844, 403.6591, 318.0, 404.5501];
Curve[331.9086, 405.7998, 448.1434, 401.3464, 450.8684, 396.0001];
Curve[453.3393, 391.1521, 435.2951, 383.4805, 431.9999, 383.0218];
Curve[428.5259, 382.538, 410.233, 382.6307, 409.5, 378.0];
Curve[409.8045, 379.9238, 421.3876, 370.5168, 402.0001, 363.6874];
Curve[386.3301, 358.1678, 345.4535, 362.3779, 345.5, 359.9999];
Curve[345.4942, 360.2959, 368.3762, 359.2238, 372.0, 358.0435];
Curve[389.1935, 352.4433, 364.4147, 343.7253, 364.875, 336.0];
Curve[365.5193, 325.1856, 382.3762, 294.0994, 390.0, 285.675];
Curve[408.286, 265.4687, 417.344, 272.0564, 438.0001, 263.8696];
Curve[454.6547, 257.2686, 417.2523, 242.3468, 408.0, 243.5193];
Curve[383.1711, 246.6655, 383.3985, 232.3274, 366.0, 219.439];
Curve[352.0869, 209.1325, 366.6143, 208.1149, 372.0, 208.9024];
Curve[374.2727, 209.2348, 386.2989, 214.7218, 380.8284, 204.0];
Curve[378.6221, 199.6753, 364.5704, 185.5353, 360.0, 184.8125];
Curve[351.8828, 183.5287, 332.7219, 196.0891, 329.1539, 192.0];
Curve[321.1773, 182.8585, 343.6019, 183.1676, 340.0227, 174.0];
Curve[335.0409, 161.2398, 311.5035, 158.2857, 310.4737, 126.0];
Curve[310.1649, 116.3195, 313.5754, 76.22575, 312.75, 72.0];
Curve[310.7936, 61.98325, 261.8854, 53.60412, 252.0, 52.62712];
Curve[238.5165, 51.29451, 155.6176, 53.91593, 152.55, 65.99998];
Curve[146.1258, 91.30679, 146.1964, 75.57425, 114.0, 83.08163];
Curve[101.5249, 85.9905, 85.49357, 98.83845, 93.0, 114.0];
Curve[96.9852, 122.0493, 101.4202, 118.0211, 96.0, 128.775];
Curve[92.91811, 134.8897, 92.05819, 140.964, 90.00001, 147.577];
Curve[85.48869, 162.0718, 88.40478, 162.2188, 86.83928, 168.0];
Curve[84.31547, 177.3202, 68.65387, 174.0181, 70.27779, 186.0];
Curve[71.84946, 197.5966, 93.93316, 251.462, 87.75, 258.0];
Curve[83.8855, 262.0863, 74.20536, 262.4716, 73.98215, 270.0];
Curve[73.80345, 276.027, 80.97349, 281.9097, 79.26, 288.0];
Curve[76.91487, 296.3353, 44.77308, 305.2533, 60.08572, 324.0];
Curve[64.14451, 328.969, 78.96831, 335.1704, 67.77274, 342.0];
Curve[60.79922, 346.254, -5.558746, 358.62, 30.00002, 372.3488];
Curve[45.19923, 378.2171, 84.23178, 361.5336, 114.0, 376.1087];
Curve[140.1327, 388.9037, 163.6664, 405.2124, 192.0, 413.3529];
};
RotMerc1: PROC [context: Context] = {
gray: Imager.Color ← Imager.MakeGray[0.5];
{action: PROC = {
context.TranslateT[4.25*72, 5.5*72];
context.ScaleT[0.333];
context.MaskFill[mercuryPath];
FOR i:NAT IN [0..9) DO
context.SetColor[gray];
context.RotateT[-10];
context.MaskFill[mercuryPath];
context.SetColor[Imager.black];
context.RotateT[-10];
context.MaskFill[mercuryPath];
ENDLOOP;
}; context.DoSave[action]};
};
RotMerc: PROC [context: Context] = {
gray: Imager.Color ← Imager.MakeGray[0.5];
context.TranslateT[4.25*72, 5.5*72];
context.ScaleT[0.333];
{action: PROC = {
context.SetColor[Imager.black];
context.MaskFill[mercuryPath];
FOR i: NAT ← 0, i+2 WHILE i<9 DO
context.SetColor[gray];
context.RotateT[-20];
context.MaskFill[mercuryPath];
context.SetColor[Imager.black];
context.RotateT[-20];
context.MaskFill[mercuryPath];
ENDLOOP;
}; context.DoSave[action]};
{action: PROC = {
FOR i: NAT IN [0..2) DO
context.ExcludeOutline[mercuryPath];
context.RotateT[-20];
ENDLOOP;
context.RotateT[-160];
FOR i: NAT ← 10, i+2 WHILE i<18 DO
context.SetColor[gray];
context.RotateT[-20];
context.MaskFill[mercuryPath];
context.SetColor[Imager.black];
context.RotateT[-20];
context.MaskFill[mercuryPath];
ENDLOOP;
}; context.DoSave[action]};
};
PageCorners: PROC [context: Context] = {
bounds: Imager.IntRectangle;
arrowHead: Imager.Trajectory;
theta: REAL;
Imager.Reset[context];
bounds ← Imager.GetViewBounds[context];
theta ← RealFns.ArcTanDeg[bounds.h, bounds.w];
arrowHead ← Imager.MoveTo[[0,0]].CurveTo[[0,.5],[0,.6],[.5,1]].LineTo[[0, .75]].LineTo[[-.5,1]].CurveTo[[0,.6],[0,.5],[0,0]];
{action: PROC = {
context.RotateT[theta-90];
context.ScaleT[80];
context.MaskFill[arrowHead];
}; context.DoSave[action]};
{action: PROC = {
context.TranslateT[bounds.w, 0];
context.RotateT[90-theta];
context.ScaleT[80];
context.MaskFill[arrowHead];
}; context.DoSave[action]};
{action: PROC = {
context.TranslateT[0, bounds.h];
context.RotateT[-90-theta];
context.ScaleT[80];
context.MaskFill[arrowHead];
}; context.DoSave[action]};
{action: PROC = {
context.TranslateT[bounds.w, bounds.h];
context.RotateT[90+theta];
context.ScaleT[80];
context.MaskFill[arrowHead];
}; context.DoSave[action]};
context.MaskStroke[Imager.MoveTo[[0, 0]].LineTo[[bounds.w, bounds.h]], 2, butt];
context.MaskStroke[Imager.MoveTo[[bounds.w, 0]].LineTo[[0, bounds.h]], 2, butt];
};
textSize: REAL ← 12.0;
Times: PROC [size: REAL] RETURNS [FONT] ~ {
RETURN [Font.CreateScaled["Xerox/PressFonts/TimesRoman/MRR", size, $Ideal]]
};
fontName: ROPE ← "Xerox/PressFonts/TimesRoman/MRR";
MaskTxt: PROC[context: Context, ropes: LIST OF REF] = {
row: INT ← 0;
font: FONT ← Font.CreateScaled[fontName, textSize, $Ideal];
{action: PROC = {
context.TranslateT[72, 720];
FOR list: LIST OF REF ← ropes, list.rest UNTIL list=NIL DO
row ← row + 1;
context.SetXY[[0, -row * textSize]];
context.ShowCharacters[list.first, font];
ENDLOOP;
}; context.DoSave[action]};
};
MaskText: PROC[context: Context, ropes: LIST OF REF] = {
curfont: FONT ← Font.CreateScaled["Xerox/PressFonts/TimesRoman/MRR", textSize, $Ideal];
altfont: FONT ← Font.CreateScaled["Xerox/PressFonts/Helvetica/MRR", textSize, $Ideal];
row: INT ← 0;
{action: PROC = {
context.TranslateT[72, 720];
FOR list: LIST OF REF ← ropes, list.rest UNTIL list=NIL DO
tempfont: FONT ~ curfont;
row ← row + 1;
context.SetXY[[0, -row * textSize]];
context.ShowCharacters[list.first, tempfont];
curfont ← altfont; altfont ← tempfont;
ENDLOOP;
}; context.DoSave[action]};
};
Text: PROC RETURNS [ropes: LIST OF REF] = {
new: LIST OF REFNIL;
txt: LIST OF ROPE ← text;
WHILE txt # NIL DO new ← CONS[txt.first, new]; txt ← txt.rest ENDLOOP;
WHILE new # NIL DO tt: LIST OF REF ← new; new ← new.rest; tt.rest ← ropes; ropes ← tt ENDLOOP;
};
text: LIST OF ROPELIST["In olden times when wishing still", "helped one, there lived a king", "whose daughters were all", "beautiful, but the youngest was", "so beautiful that the sun itself,", "which has seen so much, was", "astonished whenever it shone in", "her face. Close by the king's", "castle lay a great dark forest,", "and under an old lime-tree in", "the forest was a well, and when", "the day was very warm, the", "king's child went out into the", "forest and sat down by the side", "of the cool fountain, and when", "she was bored she took a golden", "ball, and threw it up on high", "and caught it, and this ball was", "her favorite plaything."];
NewViewer: PROC RETURNS [ViewerClasses.Viewer] ~ {
RETURN [ViewerOps.CreateViewer[flavor: $ImagerTesterViewer, info: [name: "Imager Tester"]]]
};
ContextOf: PROC [viewer: ViewerClasses.Viewer] RETURNS [Imager.Context] ~ {
ViewerOps.PaintViewer[viewer, client];
RETURN [NARROW[viewer.data]];
};
PaintProc: ViewerClasses.PaintProc
-- PROC [self: Viewer, context: Graphics.Context, whatChanged: REF ANY, clear: BOOL]
~ {
imagerContext: Imager.Context ← NARROW[self.data];
cy: REAL ← 808-GraphicsOps.UserToDevice[context,0,0].ty;
cx: REAL ← GraphicsOps.UserToDevice[context,0,0].tx;
IF imagerContext = NIL THEN {
self.data ← imagerContext ← Imager.Create[$LFDisplay];
imagerContext.ScaleT[3.527777e-4];
};
imagerContext.SetView[[Real.RoundLI[cx], Real.RoundLI[cy], self.cw, self.ch]];
};
viewerClass: ViewerClasses.ViewerClass ← NEW[ViewerClasses.ViewerClassRec ← [
paint: PaintProc
]];
ViewerOps.RegisterViewerClass[$ImagerTesterViewer, viewerClass];
END.