GGParseOutImpl.mesa
Last edited by Bier, February 10, 1987 1:40:19 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 26, 1987 3:22:53 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;
StrokeJoint: TYPE = Imager.StrokeJoint;
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.IntensityFromColor[cc];
f.PutF[" %g]", [real[1.0 - black]]];
}
ELSE {
r, g, b: REAL;
WriteBOOL[f, FALSE];
[r,g,b] ← ExtractRGB[cc];
f.PutF[" %g %g %g]", [real[r]], [real[g]], [real[b]]];
};
};
};
ExtractRGB: PROC [color: Imager.Color] RETURNS [r,g,b: REAL] = {
constant: ImagerColor.ConstantColor ← NARROW[color];
rgb: ImagerColor.RGB;
rgb ← ImagerColorPrivate.RGBFromColor[constant];
r ← rgb.R; g ← rgb.G; b ← rgb.B;
};
WriteStrokeEnd: PUBLIC PROC [f: IO.STREAM, strokeEnd: StrokeEnd] = {
rope: Rope.ROPE;
SELECT strokeEnd FROM
round => rope ← "round";
square => rope ← "square";
butt => rope ← "butt";
ENDCASE => ERROR;
f.PutRope[rope];
};
WriteStrokeJoint: PUBLIC PROC [f: IO.STREAM, strokeJoint: StrokeJoint] = {
rope: Rope.ROPE;
SELECT strokeJoint FROM
round => rope ← "round";
miter => rope ← "miter";
bevel => rope ← "bevel";
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.