DIRECTORY Convert, TEditFormat, Interpress, Imager, ViewerOps, Commander, Rope, NodeStyle, RuntimeError, Scaled, TextEdit, Real, IO, NodeProps, FSRope, FunctionCache, ImagerMemory; ArtworkInterpressImpl: CEDAR PROGRAM IMPORTS Convert, TEditFormat, Interpress, Imager, ViewerOps, Commander, Rope, NodeStyle, RuntimeError, Scaled, TextEdit, Real, IO, NodeProps, FSRope, FunctionCache, ImagerMemory ~ BEGIN ROPE: TYPE ~ Rope.ROPE; GetBounds: PROC [prop: REF, nodeStyle: NodeStyle.Ref] RETURNS [box: Imager.Box _ [0,0,0,0]] ~ { rope: ROPE ~ WITH prop SELECT FROM r: ROPE => r, ENDCASE => NIL; size: INT ~ Rope.Size[rope]; IF size # 0 THEN { i: INT _ -1; Getc: PROC RETURNS [CHAR] ~ {i_i+1; RETURN [IF i r _ r*0.001; Match["cm"] => r _ r*0.01; Match["in"] => r _ r*0.0254; Match["pt"] => r _ r*0.0254/72.27; Match["bp"] => r _ r*0.0254/72; ENDCASE => ERROR; r _ r*pointsPerMeter; GetTok[]; SELECT TRUE FROM Match["xmin"] => box.xmin _ r; Match["xmax"] => box.xmax _ r; Match["ymin"] => box.ymin _ r; Match["ymax"] => box.ymax _ r; ENDCASE => ERROR; ENDLOOP; } ELSE { box.ymax _ NodeStyle.GetTopLeading[nodeStyle]; box.ymin _ -NodeStyle.GetBottomLeading[nodeStyle]; box.xmax _ NodeStyle.GetLineLength[nodeStyle]; }; }; Floor: PROC [r: REAL] RETURNS [i: INT] ~ { i _ Real.Round[r]; IF i > r THEN i _ i-1; }; Ceiling: PROC [r: REAL] RETURNS [i: INT] ~ { i _ Real.Round[r]; IF i < r THEN i _ i+1; }; Format: TEditFormat.FormatProc ~ { inner: PROC ~ { extraIndent: REAL _ nodeStyle.GetFirstIndent; leftIndent: REAL _ nodeStyle.GetLeftIndent + extraIndent; rightIndent: REAL _ nodeStyle.GetRightIndent; trimmedLineWidth: REAL _ lineWidth.Float-leftIndent-rightIndent; box: Imager.Box _ GetBounds[NodeProps.GetProp[n: node, name: $Bounds], nodeStyle]; lineInfo.xmin _ Floor[box.xmin]; lineInfo.ymin _ Floor[box.ymin]; lineInfo.xmax _ Ceiling[box.xmax]; lineInfo.ymax _ Ceiling[box.ymax]; SELECT nodeStyle.GetLineFormatting[] FROM FlushLeft => {lineInfo.xOffset _ Scaled.FromReal[leftIndent]}; FlushRight => {lineInfo.xOffset _ Scaled.FromReal[MAX[lineWidth.Float-leftIndent-box.xmax, 0]]}; Centered, Justified => {lineInfo.xOffset _ Scaled.FromReal[leftIndent+(trimmedLineWidth-box.xmax)/2]}; ENDCASE => ERROR; }; lineInfo.startPos _ [node, 0]; lineInfo.nextPos _ [node, TextEdit.Size[node]]; lineInfo.nChars _ TextEdit.Size[node]; inner[ ! RuntimeError.UNCAUGHT => {IF NOT debug THEN {ViewerOps.BlinkDisplay[]; CONTINUE}}]; }; Resolve: TEditFormat.ResolveProc ~ { loc _ lineInfo.startPos; xmin _ lineInfo.xmin+lineInfo.xOffset.integerPart; width _ lineInfo.xmax; rightOfLine _ FALSE; }; CharPosition: TEditFormat.CharPositionProc ~ { x _ lineInfo.xmin+lineInfo.xOffset.integerPart; width _ lineInfo.xmax; }; BoundingBox: TEditFormat.BoundingBoxProc ~ { RETURN [[lineInfo.xmin, lineInfo.ymin, lineInfo.xmax, lineInfo.ymax]] }; debug: BOOL _ FALSE; useFSRope: BOOL _ TRUE; pointsPerMeter: REAL _ 72/0.0254; memoryCache: FunctionCache.Cache _ FunctionCache.GlobalCache[]; Paint: TEditFormat.PaintProc ~ { box: Imager.Box _ BoundingBox[lineInfo, lineInfo.startPos.where, lineInfo.nChars]; ipRope: ROPE _ NARROW[NodeProps.GetProp[lineInfo.startPos.node, $Interpress]]; compare: FunctionCache.CompareProc ~ {good _ argument = ipRope}; memory: Imager.Context _ NARROW[FunctionCache.Lookup[memoryCache, compare, $ArtwIP].value]; IF memory = NIL THEN { proc: PROC ~ { ipMaster: Interpress.OpenMaster ~ Interpress.FromStream[ipStream, NIL, NIL]; Imager.Trans[memory]; Imager.ScaleT[memory, pointsPerMeter]; Interpress.DoPage[ipMaster, 1, memory]; }; ipStream: IO.STREAM _ IF useFSRope THEN FSRope.StreamFromRope[ipRope] ELSE IO.RIS[ipRope]; memory _ ImagerMemory.NewMemoryContext[]; Imager.DoSave[memory, proc ! RuntimeError.UNCAUGHT => {IF NOT debug THEN {ViewerOps.BlinkDisplay[]; CONTINUE}}]; FunctionCache.Insert[memoryCache, ipRope, memory, ImagerMemory.GetContextSize[memory], $ArtwIP]; }; ImagerMemory.Replay[c: memory, into: context]; }; class: TEditFormat.ArtworkClass ~ NEW[TEditFormat.ArtworkClassRep _ [ name: $Interpress, format: Format, paint: Paint, resolve: Resolve, charPosition: CharPosition, boundingBox: BoundingBox ]]; Command: Commander.CommandProc ~ { IF Rope.Match["*on*", cmd.commandLine, FALSE] THEN TEditFormat.RegisterArtwork[class] ELSE IF Rope.Match["*off*", cmd.commandLine, FALSE] THEN TEditFormat.UnRegisterArtwork[$Interpress] ELSE {cmd.out.PutRope["Please say on or off.\n"]; RETURN}; ViewerOps.PaintEverything[]; }; Commander.Register["ArtworkInterpress", Command, "Turn ArtworkInterpress on or off"]; END. ArtworkInterpressImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Michael Plass, September 25, 1985 11:25:51 am PDT Doug Wyatt, June 24, 1985 6:46:40 pm PDT Pier, October 9, 1985 2:39:15 pm PDT Invariant: c = (IF i˜>Kšœ2žœ+˜`Kšœf˜fKšžœžœ˜—Kšœ˜—Jšœ˜Jšœ/˜/Jšœ&˜&Jš œžœžœžœžœžœ˜\Jšœ˜J˜—š œ˜$Jšœ˜Jšœ2˜2Jšœ˜Jšœžœ˜Jšœ˜J˜—š  œ"˜.Jšœ/˜/Jšœ˜Jšœ˜J˜—š  œ!˜,Jšžœ?˜EJšœ˜J˜—Jšœžœžœ˜Jšœ žœžœ˜Jšœžœ ˜!–:[maxEntries: INT _ 10, maxTotalSize: INT _ 2147483647]šœ?˜?J˜—š œ˜ JšœR˜RJšœžœžœ9˜NJšœ@˜@Jšœžœ<˜[šžœ žœžœ˜šœžœ˜JšœBžœžœ˜LJšœ˜Jšœ&˜&Jšœ'˜'Jšœ˜—Jš œ žœžœžœ žœžœžœ ˜ZJšœ)˜)Jš œ*žœžœžœžœžœ˜pKšœ`˜`Kšœ˜—Jšœ.˜.Jšœ˜J˜—šœ"žœ ˜EJšœ˜J˜Jšœ ˜ Jšœ˜Jšœ˜Jšœ˜Jšœ˜J˜—š œ˜"Kšžœ%žœžœ#˜UKšžœžœ&žœžœ+˜cKšžœ.žœ˜:K˜Kšœ˜K˜—KšœU˜UJ˜—K˜Kšžœ˜—…—ϋ