TSTranslatePrivateImpl.mesa
Michael Plass, June 24, 1985 1:54:47 pm PDT
Last Edited by: Beach, April 3, 1984 6:05:34 pm PST
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];
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.
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.
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.
Michael Plass, November 15, 1983 1:58 pm. RealOps => Real (Cedar 5).
Plass, March 12, 1985 2:29:08 pm PST
JaM --> TJaM
changes to: DIRECTORY, TSTranslatePrivateImpl, ObjectToName (local of GetLastLineFormatting, local of InitializeStateForNewNode)