TSTranslatePrivateImpl.mesa
Michael Plass, May 2, 1983 9:40 am
Last Edited by: Beach, May 24, 1983 9:14 am
DIRECTORY
LooksReader, NameSymbolTable, NodeStyle, RealOps, Rope, RopeReader, TextEdit, TextLooks, TextNode, TSTranslatePrivate, TSFont, TSGlue, TSObject, TSOps, TSTypes;
TSTranslatePrivateImpl:
PROGRAM
IMPORTS LooksReader, NameSymbolTable, NodeStyle, 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^;
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];
exceptionalskip ← RealDimn[nodeStyle.GetTopLeading[], pt];
curbaselineskip ← MaxDimn[curbaselineskip, exceptionalskip];
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[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;
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[]]]]
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.
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.