<> <> <> DIRECTORY Atom, LooksReader, NodeStyle, NodeStyleOps, Real, Rope, RopeReader, TextEdit, TextLooks, TextNode, TSTranslatePrivate, TSFont, TSGlue, TSObject, TSOps, TSTypes; TSTranslatePrivateImpl: PROGRAM IMPORTS Atom, LooksReader, NodeStyle, NodeStyleOps, Real, Rope, RopeReader, TextEdit, TSFont, TSObject, TSOps, TSTypes EXPORTS TSTranslatePrivate = BEGIN OPEN TSTypes, TSTranslatePrivate; NewState: PUBLIC PROCEDURE RETURNS [s:State] = BEGIN s _ NEW[StateRec]; s.nodeStyle _ NodeStyleOps.Create[]; s.charStyle _ NodeStyleOps.Create[]; s.ropeReader _ RopeReader.Create[]; s.looksReader _ LooksReader.Create[]; END; noUnderline: TSObject.Parameter _ NEW[TSObject.ParameterRec _ [underlineThickness, zeroDimn]]; noStrikeout: TSObject.Parameter _ NEW[TSObject.ParameterRec _ [strikeoutThickness, zeroDimn]]; fill: LIST OF REF ANY = LIST[noUnderline, noStrikeout, TSObject.fillGlue]; InitializeStateForNewNode: PUBLIC PROCEDURE [listWriter: TSObject.ListWriter, state: State] = { OPEN state^; leftFill, rightFill: LIST OF REF ANY; firstBaselineSpacing: Dimn; currentTextNode _ currentNode; rope _ TextEdit.GetRope[currentTextNode]; runs _ TextEdit.GetRuns[currentTextNode]; oldLooks _ TextLooks.allLooks; -- to force apply on first char remainingLength _ Rope.Size[rope]; tabStops _ 8.0; minTabWidth _ 1.0; bodyIndent _ zeroDimn; NodeStyleOps.ApplyAll[nodeStyle, currentNode, print]; RopeReader.SetPosition[ropeReader, rope, 0]; LooksReader.SetPosition[looksReader, runs, 0]; <> <> <> <> <> leftIndent _ Pt[nodeStyle.GetLeftIndent+nodeStyle.GetRestIndent]; galleyWidth _ Pt[nodeStyle.GetLineLength].SubDimn[Pt[nodeStyle.GetRightIndent]]; firstBaselineSpacing _ bottomLeading.MaxDimn[Pt[nodeStyle.GetTopLeading]]; bottomLeading _ Pt[nodeStyle.GetBottomLeading]; SELECT nodeStyle.GetLineFormatting FROM FlushLeft => { leftFill _ LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent]]; rightFill _ fill; endFill _ fill; }; FlushRight => { leftFill _ LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent, plus: TSGlue.fill]]; rightFill _ NIL; endFill _ NIL; }; Justified => { leftFill _ LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent]]; rightFill _ NIL; endFill _ fill; }; Centered => { leftFill _ LIST[noUnderline, noStrikeout, TSObject.MakeGlue[space: leftIndent, plus: TSGlue.fill]]; rightFill _ fill; endFill _ fill; }; ENDCASE; SELECT nodeStyle.GetLastLineFormatting FROM FlushLeft => endFill _ fill; FlushRight => endFill _ NIL; Justified => endFill _ NIL; Centered => endFill _ fill; ENDCASE; listWriter.ProduceParameter[minbaseline, Pt[nodeStyle.GetLeading]]; listWriter.ProduceParameter[mingaps, Pt[0]]; listWriter.ProduceItem[NEW[TSObject.ListParameterRec _ [ lineskip, LIST[ TSObject.MakeGlue[ Pt[0], Pt[nodeStyle.GetLeadingStretch], Pt[nodeStyle.GetLeadingShrink] ] ] ]]]; listWriter.ProduceItem[TSObject.MakeGlue[ space: firstBaselineSpacing.SubDimn[Pt[nodeStyle.GetLeading]], plus: Pt[nodeStyle.GetTopLeadingStretch], minus: Pt[nodeStyle.GetTopLeadingShrink] ]]; leftFillParameter _ IF leftFill = NIL THEN NIL ELSE NEW[TSObject.ListParameterRec _ [leftfill, leftFill]]; rightFillParameter _ IF rightFill = NIL THEN NIL ELSE NEW[TSObject.ListParameterRec _ [rightfill, rightFill]]; {firstIndent: Dimn _ Pt[nodeStyle.GetFirstIndent-nodeStyle.GetRestIndent]; firstIndentItem _ IF firstIndent = zeroDimn THEN NIL ELSE TSObject.MakeGlue[firstIndent]; }; }; FontFromStyle: PUBLIC PROCEDURE [style: NodeStyle.Ref] RETURNS [TSFont.Ref] = BEGIN face: NodeStyle.FontFace = style.GetFontFace; fontName: Rope.ROPE _ Atom.GetPName[style.GetFontFamily]; IF face = Bold OR face = BoldItalic THEN fontName _ Rope.Cat[fontName, "B"]; IF face = Italic OR face = BoldItalic THEN fontName _ Rope.Cat[fontName, "I"]; RETURN [TSFont.Lookup[Rope.Flatten[fontName], Pt[style.GetFontSize], Real.RoundI[style.GetReal[textRotation]]]] END; GetNewLooks: PUBLIC PROCEDURE [listWriter: TSObject.ListWriter, state: State, looks: TextLooks.Looks] = { OPEN state^; family: ATOM; NodeStyleOps.Copy[charStyle, nodeStyle]; NodeStyleOps.ApplyLooks[charStyle, looks, print]; IF currentNode.hascharprops THEN { ropeIndex: INT ~ ropeReader.GetIndex[]-1; charPostfix: REF ~ TextEdit.GetCharProp[currentNode, ropeIndex, $Postfix]; IF charPostfix#NIL THEN NodeStyleOps.ApplyObject[charStyle, charPostfix, print]; }; family _ charStyle.GetFontFamily; curfont _ FontFromStyle[charStyle]; tabStops _ charStyle.GetTabStops; IF tabStops=0 THEN tabStops _ 1; bodyIndent _ Pt[charStyle.GetRestIndent]; listWriter.ProduceParameter[shift, Pt[charStyle.GetVShift]]; listWriter.ProduceParameter[hue, [charStyle.GetReal[textHue]]]; listWriter.ProduceParameter[saturation, [charStyle.GetReal[textSaturation]]]; listWriter.ProduceParameter[brightness, [charStyle.GetReal[textBrightness]]]; underlining _ charStyle.GetUnderlining; strikeout _ charStyle.GetStrikeout; oldLooks _ looks }; ProduceBottomLeadingStretchAndShrink: PUBLIC PROCEDURE [ listWriter: TSObject.ListWriter, state: State ] = { listWriter.ProduceItem[TSObject.MakeGlue[ plus: Pt[state.nodeStyle.GetBottomLeadingStretch], minus: Pt[state.nodeStyle.GetBottomLeadingShrink] ]]; }; Tabify: PUBLIC PROCEDURE [ hlist: TSObject.ItemList, state: State ] RETURNS [newHList: TSObject.ItemList] = { OPEN state^; tempLineReader: TSObject.ListReader _ hlist.CreateReader[]; lineSoFar: TSObject.Box _ TSOps.Package[ tempLineReader, right, [zeroDimn,nilDimn,nilDimn,nilDimn]].box; distFromIndent: Dimn _ lineSoFar.extent[right].SubDimn[leftIndent]; widthSoFar: Dimn _ distFromIndent.AddDimn[ RealDimn[minTabWidth, [MAX[0.05, curfont.SpaceGlue[].space]]] ]; r: REAL _ widthSoFar.DimnRatio[Pt[MAX[tabStops, 0.1]]]; w: Dimn _ IntDimn[Real.RoundLI[r+0.5], Pt[MAX[tabStops, 0.1]]]; underThickness: Dimn _ tempLineReader.parameter[underlineThickness]; underBottom: Dimn _ tempLineReader.parameter[underlineBottom]; strikeThickness: Dimn _ tempLineReader.parameter[strikeoutThickness]; strikeBottom: Dimn _ tempLineReader.parameter[strikeoutBottom]; tempLineReader.DestroyReader[]; newHList _ TSObject.CreateItemList[producer: NIL]; newHList.listWriter.ProduceItem[lineSoFar]; newHList.listWriter.ProduceParameter[underlineThickness, underThickness]; newHList.listWriter.ProduceParameter[underlineBottom, underBottom]; newHList.listWriter.ProduceParameter[strikeoutThickness, strikeThickness]; newHList.listWriter.ProduceParameter[strikeoutBottom, strikeBottom]; newHList.listWriter.ProduceItem[TSObject.MakeGlue[space: w.SubDimn[distFromIndent]]]; IF leftFillParameter # NIL THEN newHList.listWriter.ProduceItem[leftFillParameter]; IF rightFillParameter # NIL THEN newHList.listWriter.ProduceItem[rightFillParameter]; oldLooks _ TextLooks.allLooks; }; END. <> <> <> <> <> <> <> < Real (Cedar 5).>> <> < TJaM>> <> <<>>