DIRECTORY TEditFormat, TextNode USING [Location], NodeStyle USING [Ref], NodeStyleOps USING [OfStyle], NodeProps USING [PutProp], Rope USING [ROPE, Cat, Find], Convert USING [RopeFromReal, RealFromRope, Error], Commander USING [Register, CommandProc], TextEdit USING [GetCharProp], Imager USING [DoSaveAll, Move, Context], MathBox, MathExpr USING [ExprFromRope, EXPR, parseError], MathConstructors, MathDisplayExpr USING [DisplayExpr, DisplayExprFromExpr, Format, Paint], Evaluator, AlgebraClasses, ViewExpr; MathToTioga: CEDAR PROGRAM IMPORTS TEditFormat, TextEdit, Imager, Rope, MathBox, MathConstructors, MathExpr, MathDisplayExpr, NodeProps, Convert, Commander, AlgebraClasses, Evaluator, ViewExpr ~ BEGIN ROPE: TYPE ~ Rope.ROPE; BOX: TYPE ~ MathBox.BOX; EXPR: TYPE ~ MathExpr.EXPR; DisplayExpr: TYPE ~ MathDisplayExpr.DisplayExpr; CharacterArtworkClass: TYPE ~ TEditFormat.CharacterArtworkClass; CharacterArtworkClassRep: TYPE ~ TEditFormat.CharacterArtworkClassRep; CharacterArtwork: TYPE ~ TEditFormat.CharacterArtwork; CharacterArtworkRep: TYPE ~ TEditFormat.CharacterArtworkRep; PaintInfo: TYPE ~ REF PaintInfoRep; PaintInfoRep: TYPE ~ RECORD [ expr: DisplayExpr _ NIL, box: BOX _ NIL ]; EvalFirst: BOOL _ FALSE; RegisterMathExprArtworkClass: PROC[] ~ { class: CharacterArtworkClass _ NEW[CharacterArtworkClassRep _ [name: $MeddleExpr, format: FormatMathExpr, data: NIL]]; TEditFormat.RegisterCharacterArtwork[class]; }; UnRegisterMathExprArtworkClass: PROC[] ~ { TEditFormat.UnregisterCharacterArtwork[$MeddleExpr]; }; FormatMathExpr: PROC[class: CharacterArtworkClass, loc: TextNode.Location, style: NodeStyle.Ref, styleOps: NodeStyleOps.OfStyle] RETURNS[CharacterArtwork] ~ { TeXToTioga: REAL ~ 20.0; -- default scaling factor from unit-sized TeX Fonts to Tioga mathExpr: EXPR _ NIL; object: AlgebraClasses.Object; displayExpr: DisplayExpr _ NIL; displayBox: BOX _ NIL; charArtwork: CharacterArtwork; postfixValue, leading, topLeading, bottomLeading: ROPE _ NIL; -- for postfix properties pointSize: REAL _ TeXToTioga; -- point size to use when rendering MEDDLE expr linearExpr: ROPE _ NARROW[TextEdit.GetCharProp[node: loc.node, index: loc.where, name: $MeddleExpr]]; exprPointSize: ROPE _ NARROW[TextEdit.GetCharProp[node: loc.node, index: loc.where, name: $MeddlePtSize]]; IF exprPointSize # NIL THEN pointSize _ Convert.RealFromRope[exprPointSize ! Convert.Error => CONTINUE]; mathExpr _ MathExpr.ExprFromRope[ViewExpr.StripHeader[linearExpr] ! MathExpr.parseError => {mathExpr _ MathConstructors.MakePlaceHolder[]; CONTINUE}]; IF EvalFirst THEN { object _ Evaluator.Eval[mathExpr]; mathExpr _ AlgebraClasses.ApplyLkpNoRecastExpr[$toExpr, object.class, LIST[object] ]; }; displayExpr _ MathDisplayExpr.DisplayExprFromExpr[mathExpr]; displayBox _ displayExpr.Format[normal]; displayBox _ MathBox.Scale[displayBox, [pointSize, pointSize]]; leading _ Convert.RopeFromReal[displayBox.Height[]]; topLeading _ Convert.RopeFromReal[displayBox.Extents[].ascent + 12.0]; bottomLeading _ Convert.RopeFromReal[displayBox.Extents[].descent + 12.0]; postfixValue _ Rope.Cat[leading, " pt the leading 2 .copy .gt 3 1 .roll .ifelse leading "]; postfixValue _ Rope.Cat[postfixValue, topLeading, " pt the topLeading 2 .copy .gt 3 1 .roll .ifelse topLeading "]; postfixValue _ Rope.Cat[postfixValue, topLeading, " pt the topIndent 2 .copy .gt 3 1 .roll .ifelse topIndent "]; postfixValue _ Rope.Cat[postfixValue, bottomLeading, " pt the bottomLeading 2 .copy .gt 3 1 .roll .ifelse bottomLeading "]; NodeProps.PutProp[loc.node, $Postfix, postfixValue]; charArtwork _ NEW[CharacterArtworkRep _ [paint: PaintMathExpr, extents: displayBox.Extents[], escapement: [displayBox.Width[], 0.0], data: NEW[PaintInfoRep _ [expr: displayExpr, box: displayBox]]]]; RETURN[charArtwork]; }; PaintMathExpr: PROC[charArtwork: CharacterArtwork, context: Imager.Context] ~ { paintInfo: PaintInfo _ NARROW[charArtwork.data]; absBox: BOX _ MathBox.ChangeOffset[paintInfo.box, [0.0, 0.0]]; DoPaint: PROC[] ~ { Imager.Move[context]; MathDisplayExpr.Paint[paintInfo.expr, context, absBox, NIL]; }; Imager.DoSaveAll[context, DoPaint]; }; DoIt: Commander.CommandProc ~ { IF Rope.Find[s1: cmd.commandLine, s2: "off", case: FALSE] # -1 THEN { UnRegisterMathExprArtworkClass[]; [] _ TEditFormat.SetArtworkEnabled[FALSE]; } ELSE { RegisterMathExprArtworkClass[]; [] _ TEditFormat.SetArtworkEnabled[TRUE]; }; }; SetEval: Commander.CommandProc ~ { IF Rope.Find[s1: cmd.commandLine, s2: "on", case: FALSE] # -1 THEN EvalFirst _ TRUE ELSE EvalFirst _ FALSE; }; Commander.Register[key: "MeddleArtwork", proc: DoIt, doc: "Turns MEDDLE Artwork Interpretation On/Off for Tioga"]; Commander.Register[key: "MathEval", proc: SetEval, doc: "Turns CaminoReal Math Evaluation On/Off for Tioga"]; END. ΪMathToTioga.mesa Copyright Σ 1987 by Xerox Corporation. All rights reserved. Carl Waldspurger, September 1, 1986 3:52:09 pm PDT Rick Beach, September 2, 1987 9:53:44 am PDT Abbreviations For Imported Types Private Type Defs (local to module) Control evaluation Procedures effects: Registers $MeddleExpr as a Tioga character artwork class. create the class register it effects: Unregisters $MeddleExpr as a Tioga character artwork class. effects: Formats math expression artwork represented by ROPE at loc. Returns character artwork for formatted expression. local declarations if the user specified a point size to use, get it and use it convert linear form of expression to internal form check for evaluation flag convert immutable expression to mutable display form format expression and get box dimensions scale box dimensions from TeX unit sizes to some reasonable size compute appropriate postfix point values to place on current node in order to set a maximum value, the following JaM code fragment does this mumble pt the leading 2 .copy .gt 3 1 .roll .ifelse leading put Postfix properties on node containing displayExpr to insure proper spacing create artwork char effects: Paints charArtwork onto context. retrieve painting information set offset to zero (context origin) local procedure to do painting within a DoSaveAll pretend that current x,y position in context is origin while actually painting effects: If command line contains "off" then unregisters $MeddleExpr Artwork. Otherwise registers $MeddleExpr Artwork. effects: Turn on evaluation before painting Tioga doc Start Code register command to turn $MeddleExpr artwork on and off register command to turn evaluation before painting on and off ΚH˜šœ™Icode™Kšœ2œ˜8—K˜Kšœ ™ Kšœ,˜,K˜—K˜šŸœœ˜*KšœE™EK˜Kšœ4˜4K˜K˜—K˜šŸœœmœ˜žKšœE™EK™=K™Kšœ™Kšœ œ Οc<˜VKšœ œœ˜Kšœ˜Kšœœ˜Kšœ œœ˜K˜Kšœ2œœ ˜XKšœ œ /˜NK™Kšœ œœL˜eK˜Kšœ<™K˜Kšœ1™1šŸœœ˜K˜Kšœ7œ˜™>Kšœm˜mK™K˜—šœ˜K˜——…—ΈΪ