DIRECTORY JaMBasic, JaMOps, LooksReader, NameSymbolTable, NodeStyle, NodeStyleExtra, RealOps, Rope, RopeReader, TextEdit, TextLooks, TextNode, TSTranslatePrivate, TSFont, TSGlue, TSObject, TSOps, TSTypes; TSTranslatePrivateImpl: PROGRAM IMPORTS JaMOps, LooksReader, NameSymbolTable, NodeStyle, NodeStyleExtra, RealOps, Rope, RopeReader, TextEdit, TextNode, TSFont, TSObject, TSOps, TSTypes EXPORTS TSTranslatePrivate = BEGIN OPEN TSTypes, TSTranslatePrivate; NewState: PUBLIC PROCEDURE RETURNS [s:State] = BEGIN s _ NEW[StateRec]; s.nodeStyle _ NodeStyle.Create[]; s.charStyle _ NodeStyle.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^; LastLineFormatting: TYPE = {Default, FlushLeft, FlushRight, Centered, Justified}; GetLastLineFormatting: PROCEDURE [] RETURNS [LastLineFormatting] = { ObjectToName: PROCEDURE [obj: JaMBasic.Object] RETURNS [name: NameSymbolTable.Name] = { WITH x:obj SELECT FROM name => RETURN [LOOPHOLE[x.id]]; string => { nameObj: name JaMBasic.Object _ JaMOps.StringToName[x]; RETURN[LOOPHOLE[nameObj.id]]; }; ENDCASE => ERROR; }; lastLineFormatting: NameSymbolTable.Name = NameSymbolTable.MakeName["lastLineFormatting"]; default: NameSymbolTable.Name = NameSymbolTable.MakeName["default"]; flushLeft: NameSymbolTable.Name = NameSymbolTable.MakeName["flushLeft"]; flushRight: NameSymbolTable.Name = NameSymbolTable.MakeName["flushRight"]; centered: NameSymbolTable.Name = NameSymbolTable.MakeName["centered"]; justified: NameSymbolTable.Name = NameSymbolTable.MakeName["justified"]; name: NameSymbolTable.Name _ ObjectToName[NodeStyleExtra.GetStyleParam[nodeStyle, lastLineFormatting, NodeStyle.GetStyleName[nodeStyle], print]]; RETURN[SELECT name FROM default => Default, flushLeft => FlushLeft, flushRight => FlushRight, centered => Centered, justified => Justified, ENDCASE => ERROR]; }; leftFill, rightFill: LIST OF REF ANY; firstBaselineSpacing: Dimn; currentTextNode _ TextNode.NarrowToTextNode[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; nodeStyle.ApplyAll[currentNode, print]; RopeReader.SetPosition[ropeReader, rope, 0]; LooksReader.SetPosition[looksReader, runs, 0]; leftIndent _ Pt[nodeStyle.GetLeftIndent[]+nodeStyle.GetBodyIndent[]]; 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[TSObject.MakeGlue[space: leftIndent]]; rightFill _ fill; endFill _ fill; }; FlushRight => { leftFill _ LIST[TSObject.MakeGlue[space: leftIndent, plus: TSGlue.fill]]; rightFill _ NIL; endFill _ NIL; }; Justified => { leftFill _ LIST[TSObject.MakeGlue[space: leftIndent]]; rightFill _ NIL; endFill _ fill; }; Centered => { leftFill _ LIST[TSObject.MakeGlue[space: leftIndent, plus: TSGlue.fill]]; rightFill _ fill; endFill _ fill; }; ENDCASE; SELECT GetLastLineFormatting[] FROM Default => NULL; 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 _ NameSymbolTable.RopeFromName[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[]], RealOps.RoundI[style.GetTextRotation[]]]] END; GetNewLooks: PUBLIC PROCEDURE [listWriter: TSObject.ListWriter, state: State, looks: TextLooks.Looks] = { OPEN state^; family: NodeStyle.Name; NodeStyle.Copy[charStyle, nodeStyle]; charStyle.ApplyLooks[looks, print]; family _ charStyle.GetFontFamily[]; curfont _ FontFromStyle[charStyle]; tabStops _ charStyle.GetTabStops[]; IF tabStops=0 THEN tabStops _ 1; bodyIndent _ Pt[charStyle.GetBodyIndent[]]; listWriter.ProduceParameter[shift, Pt[charStyle.GetVShift[]]]; listWriter.ProduceParameter[hue, [charStyle.GetTextHue[]]]; listWriter.ProduceParameter[saturation, [charStyle.GetTextSaturation[]]]; listWriter.ProduceParameter[brightness, [charStyle.GetTextBrightness[]]]; 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[RealDimn[tabStops,curfont.SpaceGlue[].space.MaxDimn[Pt[0.1]]]]; w: Dimn _ IntDimn[ RealOps.RoundLI[r,[round:rp]], RealDimn[tabStops, curfont.SpaceGlue[].space] ]; tempLineReader.DestroyReader[]; newHList _ TSObject.CreateItemList[producer: NIL]; newHList.listWriter.ProduceItem[lineSoFar]; 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. TSTranslatePrivateImpl.mesa Michael Plass, May 2, 1983 9:40 am Last Edited by: Beach, August 10, 1983 4:49 pm exceptionalskip _ RealDimn[nodeStyle.GetTopLeading[], pt]; curbaselineskip _ MaxDimn[curbaselineskip, exceptionalskip]; The following line exhibits a compiler bug: temporaries are reused when they should not be. leftIndent _ Pt[nodeStyle.GetLeftIndent[]+nodeStyle.GetRestIndent[]]; The following sop circumvents the problem. Michael Plass, June 28, 1982 9:00 am. Renamed from TPTranslatePrivateImpl. Michael Plass, July 15, 1982 11:03 am. Restored left & rightFillParameters after tabs. Michael Plass, September 7, 1982 1:39 pm. Replaced RealDimn[ ,pt] with Pt[ ]. Michael Plass, November 12, 1982 1:43 pm. Eliminated underline and strikeout on right fill glue. Michael Plass, November 16, 1982 9:56 am. GetLineLength. Michael Plass, February 15, 1983 1:14 pm. Eliminated divide checks due to zero width spaces. Michael Plass, May 2, 1983 9:40 am. Tried again to eliminate divide checks due to zero width spaces. ΚΈ– "cedar" style˜JšΟc™Jšœ™#J™.šΟk œ˜ J˜ΒJ˜—šœž˜Jšžœ‘˜˜Jšžœ˜—Jšžœžœ˜'J˜šΟnœžœž œžœ ˜.Jšž˜Jšœžœ ˜J˜!J˜!J˜#J˜%Jšžœ˜J˜—Jšœ"žœ9˜^Jšœ"žœ9˜^Jš œžœžœžœžœžœ.˜JJ˜šŸœžœž œ4˜_Jšžœ˜ Jšœžœ9˜QšŸœž œžœ˜DšŸ œž œžœ!˜Wšžœžœž˜Jšœžœžœ˜ šœ ˜ Jšœ7˜7Jšžœžœ˜Jšœ˜—Jšžœžœ˜—J˜—JšœZ˜ZJšœD˜DJšœH˜HJšœJ˜JJšœF˜FJšœH˜HJšœ‘˜‘šžœžœž˜Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšžœžœ˜—J˜—Jš œžœžœžœžœ˜%J˜J˜9J˜)J˜)Jšœ˜>J˜"J˜J˜J˜J˜'J˜,J˜.Jš:™:Jš<™J˜;J˜IJ˜IJšœ)˜)Jšœ%˜%J˜J˜J˜—šŸ$œžœž œ˜8J˜ J˜ J˜˜)J˜4J˜3J˜—J˜J˜—šŸœžœž œ˜J˜J˜ Jšœžœ"˜+Jšžœ˜ J˜;˜(J˜J˜J˜(—J˜C˜*Jšœžœ#˜=J˜—JšœžœW˜^˜J˜J˜-J˜—J˜Jšœ-žœ˜2J˜+J˜UJšžœžœžœ4˜SJšžœžœžœ5˜UJ˜J˜J˜—Jšžœ˜J˜J™KJ™XJ™OJ™bJšœ,Ÿ œ™:Jšœ^™^Jšœf™fJ˜—…—%β