<> <> DIRECTORY TEditFormatExtras, 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]; MathToTioga: CEDAR PROGRAM IMPORTS TEditFormatExtras, TextEdit, Imager, Rope, MathBox, MathConstructors, MathExpr, MathDisplayExpr, NodeProps, Convert, Commander ~ BEGIN <> <<>> ROPE: TYPE ~ Rope.ROPE; BOX: TYPE ~ MathBox.BOX; EXPR: TYPE ~ MathExpr.EXPR; DisplayExpr: TYPE ~ MathDisplayExpr.DisplayExpr; CharacterArtworkClass: TYPE ~ TEditFormatExtras.CharacterArtworkClass; CharacterArtworkClassRep: TYPE ~ TEditFormatExtras.CharacterArtworkClassRep; CharacterArtwork: TYPE ~ TEditFormatExtras.CharacterArtwork; CharacterArtworkRep: TYPE ~ TEditFormatExtras.CharacterArtworkRep; <> <<>> PaintInfo: TYPE ~ REF PaintInfoRep; PaintInfoRep: TYPE ~ RECORD [ expr: DisplayExpr _ NIL, box: BOX _ NIL ]; <> <<>> TeXToTioga: REAL ~ 20.0; -- default scaling factor from unit-sized TeX Fonts to Tioga RegisterMathExprArtworkClass: PROC[] ~ { <> <> class: CharacterArtworkClass _ NEW[CharacterArtworkClassRep _ [name: $MeddleExpr, format: FormatMathExpr, data: NIL]]; <> TEditFormatExtras.RegisterCharacterArtwork[class]; }; UnRegisterMathExprArtworkClass: PROC[] ~ { <> TEditFormatExtras.UnregisterCharacterArtwork[$MeddleExpr]; }; FormatMathExpr: PROC[class: CharacterArtworkClass, loc: TextNode.Location, style: NodeStyle.Ref, styleOps: NodeStyleOps.OfStyle] RETURNS[CharacterArtwork] ~ { <> << Returns character artwork for formatted expression.>> <<>> <> mathExpr: EXPR _ NIL; 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[linearExpr ! MathExpr.parseError => {mathExpr _ MathConstructors.MakePlaceHolder[]; CONTINUE}]; <> 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 leading ", topLeading, " pt topLeading "]; postfixValue _ Rope.Cat[postfixValue, topLeading, " pt topIndent "]; postfixValue _ Rope.Cat[postfixValue, bottomLeading, " pt 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 ~ { <> << Otherwise registers $MeddleExpr Artwork.>> <<>> IF Rope.Find[s1: cmd.commandLine, s2: "off", case: FALSE] # -1 THEN UnRegisterMathExprArtworkClass[] ELSE RegisterMathExprArtworkClass[]; }; <> Commander.Register[key: "MeddleArtwork", proc: DoIt, doc: "Turns MEDDLE Artwork Interpretation On/Off for Tioga"]; <<>> END.