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. ώGGParseOutImpl.mesa Last edited by Bier, January 28, 1987 8:41:11 pm PST Copyright c 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, January 30, 1987 11:26:28 am PST 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] ]" Κε˜codešœ™Kšœ4™4Kšœ Οmœ1™˜>Lšœ$˜$L˜—šžœ˜Lšœ žœ˜Lšœ žœ˜Lšœ4˜4Lšœ6˜6Lšœ5˜5Lšœ6˜6L˜—L˜—K˜K˜—š Ÿœžœžœžœžœ˜CKšœ žœ˜Kšžœ ž˜Kšœ˜Kšœ˜Kšœ˜Kšžœžœ˜K˜K˜K˜—š Ÿ œžœžœžœžœ˜8Lšœ4˜4K˜K˜—šŸœž œžœžœ5˜cLšœT˜TLšœS˜SL˜K˜—šŸœž œžœžœ5˜kš œžœžœžœžœžœžœ™JKšœ@™@—K™ILšœ_˜_Lšœ`˜`Lšœ^˜^L˜K˜—š Ÿœžœžœžœžœ˜7Kšžœ žœžœ˜4Kšžœžœžœ˜8Kšœ\˜\K˜K˜—š Ÿ œžœžœžœžœžœ˜5Lšžœžœžœ˜0L˜L˜—šŸ œžœžœžœžœ žœžœžœžœ˜BKšœ žœžœ˜šžœžœžœžœžœžœžœž˜>Kšœ žœžœžœ˜0Kšžœ˜—K˜K˜—š Ÿœžœžœžœžœ˜GK˜Kšžœžœ ˜5šžœžœžœž˜Kšœ ˜ Kšžœ˜—K˜K˜—K˜Kšžœ˜J˜—…— ύ