GGParseOutImpl.mesa
Last edited by Bier, January 28, 1987 8:41:11 pm PST
Copyright © 1986 by Xerox Corporation. All rights reserved.
Contents: Routines which turn various Gargoyle data structures into Rope.ROPEs and write them onto a file stream.
Pier, February 16, 1987 6:26:58 pm PST
DIRECTORY
GGBasicTypes, GGParseOut, Imager, ImagerColor, ImagerColorPrivate, ImagerTransformation, IO, Rope;
GGParseOutImpl: CEDAR PROGRAM IMPORTS Imager, ImagerTransformation, ImagerColorPrivate, IO
EXPORTS GGParseOut = BEGIN
BoundBox: TYPE = GGBasicTypes.BoundBox;
Color: TYPE = Imager.Color;
Point: TYPE = GGBasicTypes.Point;
SequenceOfReal: TYPE = GGBasicTypes.SequenceOfReal;
StrokeEnd: TYPE = Imager.StrokeEnd;
WriteColor: PUBLIC PROC [f: IO.STREAM, color: Color] = {
IF color=NIL THEN f.PutRope["[]"]
ELSE {
cc: ImagerColor.ConstantColor ← NARROW[color];
f.PutChar['[];
IF cc = Imager.black THEN {
black: REAL;
WriteBOOL[f, TRUE];
black ← ImagerColorPrivate.ComponentFromColor[cc, $Intensity];
f.PutF[" %g]", [real[1.0 - black]]];
}
ELSE {
r, g, b: REAL;
WriteBOOL[f, FALSE];
r ← ImagerColorPrivate.ComponentFromColor[cc, $Red];
g ← ImagerColorPrivate.ComponentFromColor[cc, $Green];
b ← ImagerColorPrivate.ComponentFromColor[cc, $Blue];
f.PutF[" %g %g %g]", [real[r]], [real[g]], [real[b]]];
};
};
};
WriteStrokeEnd: PUBLIC PROC [f: IO.STREAM, lineEnds: StrokeEnd] = {
rope: Rope.ROPE;
SELECT lineEnds FROM
square => rope ← "square";
butt => rope ← "butt";
round => rope ← "round";
ENDCASE => ERROR;
f.PutRope[rope];
};
WritePoint: PUBLIC PROC [f: IO.STREAM, point: Point] = {
f.PutF["[%g,%g]", [real[point.x]], [real[point.y]]];
};
WriteTransformation: PUBLIC PROC [f: IO.STREAM, transform: ImagerTransformation.Transformation] = {
f.PutF["[%g %g %g ", [real[transform.a]], [real[transform.b]], [real[transform.c]]];
f.PutF["%g %g %g]", [real[transform.d]], [real[transform.e]], [real[transform.f]]];
};
WriteFactoredTransformation: PUBLIC PROC [f: IO.STREAM, transform: ImagerTransformation.Transformation] = {
FactoredTransformation: TYPE ~ RECORD[r1: REAL, s: VEC, r2: REAL, t: VEC];
Represents Cat[Rotate[r1], Scale2[s], Rotate[r2], Translate[t]].
Gargoyle file format "[r1: REAL s: [REAL REAL] r2: REAL t: [REAL REAL] ]"
factored: ImagerTransformation.FactoredTransformation ← ImagerTransformation.Factor[transform];
f.PutF["[r1: %g s: [%g %g] ", [real[factored.r1]], [real[factored.s.x]], [real[factored.s.y]] ];
f.PutF["r2: %g t: [%g %g]]", [real[factored.r2]], [real[factored.t.x]], [real[factored.t.y]]];
};
WriteFactoredTransformationVEC: PUBLIC PROC [f: IO.STREAM, transform: ImagerTransformation.Transformation] = {
FactoredTransformation: TYPE ~ RECORD[r1: REAL, s: VEC, r2: REAL, t: VEC];
Represents Cat[Rotate[r1], Scale2[s], Rotate[r2], Translate[t]].
Gargoyle file format "[r1: REAL s: [REAL REAL] r2: REAL t: [REAL REAL] ]"
Ignores translation component
factored: ImagerTransformation.FactoredTransformation ← ImagerTransformation.Factor[transform];
f.PutF["[r1: %g s: [%g %g] r2: %g]", [real[factored.r1]], [real[factored.s.x]], [real[factored.s.y]], [real[factored.r2]] ];
};
WriteBox: PUBLIC PROC [f: IO.STREAM, box: BoundBox] = {
IF box.null THEN { f.PutRope["[0 0 -1 0]"]; RETURN};
IF box.infinite THEN { f.PutRope["[0 0 0 -1]"]; RETURN};
f.PutF["[%g %g %g %g]", [real[box.loX]], [real[box.loY]], [real[box.hiX]], [real[box.hiY]]];
};
WriteBOOL: PUBLIC PROC [f: IO.STREAM, bool: BOOL] = {
IF bool THEN f.PutRope["T"] ELSE f.PutRope["F"];
};
WriteProps: PUBLIC PROC [f: IO.STREAM, props: LIST OF REF ANY] = {
f.PutChar[IO.SP];
FOR name: LIST OF REF ANY ← props, name.rest UNTIL name=NIL DO
f.PutRope[NARROW[name.first]]; f.PutChar[IO.SP];
ENDLOOP;
};
WriteArrayOfReal: PUBLIC PROC [f: IO.STREAM, reals: SequenceOfReal] = {
f.PutChar['[];
IF reals.len > 0 THEN f.PutF["%g", [real[reals[0]]]];
FOR i: NAT IN [1..reals.len) DO
f.PutF[" %g", [real[reals[i]]]];
ENDLOOP;
f.PutChar[']];
};
END.