<> <> <> <> <> <<>> 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] = { <> <> <> 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]]]; }; 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.